Search in sources :

Example 6 with MenuListener

use of org.eclipse.swt.events.MenuListener in project cubrid-manager by CUBRID.

the class ServiceDashboardEditor method initMenu.

private void initMenu(Tree tree) {
    ActionManager manager = ActionManager.getInstance();
    Menu menu = new Menu(this.getSite().getShell(), SWT.POP_UP);
    tree.setMenu(menu);
    refreshMenuItem = new MenuItem(menu, SWT.PUSH);
    refreshMenuItem.setText(Messages.btnRefresh);
    refreshMenuItem.setImage(CubridManagerUIPlugin.getImage("icons/action/refresh.png"));
    refreshMenuItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            loadAllData();
        }
    });
    new MenuItem(menu, SWT.SEPARATOR);
    final ConnectHostAction connectHostAction = (ConnectHostAction) manager.getAction(ConnectHostAction.ID);
    connectMenuItem = new MenuItem(menu, SWT.PUSH);
    connectMenuItem.setText(connectHostAction.getText());
    connectMenuItem.setImage(connectHostAction.getImageDescriptor().createImage());
    connectMenuItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            connectHostAction.doRun(getSelectedServer());
            loadAllData();
        }
    });
    final DisConnectHostAction disConnectHostAction = (DisConnectHostAction) manager.getAction(DisConnectHostAction.ID);
    disConnectMenuItem = new MenuItem(menu, SWT.PUSH);
    disConnectMenuItem.setText(disConnectHostAction.getText());
    disConnectMenuItem.setImage(disConnectHostAction.getImageDescriptor().createImage());
    disConnectMenuItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            disConnectHostAction.doRun(getSelectedServer());
            loadAllData();
        }
    });
    new MenuItem(menu, SWT.SEPARATOR);
    final AddHostAction addHostAction = (AddHostAction) manager.getAction(AddHostAction.ID);
    addHostMenuItem = new MenuItem(menu, SWT.PUSH);
    addHostMenuItem.setText(addHostAction.getText());
    addHostMenuItem.setImage(addHostAction.getImageDescriptor().createImage());
    addHostMenuItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            addHostAction.doRun(getSelectedServer());
            loadAllData();
        }
    });
    final EditHostAction editHostAction = (EditHostAction) manager.getAction(EditHostAction.ID);
    editHostMenuItem = new MenuItem(menu, SWT.PUSH);
    editHostMenuItem.setText(editHostAction.getText());
    editHostMenuItem.setImage(editHostAction.getImageDescriptor().createImage());
    editHostMenuItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            editHostAction.doRun(getSelectedServer(), false);
            loadAllData();
        }
    });
    final DeleteHostAction deleteHostAction = (DeleteHostAction) manager.getAction(DeleteHostAction.ID);
    deleteHostMenuItem = new MenuItem(menu, SWT.PUSH);
    deleteHostMenuItem.setText(deleteHostAction.getText());
    deleteHostMenuItem.setImage(deleteHostAction.getImageDescriptor().createImage());
    deleteHostMenuItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            deleteHostAction.doRun(getSelectedServer());
            loadAllData();
        }
    });
    new MenuItem(menu, SWT.SEPARATOR);
    final StartServiceAction startServiceAction = (StartServiceAction) manager.getAction(StartServiceAction.ID);
    startServiceMenuItem = new MenuItem(menu, SWT.PUSH);
    startServiceMenuItem.setText(startServiceAction.getText());
    startServiceMenuItem.setImage(startServiceAction.getImageDescriptor().createImage());
    startServiceMenuItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            startServiceAction.doRun(getSelectedServer());
            loadAllData();
        }
    });
    final StopServiceAction stopServiceAction = (StopServiceAction) manager.getAction(StopServiceAction.ID);
    stopServiceMenuItem = new MenuItem(menu, SWT.PUSH);
    stopServiceMenuItem.setText(stopServiceAction.getText());
    stopServiceMenuItem.setImage(stopServiceAction.getImageDescriptor().createImage());
    stopServiceMenuItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            stopServiceAction.doRun(getSelectedServer());
            loadAllData();
        }
    });
    menu.addMenuListener(new MenuListener() {

        public void menuShown(MenuEvent e) {
            updateMenuItems();
        }

        public void menuHidden(MenuEvent e) {
        }
    });
}
Also used : StopServiceAction(com.cubrid.cubridmanager.ui.common.action.StopServiceAction) DisConnectHostAction(com.cubrid.cubridmanager.ui.host.action.DisConnectHostAction) MenuListener(org.eclipse.swt.events.MenuListener) DeleteHostAction(com.cubrid.cubridmanager.ui.host.action.DeleteHostAction) MenuItem(org.eclipse.swt.widgets.MenuItem) ActionManager(com.cubrid.common.ui.spi.action.ActionManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ConnectHostAction(com.cubrid.cubridmanager.ui.host.action.ConnectHostAction) DisConnectHostAction(com.cubrid.cubridmanager.ui.host.action.DisConnectHostAction) StartServiceAction(com.cubrid.cubridmanager.ui.common.action.StartServiceAction) Menu(org.eclipse.swt.widgets.Menu) AddHostAction(com.cubrid.cubridmanager.ui.host.action.AddHostAction) EditHostAction(com.cubrid.cubridmanager.ui.host.action.EditHostAction) SelectionListener(org.eclipse.swt.events.SelectionListener) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 7 with MenuListener

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

the class NavigatorUtils method createContextMenu.

public static MenuManager createContextMenu(final IWorkbenchSite workbenchSite, final Viewer viewer, 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, CoreCommands.CMD_OBJECT_OPEN);
                // Get contribution item from menu item and check it's ID
                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);
                        }
                    }
                }
            }
        }
    });
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(final IMenuManager manager) {
            ViewerColumnController columnController = ViewerColumnController.getFromControl(control);
            if (columnController != null && columnController.isClickOnHeader()) {
                columnController.fillConfigMenu(manager);
                manager.add(new Separator());
                return;
            }
            manager.add(new GroupMarker(MB_NAVIGATOR_ADDITIONS));
            final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            final DBNNode selectedNode = getSelectedNode(viewer);
            if (selectedNode != null && !selectedNode.isLocked() && workbenchSite != null) {
                // Add "Set active object" menu
                if (selectedNode.isPersisted() && selectedNode instanceof DBNDatabaseNode && !(selectedNode instanceof DBNDatabaseFolder) && ((DBNDatabaseNode) selectedNode).getObject() != null) {
                    final DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, ((DBNDatabaseNode) selectedNode).getObject());
                    if (activeContainer != null && activeContainer.supportsDefaultChange()) {
                        DBSObject activeChild;
                        activeChild = activeContainer.getDefaultObject();
                        if (activeChild != ((DBNDatabaseNode) selectedNode).getObject()) {
                            DBNDatabaseNode databaseNode = (DBNDatabaseNode) selectedNode;
                            if (databaseNode.getObject() != null && (activeChild == null || activeChild.getClass() == databaseNode.getObject().getClass())) {
                                // + databaseNode.getNodeType();
                                String text = "Set Active ";
                                // Fill context menu
                                IAction action = ActionUtils.makeAction(new NavigatorActionSetActiveObject(), workbenchSite, selection, text, null, null);
                                manager.add(action);
                            }
                        }
                    }
                }
                manager.add(new Separator());
                manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
                manager.add(new GroupMarker(IActionConstants.MB_ADDITIONS_END));
                // Add properties button
                if (PreferencesUtil.hasPropertiesContributors(selection.getFirstElement())) {
                    manager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_PROPERTIES));
                }
                if (selectedNode.isPersisted()) {
                    // Add refresh button
                    manager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REFRESH));
                }
            }
            manager.add(new GroupMarker(CoreCommands.GROUP_TOOLS));
            if (menuListener != null) {
                menuListener.menuAboutToShow(manager);
            }
        }
    });
    menuMgr.setRemoveAllWhenShown(true);
    control.setMenu(menu);
    control.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            menuMgr.dispose();
        }
    });
    return menuMgr;
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) DisposeListener(org.eclipse.swt.events.DisposeListener) MenuListener(org.eclipse.swt.events.MenuListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Control(org.eclipse.swt.widgets.Control) Menu(org.eclipse.swt.widgets.Menu) MenuEvent(org.eclipse.swt.events.MenuEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) NavigatorActionSetActiveObject(org.jkiss.dbeaver.ui.actions.navigator.NavigatorActionSetActiveObject) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) NavigatorActionSetActiveObject(org.jkiss.dbeaver.ui.actions.navigator.NavigatorActionSetActiveObject) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSObjectSelector(org.jkiss.dbeaver.model.struct.DBSObjectSelector)

Example 8 with MenuListener

use of org.eclipse.swt.events.MenuListener in project cubrid-manager by CUBRID.

the class TableConfigCellEditor method registerContextMenu.

/**
	 * register context menu
	 */
private void registerContextMenu() {
    sqlFileTableViewer.getTable().addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(sqlFileTableViewer.getTable());
        }
    });
    Menu menu = new Menu(getShell(), SWT.POP_UP);
    final MenuItem addSchemaItem = new MenuItem(menu, SWT.PUSH);
    addSchemaItem.setText(Messages.btnAddSchemaFile);
    addSchemaItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            addFile(TableConfig.TYPE_SCHEMA);
        }
    });
    final MenuItem addDataItem = new MenuItem(menu, SWT.PUSH);
    addDataItem.setText(Messages.btnAddDataFile);
    addDataItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            addFile(TableConfig.TYPE_DATA);
        }
    });
    final MenuItem addIndexItem = new MenuItem(menu, SWT.PUSH);
    addIndexItem.setText(Messages.btnAddIndexFile);
    addIndexItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            addFile(TableConfig.TYPE_INDEX);
        }
    });
    new MenuItem(menu, SWT.SEPARATOR);
    final MenuItem delItem = new MenuItem(menu, SWT.PUSH);
    delItem.setText(Messages.btnDelFiles);
    delItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            deleteSelectedFile();
        }
    });
    menu.addMenuListener(new MenuListener() {

        public void menuHidden(org.eclipse.swt.events.MenuEvent e) {
        }

        public void menuShown(org.eclipse.swt.events.MenuEvent e) {
            delItem.setEnabled(delCanEnable());
        }
    });
    sqlFileTableViewer.getTable().setMenu(menu);
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) MenuListener(org.eclipse.swt.events.MenuListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) FocusEvent(org.eclipse.swt.events.FocusEvent)

Aggregations

MenuListener (org.eclipse.swt.events.MenuListener)8 Menu (org.eclipse.swt.widgets.Menu)8 MenuItem (org.eclipse.swt.widgets.MenuItem)8 MenuEvent (org.eclipse.swt.events.MenuEvent)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)2 TableContentProvider (com.cubrid.common.ui.spi.TableContentProvider)2 TableLabelProvider (com.cubrid.common.ui.spi.TableLabelProvider)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 ExpandItem (org.eclipse.swt.widgets.ExpandItem)2 ActionManager (com.cubrid.common.ui.spi.action.ActionManager)1 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1