Search in sources :

Example 16 with IMenuListener

use of org.eclipse.jface.action.IMenuListener in project cubrid-manager by CUBRID.

the class ImportResultDialog method createDialogArea.

/**
	 * Create the dialog area
	 *
	 * @param parent Composite
	 * @return Control
	 */
protected Control createDialogArea(Composite parent) {
    Composite parentComp = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(parentComp, SWT.NONE);
    {
        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
        GridLayout layout = new GridLayout();
        layout.numColumns = 1;
        layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
        layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
        layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
        layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
        composite.setLayout(layout);
    }
    TableViewer tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
    table = tableViewer.getTable();
    {
        GridData gdData = new GridData(GridData.FILL_BOTH);
        gdData.heightHint = 400;
        gdData.widthHint = 500;
        table.setLayoutData(gdData);
    }
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableColumn tableColumn = new TableColumn(table, SWT.LEFT);
    tableColumn.setText(Messages.importColumnNO);
    tableColumn = new TableColumn(table, SWT.LEFT);
    tableColumn.setText(Messages.importColumnMessage);
    tableViewer.setLabelProvider(new TableLabelProvider(tableViewer, null));
    tableViewer.setContentProvider(new TableContentProvider());
    tableViewer.setInput(errorList);
    //Create the context menu
    MenuManager contextMenuManager = new MenuManager();
    contextMenuManager.setRemoveAllWhenShown(true);
    contextMenuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            //copy action
            Action copyAction = new Action(Messages.bind(Messages.contextCopy, "Ctrl+C")) {

                public void run() {
                    BusyIndicator.showWhile(Display.getDefault(), new Runnable() {

                        public void run() {
                            copyDataToClipboard();
                        }
                    });
                }
            };
            manager.add(copyAction);
        }
    });
    Menu contextMenu = contextMenuManager.createContextMenu(table);
    table.setMenu(contextMenu);
    //Add listener
    table.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent event) {
            if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) == 0 && event.keyCode == 'c') {
                copyDataToClipboard();
            }
        }
    });
    for (int i = 0; i < table.getColumnCount(); i++) {
        TableColumn tblColumn = table.getColumn(i);
        tblColumn.pack();
        if (tblColumn.getWidth() > 400) {
            tblColumn.setWidth(400);
        }
    }
    Label label = new Label(composite, SWT.LEFT);
    label.setForeground(ResourceManager.getColor(255, 0, 0));
    label.setText(message);
    return composite;
}
Also used : Action(org.eclipse.jface.action.Action) Composite(org.eclipse.swt.widgets.Composite) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) TableColumn(org.eclipse.swt.widgets.TableColumn) IMenuListener(org.eclipse.jface.action.IMenuListener) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) TableContentProvider(com.cubrid.common.ui.spi.TableContentProvider) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 17 with IMenuListener

use of org.eclipse.jface.action.IMenuListener in project cubrid-manager by CUBRID.

the class SchemaInfoEditorPart method createContextMenu.

/**
	 * 
	 * Create the context menu
	 * 
	 * @param control Control
	 */
private void createContextMenu(final Control control) {
    MenuManager contextMenuManager = new MenuManager();
    contextMenuManager.setRemoveAllWhenShown(true);
    contextMenuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            ISelectionProvider provider = ActionManager.getInstance().getSelectionProvider();
            if (!(provider instanceof TreeViewer)) {
                return;
            }
            TreeViewer viewer = (TreeViewer) provider;
            viewer.setSelection(new StructuredSelection(schemaNode), true);
            viewer.getTree().setFocus();
            MenuProvider menuProvider = new MenuProvider();
            String type = schemaNode.getType();
            if (NodeType.SYSTEM_TABLE.equals(type)) {
                menuProvider.buildSystemTableMenu(manager);
            } else if (NodeType.SYSTEM_VIEW.equals(type)) {
                menuProvider.buildSystemViewMenu(manager);
            } else if (NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(type)) {
                menuProvider.buildUserTableMenu(manager, schemaNode);
            } else if (NodeType.USER_PARTITIONED_TABLE.equals(type)) {
                menuProvider.buildPartitionedTableMenu(manager);
            } else if (NodeType.USER_TABLE.equals(type)) {
                menuProvider.buildUserTableMenu(manager, schemaNode);
            } else if (NodeType.USER_VIEW.equals(type)) {
                menuProvider.buildUserViewMenu(manager);
            }
            manager.remove(ShowSchemaEditorAction.ID);
        }
    });
    Menu contextMenu = contextMenuManager.createContextMenu(control);
    control.setMenu(contextMenu);
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) MenuProvider(com.cubrid.common.ui.spi.action.MenuProvider) IMenuListener(org.eclipse.jface.action.IMenuListener)

Example 18 with IMenuListener

use of org.eclipse.jface.action.IMenuListener in project cubrid-manager by CUBRID.

the class QueryPlanCompositeWithHistory method setupContextMenu.

private void setupContextMenu(final Tree tree) {
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
        //				IAction showSchemaAction = ActionManager.getInstance().getAction(ShowSchemaAction.ID);
        //				if (showSchemaAction != null) {
        //					manager.add(showSchemaAction);
        //
        //					showSchemaAction.setEnabled(false);
        //					if (DatabaseNavigatorMenu.SELF_DATABASE_ID.equals(editor.getSelectedDatabase().getId())) {
        //						return;
        //					}
        //
        //					if (editor.getSelectedDatabase().getDatabaseInfo() == null) {
        //						return;
        //					}
        //
        //					if (tree.getSelection() != null && tree.getSelection().length > 0) {
        //						String tname = tree.getSelection()[0].getText(1);
        //						if (tname == null || tname.length() == 0) {
        //							return;
        //						}
        //
        //						int ep = tname.indexOf(' ');
        //						if (ep != -1) {
        //							tname = tname.substring(0, ep);
        //						}
        //						editor.setCurrentSchemaName(tname);
        //						if (tname != null) {
        //							showSchemaAction.setEnabled(true);
        //						}
        //					}
        //				}
        }
    });
    Menu contextMenu = menuManager.createContextMenu(tree);
    tree.setMenu(contextMenu);
}
Also used : MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) TabContextMenuManager(com.cubrid.common.ui.spi.util.TabContextMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) IMenuListener(org.eclipse.jface.action.IMenuListener)

Example 19 with IMenuListener

use of org.eclipse.jface.action.IMenuListener in project cubrid-manager by CUBRID.

the class BrokerDashboardViewPart method createPartControl.

/**
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 * 
	 * @param parent the parent composite
	 */
public void createPartControl(Composite parent) {
    final ScrolledComposite scrolledComp = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
    composite = new Composite(scrolledComp, SWT.NONE);
    composite.setLayout(new GridLayout());
    BrokerTblColumnSetHelp bcsh = BrokerTblColumnSetHelp.getInstance();
    bcsh.loadSetting(BrokerTblColumnSetHelp.StatusColumn.BrokerStatusBasicColumn, BrokerStatusBasicColumn.values());
    bcsh.loadSetting(BrokerTblColumnSetHelp.StatusColumn.BrokerStatusAsColumn, BrokerStatusAsColumn.values());
    bcsh.loadSetting(BrokerTblColumnSetHelp.StatusColumn.BrokerStatusJqColumn, BrokerStatusJqColumn.values());
    brokerTablePart.setServerInfo(serverInfo);
    brokerTablePart.setAppendDiag(true);
    basicTableViewer = brokerTablePart.createBasicTable(composite);
    asTableViewer = brokerTablePart.createAsTable(composite);
    jqTableViewer = brokerTablePart.createJobTable(composite);
    makeActions();
    composite.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent event) {
            updateTableLayout();
        }
    });
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            IStructuredSelection selection = (IStructuredSelection) asTableViewer.getSelection();
            ApplyServerInfo as = (ApplyServerInfo) (selection.toArray()[0]);
            RestartAction restartAcion = new RestartAction(as.getAs_id());
            manager.add(restartAcion);
        }
    });
    Menu contextMenu = menuManager.createContextMenu(asTableViewer.getControl());
    asTableViewer.getControl().setMenu(contextMenu);
    scrolledComp.setContent(composite);
    scrolledComp.setExpandHorizontal(true);
    scrolledComp.setExpandVertical(true);
    scrolledComp.setMinHeight(300);
    scrolledComp.setMinWidth(800);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ApplyServerInfo(com.cubrid.cubridmanager.core.broker.model.ApplyServerInfo) IMenuListener(org.eclipse.jface.action.IMenuListener) GridLayout(org.eclipse.swt.layout.GridLayout) BrokerTblColumnSetHelp(com.cubrid.cubridmanager.ui.broker.editor.internal.BrokerTblColumnSetHelp) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 20 with IMenuListener

use of org.eclipse.jface.action.IMenuListener in project cubrid-manager by CUBRID.

the class MonitorDashboardEditor method configureGraphicalViewer.

/**
	 * @see org.eclipse.gef.ui.parts.GraphicalEditor.configureGraphicalViewer
	 */
protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();
    GraphicalViewer viewer = getGraphicalViewer();
    ScalableFreeformRootEditPart rootEditPart = new ScalableFreeformRootEditPart();
    viewer.setRootEditPart(rootEditPart);
    viewer.setEditPartFactory(new MonitorEditPartFacotry());
    ZoomManager manager = rootEditPart.getZoomManager();
    double[] zoomLevels = new double[] { 1.0, 1.2, 1.4, 1.6, 1.8, 2.0 };
    manager.setZoomLevels(zoomLevels);
    getActionRegistry().registerAction(new ZoomInAction(manager));
    getActionRegistry().registerAction(new ZoomOutAction(manager));
    KeyHandler keyHandler = new GefViewerKeyHandler(viewer);
    keyHandler.put(KeyStroke.getReleased('', 97, SWT.CONTROL), getActionRegistry().getAction(ActionFactory.SELECT_ALL.getId()));
    keyHandler.put(KeyStroke.getPressed('+', SWT.KEYPAD_ADD, 0), getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));
    keyHandler.put(KeyStroke.getPressed('-', SWT.KEYPAD_SUBTRACT, 0), getActionRegistry().getAction(GEFActionConstants.ZOOM_OUT));
    viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.CTRL), MouseWheelZoomHandler.SINGLETON);
    viewer.setKeyHandler(keyHandler);
    //initialize context menu
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {

        /**
			 * get menus to show.
			 * 
			 * @param manager IMenuManager
			 */
        public void menuAboutToShow(IMenuManager manager) {
            IStructuredSelection selection = (IStructuredSelection) getGraphicalViewer().getSelection();
            String[] ids = new String[] {};
            if (null == selection || selection.isEmpty() || selection.getFirstElement() instanceof DashboardPart) {
                manager.add(getActionRegistry().getAction(ActionFactory.SELECT_ALL.getId()));
                ids = new String[] { AddHostMonitorAction.ID, SEPARATOR, DashboardRefreshAction.ID };
            } else if (selection.getFirstElement() instanceof HostMonitorPart) {
                ids = new String[] { MonitorDetailAction.ID, DeleteHostMonitorAction.ID, EditAliasNameAction.ID, SEPARATOR, //HARoleChangeAction.ID, SEPARATOR,
                HostDashboardHistoryAction.ID, AddDatabaseMonitorAction.ID, AddBrokerMonitorAction.ID, SEPARATOR, HideHostAction.ID, MinimizeFigureAction.ID, DashboardRefreshAction.ID };
            } else if (selection.getFirstElement() instanceof DatabaseMonitorPart) {
                ids = new String[] { MonitorDetailAction.ID, DeleteDatabaseMonitorAction.ID, EditAliasNameAction.ID, SEPARATOR, DbDashboardHistoryAction.ID, OpenApplyLogDBLogAction.ID, OpenCopyLogDBLogAction.ID, OpenDatabaseLogAction.ID, SEPARATOR, ShowHostAction.ID, MinimizeFigureAction.ID, DashboardRefreshAction.ID };
            } else if (selection.getFirstElement() instanceof BrokerMonitorPart) {
                ids = new String[] { MonitorDetailAction.ID, DeleteBrokerMonitorAction.ID, EditAliasNameAction.ID, SEPARATOR, ShowBrokerClientAction.ID, ShowBrokerDabaseAction.ID, SEPARATOR, ShowHostAction.ID, MinimizeFigureAction.ID, DashboardRefreshAction.ID };
            } else if (selection.getFirstElement() instanceof ClientMonitorPart) {
                ids = new String[] { EditAliasNameAction.ID };
            } else if (selection.getFirstElement() instanceof BrokerDBListMonitorPart) {
                ids = new String[] { EditAliasNameAction.ID };
            }
            for (String id : ids) {
                if (id.equals(SEPARATOR)) {
                    manager.add(new Separator());
                } else {
                    IAction action = ActionManager.getInstance().getAction(id);
                    ((ISelectionAction) action).setSelectionProvider(getGraphicalViewer());
                    ActionManager.addActionToManager(manager, action);
                }
            }
            manager.update(true);
        }
    });
    viewer.setContextMenu(menuManager);
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) BrokerDBListMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.BrokerDBListMonitorPart) IAction(org.eclipse.jface.action.IAction) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) BrokerMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.BrokerMonitorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) HostMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.HostMonitorPart) IMenuListener(org.eclipse.jface.action.IMenuListener) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) ClientMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.ClientMonitorPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) DashboardPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.DashboardPart) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) DatabaseMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.DatabaseMonitorPart) MonitorEditPartFacotry(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.MonitorEditPartFacotry) KeyHandler(org.eclipse.gef.KeyHandler) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction) Separator(org.eclipse.jface.action.Separator)

Aggregations

IMenuListener (org.eclipse.jface.action.IMenuListener)48 IMenuManager (org.eclipse.jface.action.IMenuManager)48 MenuManager (org.eclipse.jface.action.MenuManager)47 Menu (org.eclipse.swt.widgets.Menu)43 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 Separator (org.eclipse.jface.action.Separator)9 GridData (org.eclipse.swt.layout.GridData)8 Action (org.eclipse.jface.action.Action)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 IAction (org.eclipse.jface.action.IAction)5 TreeViewer (org.eclipse.jface.viewers.TreeViewer)5 FocusEvent (org.eclipse.swt.events.FocusEvent)5 Composite (org.eclipse.swt.widgets.Composite)5 List (java.util.List)4 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4 TreeColumn (org.eclipse.swt.widgets.TreeColumn)4 TableViewer (org.eclipse.jface.viewers.TableViewer)3 ITreeContextualAction (org.talend.commons.ui.swt.actions.ITreeContextualAction)3 ConfigureColumnsAction (org.talend.designer.runtime.visualization.internal.actions.ConfigureColumnsAction)3 CopyAction (org.talend.designer.runtime.visualization.internal.actions.CopyAction)3