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.com.packtpub.e4.application.popupmenu.hello
, which will be used in code later.Hello
helloCommand - com.packtpub.e4.application.command.hello
View Menu
and right-click to choose Add child | Handled Menu Item. Use the same label and command as for the pop-up menu.Hello
class's 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. Since this returns a boolean
value indicating success, log an error if the registration does not work:public void create(Composite parent, EMenuService menu) { if (!menu.registerContextMenu(parent, "com.packtpub.e4.application.popupmenu.hello")) { logService.log(LogService.LOG_ERROR, "Failed to register pop-up menu"); } ...
Hello
part. The pop-up menu should be shown, and the Hello
command can be run.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 popup 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 popup menu.
Adding a View Menu is exactly the same as a Popup Menu, except that no additional code is required to make it happen.
3.137.221.163