A pop-up menu is very similar to creating a toolbar or view menu; however, there are a few extra steps required to hook it up to the viewer and to ensure that the right pop-up menu is connected to the right part. As with the view menu, a tag is required; but instead of being a generic hard-coded value, the pop-up tag requires a tight binding with the pop-up menu.
Create a method called
createPopupMenu
in theSampleView
class. It will need to take an SWTControl
parameter, which will be the one that is used to trigger the menu.Ensure that the
createPopupMenu
is called from the end of thecreatePartControl
method, passing in thecontrol
from theviewer
as the argument:createPopupMenu(viewer.getControl());
First, create a pop-up menu with a
MMenuFactory.INSTANCE.createPopupMenu()
call. Assign it to a local variablemenu
, so that it can be referred to throughout the method.Set the
elementId
of themenu
to be that of thepart
, usingmenu.setElementId(part.getElementId...