@Override protected String getContextMenuId(StructuredViewer viewer) { return ((CommonViewer)viewer).getNavigatorContentService().getViewerDescriptor().getPopupMenuId(); }
protected String getContextMenuId(StructuredViewer viewer) { return ((CommonViewer)viewer).getNavigatorContentService().getViewerDescriptor().getPopupMenuId(); }
/** * Prepares the menu for object contributions, if the option is set in the extension. The option * is controlled by the &lgt;popupMenu /> element's 'allowPlatformContributions' attribute. * Clients may choose to ignore this setting by supplying a value of <b>true</b> for the * <code>force</code> attribute. * * @param menu * The context menu of the IViewPart * @param aSelectionProvider * The selection provider that will supplement actions with a valid, current * selection. * @param force * A value of 'true' forces the menu to be registered for object/view contributions. * Otherwise, the option from the extension point will be respected. See * <b>org.eclipse.ui.navigator.viewer/viewer</b> for more information. */ public void prepareMenuForPlatformContributions(MenuManager menu, ISelectionProvider aSelectionProvider, boolean force) { Assert.isTrue(!disposed); if (commonViewerSite instanceof ICommonViewerWorkbenchSite) { /* * Hooks into the Eclipse framework for Object contributions, and View contributions. */ if (force || viewerDescriptor.allowsPlatformContributionsToContextMenu()) { ((ICommonViewerWorkbenchSite) commonViewerSite).registerContextMenu(contentService.getViewerDescriptor().getPopupMenuId(), menu, aSelectionProvider); } } }
/** * <p> * Initializes and registers the context menu. * </p> */ protected void initContextMenu() { MenuManager menuMgr = new MenuManager(contentService .getViewerDescriptor().getPopupMenuId()); menuMgr.setRemoveAllWhenShown(true); menuMgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { fillContextMenu(manager); } }); TreeViewer commonViewer = commonNavigator.getCommonViewer(); Menu menu = menuMgr.createContextMenu(commonViewer.getTree()); commonViewer.getTree().setMenu(menu); actionService.prepareMenuForPlatformContributions(menuMgr, commonViewer, false); }