The pop-up menu can be created in an almost identical way to the view menu. As before, it needs to be registered with the menu service but the code can be dramatically simplified by representing it in the fragment.e4xmi
file.
fragment.e4xmi
file, and go to the Menus element beneath the Sample View part descriptor. Add a child Popup Menu to the Menus element, either with the context-sensitive menu and by choosing Add child | Popup Menu, or by selecting Popup Menu from the dropdown and clicking on the Add button.com.packtpub.e4.migration.views.SampleView.popup
.Action 1
similar to before by setting these:Action 1
Action 1 tooltip
platform:/plugin/org.eclipse.ui/icons/full/obj16/info_tsk.png
or use the Find … button as beforeAction 2
command.createPopupMenu
call from the createPartControl
method with a call to register the pop-up menu with the viewer's control:// createPopupMenu(viewer.getControl()); menuService.registerContextMenu( viewer.getControl(), part.getElementId() + ".popup");
The pop-up menu is created in the same way as the view menu, but with a different top-level type. Creating a pop-up menu is easier in the model fragment, since there are fewer steps in hooking it up. However, it is still necessary to ensure that the SWT control is registered with the listeners to show the pop-up menu.
Unlike Eclipse 3.x menus, which are typically bound by the instance, Eclipse 4.x menus are tied by the identifiers stored in the element's ID. The identifier used in the registerContextMenu
must be the same as the ID of the pop-up menu in the fragment. This can either be a well-known hard-coded string, or it can be dynamically created from the part's ID. In this case, the part's ID was appended with .popup
to disambiguate it from the part itself.
Currently the hookDoubleClick
action instantiates and runs the handler directly. This can be changed to look up the command dynamically and then execute that instead.
To look up a command, inject an instance of ICommandService
and then use getCommand
with the ID of the command (com.packtpub.e4.migration.command.double
in this case). It can be invoked with command.executeWithChecks(new ExecutionEvent())
.
Selection is not transferred between Eclipse 3.x and Eclipse 4.x services. To ensure that the ISelection
is injected appropriately, inject the ESelectionService
into the part. Either the selection can be set just prior to the command being executed, or a selection listener can be added to the viewer that forwards the selection on to the Eclipse 4.x selection service:
@Inject ESelectionService selectionService; viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { selectionService.setSelection(event.getSelection()); } });
Q1. What is the Eclipse 4.x replacement for Action
instances?
Q2. How is a selection obtained from a DoubleClickEvent
?
Q3. What tag needs to be added to allow a view menu to be shown?
Q4. How are classes connected to a handler?
Q5. What is the difference between a platform:
URI and a bundleclass:
URI?
Q6. What is the difference between a part and a part descriptor?
Q7. How is a pop-up menu connected to the viewer?
Q8. How can a selection be forwarded from an Eclipse 3.x view to an Eclipse 4.x part?
18.117.189.7