Example usage for org.eclipse.jface.window ApplicationWindow getMenuBarManager

List of usage examples for org.eclipse.jface.window ApplicationWindow getMenuBarManager

Introduction

In this page you can find the example usage for org.eclipse.jface.window ApplicationWindow getMenuBarManager.

Prototype

public MenuManager getMenuBarManager() 

Source Link

Document

Returns the menu bar manager for this window (if it has one).

Usage

From source file:org.apache.commons.jelly.tags.jface.MenuManagerTag.java

License:Apache License

public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {

    Map attributes = getAttributes();
    text = attributes.remove("text").toString();

    if (text == null)
        throw new MissingAttributeException("text attribute is missing");

    mm = new MenuManager(text);

    ApplicationWindow window = (ApplicationWindow) getParentWindow();
    if (window != null) {
        window.getMenuBarManager().add(mm);
    }//from w ww.  jav  a2  s . c  o m

    // invoke by body just in case some nested tag configures me
    invokeBody(output);
}

From source file:org.eclipse.e4.xwt.vex.VEXEditor.java

License:Open Source License

protected boolean handleInputChanged(IDocument newInput) {
    VEXCodeSynchronizer codeSynchronizer = getCodeSynchronizer();
    if (codeSynchronizer != null) {
        boolean handling = codeSynchronizer.handleInputChanged(newInput);
        if (!handling) {
            return false;
        }//from   w  w w .  ja  va2  s .  c  o m
    }

    // View synchronize
    try {
        ApplicationWindow applicationWindow = (ApplicationWindow) getSite().getPage().getWorkbenchWindow();
        MenuManager menuManager = applicationWindow.getMenuBarManager();
        if (menuManager != null) {
            menuManager.updateAll(true);
        }

        String value = newInput.get();
        IFile file = (IFile) getEditorInput().getAdapter(IFile.class);

        if (container.getDisplay() != null) {
            container.setCursor(container.getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
            while (!container.getDisplay().readAndDispatch()) {
            }
            if (render != null && render.updateView(value, file)) {
                if (loadingMessage != null && !loadingMessage.isDisposed()) {
                    loadingMessage.dispose();
                    loadingMessage = null;
                }
                return true;
            }
            if (loadingMessage != null && !loadingMessage.isDisposed()) {
                loadingMessage.stop();
                loadingMessage.setText("No window found or an error occurs."); //$NON-NLS-1$
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        container.setCursor(null);
        if (render != null) {
            getFileChecker().doCheck(render.getHostClassName());
        }
    }
    return false;
}

From source file:org.eclipse.pde.internal.ui.tests.macro.MacroUtil.java

License:Open Source License

private static CommandTarget locateMenuBarItem(Shell shell, IPath path, Iterator parents, int line)
        throws CoreException {
    MenuItem item = null;/*  w  w  w.j  a va2 s.  co m*/
    Object data = shell.getData();
    Menu menuBar = shell.getMenuBar();

    if (data instanceof ApplicationWindow && parents != null) {
        ApplicationWindow window = (ApplicationWindow) data;
        MenuManager manager = window.getMenuBarManager();
        item = locateMenuItem(manager, path.toString(), parents, line);
    } else {
        item = locateMenuItem(menuBar, path.toString(), line);
    }
    if (item != null)
        return new CommandTarget(item, menuBar);
    throwCoreException("Cannot locate menu item: " + path.toString(), line);
    return null;
}

From source file:org.eclipse.rap.demo.presentation.DemoPresentationWorkbenchWindowAdvisor.java

License:Open Source License

private void createMenuBar(final Composite banner) {
    final Composite menuBar = new Composite(banner, SWT.NONE);
    menuBar.setBackgroundMode(SWT.INHERIT_FORCE);
    FormData fdMenuBar = new FormData();
    menuBar.setLayoutData(fdMenuBar);/*w w  w  . ja  v a2  s  .c  o m*/
    fdMenuBar.top = new FormAttachment(100, -26);
    fdMenuBar.left = new FormAttachment(0, 10);
    fdMenuBar.bottom = new FormAttachment(100, -8);

    final ApplicationWindow window = (ApplicationWindow) getWindowConfigurer().getWindow();
    MenuManager menuBarManager = window.getMenuBarManager();
    IContributionItem[] menuBarItems = menuBarManager.getItems();
    List<Action> actions = new ArrayList<Action>();
    for (int i = 0; i < menuBarItems.length; i++) {
        final MenuManager menuManager = (MenuManager) menuBarItems[i];
        actions.add(new Action() {
            @Override
            public String getId() {
                return menuManager.getId();
            }

            @Override
            public String getText() {
                return menuManager.getMenuText();
            }

            @Override
            public void run() {
                final Shell shell = window.getShell();
                final Color background = new Color(shell.getDisplay(), 9, 34, 60);
                final PopupDialog popupDialog = new PopupDialog(shell, SWT.RESIZE | SWT.ON_TOP, false, false,
                        false, false, null, null) {
                    @Override
                    protected Control createDialogArea(Composite parent) {
                        final Composite popup = new Composite(parent, SWT.NONE);
                        popup.setBackgroundMode(SWT.INHERIT_FORCE);
                        popup.setLayout(new FormLayout());
                        popup.setBackground(background);

                        Label roundedCornerLeft = new Label(popup, SWT.NONE);
                        roundedCornerLeft.setImage(Images.IMG_BANNER_ROUNDED_LEFT);
                        roundedCornerLeft.pack();
                        FormData fdRoundedCornerLeft = new FormData();
                        roundedCornerLeft.setLayoutData(fdRoundedCornerLeft);
                        fdRoundedCornerLeft.top = new FormAttachment(100, -5);
                        fdRoundedCornerLeft.left = new FormAttachment(0, 0);

                        Label roundedCornerRight = new Label(popup, SWT.NONE);
                        roundedCornerRight.setImage(Images.IMG_BANNER_ROUNDED_RIGHT);
                        roundedCornerRight.pack();
                        FormData fdRoundedCornerRight = new FormData();
                        roundedCornerRight.setLayoutData(fdRoundedCornerRight);
                        fdRoundedCornerRight.top = new FormAttachment(100, -5);
                        fdRoundedCornerRight.left = new FormAttachment(100, -5);

                        final Composite content = new Composite(popup, SWT.NONE);
                        FormData fdContent = new FormData();
                        content.setLayoutData(fdContent);
                        fdContent.top = new FormAttachment(0, 5);
                        fdContent.left = new FormAttachment(0, 14);

                        content.setLayout(new FillLayout(SWT.VERTICAL));
                        IContributionItem[] menuItems = menuManager.getItems();
                        for (int j = 0; j < menuItems.length; j++) {
                            IContributionItem contributionItem = menuItems[j];
                            if (contributionItem instanceof ActionContributionItem) {
                                ActionContributionItem actionItem = (ActionContributionItem) contributionItem;
                                Action action = (Action) actionItem.getAction();
                                new ActionBarButton(action, content) {
                                    @Override
                                    public void run() {
                                        close();
                                        super.run();
                                    }
                                };
                            }

                        }
                        content.pack();

                        return popup;
                    }
                };

                final Composite popup = new Composite(shell, SWT.NONE);
                popup.setBackgroundMode(SWT.INHERIT_FORCE);
                popup.setLayout(new FormLayout());

                Label roundedCornerLeft = new Label(popup, SWT.NONE);
                roundedCornerLeft.setImage(Images.IMG_BANNER_ROUNDED_LEFT);
                roundedCornerLeft.pack();
                FormData fdRoundedCornerLeft = new FormData();
                roundedCornerLeft.setLayoutData(fdRoundedCornerLeft);
                fdRoundedCornerLeft.top = new FormAttachment(100, -5);
                fdRoundedCornerLeft.left = new FormAttachment(0, 0);
                roundedCornerLeft.moveAbove(banner);

                Label roundedCornerRight = new Label(popup, SWT.NONE);
                roundedCornerRight.setImage(Images.IMG_BANNER_ROUNDED_RIGHT);
                roundedCornerRight.pack();
                FormData fdRoundedCornerRight = new FormData();
                roundedCornerRight.setLayoutData(fdRoundedCornerRight);
                fdRoundedCornerRight.top = new FormAttachment(100, -5);
                fdRoundedCornerRight.left = new FormAttachment(100, -5);
                roundedCornerRight.moveAbove(banner);

                final Composite content = new Composite(popup, SWT.NONE);
                FormData fdContent = new FormData();
                content.setLayoutData(fdContent);
                fdContent.top = new FormAttachment(0, 5);
                fdContent.left = new FormAttachment(0, 14);

                content.setLayout(new FillLayout(SWT.VERTICAL));
                IContributionItem[] menuItems = menuManager.getItems();
                for (int j = 0; j < menuItems.length; j++) {
                    IContributionItem contributionItem = menuItems[j];
                    if (contributionItem instanceof ActionContributionItem) {
                        ActionContributionItem actionItem = (ActionContributionItem) contributionItem;
                        Action action = (Action) actionItem.getAction();
                        new ActionBarButton(action, content);
                    }

                }
                content.pack();

                popup.setBackground(background);
                Rectangle popUpBounds = calculatePopUpBounds(banner, menuBar, content);
                popup.setBounds(popUpBounds);
                shell.addControlListener(new ControlAdapter() {
                    @Override
                    public void controlResized(ControlEvent e) {
                        Rectangle popUpBounds = calculatePopUpBounds(banner, menuBar, content);
                        popup.setBounds(popUpBounds);
                    }
                });
                popup.moveAbove(null);

                popupDialog.open();
                Listener closeListener = new Listener() {
                    public void handleEvent(Event event) {
                        if (popupDialog.getShell() != null) {
                            popupDialog.getShell().removeListener(SWT.Close, this);
                            popupDialog.getShell().removeListener(SWT.Deactivate, this);
                            popupDialog.getShell().removeListener(SWT.Dispose, this);
                            popupDialog.close();
                        }
                        if (!popup.isDisposed()) {
                            popup.dispose();
                        }
                    }
                };
                popupDialog.getShell().addListener(SWT.Deactivate, closeListener);
                popupDialog.getShell().addListener(SWT.Close, closeListener);
                popupDialog.getShell().addListener(SWT.Dispose, closeListener);
                //          content.addListener( SWT.Dispose, closeListener );
                //          Shell controlShell = content.getShell();
                //          controlShell.addListener( SWT.Move, closeListener );

                popupDialog.getShell().setAlpha(0);
                popupDialog.getShell().setActive();
                popupDialog.getShell().setBounds(popUpBounds);

                //          shell.addMouseListener( new MouseAdapter() {
                //            public void mouseUp( final MouseEvent e ) {
                //
                //System.out.println( "mouseup" );
                //              shell.removeMouseListener( this );
                //              popup.dispose();
                //            }
                //          } );

            }

            private Rectangle calculatePopUpBounds(Composite banner, Composite menuBar, Composite content) {
                Rectangle menuBarBounds = menuBar.getBounds();
                Rectangle bannerBounds = banner.getBounds();
                Display display = menuBar.getDisplay();
                Shell shell = menuBar.getShell();
                Point bannerPosition = display.map(banner.getParent(), shell, banner.getLocation());

                return new Rectangle(bannerPosition.x, bannerBounds.height - 5, menuBarBounds.width + 10,
                        content.getSize().y + 10);
            }
        });
    }
    ActionBar.create(actions, menuBar);
}

From source file:org.jboss.tools.common.model.handlers.ProjectPropertiesHandler.java

License:Open Source License

public static IMenuManager findWorkbenchMenuManager(String id) {
    Object o = ModelPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
    if (!(o instanceof ApplicationWindow))
        return null;
    ApplicationWindow a = (ApplicationWindow) o;
    IContributionItem i = a.getMenuBarManager().find(id);
    return (!(i instanceof IMenuManager)) ? null : (IMenuManager) i;
}

From source file:org.pentaho.ui.xul.jface.tags.JfaceMenubar.java

License:Open Source License

public JfaceMenubar(Element self, XulComponent parent, XulDomContainer domContainer, String tagName) {
    super("menubar");

    ApplicationWindow window = ApplicationWindowLocal.getApplicationWindow();

    if (window == null) {
        logger.error("No ApplicationWindow available via ApplicationWindowLocal");
    } else {//  w  ww. j a v  a 2s .  co  m
        menuManager = window.getMenuBarManager();
    }

    logger.debug("JfaceMenubar grabbed window's MenuManager: " + menuManager);
    // System.out.println("JfaceMenubar grabbed window's MenuManager: "+menuManager);
    setManagedObject(menuManager);
    this.parent = parent;
}