In Eclipse, how do I contribute a context/pop-up menu to a control in a dialog?

eclipse-plugin, eclipse-rcp, jface

Solution

Use `IMenuService` of workbench window:

IMenuService mSvc = (IMenuService) window.getService(IMenuService.class);
MenuManager mgr = new MenuManager();
mSvc.populateContributionManager(mgr, "popup:my.dialog.menu");
control.setMenu(mgr.createContextMenu(control));

Problem

Normally, in an Editor, one can contribute a context menu (declared in a org.eclipse.ui.menus extension) with something like the following. ``` MenuManager menuManager = new MenuManager(); Control menuParent = ... ;//some Control in the editor Menu contextMenu = menuManager.createContextMenu(menuParent); menuParent.setMenu(contextMenu); getEditorSite().registerContextMenu(CONTEXT_MENU_ID, menuManager, getMySelectionProvider(), false); ``` I would like to do similar but in a Dialog. Apparently, my Googling skills are lacking today because I can't seem to find anything but one person asking the same thing on DZone without success. Is it even possible to contribute a menu via an extension point to a control in a Dialog?

Original source