Time for action – creating the view menu

The view menu is the dropdown shown with a triangular icon, and is currently created in the SampleView class in the createView method. This can be recreated in the fragment editor by adding a view menu to the part descriptor.

  1. Open the fragment.e4xmi file and navigate to the Sample View part descriptor. Under that, there is a Menus element and a dropdown choice box. Select View Menu from the list and click on the Add button to add a View Menu.
  2. In the newly created View Menu, there is a drop-down choice box. Choose Handled Menu Item and click on Add.
  3. Add the following to the Handled Menu Item:
    1. Label: Action 1
    2. Tooltip: Action 1 tooltip
    3. Icon URI: platform:/plugin/org.eclipse.ui/icons/full/obj16/info_tsk.png or use the Find … button as before
    4. Ensure that the Enabled checkbox is selected
    5. Click on the Find … button next to the Command field and choose the Action 1 command from the list
  4. The Handled Menu Item should look like this:
    Time for action – creating the view menu
  5. Comment out the createViewMenu from the SampleView class, and run the application. The view menu should still be shown with a single Action 1.
  6. To replicate the original view, click on the View Menu element and use the drop-down to select a Separator; then repeat the above steps to add Action 2 as an element. Now when the application is run, the view menu will be identical to the original implementation. It will look like:
    Time for action – creating the view menu

What just happened?

The view menu used to be created with the createViewMenu method. Instead of doing this programmatically, it can be created in the fragment, in a very similar way to the toolbar.

A tag ViewMenu is automatically added to the View Menu in the Supplementary tab, which allows the view to be shown. This takes the same effect as setting the tag manually from the code before.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.70.203