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

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

Introduction

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

Prototype

@Deprecated
public Menu createMenuBar(Shell parent) 

Source Link

Document

Creates and returns an SWT menu bar control for this menu, for use in the given Shell, and installs all registered contributions.

Usage

From source file:net.yatomiya.e4.ui.workbench.renderers.swt.MenuManagerRenderer.java

License:Open Source License

@Override
public Object createWidget(MUIElement element, Object parent) {
    if (!(element instanceof MMenu))
        return null;

    final MMenu menuModel = (MMenu) element;
    Menu newMenu = null;//from   w w w. ja  v  a  2  s . co  m
    MenuManager menuManager = null;
    boolean menuBar = false;

    if (parent instanceof Decorations) {
        MUIElement container = (MUIElement) ((EObject) element).eContainer();
        if (container instanceof MWindow) {
            menuManager = getManager(menuModel);
            if (menuManager == null) {
                menuManager = new MenuManager(NO_LABEL, menuModel.getElementId());
                linkModelToManager(menuModel, menuManager);
            }
            newMenu = menuManager.createMenuBar((Decorations) parent);
            ((Decorations) parent).setMenuBar(newMenu);
            newMenu.setData(menuManager);
            menuBar = true;
        } else {
            menuManager = getManager(menuModel);
            if (menuManager == null) {
                menuManager = new MenuManager(NO_LABEL, menuModel.getElementId());
                linkModelToManager(menuModel, menuManager);
            }
            newMenu = menuManager.createContextMenu((Control) parent);
            // we can't be sure this is the correct parent.
            // ((Control) parent).setMenu(newMenu);
            newMenu.setData(menuManager);
        }
    } else if (parent instanceof Menu) {
        // Object data = ((Menu) parent).getData();
        logger.debug(new Exception(), "Trying to render a sub menu " //$NON-NLS-1$
                + menuModel + "\n\t" + parent); //$NON-NLS-1$
        return null;

    } else if (parent instanceof Control) {
        menuManager = getManager(menuModel);
        if (menuManager == null) {
            menuManager = new MenuManager(NO_LABEL, menuModel.getElementId());
            linkModelToManager(menuModel, menuManager);
        }
        newMenu = menuManager.createContextMenu((Control) parent);
        // we can't be sure this is the correct parent.
        // ((Control) parent).setMenu(newMenu);
        if (element instanceof MPopupMenu && element.isVisible()) {
            Object data = getUIContainer(element);
            if (data instanceof Control && parent.equals(data)) {
                ((Control) parent).setMenu(newMenu);
            }
        }
        newMenu.setData(menuManager);
    }
    if (menuManager != null && !menuManager.getRemoveAllWhenShown()) {
        processContributions(menuModel, menuModel.getElementId(), menuBar, menuModel instanceof MPopupMenu);
    }
    if (newMenu != null) {
        newMenu.addDisposeListener(new DisposeListener() {
            @Override
            public void widgetDisposed(DisposeEvent e) {
                cleanUp(menuModel);
                MenuManager manager = getManager(menuModel);
                if (manager != null) {
                    manager.markDirty();
                }
            }
        });
    }
    return newMenu;
}

From source file:org.csstudio.sds.ui.internal.runmode.ShellRunModeBox.java

License:Open Source License

/**
 * Creates a toolbar for the graphical viewer.
 *
 * @param shell/*  w ww . j  a  v a2  s .c om*/
 *            the shell
 * @param graphicalViewer
 *            the graphical viewer
 */
@SuppressWarnings("deprecation")
protected void createToolbar(final Shell shell, final GraphicalViewer graphicalViewer) {
    // menu bar
    MenuManager menuManager = new MenuManager();

    // configure zoom actions
    RootEditPart rootEditPart = graphicalViewer.getRootEditPart();

    if (rootEditPart instanceof ScalableFreeformRootEditPart) {
        final ZoomManager zm = ((ScalableFreeformRootEditPart) rootEditPart).getZoomManager();

        final List<String> zoomLevels = new ArrayList<String>(3);
        zoomLevels.add(ZoomManager.FIT_ALL);
        zoomLevels.add(ZoomManager.FIT_WIDTH);
        zoomLevels.add(ZoomManager.FIT_HEIGHT);
        zm.setZoomLevelContributions(zoomLevels);

        if (zm != null) {
            MenuManager zoomManager = new MenuManager("Zoom");
            final IAction zoomIn = new ZoomInAction(zm);
            final IAction zoomOut = new ZoomOutAction(zm);

            zoomManager.add(zoomIn);
            zoomManager.add(zoomOut);

            menuManager.add(zoomManager);
        }

        MenuManager layerManager = new MenuManager("Layers");
        layerManager.add(new ChangeLayerVisibilityAction(graphicalViewer));
        menuManager.add(layerManager);
    }

    // Added by Markus Moeller, 2009-01-26
    // Search for the screenshot plugin
    IExtensionRegistry extReg = Platform.getExtensionRegistry();
    IConfigurationElement[] confElements = extReg
            .getConfigurationElementsFor("org.csstudio.utility.screenshot.ImageWorker");

    if (confElements.length > 0) {
        for (int i = 0; i < confElements.length; i++) {
            if (confElements[i].getContributor().getName()
                    .compareToIgnoreCase("org.csstudio.utility.screenshot") == 0) {
                MenuManager captureManager = new MenuManager("Screenshot");

                captureManager.add(new OpenScreenshotAction());
                menuManager.add(captureManager);
            }
        }
    }

    Menu menu = menuManager.createMenuBar(shell);
    shell.setMenuBar(menu);
}

From source file:org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer.java

License:Open Source License

@Override
public Object createWidget(MUIElement element, Object parent) {
    if (!(element instanceof MMenu))
        return null;

    final MMenu menuModel = (MMenu) element;
    Menu newMenu = null;//from   ww  w.  j  a v a 2 s. c  o  m
    MenuManager menuManager = null;
    boolean menuBar = false;

    if (parent instanceof Decorations) {
        MUIElement container = (MUIElement) ((EObject) element).eContainer();
        if (container instanceof MWindow) {
            menuManager = getManager(menuModel);
            if (menuManager == null) {
                menuManager = new MenuManager(NO_LABEL, menuModel.getElementId());
                linkModelToManager(menuModel, menuManager);
            }
            newMenu = menuManager.createMenuBar((Decorations) parent);
            ((Decorations) parent).setMenuBar(newMenu);
            newMenu.setData(menuManager);
            menuBar = true;
        } else {
            menuManager = getManager(menuModel);
            if (menuManager == null) {
                menuManager = new MenuManager(NO_LABEL, menuModel.getElementId());
                linkModelToManager(menuModel, menuManager);
            }
            newMenu = menuManager.createContextMenu((Control) parent);
            // we can't be sure this is the correct parent.
            // ((Control) parent).setMenu(newMenu);
            newMenu.setData(menuManager);
        }
    } else if (parent instanceof Menu) {
        // Object data = ((Menu) parent).getData();
        logger.debug(new Exception(), "Trying to render a sub menu " //$NON-NLS-1$
                + menuModel + "\n\t" + parent); //$NON-NLS-1$
        return null;

    } else if (parent instanceof Control) {
        menuManager = getManager(menuModel);
        if (menuManager == null) {
            menuManager = new MenuManager(NO_LABEL, menuModel.getElementId());
            linkModelToManager(menuModel, menuManager);
        }
        newMenu = menuManager.createContextMenu((Control) parent);
        // we can't be sure this is the correct parent.
        // ((Control) parent).setMenu(newMenu);
        newMenu.setData(menuManager);
    }
    if (!menuManager.getRemoveAllWhenShown()) {
        processContributions(menuModel, menuBar, menuModel instanceof MPopupMenu);
    }
    if (newMenu != null) {
        newMenu.addDisposeListener(new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
                cleanUp(menuModel);
            }
        });
    }
    return newMenu;
}

From source file:org.eclipse.e4.ui.workbench.renderers.swt.RenderedMenuRenderer.java

License:Open Source License

public Object createWidget(final MUIElement element, Object parent) {
    if (!(element instanceof MRenderedMenu))
        return null;

    MRenderedMenu menuModel = (MRenderedMenu) element;
    Object contributionManager = menuModel.getContributionManager();
    if (contributionManager instanceof MenuManager) {
        Menu newMenu = null;//from w  ww.ja v  a2  s  .co  m
        MenuManager mm = (MenuManager) contributionManager;
        MUIElement container = (MUIElement) ((EObject) menuModel).eContainer();
        if (parent instanceof Decorations && container instanceof MWindow) {
            newMenu = mm.createMenuBar((Decorations) parent);
        } else if (parent instanceof Menu) {
            mm.update(true);
            newMenu = mm.getMenu();
        } else {
            newMenu = mm.createContextMenu((Control) parent);
        }
        mm.update(true);
        return newMenu;
    } else if (contributionManager instanceof IMenuCreator) {
        final IMenuCreator creator = (IMenuCreator) contributionManager;
        if (parent instanceof Control) {
            Control control = (Control) parent;
            return creator.getMenu(control);
        } else if (parent instanceof Menu) {
            int addIndex = calcVisibleIndex(menuModel);
            MenuItem newItem = new MenuItem((Menu) parent, SWT.CASCADE, addIndex);
            setItemText(menuModel, newItem);
            newItem.setImage(getImage(menuModel));
            newItem.setEnabled(menuModel.isEnabled());
            Menu menu = (Menu) parent;
            newItem.setMenu(creator.getMenu(menu));
            return newItem;
        }
    }

    return null;
}

From source file:org.eclipse.ui.tests.menus.MenuBaseTests.java

License:Open Source License

public void testBasicMenuPopulation() throws Exception {
    MenuManager manager = new MenuManager("Test Menu", TEST_CONTRIBUTIONS_CACHE_ID);
    menuService.populateContributionManager(manager, "menu:" + TEST_CONTRIBUTIONS_CACHE_ID);

    Shell shell = window.getShell();/*  w ww . ja va 2 s  . c  o m*/

    // Test the initial menu creation
    manager.createMenuBar((Decorations) shell);
    MenuItem[] menuItems = manager.getMenu().getItems();

    // NOTE: Uncomment to print the info needed to update the 'expected'
    // arrays
    //      printIds(items);
    //      printClasses(items);
    //      printMenuItemLabels(menuItems);

    // Correct number of items?
    assertEquals("createMenuBar: Bad count", expectedMenuItemLabels.length, menuItems.length);

    int diffIndex = checkMenuItemLabels(menuItems, expectedMenuItemLabels);
    assertTrue("createMenuBar: Index mismatch at index " + diffIndex, diffIndex == ALL_OK);

    // Test the update mechanism

    // KLUDGE!! Test commented out until bug 170353 is fixed...
    //      manager.update(true);
    //      menuItems = manager.getMenu().getItems();
    //      
    //      // Correct number of items?
    //      assertTrue("manager.update(true): Bad count", menuItems.length == expectedMenuItemLabels.length);
    //
    //      diffIndex = checkMenuItemLabels(menuItems, expectedMenuItemLabels);
    //      assertTrue("manager.update(true): Index mismatch at index " + diffIndex , diffIndex == ALL_OK);

    menuService.releaseContributions(manager);
    manager.dispose();
}

From source file:pt.iscte.dcti.visual_tracer.view.PrincipalView.java

License:Open Source License

private void defineMenus() {
    // menu manager
    MenuManager menuManager = new MenuManager();

    // Menu Files 
    MenuManager fileMenuManager = new MenuManager("&File");

    //Menu Help/*  w ww  . ja  va 2  s .co m*/
    MenuManager helpMenuManager = new MenuManager("&Help");

    // adding menus
    menuManager.add(fileMenuManager);
    menuManager.add(helpMenuManager);

    fileMenuManager.add(new Separator());
    fileMenuManager.add(_actionExit);

    helpMenuManager.add(_actionHelpContent);
    helpMenuManager.add(_actionDeveloperHelpContent);
    helpMenuManager.add(_actionAbout);
    helpMenuManager.add(_actionViewGPL);

    menuManager.updateAll(true);
    getShell().setMenuBar(menuManager.createMenuBar((Decorations) getShell()));
}