List of usage examples for org.eclipse.jface.action MenuManager replaceItem
public boolean replaceItem(final String identifier, final IContributionItem replacementItem)
From source file:com.nokia.tools.carbide.ui.productsupport.perspectivehack.CarbideMenuCustomizer.java
License:Open Source License
@Override protected void customizeMenu(MenuManager mgr) { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (MENU_WINDOW.equals(mgr.getId())) { // Preference -filter replaceAction(mgr, MENU_WINDOW_PREFERENCES, new Runnable() { public void run() { PreferenceDialog prefdlg = PreferencesUtil.createPreferenceDialogOn( Display.getCurrent().getActiveShell(), GENERAL_PREFERENCES_ID, new String[] { GENERAL_PREFERENCES_ID, EXTERNALTOOLS_PREFERENCES_ID, THIRDPARTYICONS_PREFERENCES_ID, PLUGINHANDLING_PREFERENCES_ID, COMPONENTSTORE_PREFERENCES_ID, PATHHANDLING_PREFERENCES_ID, STARTUPTIPS_PREFERENCES_ID, EXAMPLETHEMES_PREFERENCES_ID /* * UPDATE_INSTALL_PREFERENCES_ID, * AUTOMATIC_UPDATES_PREFERENCES_ID *///from ww w. ja v a 2 s . co m }, null); PreferenceManager pManager = prefdlg.getPreferenceManager(); pManager.remove(PREFERENCES_ANT); pManager.remove(PREFERENCES_JAVA); pManager.remove(PREFERENCES_RUN_DEBUG); pManager.remove(PREFERENCES_TEAM); prefdlg.open(); } }); // // Remove Other -command under Show View in Window-menu // for (IContributionItem item2 : mgr.getItems()) { // if (SHOW_VIEW_ID.equals(item2.getId())) { // if (item2 instanceof MenuManager) { // MenuManager mgr2 = (MenuManager) item2; // mgr2.getMenu().addMenuListener( // new MenuAdapter() { // // /* // * (non-Javadoc) // * // * @see // org.eclipse.swt.events.MenuAdapter#menuShown(org.eclipse.swt.events.MenuEvent) // */ // @Override // public void menuShown(MenuEvent e) { // Menu menu = ((Menu) e.widget); // // removes show other and // // separator // MenuItem[] items = menu // .getItems(); // if (items.length > 2) { // items[items.length - 1] // .dispose(); // items[items.length - 2] // .dispose(); // } // } // // }); // } // } // } } else if (MENU_FILE.equals(mgr.getId())) { removePropertiesMenuItem(mgr); // Import replacement IContributionItem contrib = mgr.find(MENU_FILE_IMPORT); if (contrib instanceof ActionContributionItem) { mgr.replaceItem(MENU_FILE_IMPORT, new ActionContributionItem(new ImportAction(window))); } // Export replacement contrib = mgr.find(MENU_FILE_EXPORT); if (contrib instanceof ActionContributionItem) { mgr.replaceItem(MENU_FILE_EXPORT, new ActionContributionItem(new ExportAction(window))); } } else if (MENU_HELP.equals(mgr.getId())) { replaceAction(mgr, MENU_HELP_ABOUT, new Runnable() { public void run() { new CarbideAboutDialog(Display.getCurrent().getActiveShell()).open(); } }); } }
From source file:net.sf.groovyMonkey.actions.RecreateMonkeyMenuAction.java
License:Open Source License
private void createTheMenu(final List<Association> menuData, final IAction action) { final MenuManager outerManager = ((WorkbenchWindow) window).getMenuManager(); if (outerManager == null) return;/* www . j ava2 s . c o m*/ final String menuName = getDefault().getPreferenceStore().getString(MONKEY_MENU_NAME); final IMenuManager menuManager = new MenuManager(menuName, MENU_PATH); outerManager.replaceItem(MENU_PATH, menuManager); final MonkeyMenuStruct current = new MonkeyMenuStruct(); current.key = ""; current.menu = menuManager; current.submenu = new MonkeyMenuStruct(); final SortedSet<Association> sorted = new TreeSet<Association>(); sorted.addAll(menuData); for (final Association association : sorted) addNestedMenuAction(current, association.key, association.file); final IWorkbenchWindow _window = window; if (sorted.size() != 0) menuManager.add(new Separator()); menuManager.add(new Action("Create New Script") { @Override public void run() { final IWorkbenchWindowActionDelegate delegate = new NewGroovyMonkeyScriptAction(); delegate.init(_window); delegate.run(action); } }); menuManager.add(new Action("Paste New Script") { @Override public void run() { final IWorkbenchWindowActionDelegate delegate = new PasteScriptFromClipboardAction(); delegate.init(_window); delegate.run(action); } }); menuManager.add(new Action("Pull scripts from URL") { @Override public void run() { final IWorkbenchWindowActionDelegate delegate = new PasteScriptsFromURL(); delegate.init(_window); delegate.run(action); } }); if (sorted.size() == 0) menuManager.add(new Action("Examples") { @Override public void run() { final IWorkbenchWindowActionDelegate delegate = new CreateGroovyMonkeyExamplesAction(); delegate.init(_window); delegate.run(action); } }); final IMenuManager editMenu = menuManager.findMenuUsingPath(MENU_EDIT_PATH) != null ? menuManager.findMenuUsingPath(MENU_EDIT_PATH) : new MenuManager("Edit Script", MENU_EDIT_PATH); menuManager.add(editMenu); current.key = ""; current.menu = editMenu; current.submenu = new MonkeyMenuStruct(); for (final Association association : sorted) addNestedMenuEditAction(current, association.key, association.file); outerManager.updateAll(true); }