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

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

Introduction

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

Prototype

@Override
public void dispose() 

Source Link

Document

Disposes of this menu manager and frees all allocated SWT resources.

Usage

From source file:com.google.cloud.tools.eclipse.ui.util.OpenDropDownMenuHandler.java

License:Apache License

/**
 * Opens drop-down menu.//from   w ww . j a v a  2s.  c  o  m
 */
private static void openDropDownMenu(final String menuId, final ToolItem toolItem,
        final IMenuService menuService) {
    final MenuManager menuManager = new MenuManager();
    Menu menu = menuManager.createContextMenu(toolItem.getParent());
    menuManager.addMenuListener(new IMenuListener2() {
        @Override
        public void menuAboutToHide(IMenuManager manager) {
            toolItem.getDisplay().asyncExec(new Runnable() {
                @Override
                public void run() {
                    menuService.releaseContributions(menuManager);
                    menuManager.dispose();
                }
            });
        }

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            menuService.populateContributionManager(menuManager, "menu:" + menuId);
        }
    });
    // place the menu below the drop-down item
    Rectangle itemBounds = toolItem.getBounds();
    Point point = toolItem.getParent().toDisplay(new Point(itemBounds.x, itemBounds.y + itemBounds.height));
    menu.setLocation(point.x, point.y);
    menu.setVisible(true);
}

From source file:com.nokia.tools.carbide.ui.dialogs.CarbideAboutDialog.java

License:Open Source License

/**
 * Create the context menu for the text widget.
 * /*www .  jav  a2s.  c  o m*/
 * @since 3.4
 */
private void createTextMenu() {
    final MenuManager textManager = new MenuManager();
    textManager.add(new CommandContributionItem(new CommandContributionItemParameter(PlatformUI.getWorkbench(),
            null, IWorkbenchCommandConstants.EDIT_COPY, CommandContributionItem.STYLE_PUSH)));
    textManager.add(new CommandContributionItem(new CommandContributionItemParameter(PlatformUI.getWorkbench(),
            null, IWorkbenchCommandConstants.EDIT_SELECT_ALL, CommandContributionItem.STYLE_PUSH)));
    text.setMenu(textManager.createContextMenu(text));
    text.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            textManager.dispose();
        }
    });

}

From source file:com.nokia.tools.s60.editor.ScreenModelMediator.java

License:Open Source License

public void disposeViewer(final GraphicalViewer viewer) {
    if (viewer == null) {
        return;//w w w.j a  v  a  2  s. com
    }
    for (Iterator<GraphicalViewer> i = viewers.values().iterator(); i.hasNext();) {
        if (i.next() == viewer) {
            i.remove();
        }
    }
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            SelectionSynchronizer synchronizer = (SelectionSynchronizer) editor
                    .getAdapter(SelectionSynchronizer.class);
            if (synchronizer != null) {
                synchronizer.removeViewer(viewer);
            }
            MenuManager manager = viewer.getContextMenu();
            if (manager != null) {
                manager.dispose();
            }
            Control control = viewer.getControl();
            if (control != null && !control.isDisposed() && control.getParent() != null) {
                control.getParent().dispose();
            }
        }
    });
    removeAdapters((EObject) viewer.getContents().getModel());
}

From source file:de.walware.ecommons.ui.actions.SimpleContributionItem.java

License:Open Source License

protected void initDropDownMenu(final MenuManager menuManager) {
    final Menu menu = menuManager.getMenu();
    menuManager.addMenuListener(new IMenuListener2() {
        @Override//from w w w .ja va2 s. co m
        public void menuAboutToShow(final IMenuManager manager) {
            dropDownMenuAboutToShow(manager);
        }

        @Override
        public void menuAboutToHide(final IMenuManager manager) {
            menu.getDisplay().asyncExec(new Runnable() {
                @Override
                public void run() {
                    menuManager.dispose();
                }
            });
        }
    });
}

From source file:de.walware.ecommons.ui.util.MenuUtil.java

License:Open Source License

public static void registerOneWayMenu(final MenuManager menuManager, final String id) {
    final IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService(IMenuService.class);
    final Menu menu = menuManager.getMenu();
    menuManager.addMenuListener(new IMenuListener2() {
        @Override/*from  w w w.  j av a  2  s. co m*/
        public void menuAboutToShow(final IMenuManager manager) {
            menuService.populateContributionManager(menuManager, "menu:" + id); //$NON-NLS-1$
        }

        @Override
        public void menuAboutToHide(final IMenuManager manager) {
            menu.getDisplay().asyncExec(new Runnable() {
                @Override
                public void run() {
                    menuService.releaseContributions(menuManager);
                    menuManager.dispose();
                }
            });
        }
    });
}

From source file:de.walware.statet.nico.ui.console.NIConsolePage.java

License:Open Source License

protected void contributeToActionBars(final IServiceLocator serviceLocator, final IActionBars actionBars,
        final HandlerCollection handlers) {
    fMultiActionHandler.registerActions(actionBars);

    final IToolBarManager toolBarManager = actionBars.getToolBarManager();
    toolBarManager.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fOutputClearAllAction);
    toolBarManager.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fOutputScrollLockAction);

    toolBarManager.appendToGroup(IConsoleConstants.LAUNCH_GROUP, new HandlerContributionItem(
            new CommandContributionItemParameter(serviceLocator, CancelHandler.MENU_ID,
                    NicoUI.CANCEL_CURRENT_COMMAND_ID, null, null, null, null, Messages.CancelAction_name, null,
                    Messages.CancelAction_tooltip, HandlerContributionItem.STYLE_PULLDOWN, null, false),
            fPageHandlers.get(NicoUI.CANCEL_CURRENT_COMMAND_ID)) {
        // Workaround for E-Bug #366528
        @Override//from  w  w  w  .  j av  a2  s .c o m
        protected void initDropDownMenu(final MenuManager menuManager) {
            menuManager.addMenuListener(new IMenuListener2() {
                @Override
                public void menuAboutToShow(final IMenuManager manager) {
                    manager.add(new CommandContributionItem(new CommandContributionItemParameter(serviceLocator,
                            null, NicoUI.CANCEL_CURRENT_COMMAND_ID, CommandContributionItem.STYLE_PUSH)));
                    manager.add(new CommandContributionItem(new CommandContributionItemParameter(serviceLocator,
                            null, NicoUI.CANCEL_PAUSE_COMMAND_ID, CommandContributionItem.STYLE_PUSH)));
                    manager.add(new CommandContributionItem(new CommandContributionItemParameter(serviceLocator,
                            null, NicoUI.CANCEL_ALL_COMMAND_ID, CommandContributionItem.STYLE_PUSH)));
                }

                @Override
                public void menuAboutToHide(final IMenuManager manager) {
                    display.asyncExec(new Runnable() {
                        @Override
                        public void run() {
                            menuManager.dispose();
                        }
                    });
                }
            });
        }
    });
    toolBarManager.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fTerminateAction);
    toolBarManager.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fRemoveAction);
    toolBarManager.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fRemoveAllAction);

    final IMenuManager menuManager = actionBars.getMenuManager();
    menuManager.add(new Separator(NICO_CONTROL_MENU_ID));
    menuManager.add(new Separator(SharedUIResources.ADDITIONS_MENU_ID));

    menuManager.add(new Separator("tracking")); //$NON-NLS-1$
    final MenuManager trackingMenu = new MenuManager("Open In Editor") {
        @Override
        public boolean isVisible() {
            return !getTool().getTracks().isEmpty();
        }
    };
    trackingMenu.add(new OpenTrackingFilesContributionItem(getTool()));
    menuManager.add(trackingMenu);
    menuManager.add(new SimpleContributionItem("Export Console Output...", null) {
        @Override
        protected void execute() throws ExecutionException {
            final ToolProcess tool = getTool();
            if (tool == null) {
                return;
            }
            final ExportConsoleOutputWizard wizard = new ExportConsoleOutputWizard(NIConsolePage.this);
            final WizardDialog dialog = new NicoWizardDialog(getSite().getShell(), wizard);
            dialog.setBlockOnOpen(false);
            dialog.open();
        }
    });

    menuManager.add(new Separator("settings")); //$NON-NLS-1$
    menuManager.add(new SimpleContributionItem("Preferences...", "P") {
        @Override
        protected void execute() throws ExecutionException {
            final Shell shell = getSite().getShell();
            final List<String> pageIds = new ArrayList<String>();
            NIConsolePage.this.collectContextMenuPreferencePages(pageIds);
            if (!pageIds.isEmpty() && (shell == null || !shell.isDisposed())) {
                org.eclipse.ui.dialogs.PreferencesUtil.createPreferenceDialogOn(shell, pageIds.get(0),
                        pageIds.toArray(new String[pageIds.size()]), null).open();
            }
        }
    });

    menuManager.add(new Separator());
}

From source file:eu.esdihumboldt.hale.ui.views.styledmap.handler.ShowLayoutMenuHandler.java

License:Open Source License

/**
 * @see IHandler#execute(ExecutionEvent)
 *///from  ww w . jav  a 2s .  c  o  m
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IViewPart viewPart = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().findView(StyledMapView.ID);

    if (viewPart instanceof MapView) {
        // view visible - show layout menu
        final MenuManager manager = new MenuManager();
        manager.setRemoveAllWhenShown(true);
        final IconPainterLayoutContribution contribution = new IconPainterLayoutContribution();
        manager.addMenuListener(new IMenuListener() {

            @Override
            public void menuAboutToShow(IMenuManager manager) {
                // populate context menu
                manager.add(contribution);
            }

        });
        Shell shell = HandlerUtil.getActiveShell(event);

        final Menu menu = manager.createContextMenu(shell);

        // determine location
        Point cursorLocation = Display.getCurrent().getCursorLocation();

        // default to cursor location
        Point location = cursorLocation;

        // try to determine from control
        Control cursorControl = Display.getCurrent().getCursorControl();
        if (cursorControl != null) {
            if (cursorControl instanceof ToolBar) {
                ToolBar bar = (ToolBar) cursorControl;
                ToolItem item = bar.getItem(bar.toControl(cursorLocation));
                if (item != null) {
                    Rectangle bounds = item.getBounds();
                    location = bar.toDisplay(bounds.x, bounds.y + bounds.height);
                }
            } else {
                // show below control
                location = cursorControl.toDisplay(0, cursorControl.getSize().y);
            }
        }

        menu.setLocation(location);

        menu.addMenuListener(new MenuListener() {

            @Override
            public void menuShown(MenuEvent e) {
                // do nothing
            }

            @Override
            public void menuHidden(MenuEvent e) {
                Display.getCurrent().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        /*
                         * Dispose everything as it is used only once. Done
                         * asynchronously as otherwise we interfere with the
                         * menu click handling.
                         */
                        manager.dispose();
                        contribution.dispose();
                        menu.dispose();
                    }
                });
            }
        });

        // show menu
        menu.setVisible(true);
    } else {
        // view not visible - just show map perspective
        try {
            PlatformUI.getWorkbench().showPerspective(StyledMapPerspective.ID,
                    HandlerUtil.getActiveWorkbenchWindow(event));
        } catch (WorkbenchException e) {
            log.error("Could not open map perspective", e);
        }
    }

    return null;
}

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

License:Open Source License

public void cleanUpCopy(ContributionRecord record, MMenuElement copy) {
    modelContributionToRecord.remove(copy);
    if (copy instanceof MMenu) {
        MMenu menuCopy = (MMenu) copy;//from w w w . j  a  v a  2  s.  c om
        cleanUp(menuCopy);
        MenuManager copyManager = getManager(menuCopy);
        clearModelToManager(menuCopy, copyManager);
        if (copyManager != null) {
            record.getManagerForModel().remove(copyManager);
            copyManager.dispose();
        }
    } else {
        IContributionItem ici = getContribution(copy);
        clearModelToContribution(copy, ici);
        if (ici != null) {
            record.getManagerForModel().remove(ici);
        }
    }
}

From source file:org.dawnsci.plotting.views.ToolPageSite.java

License:Open Source License

/**
 * Disposes of the menu extender contributions.
 *//*from   w w w .  java  2s . com*/
protected void dispose() {
    if (menuExtenders != null) {
        HashSet<MenuManager> managers = new HashSet<MenuManager>(menuExtenders.size());
        for (int i = 0; i < menuExtenders.size(); i++) {
            PopupMenuExtender ext = (PopupMenuExtender) menuExtenders.get(i);
            managers.add(ext.getManager());
            ext.dispose();
        }
        if (managers.size() > 0) {
            for (Iterator<MenuManager> iterator = managers.iterator(); iterator.hasNext();) {
                MenuManager mgr = (MenuManager) iterator.next();
                mgr.dispose();
            }
        }
        menuExtenders = null;
    }
    subActionBars.dispose();
    serviceLocator.dispose();
}

From source file:org.eclipse.e4.tools.ui.designer.actions.NewChildAction.java

License:Open Source License

public void dispose() {
    Collection<MenuManager> values = menus.values();
    for (MenuManager mm : values) {
        mm.dispose();
    }//  w ww  .j av a2  s  . c om
    menus.clear();
}