Plugging In Popup Menu Actions

The org.eclipse.ui.popupMenus extension point from the base Eclipse Platform is used to contribute popup menus.

The primary element in the markup for this extension point is the <objectContribution> element, which scopes the remote objects to which the child elements apply:

Within each <objectContribution> element are zero or more <menu> elements for optionally defining cascading submenus, and <action> elements for the actual actions. To have the actions show up in a cascading menu, use the <menu> element with these attributes:

Within each <menu> element are one or more <separator> elements that partition the cascading menu into groups. Groups are simply named physical areas of the menu. The order in which they are defined is the order they appear in the menu. Actions always go into groups. Groups avoid the need to specify relative information to identify where within a pop-up menu to place actions. There is only one attribute for this element:

Finally, within <objectContribution> elements are one or more <action> elements identifying the actual actions, each of which only show up if the scoping criteria is met for that parent <objectContribution> element. The attributes for <action> elements are:

The path attribute for the <menu> element, and the menubarPath attribute for the <action> element, are the most difficult to master. The rules are reasonably simple though:

  1. To have your action show up in the initial pop-up menu, just specify a group name on the menubarPath attribute. That name can be one of the RSE-supplied group names defined in Table 4, or your own group name, which will be created and appended to the end of the pop-up menu. The default group is "additions".
    Example: menubarPath="myGroup"
  2. To have your action show up in a simple RSE-supplied cascading menu within the pop-up menu, in your <action> element, specify the RSE-supplied menu ID from Table 4 in the menubarPath attribute, then a slash followed by the name of a group. The only RSE-supplied group for cascading menus is "additions". If you specify anything else for the group, the group will be created for you at the bottom of the menu.
    Example: menubarPath="menu.new/myGroup"
  3. To have your action show up in a simple cascading menu of your own, first define the menu with a <menu> element, giving it an ID via the id attribute. In your <action> element, in the menubarPath attribute specify that id followed by a slash and then the name of a group. That group name can be one specified on a <separator> element within your menu, or a new name, which results in a new group at the bottom of the menu. In the latter case, there will be no separators delimiting the group, while in the former case there will be.
    Example: menubarPath="myMenu1/myGroup"
  4. To have your action show up in a multi-cascading menu of your own, define each of the menu via <menu> elements. For all but the first, identify the parent menu using the path attribute, specifying the Ids for each of the parent menus, slash-separated. At the end of the path attribute, specify the group within the final parent menu into which this menu will be placed. Again, this will either be a group defined with a <separator> element in the parent menu element, or specify a non-existing group that will be created for you. Once your multi-cascading menu is created, you identify it in your <action> element via the menubarPath attribute, specifying all the menu Ids up to the final menu, slash-separated, and then the group within that final menu, as usual.
    Example: menubarPath="myMenu1/myMenu2/myGroup"

Programming Details

To use this extension point you will create a class that extends the SystemAbstractPopupMenuExtensionAction class in the package org.eclipse.rse.ui.actions. This is your action class, and when the user selects your action, the run() method in your action class will be called. You will rarely extend the SystemAbstractPopupMenuExtensionAction base class directly, though. Instead there are subclasses of it that offer additional functionality for specific types of remote objects, as shown here:

Base Class Description
SystemAbstractPopupMenuExtensionAction in org.eclipse.rse.ui plugin Base class offering generic support for any remote object pop-up menu action, for any system type.
SystemAbstractRemoteFilePopupMenuExtensionAction in org.eclipse.rse.files.ui plugin Specialized base class offering specific support for any remote file object pop-up menu action, for any system type.


See the pop-up menu action tutorial for a step-by-step example.

See the Eclipse Platform Programmer's Guide for more background information.