Example usage for org.eclipse.jface.action IContributionManager add

List of usage examples for org.eclipse.jface.action IContributionManager add

Introduction

In this page you can find the example usage for org.eclipse.jface.action IContributionManager add.

Prototype

void add(IContributionItem item);

Source Link

Document

Adds a contribution item to this manager.

Usage

From source file:org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage.java

License:Open Source License

/**
 * Configures (or reconfigures) the page according to the given
 * configuration.//from  w ww.  j  av a2s.c  om
 * 
 * @param configuration
 */
public void setConfiguration(ContentOutlineConfiguration configuration) {
    // intentionally do not check to see if the new configuration != old
    // configuration
    if (getTreeViewer() != null) {
        // remove the key listeners
        if (getControl() != null && !getControl().isDisposed()) {
            KeyListener[] listeners = getConfiguration().getKeyListeners(getTreeViewer());
            if (listeners != null) {
                for (int i = 0; i < listeners.length; i++) {
                    getControl().removeKeyListener(listeners[i]);
                }
            }
        }

        IContributionManager toolbar = getSite().getActionBars().getToolBarManager();
        if (toolbar != null) {
            IContributionItem[] toolbarItems = getConfiguration().getToolbarContributions(getTreeViewer());
            if (toolbarItems != null && toolbarItems.length > 0) {
                for (int i = 0; i < toolbarItems.length; i++) {
                    toolbar.remove(toolbarItems[i]);
                }
                toolbar.update(false);
            }
        }

        IContributionManager menubar = getSite().getActionBars().getMenuManager();
        if (menubar != null) {
            IContributionItem[] menuItems = getConfiguration().getMenuContributions(getTreeViewer());
            if (menuItems != null && menuItems.length > 0) {
                for (int i = 0; i < menuItems.length; i++) {
                    menubar.remove(menuItems[i]);
                }
                menubar.remove(IWorkbenchActionConstants.MB_ADDITIONS);
                menubar.update(false);
            }
        }
        // clear the DnD listeners and transfer types
        if (fDragAdapter != null && !fDragAdapter.isEmpty() && fDragSource != null && !fDragSource.isDisposed()
                && fDragSource.getTransfer().length > 0) {
            if (fActiveDragListeners != null) {
                for (int i = 0; i < fActiveDragListeners.length; i++) {
                    fDragAdapter.removeDragSourceListener(fActiveDragListeners[i]);
                }
            }
            fActiveDragListeners = null;
            fDragSource.removeDragListener(fDragAdapter);
            fDragSource.setTransfer(new Transfer[0]);
        }
        if (fDropAdapter != null && !fDropAdapter.isEmpty() && fDropTarget != null && !fDropTarget.isDisposed()
                && fDropTarget.getTransfer().length > 0) {
            if (fActiveDropListeners != null) {
                for (int i = 0; i < fActiveDropListeners.length; i++) {
                    fDropAdapter.removeDropTargetListener(fActiveDropListeners[i]);
                }
            }
            fActiveDropListeners = null;
            fDropTarget.removeDropListener(fDropAdapter);
            fDropTarget.setTransfer(new Transfer[0]);
        }
        getConfiguration().getContentProvider(getTreeViewer()).inputChanged(getTreeViewer(), fInput, null);
        // release any ties to this tree viewer
        getConfiguration().unconfigure(getTreeViewer());
    }

    fConfiguration = configuration;

    if (getTreeViewer() != null && getControl() != null && !getControl().isDisposed()) {
        // (re)set the providers
        getTreeViewer().setLabelProvider(getConfiguration().getLabelProvider(getTreeViewer()));
        getTreeViewer().setContentProvider(getConfiguration().getContentProvider(getTreeViewer()));

        // view toolbar
        IContributionManager toolbar = getSite().getActionBars().getToolBarManager();
        if (toolbar != null) {
            IContributionItem[] toolbarItems = getConfiguration().getToolbarContributions(getTreeViewer());
            if (toolbarItems != null) {
                for (int i = 0; i < toolbarItems.length; i++) {
                    toolbar.add(toolbarItems[i]);
                }
                toolbar.update(true);
            }
        }
        // view menu
        IContributionManager menu = getSite().getActionBars().getMenuManager();
        if (menu != null) {
            IContributionItem[] menuItems = getConfiguration().getMenuContributions(getTreeViewer());
            if (menuItems != null) {
                for (int i = 0; i < menuItems.length; i++) {
                    menuItems[i].setVisible(true);
                    menu.add(menuItems[i]);
                    menuItems[i].update();
                }
                menu.update(true);
            }
        }
        // add the allowed DnD listeners and types
        TransferDragSourceListener[] dragListeners = getConfiguration()
                .getTransferDragSourceListeners(getTreeViewer());
        if (fDragAdapter != null && dragListeners.length > 0) {
            for (int i = 0; i < dragListeners.length; i++) {
                fDragAdapter.addDragSourceListener(dragListeners[i]);
            }
            fActiveDragListeners = dragListeners;
            fDragSource.addDragListener(fDragAdapter);
            fDragSource.setTransfer(fDragAdapter.getTransfers());
        }
        TransferDropTargetListener[] dropListeners = getConfiguration()
                .getTransferDropTargetListeners(getTreeViewer());
        if (fDropAdapter != null && dropListeners.length > 0) {
            for (int i = 0; i < dropListeners.length; i++) {
                fDropAdapter.addDropTargetListener(dropListeners[i]);
            }
            fActiveDropListeners = dropListeners;
            fDropTarget.addDropListener(fDropAdapter);
            fDropTarget.setTransfer(fDropAdapter.getTransfers());
        }
        // add the key listeners
        KeyListener[] listeners = getConfiguration().getKeyListeners(getTreeViewer());
        if (listeners != null) {
            for (int i = 0; i < listeners.length; i++) {
                getControl().addKeyListener(listeners[i]);
            }
        }
    }

    if (fInput != null) {
        setInput(fInput);
    }
}

From source file:org.eclipse.wst.xml.ui.tests.viewer.ViewerTestXML.java

License:Open Source License

protected void addActions(IContributionManager mgr) {
    if (mgr != null) {
        mgr.add(new Action() {
            public String getText() {
                return getToolTipText();
            }/*  w  ww .  j  a  va2  s  .  c o  m*/

            public String getToolTipText() {
                return "New XML";
            }

            public void run() {
                super.run();
                BusyIndicator.showWhile(getSite().getShell().getDisplay(), new Runnable() {
                    public void run() {
                        setupViewerForNew();
                        fSourceViewer.setEditable(true);
                    }
                });
            }
        });
        mgr.add(new Separator());
        mgr.add(new Action() {
            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Change Visibility";
            }

            public void run() {
                super.run();
                NumberInputDialog dlg = new NumberInputDialog(fSourceViewer.getControl().getShell());
                int proceed = dlg.open();
                if (proceed == Window.CANCEL)
                    return;
                fSourceViewer.resetVisibleRegion();
                fSourceViewer.setVisibleRegion(dlg.startValue, dlg.lengthValue);
            }
        });
        mgr.add(new Action() {
            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Show All";
            }

            public void run() {
                super.run();
                fSourceViewer.resetVisibleRegion();
            }
        });
        mgr.add(new Separator());
        mgr.add(new Action() {
            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Change Visibility in Editor";
            }

            public void run() {
                super.run();
                StructuredTextViewer sourceViewer = null;
                IEditorPart part = getViewSite().getWorkbenchWindow().getActivePage().getActiveEditor();
                if (part != null && part instanceof StructuredTextEditor) {
                    sourceViewer = ((StructuredTextEditor) part).getTextViewer();
                }
                if (sourceViewer != null) {
                    NumberInputDialog dlg = new NumberInputDialog(sourceViewer.getControl().getShell());
                    int proceed = dlg.open();
                    if (proceed == Window.CANCEL)
                        return;
                    sourceViewer.resetVisibleRegion();
                    sourceViewer.setVisibleRegion(dlg.startValue, dlg.lengthValue);
                }
            }
        });
        mgr.add(new Action() {
            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Show All in Editor";
            }

            public void run() {
                super.run();
                StructuredTextViewer sourceViewer = null;
                IEditorPart part = getViewSite().getWorkbenchWindow().getActivePage().getActiveEditor();
                if (part != null && part instanceof StructuredTextEditor) {
                    sourceViewer = ((StructuredTextEditor) part).getTextViewer();
                }
                if (sourceViewer != null) {
                    sourceViewer.resetVisibleRegion();
                }
            }
        });
        mgr.add(new Separator());
        // no longer able to set input to NULL
        // mgr.add(new Action() {
        // public String getText() {
        // return getToolTipText();
        // }
        //
        // public String getToolTipText() {
        // return "Set Input to NULL";
        // }
        // public void run() {
        // super.run();
        // viewer.setInput(null);
        // }
        // });
        mgr.add(new Action() {
            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Take Input from Active Editor";
            }

            public void run() {
                super.run();
                ITextEditor textEditor = getActiveEditor();
                if (textEditor != null) {
                    setupViewerForEditor(textEditor);
                    fSourceViewer.setEditable(true);
                }
            }
        });
        mgr.add(new Action() {
            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Take Input and Follow Selection";
            }

            public void run() {
                super.run();
                followSelection();
                fSourceViewer.setEditable(true);
            }
        });
        mgr.add(new Action() {
            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Take Input and Follow Selection As ReadOnly";
            }

            public void run() {
                super.run();
                followSelection();
                fSourceViewer.setEditable(false);
            }
        });
        mgr.add(new Action() {
            public String getText() {
                return getToolTipText();
            }

            public String getToolTipText() {
                return "Stop Following Selection";
            }

            public void run() {
                super.run();
                stopFollowSelection();
            }
        });
    }
}

From source file:org.fusesource.ide.foundation.ui.util.Menus.java

License:Open Source License

/**
 * Adds the action or contribution item to the menu only if its not already been added
 *///from  w  w w  . j a va2  s .c  o m
public static void addAction(IContributionManager manager, Object actionOrContributionItem) {
    if (actionOrContributionItem instanceof IAction) {
        IAction action = (IAction) actionOrContributionItem;
        String id = getActionId(action);
        if (id == null || manager.find(id) != null) {
            return;
        }
        manager.add(action);
    } else if (actionOrContributionItem instanceof IContributionItem) {
        IContributionItem contributionItem = (IContributionItem) actionOrContributionItem;
        String id = getContributionItemId(contributionItem);
        if (id == null || manager.find(id) != null) {
            return;
        }
        manager.add(contributionItem);
    }
}

From source file:org.jcryptool.analysis.substitution.views.SubstitutionAnalysisView.java

License:Open Source License

private void addContributionItem(IContributionManager manager, final String commandId,
        final ImageDescriptor icon, final String tooltip) {
    CommandContributionItemParameter param = new CommandContributionItemParameter(serviceLocator, null,
            commandId, SWT.PUSH);/*from   w  w w.  j  av  a  2s.c  o  m*/
    if (icon != null)
        param.icon = icon;
    if (tooltip != null && !tooltip.equals(""))
        param.tooltip = tooltip;
    CommandContributionItem item = new CommandContributionItem(param);
    manager.add(item);
}

From source file:org.jcryptool.visual.crtverification.views.CrtVerViewComposite.java

License:Open Source License

private void addContributionItem(IContributionManager manager, final String commandId,
        final ImageDescriptor icon, final String tooltip) {
    CommandContributionItemParameter param = new CommandContributionItemParameter(PlatformUI.getWorkbench(),
            null, commandId, SWT.PUSH);//w w w . j a  va 2s  .  c  o m
    if (icon != null)
        param.icon = icon;
    if (tooltip != null && !tooltip.equals(""))
        param.tooltip = tooltip;
    CommandContributionItem item = new CommandContributionItem(param);
    manager.add(item);
}

From source file:org.jcryptool.visual.ECDH.ui.view.ECDHComposite.java

License:Open Source License

private void addContributionItem(IContributionManager manager, final String commandId,
        final ImageDescriptor icon, final String tooltip, int Style) {
    CommandContributionItemParameter param = new CommandContributionItemParameter(serviceLocator, null,
            commandId, Style);// w ww .j  av a2s  .co m
    if (icon != null)
        param.icon = icon;
    if (tooltip != null && !tooltip.equals(""))
        param.tooltip = tooltip;
    CommandContributionItem item = new CommandContributionItem(param);
    manager.add(item);
}

From source file:org.jcryptool.visual.sigVerification.ui.view.ModelComposite.java

License:Open Source License

private void addContributionItem(IContributionManager manager, final String commandId,
        final ImageDescriptor icon, final String tooltip, int Style) {
    CommandContributionItemParameter param = new CommandContributionItemParameter(PlatformUI.getWorkbench(),
            null, commandId, Style);
    if (icon != null)
        param.icon = icon;// w w  w.j  av  a  2  s . c o  m
    if (tooltip != null && !tooltip.equals(""))
        param.tooltip = tooltip;
    CommandContributionItem item = new CommandContributionItem(param);
    manager.add(item);
}

From source file:org.jkiss.dbeaver.ext.db2.editors.DB2RoutineDDLEditor.java

License:Apache License

@Override
protected void contributeEditorCommands(IContributionManager contributionManager) {
    super.contributeEditorCommands(contributionManager);

    contributionManager.add(new Separator());
    contributionManager.add(new ControlContribution("DDLFormat") {
        @Override/*from   w w w  . ja  va  2  s .  c om*/
        protected Control createControl(Composite parent) {
            DB2DDLFormat ddlFormat = DB2DDLFormat.getCurrentFormat(getSourceObject().getDataSource());
            final Combo ddlFormatCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN);
            ddlFormatCombo.setToolTipText("DDL Format");
            for (DB2DDLFormat format : DB2DDLFormat.values()) {
                ddlFormatCombo.add(format.getTitle());
                if (format == ddlFormat) {
                    ddlFormatCombo.select(ddlFormatCombo.getItemCount() - 1);
                }
            }

            ddlFormatCombo.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    for (DB2DDLFormat format : DB2DDLFormat.values()) {
                        if (format.ordinal() == ddlFormatCombo.getSelectionIndex()) {
                            getEditorInput().getDatabaseObject().getDataSource().getContainer()
                                    .getPreferenceStore()
                                    .setValue(DB2Constants.PREF_KEY_DDL_FORMAT, format.name());
                            refreshPart(this, true);
                            break;
                        }
                    }
                }
            });
            return ddlFormatCombo;
        }
    });
}

From source file:org.jkiss.dbeaver.ext.db2.model.app.DB2ServerApplicationEditor.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    forceApplicationAction = new ForceApplicationAction();
    applicationViewer = new SessionManagerViewer(this, parent,
            new DB2ServerApplicationManager((DB2DataSource) getExecutionContext())) {

        @Override// w w  w  . j  av  a2  s .co  m
        @SuppressWarnings("rawtypes")
        protected void contributeToToolbar(DBAServerSessionManager sessionManager,
                IContributionManager contributionManager) {
            contributionManager.add(forceApplicationAction);
            contributionManager.add(new Separator());
        }

        @Override
        protected void onSessionSelect(DBAServerSession session) {
            super.onSessionSelect(session);
            forceApplicationAction.setEnabled(session != null);
        }
    };

    applicationViewer.refreshSessions();
}

From source file:org.jkiss.dbeaver.ext.exasol.editors.ExasolLockEditor.java

License:Apache License

@SuppressWarnings("unchecked")
@Override/*from  w ww .j  a v a  2  s  . c  o  m*/
protected LockManagerViewer createLockViewer(DBCExecutionContext executionContext, Composite parent) {
    @SuppressWarnings("rawtypes")
    DBAServerLockManager<DBAServerLock, DBAServerLockItem> lockManager = (DBAServerLockManager) new ExasolLockManager(
            (ExasolDataSource) executionContext.getDataSource());

    return new LockManagerViewer(this, parent, lockManager) {
        @Override
        protected void contributeToToolbar(
                DBAServerLockManager<DBAServerLock, DBAServerLockItem> sessionManager,
                IContributionManager contributionManager) {
            contributionManager.add(new Separator());
        }

        @SuppressWarnings("serial")
        @Override
        protected void onLockSelect(final DBAServerLock lock) {
            super.onLockSelect(lock);
            if (lock != null) {
                final ExasolLock pLock = (ExasolLock) lock;
                super.refreshDetail(new HashMap<String, Object>() {
                    {
                        put(sidHold, BigInteger.valueOf(pLock.getHold_sid()));
                        put(sidWait, BigInteger.valueOf(pLock.getWait_sid().longValue()));
                    }
                });
            }
        }
    };
}