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

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

Introduction

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

Prototype

@Override
    public void setVisible(boolean visible) 

Source Link

Usage

From source file:au.gov.ansto.bragg.emu.ui.internal.EmuWorkbenchLauncher.java

License:Open Source License

private void hideMenus(WorkbenchWindow window) {
    WorkbenchWindow workbenchWin = (WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    MenuManager menuManager = ((WorkbenchWindow) window).getMenuManager();
    IContributionItem[] items = menuManager.getItems();

    for (IContributionItem item : items) {
        item.setVisible(false);//from  w w w .j a  v a  2  s.c  o  m
    }
    menuManager.setVisible(false);
    menuManager.setRemoveAllWhenShown(true);

    IContributionItem[] menubarItems = ((WorkbenchWindow) window).getMenuBarManager().getItems();
    for (IContributionItem item : menubarItems) {
        item.setVisible(false);
    }
    ((WorkbenchWindow) window).getMenuBarManager().setVisible(false);
    ((WorkbenchWindow) window).getMenuBarManager().setRemoveAllWhenShown(true);
}

From source file:au.gov.ansto.bragg.quokka.ui.QuokkaWorkbenchLauncher.java

License:Open Source License

private void hideMenus(WorkbenchWindow window) {
    WorkbenchWindow workbenchWin = (WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    MenuManager menuManager = ((WorkbenchWindow) window).getMenuManager();
    IContributionItem[] items = menuManager.getItems();

    for (IContributionItem item : items) {
        item.setVisible(false);/*from   ww  w . java 2  s .c  o m*/
    }
    menuManager.setVisible(false);
    menuManager.setRemoveAllWhenShown(true);

    //           IHandlerService service = (IHandlerService) window.getService(IHandlerService.class);
    //           if (service != null)
    //            try {
    //               service.executeCommand("org.eclipse.ui.ToggleCoolbarAction",
    //                       null);
    //            } catch (Exception e) {
    //               // TODO Auto-generated catch block
    //               e.printStackTrace();
    //            } 

    IContributionItem[] menubarItems = ((WorkbenchWindow) window).getMenuBarManager().getItems();
    for (IContributionItem item : menubarItems) {
        item.setVisible(false);
    }
    ((WorkbenchWindow) window).getMenuBarManager().setVisible(false);
    ((WorkbenchWindow) window).getMenuBarManager().setRemoveAllWhenShown(true);

    IToolBarManager toolbarManager = ((WorkbenchWindow) window).getToolBarManager2();
    IContributionItem[] barItems = toolbarManager.getItems();
    for (IContributionItem item : barItems) {
        item.setVisible(false);
    }
    //       toolbarManager.removeAll();
    //       toolbarManager.update(true);

    IContributionItem[] coolbarItems = ((WorkbenchWindow) window).getCoolBarManager2().getItems();
    for (IContributionItem item : coolbarItems) {
        //          if (!item.getId().equals("org.eclipse.debug.ui.launch.toolbar") && !item.getId().equals("org.eclipse.debug.ui.launchActionSet")
        //                && !item.getId().equals("org.eclipse.debug.ui.launch.toolbar")){
        //             item.setVisible(false);
        //          }
        //          if (   false
        //                || item.getId().equals("group.file") 
        //                || item.getId().equals("org.eclipse.ui.workbench.file")
        //                || item.getId().equals("additions") 
        //                || item.getId().equals("org.eclipse.debug.ui.main.toolbar") 
        //                || item.getId().equals("org.eclipse.wst.xml.ui.design.DesignToolBar") 
        //                || item.getId().equals("org.eclipse.wst.xml.ui.perspective.NewFileToolBar")
        //                || item.getId().equals("org.eclipse.jdt.debug.ui.JavaSnippetToolbarActions")
        //                || item.getId().equals("org.eclipse.debug.ui.launchActionSet")
        //                || item.getId().equals("org.eclipse.dltk.tcl.ui.debug.consoleActionSet")
        //                || item.getId().equals("org.eclipse.search.searchActionSet")
        //                || item.getId().equals("group.nav")
        //                || item.getId().equals("org.eclipse.ui.workbench.navigate")
        //                || item.getId().equals("group.editor")
        //                || item.getId().equals("group.help")
        //                || item.getId().equals("org.eclipse.ui.workbench.help")
        //                || item.getId().equals("org.eclipse.mylyn.tasks.ui.trim.container")
        //                ) {
        item.setVisible(false);
        //          }
    }

    //       removeUnWantedPerspectives();
}

From source file:com.vectrace.MercurialEclipse.history.MercurialHistoryPage.java

License:Open Source License

private void contributeActions() {

    final Action updateAction = new Action(Messages.getString("MercurialHistoryPage.updateAction.name")) { //$NON-NLS-1$
        private MercurialRevision rev;

        @Override/* ww  w. ja  va2s .com*/
        public void run() {
            if (rev == null) {
                return;
            }
            try {
                HgRoot root = resource != null ? MercurialTeamProvider.getHgRoot(resource) : hgRoot;
                Assert.isNotNull(root);

                UpdateJob job = new UpdateJob(rev.getContentIdentifier(), true, root, false);

                if (!job.confirmDataLoss(getControl().getShell())) {
                    return;
                }

                JobChangeAdapter adap = new JobChangeAdapter() {
                    @Override
                    public void done(IJobChangeEvent event) {
                        refresh();
                    }
                };
                job.addJobChangeListener(adap);
                job.schedule();
            } catch (HgException e) {
                MercurialEclipsePlugin.logError(e);
            }
        }

        @Override
        public boolean isEnabled() {
            MercurialRevision[] revs = getSelectedRevisions();
            if (revs != null && revs.length == 1) {
                rev = revs[0];
                return true;
            }
            rev = null;
            return false;
        }
    };
    updateAction.setImageDescriptor(MercurialEclipsePlugin.getImageDescriptor("actions/update.gif")); //$NON-NLS-1$

    stripAction = new Action() {
        {
            setText("Strip...");
            setImageDescriptor(MercurialEclipsePlugin.getImageDescriptor("actions/revert.gif"));
        }

        @Override
        public void run() {
            final Shell shell = MercurialEclipsePlugin.getActiveShell();

            shell.getDisplay().asyncExec(new Runnable() {

                public void run() {
                    ChangeSet changeSet = null;

                    MercurialRevision[] revisions = getSelectedRevisions();
                    if (revisions == null || revisions.length != 1) {
                        return;
                    }
                    changeSet = revisions[0].getChangeSet();

                    StripHandler.openWizard(changeSet.getHgRoot(), shell, changeSet);
                }
            });
        }

        @Override
        public boolean isEnabled() {
            MercurialRevision[] revs = getSelectedRevisions();
            if (revs != null && revs.length == 1) {
                return true;
            }
            return false;
        }
    };

    backoutAction = new Action() {
        {
            setText("Backout...");
            setImageDescriptor(MercurialEclipsePlugin.getImageDescriptor("actions/revert.gif"));
        }

        @Override
        public void run() {
            final Shell shell = MercurialEclipsePlugin.getActiveShell();

            shell.getDisplay().asyncExec(new Runnable() {

                public void run() {
                    ChangeSet changeSet = null;

                    MercurialRevision[] revisions = getSelectedRevisions();
                    if (revisions == null || revisions.length != 1) {
                        return;
                    }
                    changeSet = revisions[0].getChangeSet();

                    BackoutWizard backoutWizard = new BackoutWizard(changeSet.getHgRoot(), changeSet);
                    WizardDialog dialog = new WizardDialog(shell, backoutWizard);
                    dialog.setBlockOnOpen(true);
                    int result = dialog.open();

                    if (result == Window.OK) {
                        new RefreshWorkspaceStatusJob(changeSet.getHgRoot(), RefreshRootJob.ALL).schedule();
                    }
                }
            });
        }

        @Override
        public boolean isEnabled() {
            MercurialRevision[] revs = getSelectedRevisions();
            if (revs != null && revs.length == 1) {
                return true;
            }
            return false;
        }
    };

    // Contribute actions to popup menu
    final MenuManager menuMgr = new MenuManager();
    final MenuManager bisectMenu = new MenuManager("Bisect");
    final MenuManager undoMenu = new MenuManager("Undo",
            MercurialEclipsePlugin.getImageDescriptor("undo_edit.gif"), null);

    undoMenu.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {
            undoMenu.add(backoutAction);
            undoMenu.add(stripAction);
        }
    });

    bisectMenu.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager menuMgr1) {
            bisectMenu.add(bisectMarkBadAction);
            bisectMenu.add(bisectMarkGoodAction);
            bisectMenu.add(bisectResetAction);
        }
    });

    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager menuMgr1) {
            // enablement
            updateAction.setEnabled(updateAction.isEnabled());
            bisectMarkBadAction.setEnabled(bisectMarkBadAction.isEnabled());
            bisectMarkGoodAction.setEnabled(bisectMarkGoodAction.isEnabled());
            bisectResetAction.setEnabled(bisectResetAction.isEnabled());
            exportAsBundleAction.setEnabled(true);
            mergeWithCurrentChangesetAction.setEnabled(true);
            stripAction.setEnabled(stripAction.isEnabled());
            backoutAction.setEnabled(backoutAction.isEnabled());
            undoMenu.setVisible(stripAction.isEnabled() || backoutAction.isEnabled());

            // layout
            if (resource instanceof IFile) {
                IStructuredSelection sel = updateActionEnablement();
                menuMgr1.add(openAction);
                menuMgr1.add(openEditorAction);
                menuMgr1.add(new Separator(IWorkbenchActionConstants.GROUP_FILE));
                if (sel.size() == 2) {
                    menuMgr1.add(compareTwo);
                } else {
                    menuMgr1.add(compareWithPrevAction);
                    menuMgr1.add(compareWithCurrAction);
                    menuMgr1.add(compareWithOtherAction);
                    menuMgr1.add(new Separator());
                    menuMgr1.add(revertAction);
                }
            }
            menuMgr1.add(mergeWithCurrentChangesetAction);
            menuMgr1.add(undoMenu);
            menuMgr1.add(new Separator());
            menuMgr1.add(updateAction);
            menuMgr1.add(bisectMenu);
            menuMgr1.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
            menuMgr1.add(exportAsBundleAction);
        }
    });

    bisectMenu.setRemoveAllWhenShown(true);
    undoMenu.setRemoveAllWhenShown(true);
    menuMgr.setRemoveAllWhenShown(true);
    viewer.getTable().setMenu(menuMgr.createContextMenu(viewer.getTable()));
    getSite().registerContextMenu(MercurialEclipsePlugin.ID + ".hgHistoryPage", menuMgr, viewer);
}

From source file:de.babe.eclipse.applications.quickREx.ApplicationActionBarAdvisor.java

License:Open Source License

protected void fillMenuBar(IMenuManager menuBar) {
    MenuManager fileMenu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE);
    menuBar.add(fileMenu);/* w  ww  . j a  va  2  s  . c o m*/
    fileMenu.add(newWizardAction);
    fileMenu.add(new Separator());
    fileMenu.add(exitAction);

    MenuManager qrViewMenu = new MenuManager("&Evaluating", "de.babe.eclipse.applications.quickREx.qrViewMenu");
    menuBar.add(qrViewMenu);
    qrViewMenu.add(useJDKREAction);
    qrViewMenu.add(useOROPerlREAction);
    qrViewMenu.add(useOROAwkREAction);
    qrViewMenu.add(useJRegexAction);
    qrViewMenu.add(useJakartaRegexpAction);
    qrViewMenu.add(new Separator());
    qrViewMenu.add(grepAction);
    qrViewMenu.add(new Separator());
    qrViewMenu.add(keepREAction);
    qrViewMenu.add(saveTestTextAction);
    qrViewMenu.add(loadTestTextAction);
    qrViewMenu.add(new Separator());
    qrViewMenu.add(organizeREsAction);
    qrViewMenu.add(organizeTestTextAction);

    MenuManager reLibViewMenu = new MenuManager("&Library",
            "de.babe.eclipse.applications.quickREx.reLibViewMenu");
    menuBar.add(reLibViewMenu);
    reLibViewMenu.add(showLibraryAction);
    reLibViewMenu.add(new Separator());
    reLibViewMenu.add(searchREAction);

    MenuManager helpMenu = new MenuManager("&Help", "de.babe.eclipse.applications.quickREx.helpMenu");
    menuBar.add(helpMenu);
    helpMenu.add(helpContentsAction);
    helpMenu.add(helpSearchAction);
    helpMenu.add(new Separator());
    helpMenu.add(aboutAction);
    helpMenu.add(new Separator());
    helpMenu.add(preferencesAction);

    // Real bad! This is to get rid of the search-menu which is added probably due to the
    // fact that the QR-Plugin uses the search-result-view... 
    MenuManager searchMenu = new MenuManager("", "org.eclipse.search.menu");
    menuBar.add(searchMenu);
    searchMenu.setVisible(false);
    searchMenu.setRemoveAllWhenShown(true);
}

From source file:edu.buffalo.cse.green.editor.DiagramEditor.java

License:Open Source License

/**
 * Creates the editor's context menu./*  w w w  .  j  a  v  a  2  s .  c o m*/
 */
private void buildMenu(IMenuManager menuManager) {
    Map<String, MenuManager> menus = new HashMap<String, MenuManager>();
    Map<MenuManager, List<ContextAction>> mActions = new HashMap<MenuManager, List<ContextAction>>();

    MenuManager inv = new MenuManager("inv");
    inv.setVisible(false);
    menus.put(Submenu.Invisible.toString(), inv);

    // get all actions that must be added to the menu
    List<ContextAction> actions = new ArrayList<ContextAction>();

    actions.addAll(PlugIn.getActions());

    // moved to PlugIn, after the xml plugins are initialized
    // so that accelerator keys work.
    /*for (Class partClass : PlugIn.getRelationships()) {
       ContextAction action =
    new AlterRelationshipVisibilityAction(partClass);
       actions.add(action);
       action =
    new IncrementalExploreSingleAction(partClass);
       actions.add(action);
    }*/

    // add the actions to their appropriate submenus
    List<ContextAction> lastItems = new ArrayList<ContextAction>();

    for (ContextAction action : actions) {
        // add in menu group if it doesn't exist
        MenuManager submenu = menus.get(action.getPath());

        // initialize the action
        action.calculateEnabled();
        action.setSelectionProvider(this);
        action.setText(action.getLabel());

        // if the submenu doesn't exist, create it
        if (submenu == null) {
            submenu = createMenuGroup(menus, action.getPath());

            // add it to the end if it's a menu item
            if (submenu == null) {
                lastItems.add(action);
                continue;
            }

            List<ContextAction> actionList = mActions.get(submenu);

            if (actionList == null) {
                actionList = new ArrayList<ContextAction>();
                mActions.put(submenu, actionList);
            }

            actionList.add(action);
        }
    }

    // sort the menu alphabetically
    while (mActions.keySet().size() > 0) {
        String firstAlpha = "zzz";
        MenuManager addMenu = null;

        for (MenuManager menu : mActions.keySet()) {
            if (menu.getMenuText().compareTo(firstAlpha) < 0) {
                firstAlpha = menu.getMenuText();
                addMenu = menu;
            }
        }

        _contextMenu.add(addMenu);
        List<ContextAction> actionList = mActions.get(addMenu);
        mActions.remove(addMenu);

        while (actionList.size() > 0) {
            firstAlpha = "zzz";
            ContextAction addAction = null;

            for (ContextAction cAction : actionList) {
                if (cAction.getLabel().compareTo(firstAlpha) < 0) {
                    firstAlpha = cAction.getLabel();
                    addAction = cAction;
                }
            }

            addMenu.add(addAction);
            actionList.remove(addAction);
        }
    }

    while (lastItems.size() > 0) {
        String firstAlpha = "zzz";
        ContextAction addAction = null;

        for (ContextAction cAction : lastItems) {
            if (cAction.getLabel().compareTo(firstAlpha) < 0) {
                firstAlpha = cAction.getLabel();
                addAction = cAction;
            }
        }

        _contextMenu.add(addAction);
        lastItems.remove(addAction);
    }

    // add quick fixes, if applicable
    IJavaElement element = getContext().getElement();

    if (element instanceof IMember) {
        MemberModel model = (MemberModel) getRootModel().getModelFromElement(element);
        model.appendQuickFixActionsToMenu(_contextMenu);
    }
}

From source file:edu.buffalo.cse.green.editor.model.MemberModel.java

License:Open Source License

/**
 * Appends quick fix actions for this element to the given menu.
 * /*from ww  w  .  ja va2 s  .  c om*/
 * @param menu - The target menu.
 */
public void appendQuickFixActionsToMenu(MenuManager menu) {
    List<QuickFix> fixes = getQuickFixes();

    if (fixes.size() > 0) {
        MenuManager qf = new MenuManager("Quick Fixes", DESC_OBJS_QUICK_FIX, null);
        qf.setVisible(true);
        menu.add(new Separator());
        menu.add(qf);

        for (QuickFix fix : fixes) {
            qf.add(new QuickFixAction(fix));
        }
    }
}

From source file:edu.harvard.i2b2.eclipse.ApplicationActionBarAdvisor.java

License:Open Source License

@Override
protected void fillMenuBar(IMenuManager menuBar) {
    // Creates the menu bar and binds actions 

    MenuManager fileMenu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE);
    menuBar.add(fileMenu);//w ww .  j  a va  2 s.  c o m
    fileMenu.add(preferencesAction);
    fileMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    fileMenu.add(exitAction);

    // editMenu imported from SQL explorer
    MenuManager editMenu = new MenuManager("&Edit", IWorkbenchActionConstants.M_EDIT);
    // create edit menu
    menuBar.add(editMenu);
    editMenu.setVisible(false);

    // navigateMenu imported from SQL explorer
    MenuManager navigateMenu = new MenuManager("&Navigate", IWorkbenchActionConstants.M_NAVIGATE);
    // navigate menu is used by text editor        
    menuBar.add(navigateMenu);
    navigateMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    navigateMenu.setVisible(false);

    MenuManager perspectivesMenu = new MenuManager("Open Perspectives", "perspectives");
    perspectivesMenu.add(perspectives);

    MenuManager viewsMenu = new MenuManager("Show View", "views");
    viewsMenu.add(views);

    MenuManager windowMenu = new MenuManager("&Window", "window");
    windowMenu.add(perspectivesMenu);
    windowMenu.add(viewsMenu);
    windowMenu.add(propertiesAction);
    menuBar.add(windowMenu);

    MenuManager helpMenu = new MenuManager("&Help", "help");
    helpMenu.add(helpAction);
    helpMenu.add(aboutAction);
    helpMenu.add(introAction);
    helpMenu.add(new UpdateAction(this.getActionBarConfigurer().getWindowConfigurer().getWindow()));
    helpMenu.add(new SearchAndUpdateAction(this.getActionBarConfigurer().getWindowConfigurer().getWindow()));
    //helpMenu.add(new ProductConfigurationAction(this.getActionBarConfigurer().getWindowConfigurer().getWindow()));
    //helpMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
    menuBar.add(helpMenu);
}

From source file:hydrograph.ui.dataviewer.window.DebugDataViewer.java

License:Apache License

/**
 * Create the menu manager./*  ww w  . j  ava2  s .  co m*/
 * 
 * @return the menu manager
 */
@Override
protected MenuManager createMenuManager() {
    MenuManager menuManager = new MenuManager(MenuConstants.MENU);
    menuManager.setVisible(true);

    createFileMenu(menuManager);
    createEditMenu(menuManager);
    createViewMenu(menuManager);
    createDataMenu(menuManager);
    createWindowMenu(menuManager);

    return menuManager;
}

From source file:hydrograph.ui.dataviewer.window.DebugDataViewer.java

License:Apache License

private MenuManager createMenu(MenuManager menuManager, String menuName) {
    MenuManager menu = new MenuManager(menuName);
    menuManager.add(menu);//from  ww  w  .ja  v a  2s  .  co  m
    menuManager.setVisible(true);
    return menu;
}

From source file:hydrograph.ui.dataviewer.window.DebugDataViewer.java

License:Apache License

private void createFileMenu(MenuManager menuManager) {
    MenuManager fileMenu = createMenu(menuManager, MenuConstants.FILE);
    menuManager.add(fileMenu);/*from w w w.  ja va2 s .com*/
    fileMenu.setVisible(true);

    if (actionFactory == null) {
        actionFactory = new ActionFactory(this);
    }

    fileMenu.add(actionFactory.getAction(ExportAction.class.getName()));
}