It's useful to be able to add contributions to pop-up menus so that they can be used by different places. Fortunately, this can be done fairly easily with the menuContribution
element and a combination of enablement tests. This allows the removal of the Action
introduced in the first part of this chapter with a more generic command and handler pairing.
There is a deprecated extension point—which still works in Eclipse 4.2 today—called objectContribution
, which is a single specialized hook for contributing a pop-up menu to an object. This has been deprecated for some time, but often older tutorials or examples may refer to it.
Open the
TimeZoneTableView
class and add thehookContextMenu()
method as follows:private void hookContextMenu(Viewer viewer) { MenuManager manager = new MenuManager("#PopupMenu"); Menu menu = manager.createContextMenu(viewer.getControl()); viewer.getControl().setMenu(menu); getSite().registerContextMenu...