Example usage for org.eclipse.jface.action MenuManager getId

List of usage examples for org.eclipse.jface.action MenuManager getId

Introduction

In this page you can find the example usage for org.eclipse.jface.action MenuManager getId.

Prototype

@Override
public String getId() 

Source Link

Document

Returns the menu id.

Usage

From source file:bilab.BilabActionBarAdvisor.java

License:Open Source License

/**
 * Adds a <code>GroupMarker</code> or <code>Separator</code> to a menu. The
 * test for whether a separator should be added is done by checking for the
 * existence of a preference matching the string useSeparator.MENUID.GROUPID
 * that is set to <code>true</code>.
 * //from  w  w w .  j  ava2 s.  c  o m
 * @param menu
 *            the menu to add to
 * @param string
 *            the group id for the added separator or group marker
 */
private void addSeparatorOrGroupMarker(final MenuManager menu, final String groupId) {
    final String prefId = "useSeparator." + menu.getId() + "." + groupId; //$NON-NLS-1$ //$NON-NLS-2$
    final boolean addExtraSeparators = BilabPlugin.getDefault().getPreferenceStore().getBoolean(prefId);
    if (addExtraSeparators) {
        menu.add(new Separator(groupId));
    } else {
        menu.add(new GroupMarker(groupId));
    }
}

From source file:com.aptana.ui.actions.DefaultNavigatorActionProvider.java

License:Open Source License

/**
 * The default behavior is to show the same content as clicking the dropdown arrow. Subclass could override.
 * /*from   w w w.j av  a  2  s. co m*/
 * @param parent
 *            the parent toolbar
 */
protected void run(ToolBar parent) {
    if (!isEnabled()) {
        return;
    }
    Point toolbarLocation = parent.getLocation();
    toolbarLocation = parent.getParent().toDisplay(toolbarLocation.x, toolbarLocation.y);
    Point toolbarSize = parent.getSize();
    MenuManager menuManager = new MenuManager(null, getMenuId());
    IMenuService menuService = (IMenuService) partSite.getService(IMenuService.class);
    menuService.populateContributionManager(menuManager, MenuUtil.menuUri(menuManager.getId()));
    fillMenu(menuManager);
    Menu menu = menuManager.createContextMenu(parent);
    menu.setLocation(toolbarLocation.x, toolbarLocation.y + toolbarSize.y + 2);
    menu.setVisible(true);
}

From source file:com.github.sdbg.debug.ui.internal.objectinspector.ObjectInspectorView.java

License:Open Source License

private void hookContextMenu() {
    // treeViewer context menu
    MenuManager treeMenuManager = new MenuManager("#PopupMenu");
    treeMenuManager.add(new Separator("additions1"));
    treeMenuManager.add(new Separator("additions2"));
    treeMenuManager.add(new Separator("additions3"));

    //treeMenuManager.setRemoveAllWhenShown(true);

    Menu menu = treeMenuManager.createContextMenu(treeViewer.getControl());
    treeViewer.getControl().setMenu(menu);
    getSite().registerContextMenu(treeMenuManager, treeViewer);

    // treeViewer context menu
    MenuManager textMenuManager = new MenuManager("#SourcePopupMenu", "#SourcePopupMenu");

    textMenuManager.setRemoveAllWhenShown(true);
    textMenuManager.addMenuListener(new IMenuListener() {
        @Override//from w ww . j a va 2 s.  c o m
        public void menuAboutToShow(IMenuManager manager) {
            ObjectInspectorView.this.fillContextMenu(manager);
        }
    });

    menu = textMenuManager.createContextMenu(sourceViewer.getControl());
    sourceViewer.getControl().setMenu(menu);
    getSite().registerContextMenu(textMenuManager.getId(), textMenuManager, sourceViewer);
}

From source file:com.google.code.t4eclipse.core.utility.MenuUtility.java

License:Open Source License

private static String getMenuItemActionID(MenuItem item) {
    Object data = item.getData();
    if (data == null || isSeparator(item)) {
        return "";
    }/*w  w  w .j a  v a2 s  . c o m*/

    if (data instanceof ActionContributionItem) {
        ActionContributionItem ci = (ActionContributionItem) data;
        IAction ac = ci.getAction();
        if (ac != null)
            return ac.getId() != null ? ac.getId() : "";
    }

    if (data instanceof MenuManager) {
        MenuManager mm = (MenuManager) data;
        return mm.getId() != null ? mm.getId() : "";
    }

    if (data instanceof ActionSetContributionItem) {
        ActionSetContributionItem ascItem = (ActionSetContributionItem) data;
        return ascItem.getActionSetId() != null ? ascItem.getActionSetId() : "";
    }

    if (data instanceof NewWizardMenu) {
        NewWizardMenu nwMenu = (NewWizardMenu) data;
        if (nwMenu.isSeparator()) {
            return "";
        }

        //get actions map using reflect
        ObjectResult result = ReflectionUtil.getField("actions", nwMenu);
        if (result.result == null) {
            return "";
        }

        Map actions = (Map) result.result;
        Iterator iterator = actions.values().iterator();
        NewWizardShortcutAction action = null;
        while (iterator.hasNext()) {
            action = (NewWizardShortcutAction) iterator.next();
            if (action.getText().equals(item.getText())) {
                return action.getWizardDescriptor().getId();
            }
        }
    }

    if (data instanceof HandledContributionItem) {
        HandledContributionItem hcItem = (HandledContributionItem) data;
        return hcItem.getId();
    }

    return "";
}

From source file:com.google.dart.tools.deploy.ApplicationActionBarAdvisor.java

License:Open Source License

/**
 * Adds a <code>GroupMarker</code> or <code>Separator</code> to a menu. The test for whether a
 * separator should be added is done by checking for the existence of a preference matching the
 * string useSeparator.MENUID.GROUPID that is set to <code>true</code>.
 * /*from  w  w w  .  j  a v a  2s.  c  o m*/
 * @param menu the menu to add to
 * @param groupId the group id for the added separator or group marker
 */
private void addSeparatorOrGroupMarker(MenuManager menu, String groupId) {
    String prefId = "useSeparator." + menu.getId() + "." + groupId; //$NON-NLS-1$ //$NON-NLS-2$
    boolean addExtraSeparators = IDEWorkbenchPlugin.getDefault().getPreferenceStore().getBoolean(prefId);
    if (addExtraSeparators) {
        menu.add(new Separator(groupId));
    } else {
        menu.add(new GroupMarker(groupId));
    }
}

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   www  . j  av  a 2s  . c  om*/
                }, 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:es.cv.gvcase.mdt.common.part.MOSKittMultiPageEditor.java

License:Open Source License

protected void setUndoContextForUndoAction() {
    // update undo/redo menu
    IWorkbenchPart workbenchpart = this;
    if (workbenchpart != null && workbenchpart.getSite() instanceof EditorSite) {
        IContributionItem[] items = ((org.eclipse.ui.internal.EditorMenuManager) ((org.eclipse.ui.internal.EditorSite) workbenchpart
                .getSite()).getActionBars().getMenuManager()).getParent().getItems();
        for (IContributionItem item : items) {
            if (item instanceof MenuManager) {
                MenuManager menuManager = ((MenuManager) item);
                if (menuManager.getId().equals("edit")) { //$NON-NLS-1$
                    for (IContributionItem menuItem : menuManager.getItems()) {
                        if (menuItem instanceof ActionContributionItem) {
                            ActionContributionItem actionItem = (ActionContributionItem) menuItem;
                            if (actionItem.getId().equals("undo")) { //$NON-NLS-1$
                                if (actionItem.getAction() instanceof LabelRetargetAction) {
                                    LabelRetargetAction labelAction = (LabelRetargetAction) actionItem
                                            .getAction();
                                    if (labelAction.getActionHandler() instanceof GlobalUndoAction) {
                                        GlobalUndoAction globalUndoAction = (GlobalUndoAction) labelAction
                                                .getActionHandler();
                                        IUndoContext undoContext = (IUndoContext) getAdapter(
                                                IUndoContext.class);
                                        globalUndoAction.setUndoContext(undoContext);
                                        IUndoableOperation operation = PlatformUI.getWorkbench()
                                                .getOperationSupport().getOperationHistory()
                                                .getUndoOperation(undoContext);
                                        if (operation != null) {
                                            String label = operation.getLabel();
                                            labelAction.setText(Messages.MOSKittMultiPageEditor_26 + label);
                                        }
                                    }//from w w  w. ja  v  a2 s  .c o m
                                    if (labelAction.getActionHandler() instanceof UndoActionHandler) {
                                        UndoActionHandler undoAction = (UndoActionHandler) labelAction
                                                .getActionHandler();
                                        IUndoContext undoContext = (IUndoContext) getAdapter(
                                                IUndoContext.class);
                                        undoAction.setContext(undoContext);
                                        IUndoableOperation operation = PlatformUI.getWorkbench()
                                                .getOperationSupport().getOperationHistory()
                                                .getUndoOperation(undoContext);
                                        if (operation != null) {
                                            String label = operation.getLabel();
                                            labelAction.setText(Messages.MOSKittMultiPageEditor_27 + label);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:es.cv.gvcase.mdt.common.part.MOSKittMultiPageEditor.java

License:Open Source License

protected void setUndoContextForRedoAction() {
    // update undo/redo menu
    IWorkbenchPart workbenchpart = this;
    if (workbenchpart != null && workbenchpart.getSite() instanceof EditorSite) {
        IContributionItem[] items = ((org.eclipse.ui.internal.EditorMenuManager) ((org.eclipse.ui.internal.EditorSite) workbenchpart
                .getSite()).getActionBars().getMenuManager()).getParent().getItems();
        for (IContributionItem item : items) {
            if (item instanceof MenuManager) {
                MenuManager menuManager = ((MenuManager) item);
                if (menuManager.getId().equals("edit")) { //$NON-NLS-1$
                    for (IContributionItem menuItem : menuManager.getItems()) {
                        if (menuItem instanceof ActionContributionItem) {
                            ActionContributionItem actionItem = (ActionContributionItem) menuItem;
                            if (actionItem.getId().equals("redo")) { //$NON-NLS-1$
                                if (actionItem.getAction() instanceof LabelRetargetAction) {
                                    LabelRetargetAction labelAction = (LabelRetargetAction) actionItem
                                            .getAction();
                                    if (labelAction.getActionHandler() instanceof GlobalRedoAction) {
                                        GlobalRedoAction globalRedoAction = (GlobalRedoAction) labelAction
                                                .getActionHandler();
                                        IUndoContext undoContext = (IUndoContext) getAdapter(
                                                IUndoContext.class);
                                        globalRedoAction.setUndoContext(undoContext);
                                        IUndoableOperation operation = PlatformUI.getWorkbench()
                                                .getOperationSupport().getOperationHistory()
                                                .getUndoOperation(undoContext);
                                        if (operation != null) {
                                            String label = operation.getLabel();
                                            labelAction.setText(Messages.MOSKittMultiPageEditor_30 + label);
                                        }
                                    }//from   w w w .ja v  a  2  s.c  o m
                                    if (labelAction.getActionHandler() instanceof RedoActionHandler) {
                                        RedoActionHandler redoAction = (RedoActionHandler) labelAction
                                                .getActionHandler();
                                        IUndoContext undoContext = (IUndoContext) getAdapter(
                                                IUndoContext.class);
                                        redoAction.setContext(undoContext);
                                        IUndoableOperation operation = PlatformUI.getWorkbench()
                                                .getOperationSupport().getOperationHistory()
                                                .getUndoOperation(undoContext);
                                        if (operation != null) {
                                            String label = operation.getLabel();
                                            labelAction.setText(Messages.MOSKittMultiPageEditor_31 + label);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:gda.rcp.ApplicationActionBarAdvisor.java

License:Open Source License

/**
 * Adds a <code>GroupMarker</code> or <code>Separator</code> to a menu. The test for whether a separator should be
 * added is done by checking for the existence of a preference matching the string useSeparator.MENUID.GROUPID that
 * is set to <code>true</code>.
 * /*w ww.  j a  v  a2 s .co  m*/
 * @param menu
 *            the menu to add to
 * @param groupId
 *            the group id for the added separator or group marker
 */
private void addSeparatorOrGroupMarker(MenuManager menu, String groupId) {
    String prefId = "useSeparator." + menu.getId() + "." + groupId; //$NON-NLS-1$ //$NON-NLS-2$
    boolean addExtraSeparators = GDAClientActivator.getDefault().getPreferenceStore().getBoolean(prefId);
    if (addExtraSeparators) {
        menu.add(new Separator(groupId));
    } else {
        menu.add(new GroupMarker(groupId));
    }
}

From source file:net.bioclipse.cdk.ui.sdfeditor.editor.MoleculesEditor.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {

    molTableViewer = new MoleculeTableViewer(parent, SWT.NONE);
    //        molTableViewer.setContentProvider( contentProvider =
    //                                        new MoleculeViewerContentProvider() );

    //molTableViewer.setInput( getEditorInput() );
    getIndexFromInput(getEditorInput());

    MenuManager menuMgr = new MenuManager("Molecuels table", "net.bioclipse.cdk.ui.sdfeditor.menu");
    menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
    getSite().registerContextMenu("net.bioclipse.cdk.ui.sdfeditor.menu", menuMgr, molTableViewer);
    Menu menu = menuMgr.createContextMenu(molTableViewer.getControl());
    molTableViewer.getControl().setMenu(menu);
    logger.debug("Menu id for SDFEditor " + menuMgr.getId());

    getSite().setSelectionProvider(molTableViewer);

}