Pop-up and view menus are defined declaratively in the Application.e4xmi
file. These are specific to a part, so the option is defined underneath the part declaration.
Application.e4xmi
file.Hello
helloCommand - com.packtpub.e4.application.command.hello
com.packtpub.e4.application.popupmenu.hello
:org.eclipse.e4.ui.workbench.swt
dependency to the dependencies tab of the plugin.xml
editor.Hello
class' create()
method, that registers the context menu with the ID specified. To do this, a new parameter EMenuService menu
needs to be passed, from which registerContextMenu()
can be called:public void create(Composite parent, EMenuService menu) { menu.registerContextMenu(parent, "com.packtpub.e4.application.popupmenu.hello");
The pop-up menu can be associated with a part, but it doesn't get shown by default. Instead, it has to be registered with a SWT widget. The pop-up menu can be for the entire part's component, or it can be just for specific components in the part.
The EMenuService
is the interface to the E4 menus. It gets injected into the creation of the widget and provides the detector to listen to the mouse and keyboard events that trigger the pop-up menu.
Adding a View Menu is exactly the same as a Popup Menu, except that no additional code is required to make it happen.