Search in sources :

Example 41 with MenuEvent

use of org.eclipse.swt.events.MenuEvent in project webtools.sourceediting by eclipse.

the class BaseGroupActionDelegate method getMenu.

/* (non-Javadoc)
     * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu)
     */
public Menu getMenu(Menu parent) {
    // Create the new menu. The menu will get filled when it is about to be shown. see fillMenu(Menu).
    Menu menu = new Menu(parent);
    /**
     * Add listener to repopulate the menu each time
     * it is shown because MenuManager.update(boolean, boolean)
     * doesn't dispose pulldown ActionContribution items for each popup menu.
     */
    menu.addMenuListener(new MenuAdapter() {

        public void menuShown(MenuEvent e) {
            if (fFillMenu) {
                Menu m = (Menu) e.widget;
                MenuItem[] items = m.getItems();
                for (int i = 0; i < items.length; i++) {
                    items[i].dispose();
                }
                fillMenu(m);
                fFillMenu = false;
            }
        }
    });
    return menu;
}
Also used : MenuAdapter(org.eclipse.swt.events.MenuAdapter) Menu(org.eclipse.swt.widgets.Menu) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 42 with MenuEvent

use of org.eclipse.swt.events.MenuEvent in project webtools.sourceediting by eclipse.

the class RefactorGroupActionDelegate method getMenu.

/* (non-Javadoc)
	 * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu)
	 */
public Menu getMenu(Menu parent) {
    // Create the new menu. The menu will get filled when it is about to be shown. see fillMenu(Menu).
    Menu menu = new Menu(parent);
    /**
     * Add listener to repopulate the menu each time
     * it is shown because MenuManager.update(boolean, boolean)
     * doesn't dispose pulldown ActionContribution items for each popup menu.
     */
    menu.addMenuListener(new MenuAdapter() {

        public void menuShown(MenuEvent e) {
            if (fFillMenu) {
                Menu m = (Menu) e.widget;
                MenuItem[] items = m.getItems();
                for (int i = 0; i < items.length; i++) {
                    items[i].dispose();
                }
                fillMenu(m);
                fFillMenu = false;
            }
        }
    });
    return menu;
}
Also used : MenuAdapter(org.eclipse.swt.events.MenuAdapter) Menu(org.eclipse.swt.widgets.Menu) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 43 with MenuEvent

use of org.eclipse.swt.events.MenuEvent in project netxms by netxms.

the class FilterBuilder method createColumnSelectionMenu.

/**
 * Create menu for selecting log column
 *
 * @param listener selection listener
 */
private void createColumnSelectionMenu(final ColumnSelectionHandler handler, Control linkControl) {
    if (logHandle == null)
        return;
    if (columnSelectionMenu != null)
        columnSelectionMenu.dispose();
    columnSelectionMenu = new Menu(getShell(), SWT.POP_UP);
    getShell().setMenu(columnSelectionMenu);
    for (final LogColumn lc : logHandle.getColumns()) {
        MenuItem item = new MenuItem(columnSelectionMenu, SWT.PUSH);
        item.setText(lc.getDescription());
        item.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                handler.columnSelected(lc);
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
    }
    columnSelectionMenu.addMenuListener(new MenuListener() {

        @Override
        public void menuShown(MenuEvent e) {
        }

        @Override
        public void menuHidden(MenuEvent e) {
            getShell().setMenu(null);
        }
    });
    columnSelectionMenu.setVisible(true);
    Point p = linkControl.getParent().toDisplay(linkControl.getLocation());
    p.y += linkControl.getSize().y;
    columnSelectionMenu.setLocation(p);
}
Also used : LogColumn(org.netxms.client.log.LogColumn) MenuListener(org.eclipse.swt.events.MenuListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) Point(org.eclipse.swt.graphics.Point) SelectionListener(org.eclipse.swt.events.SelectionListener) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 44 with MenuEvent

use of org.eclipse.swt.events.MenuEvent in project dbeaver by serge-rider.

the class ToolsContextMenuHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
    final Shell activeShell = HandlerUtil.getActiveShell(event);
    if (part == null || activeShell == null) {
        return null;
    }
    final Control focusControl = activeShell.getDisplay().getFocusControl();
    if (focusControl == null) {
        return null;
    }
    Point location = getLocationFromControl(activeShell, focusControl);
    if (menuManager != null) {
        menuManager.dispose();
    }
    menuManager = new MenuManager();
    menuManager.add(ActionUtils.makeCommandContribution(part.getSite(), ConnectionCommands.CMD_CONNECT));
    menuManager.add(ActionUtils.makeCommandContribution(part.getSite(), ConnectionCommands.CMD_DISCONNECT));
    menuManager.add(ActionUtils.makeCommandContribution(part.getSite(), ConnectionCommands.CMD_INVALIDATE));
    if (part instanceof IEditorPart) {
        menuManager.add(new Separator());
        menuManager.add(ActionUtils.makeCommandContribution(part.getSite(), ConnectionCommands.CMD_COMMIT));
        menuManager.add(ActionUtils.makeCommandContribution(part.getSite(), ConnectionCommands.CMD_ROLLBACK));
        {
            final MenuManager txnMenu = new MenuManager(DBeaverActivator.getPluginResourceBundle().getString("command.org.jkiss.dbeaver.core.transaction_mode.name"));
            txnMenu.add(new DataSourceTransactionModeContributor());
            menuManager.add(txnMenu);
        }
    }
    menuManager.add(new Separator());
    {
        menuManager.add(ActionUtils.makeCommandContribution(part.getSite(), SQLEditorCommands.CMD_SQL_EDITOR_OPEN));
    /*
            final MenuManager toolsMenu = new MenuManager(
                DBeaverActivator.getPluginResourceBundle().getString("menu.database.tools"));
            toolsMenu.add(new DataSourceToolsContributor());
            menuManager.add(toolsMenu);
*/
    }
    if (part instanceof IEditorPart) {
        menuManager.add(ActionUtils.makeCommandContribution(part.getSite(), CoreCommands.CMD_LINK_EDITOR, CoreMessages.action_menu_tools_find_in_navigator, null));
    }
    final Menu contextMenu = menuManager.createContextMenu(focusControl);
    if (location != null) {
        contextMenu.setLocation(location);
    }
    contextMenu.setVisible(true);
    contextMenu.addMenuListener(new MenuAdapter() {

        @Override
        public void menuShown(MenuEvent e) {
            int keyIndex = 1;
            for (MenuItem item : contextMenu.getItems()) {
                if (/*item.getMenu() == null && */
                !CommonUtils.isEmpty(item.getText())) {
                    item.setText(String.valueOf(keyIndex) + ". " + item.getText());
                    keyIndex++;
                    if (keyIndex >= 10) {
                        break;
                    }
                }
            }
        }
    });
    return null;
}
Also used : MenuAdapter(org.eclipse.swt.events.MenuAdapter) Point(org.eclipse.swt.graphics.Point) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) MenuManager(org.eclipse.jface.action.MenuManager) Separator(org.eclipse.jface.action.Separator) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 45 with MenuEvent

use of org.eclipse.swt.events.MenuEvent in project dbeaver by serge-rider.

the class NavigatorUtils method createContextMenu.

public static MenuManager createContextMenu(final IWorkbenchSite workbenchSite, final Viewer viewer, final ISelectionProvider selectionProvider, final IMenuListener menuListener) {
    final Control control = viewer.getControl();
    final MenuManager menuMgr = new MenuManager();
    Menu menu = menuMgr.createContextMenu(control);
    menu.addMenuListener(new MenuListener() {

        @Override
        public void menuHidden(MenuEvent e) {
        }

        @Override
        public void menuShown(MenuEvent e) {
            Menu m = (Menu) e.widget;
            DBNNode node = getSelectedNode(viewer.getSelection());
            if (node != null && !node.isLocked() && node.allowsOpen()) {
                String commandID = NavigatorUtils.getNodeActionCommand(DBXTreeNodeHandler.Action.open, node, NavigatorCommands.CMD_OBJECT_OPEN);
                // Get contribution item from menu item and check it's ID
                try {
                    for (MenuItem item : m.getItems()) {
                        Object itemData = item.getData();
                        if (itemData instanceof IContributionItem) {
                            String contribId = ((IContributionItem) itemData).getId();
                            if (contribId != null && contribId.equals(commandID)) {
                                m.setDefaultItem(item);
                            }
                        }
                    }
                } catch (Exception ex) {
                    log.debug(ex);
                }
            }
        }
    });
    menuMgr.addMenuListener(manager -> {
        ViewerColumnController columnController = ViewerColumnController.getFromControl(control);
        if (columnController != null && columnController.isClickOnHeader()) {
            columnController.fillConfigMenu(manager);
            manager.add(new Separator());
            return;
        }
        manager.add(new Separator());
        addStandardMenuItem(workbenchSite, manager, selectionProvider);
        if (menuListener != null) {
            menuListener.menuAboutToShow(manager);
        }
    });
    menuMgr.setRemoveAllWhenShown(true);
    control.setMenu(menu);
    return menuMgr;
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) MenuListener(org.eclipse.swt.events.MenuListener) DBCException(org.jkiss.dbeaver.model.exec.DBCException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) MenuEvent(org.eclipse.swt.events.MenuEvent)

Aggregations

MenuEvent (org.eclipse.swt.events.MenuEvent)45 Menu (org.eclipse.swt.widgets.Menu)37 MenuItem (org.eclipse.swt.widgets.MenuItem)29 SelectionEvent (org.eclipse.swt.events.SelectionEvent)25 MenuAdapter (org.eclipse.swt.events.MenuAdapter)24 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)21 MenuListener (org.eclipse.swt.events.MenuListener)18 Point (org.eclipse.swt.graphics.Point)14 MenuManager (org.eclipse.jface.action.MenuManager)13 Event (org.eclipse.swt.widgets.Event)11 Listener (org.eclipse.swt.widgets.Listener)9 Rectangle (org.eclipse.swt.graphics.Rectangle)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 FocusEvent (org.eclipse.swt.events.FocusEvent)7 Composite (org.eclipse.swt.widgets.Composite)7 TableItem (org.eclipse.swt.widgets.TableItem)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 DisposeEvent (org.eclipse.swt.events.DisposeEvent)6 GridData (org.eclipse.swt.layout.GridData)6