Search in sources :

Example 31 with IMenuListener

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

the class QueryExecuter method registerInputMethodContextMenu.

/**
	 *
	 * Register input method context menu for styled text
	 *
	 * @param text StyledText
	 * @param isEditable boolean
	 */
public void registerInputMethodContextMenu(final StyledText text, final boolean isEditable, final String type, final TableItem item, final int column) {
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(text);
        }
    });
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
            if (copyAction instanceof CopyAction) {
                manager.add(copyAction);
                if (!copyAction.isEnabled()) {
                    FocusAction.changeActionStatus(copyAction, text);
                }
            }
            if (!isEditable) {
                return;
            }
            IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
            if (pasteAction instanceof PasteAction) {
                manager.add(pasteAction);
                if (!pasteAction.isEnabled()) {
                    FocusAction.changeActionStatus(pasteAction, text);
                }
            }
            IAction inputAction = ActionManager.getInstance().getAction(InputMethodAction.ID);
            if (inputAction instanceof InputMethodAction) {
                manager.add(inputAction);
                if (!inputAction.isEnabled()) {
                    FocusAction.changeActionStatus(inputAction, text);
                } else {
                    ((InputMethodAction) inputAction).setType(type);
                    ((InputMethodAction) inputAction).setTableItem(item);
                    ((InputMethodAction) inputAction).setColumn(column);
                    ((InputMethodAction) inputAction).setQueryExecuter(executer);
                }
                if (isEditMode()) {
                    inputAction.setEnabled(true);
                } else {
                    inputAction.setEnabled(false);
                }
            }
        }
    });
    Menu contextMenu = menuManager.createContextMenu(text);
    text.setMenu(contextMenu);
    text.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
            if (!copyAction.isEnabled()) {
                FocusAction.changeActionStatus(copyAction, text);
            }
            IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
            if (pasteAction != null && !pasteAction.isEnabled()) {
                FocusAction.changeActionStatus(pasteAction, text);
            }
            IAction inputAction = ActionManager.getInstance().getAction(InputMethodAction.ID);
            if (inputAction != null) {
                FocusAction.changeActionStatus(inputAction, text);
            }
        }
    });
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) IAction(org.eclipse.jface.action.IAction) CopyAction(com.cubrid.common.ui.query.action.CopyAction) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FocusEvent(org.eclipse.swt.events.FocusEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) PasteAction(com.cubrid.common.ui.query.action.PasteAction) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) InputMethodAction(com.cubrid.common.ui.query.action.InputMethodAction) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

Example 32 with IMenuListener

use of org.eclipse.jface.action.IMenuListener in project azure-tools-for-java by Microsoft.

the class QueueFileEditor method createTablePopUp.

private void createTablePopUp(Composite parent) {
    MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            if (tableViewer.getSelection().isEmpty()) {
                return;
            }
            if (tableViewer.getSelection() instanceof IStructuredSelection) {
                manager.add(fileEditorVirtualNode.createPopupAction(OPEN));
                Action action = fileEditorVirtualNode.createPopupAction(DEQUEUE);
                if (queueTable.getSelectionIndex() != 0) {
                    action.setEnabled(false);
                }
                manager.add(action);
            }
        }
    });
    Menu menu = menuMgr.createContextMenu(tableViewer.getControl());
    tableViewer.getControl().setMenu(menu);
}
Also used : Action(org.eclipse.jface.action.Action) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Menu(org.eclipse.swt.widgets.Menu) IMenuListener(org.eclipse.jface.action.IMenuListener)

Example 33 with IMenuListener

use of org.eclipse.jface.action.IMenuListener in project azure-tools-for-java by Microsoft.

the class ServiceExplorerView method hookContextMenu.

private void hookContextMenu() {
    MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            if (viewer.getSelection().isEmpty()) {
                return;
            }
            if (viewer.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
                Node node = ((TreeNode) selection.getFirstElement()).node;
                if (node.hasNodeActions()) {
                    for (final NodeAction nodeAction : node.getNodeActions()) {
                        ImageDescriptor imageDescriptor = nodeAction.getIconPath() != null ? Activator.getImageDescriptor("icons/" + nodeAction.getIconPath()) : null;
                        Action action = new Action(nodeAction.getName(), imageDescriptor) {

                            public void run() {
                                nodeAction.fireNodeActionEvent();
                            }
                        };
                        action.setEnabled(nodeAction.isEnabled());
                        manager.add(action);
                    }
                }
            }
        }
    });
    Menu menu = menuMgr.createContextMenu(viewer.getControl());
    viewer.getControl().setMenu(menu);
}
Also used : NodeAction(com.microsoft.tooling.msservices.serviceexplorer.NodeAction) Action(org.eclipse.jface.action.Action) NodeAction(com.microsoft.tooling.msservices.serviceexplorer.NodeAction) Node(com.microsoft.tooling.msservices.serviceexplorer.Node) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IMenuManager(org.eclipse.jface.action.IMenuManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Menu(org.eclipse.swt.widgets.Menu) IMenuListener(org.eclipse.jface.action.IMenuListener)

Example 34 with IMenuListener

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

the class BrokerStatusView method createAsTable.

/**
	 * Create app server table
	 * 
	 * @param comp the parent composite
	 * 
	 */
private void createAsTable(Composite comp) {
    Composite asComposite = new Composite(comp, SWT.NONE);
    GridData gdAs = new GridData(SWT.FILL, SWT.FILL, true, true);
    asComposite.setLayoutData(gdAs);
    asComposite.setLayout(new GridLayout());
    asTableViewer = new TableViewer(asComposite, SWT.FULL_SELECTION | SWT.NO_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    Table asTable = asTableViewer.getTable();
    asTable.setHeaderVisible(true);
    asTable.setLinesVisible(true);
    asTable.setLayoutData(gdAs);
    TableLayout asLayout = new TableLayout();
    setAsLayout(asLayout);
    asTable.setLayout(asLayout);
    TableColumn tblColumn = new TableColumn(asTable, SWT.CENTER);
    tblColumn.setText(Messages.tblAsId);
    tblColumn.setToolTipText(Messages.tblAsId);
    tblColumn = new TableColumn(asTable, SWT.CENTER);
    tblColumn.setText(Messages.tblAsProcess);
    tblColumn.setToolTipText(Messages.tblAsProcess);
    tblColumn = new TableColumn(asTable, SWT.CENTER);
    tblColumn.setText(Messages.tblAsQps);
    tblColumn.setToolTipText(Messages.tblAsQps);
    tblColumn = new TableColumn(asTable, SWT.CENTER);
    tblColumn.setText(Messages.tblAsLqs);
    tblColumn.setToolTipText(Messages.tblAsLqs);
    tblColumn = new TableColumn(asTable, SWT.CENTER);
    tblColumn.setText(Messages.tblAsPort);
    tblColumn.setToolTipText(Messages.tblAsPort);
    tblColumn = new TableColumn(asTable, SWT.CENTER);
    tblColumn.setText(Messages.tblAsSize);
    tblColumn.setToolTipText(Messages.tblAsSize);
    tblColumn = new TableColumn(asTable, SWT.CENTER);
    tblColumn.setText(Messages.tblAsStatus);
    tblColumn.setToolTipText(Messages.tblAsStatus);
    tblColumn = new TableColumn(asTable, SWT.CENTER);
    tblColumn.setText(Messages.tblAsDb);
    tblColumn.setToolTipText(Messages.tblAsDb);
    tblColumn = new TableColumn(asTable, SWT.CENTER);
    tblColumn.setText(Messages.tblAsHost);
    tblColumn.setToolTipText(Messages.tblAsHost);
    tblColumn = new TableColumn(asTable, SWT.CENTER);
    tblColumn.setText(Messages.tblAsLastAccess);
    tblColumn.setToolTipText(Messages.tblAsLastAccess);
    tblColumn = new TableColumn(asTable, SWT.CENTER);
    tblColumn.setText(Messages.tblAsLct);
    tblColumn.setToolTipText(Messages.tblAsLct);
    tblColumn = new TableColumn(asTable, SWT.CENTER);
    tblColumn.setText(Messages.tblAsClientIp);
    tblColumn.setToolTipText(Messages.tblAsClientIp);
    tblColumn = new TableColumn(asTable, SWT.CENTER);
    tblColumn.setText(Messages.tblAsCur);
    tblColumn.setToolTipText(Messages.tblAsCur);
    asTableViewer.setContentProvider(new ApplyServerContentProvider());
    asTableViewer.setLabelProvider(new ApplyServerLabelProvider());
    asTableViewer.setInput(asinfoLst);
    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);
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableColumn(org.eclipse.swt.widgets.TableColumn) ApplyServerInfo(com.cubrid.cubridmanager.core.broker.model.ApplyServerInfo) IMenuListener(org.eclipse.jface.action.IMenuListener) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) 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) TableLayout(org.eclipse.jface.viewers.TableLayout)

Example 35 with IMenuListener

use of org.eclipse.jface.action.IMenuListener in project tdi-studio-se by Talend.

the class BusinessAssignmentComposite method createPopupMenu.

private void createPopupMenu() {
    //$NON-NLS-1$
    MenuManager menuMgr = new MenuManager("#PopUp");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager mgr) {
            BusinessAssignment businessAssignment = getBusinessAssignment(tableViewer.getSelection());
            if (businessAssignment != null) {
                repositoryNode = createRepositoryNode(businessAssignment);
                if (repositoryNode != null) {
                    List<ITreeContextualAction> contextualsActions = ActionsHelper.getRepositoryContextualsActions();
                    for (ITreeContextualAction action : contextualsActions) {
                        if (action.isReadAction() || action.isEditAction() || action.isPropertiesAction()) {
                            action.init(null, new StructuredSelection(repositoryNode));
                            if (action.isVisible()) {
                                ((AContextualAction) action).setAvoidUnloadResources(true);
                                mgr.add(action);
                            }
                        }
                    }
                    if (ProjectManager.getInstance().isInCurrentMainProject(repositoryNode)) {
                        CorePlugin.getDefault().getDiagramModelService().addDeleteAssignmentAction(mgr, tableViewer.getSelection());
                    }
                }
            }
        }
    });
    Menu menu = menuMgr.createContextMenu(tableViewer.getControl());
    tableViewer.getControl().setMenu(menu);
}
Also used : BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) List(java.util.List) IMenuManager(org.eclipse.jface.action.IMenuManager) ITreeContextualAction(org.talend.commons.ui.swt.actions.ITreeContextualAction) Menu(org.eclipse.swt.widgets.Menu) IMenuListener(org.eclipse.jface.action.IMenuListener)

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