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.wb.internal.core.model.util.factory.FactoryActionsSupport.java

License:Open Source License

/**
 * Adds {@link FactoryApplyAction}'s from given factory type.
 *//*from   w w w  .ja  va 2 s  .com*/
private void addApplyActions(IContributionManager manager, String typeName) throws Exception {
    ClassLoader classLoader = EditorState.get(m_editor).getEditorLoader();
    Class<?> factoryClass = classLoader.loadClass(typeName);
    Collection<FactoryMethodDescription> descriptions = FactoryDescriptionHelper
            .getDescriptionsMap(m_editor, factoryClass, true).values();
    for (FactoryMethodDescription description : descriptions) {
        Class<?> componentClass = m_component.getDescription().getComponentClass();
        if (componentClass.isAssignableFrom(description.getReturnClass())) {
            manager.add(new FactoryApplyAction(m_component, description));
        }
    }
}

From source file:org.eclipse.wb.internal.layout.group.model.AnchorsSupport.java

License:Open Source License

public void fillContributionManager(AbstractComponentInfo component, IContributionManager manager,
        boolean isHorizontal) {
    if (isHorizontal) {
        manager.add(new SetAnchorAction(component, Messages.AnchorsSupport_anchoredLeft, "h/menu/left.gif",
                true, LEADING));//from   ww w.  j  av a2 s  .  c  om
        manager.add(new SetAnchorAction(component, Messages.AnchorsSupport_anchoredRight, "h/menu/right.gif",
                true, TRAILING));
        manager.add(new MakeResizeableAction(component, "h/menu/both.gif", isHorizontal));
    } else {
        manager.add(new SetAnchorAction(component, Messages.AnchorsSupport_anchoredTop, "v/menu/top.gif", false,
                LEADING));
        manager.add(new SetAnchorAction(component, Messages.AnchorsSupport_anchoredBottom, "v/menu/bottom.gif",
                false, TRAILING));
        manager.add(new MakeResizeableAction(component, "v/menu/both.gif", isHorizontal));
    }
}

From source file:org.eclipse.wb.internal.swt.model.layout.form.actions.PredefinedAnchorsActions.java

License:Open Source License

public void contributeActions(List<C> selection, IContributionManager manager) {
    manager.add(new SetCornerAnchorsAction<C>(selection, ModelMessages.PredefinedAnchorsActions_topLeft,
            "top_left.gif", IPositionConstants.LEFT | IPositionConstants.TOP));
    manager.add(new SetCornerAnchorsAction<C>(selection, ModelMessages.PredefinedAnchorsActions_topRight,
            "top_right.gif", IPositionConstants.TOP | IPositionConstants.RIGHT));
    manager.add(new SetCornerAnchorsAction<C>(selection, ModelMessages.PredefinedAnchorsActions_bottomLeft,
            "bottom_left.gif", IPositionConstants.LEFT | IPositionConstants.BOTTOM));
    manager.add(new SetCornerAnchorsAction<C>(selection, ModelMessages.PredefinedAnchorsActions_bottomRight,
            "bottom_right.gif", IPositionConstants.BOTTOM | IPositionConstants.RIGHT));
    manager.add(new Separator());
    manager.add(new SetCornerAnchorsAction<C>(selection, ModelMessages.PredefinedAnchorsActions_leftRightTop,
            "top_left_right.gif", IPositionConstants.LEFT | IPositionConstants.TOP | IPositionConstants.RIGHT));
    manager.add(new SetCornerAnchorsAction<C>(selection, ModelMessages.PredefinedAnchorsActions_leftRightBottom,
            "bottom_left_right.gif",
            IPositionConstants.LEFT | IPositionConstants.BOTTOM | IPositionConstants.RIGHT));
    manager.add(new SetCornerAnchorsAction<C>(selection, ModelMessages.PredefinedAnchorsActions_topBottomLeft,
            "top_bottom_left.gif",
            IPositionConstants.TOP | IPositionConstants.LEFT | IPositionConstants.BOTTOM));
    manager.add(new SetCornerAnchorsAction<C>(selection, ModelMessages.PredefinedAnchorsActions_topBottomRight,
            "top_bottom_right.gif",
            IPositionConstants.BOTTOM | IPositionConstants.RIGHT | IPositionConstants.TOP));
    manager.add(new Separator());
    manager.add(/*w  ww  .  ja  va2  s  .  com*/
            new SetCornerAnchorsAction<C>(selection, ModelMessages.PredefinedAnchorsActions_TopBottomLeftRight,
                    "top_bottom_left_right.gif", IPositionConstants.BOTTOM | IPositionConstants.RIGHT
                            | IPositionConstants.TOP | IPositionConstants.LEFT));
    manager.add(new Separator());
    manager.add(new SetCornerAnchorsAction<C>(selection, ModelMessages.PredefinedAnchorsActions_topLeftRelative,
            "top_left_relative.gif", IPositionConstants.TOP | IPositionConstants.LEFT, true));
    manager.add(
            new SetCornerAnchorsAction<C>(selection, ModelMessages.PredefinedAnchorsActions_topRightRelative,
                    "top_right_relative.gif", IPositionConstants.TOP | IPositionConstants.RIGHT, true));
    manager.add(
            new SetCornerAnchorsAction<C>(selection, ModelMessages.PredefinedAnchorsActions_bottomLeftRelative,
                    "bottom_left_relative.gif", IPositionConstants.LEFT | IPositionConstants.BOTTOM, true));
    manager.add(
            new SetCornerAnchorsAction<C>(selection, ModelMessages.PredefinedAnchorsActions_bottomRightRelative,
                    "bottom_right_relative.gif", IPositionConstants.BOTTOM | IPositionConstants.RIGHT, true));
    manager.add(new Separator());
    manager.add(new SetCornerAnchorsAction<C>(selection,
            ModelMessages.PredefinedAnchorsActions_topLeftRightRelative, "top_left_right_relative.gif",
            IPositionConstants.TOP | IPositionConstants.LEFT | IPositionConstants.RIGHT, true));
    manager.add(new SetCornerAnchorsAction<C>(selection,
            ModelMessages.PredefinedAnchorsActions_bottomLeftRightRelative, "bottom_left_right_relative.gif",
            IPositionConstants.BOTTOM | IPositionConstants.LEFT | IPositionConstants.RIGHT, true));
    manager.add(new SetCornerAnchorsAction<C>(selection,
            ModelMessages.PredefinedAnchorsActions_topBottomRightRelative, "top_bottom_right_relative.gif",
            IPositionConstants.BOTTOM | IPositionConstants.TOP | IPositionConstants.RIGHT, true));
    manager.add(new SetCornerAnchorsAction<C>(selection,
            ModelMessages.PredefinedAnchorsActions_topBottomLeftRelative, "top_bottom_left_relative.gif",
            IPositionConstants.BOTTOM | IPositionConstants.TOP | IPositionConstants.LEFT, true));
}

From source file:org.eclipse.wb.internal.swt.model.layout.form.LayoutAssistantPage.java

License:Open Source License

private void fillAlignmentActions(final IContributionManager manager) {
    ArrayList<Object> actions = Lists.newArrayList();
    new FormLayoutEditPolicy.FormLayoutAlignmentActionsSupport<C>(m_layout, m_placementsSupport)
            .addAlignmentActions(GenericsUtils.<ObjectInfo>cast(m_selection), actions);
    for (Object action : actions) {
        if (action instanceof IContributionItem) {
            manager.add((IContributionItem) action);
        } else if (action instanceof IAction) {
            manager.add((IAction) action);
        }//from   w  w  w  .j a v a 2s .co  m
    }
}

From source file:org.eclipse.wb.internal.swt.model.layout.form.LayoutAssistantPage.java

License:Open Source License

private void fillComplexAnchorsActions(IContributionManager manager) {
    manager.add(new SetCornerAnchorsAction(m_selection, ModelMessages.LayoutAssistantPage_alignmentTopLeft,
            "assistant/top_left.gif", IPositionConstants.LEFT | IPositionConstants.TOP));
    manager.add(new SetCornerAnchorsAction(m_selection, ModelMessages.LayoutAssistantPage_alignmentTopRight,
            "assistant/top_right.gif", IPositionConstants.TOP | IPositionConstants.RIGHT));
    manager.add(new SetCornerAnchorsAction(m_selection, ModelMessages.LayoutAssistantPage_alignmentBottomLeft,
            "assistant/bottom_left.gif", IPositionConstants.LEFT | IPositionConstants.BOTTOM));
    manager.add(new SetCornerAnchorsAction(m_selection, ModelMessages.LayoutAssistantPage_alignmentBottomRight,
            "assistant/bottom_right.gif", IPositionConstants.BOTTOM | IPositionConstants.RIGHT));
    manager.add(new Separator());
    manager.add(new SetCornerAnchorsAction(m_selection, ModelMessages.LayoutAssistantPage_alignmentLeftRightTop,
            "assistant/top_left_right.gif",
            IPositionConstants.LEFT | IPositionConstants.TOP | IPositionConstants.RIGHT));
    manager.add(new SetCornerAnchorsAction(m_selection,
            ModelMessages.LayoutAssistantPage_alignmentLeftRightBottom, "assistant/bottom_left_right.gif",
            IPositionConstants.LEFT | IPositionConstants.BOTTOM | IPositionConstants.RIGHT));
    manager.add(new SetCornerAnchorsAction(m_selection,
            ModelMessages.LayoutAssistantPage_alignmentTopBottomLeft, "assistant/top_bottom_left.gif",
            IPositionConstants.TOP | IPositionConstants.LEFT | IPositionConstants.BOTTOM));
    manager.add(new SetCornerAnchorsAction(m_selection,
            ModelMessages.LayoutAssistantPage_alignmentTopLBottomRight, "assistant/top_bottom_right.gif",
            IPositionConstants.BOTTOM | IPositionConstants.RIGHT | IPositionConstants.TOP));
    manager.add(new SetCornerAnchorsAction(m_selection, ModelMessages.LayoutAssistantPage_alignmentAll,
            "assistant/top_bottom_left_right.gif", IPositionConstants.BOTTOM | IPositionConstants.RIGHT
                    | IPositionConstants.TOP | IPositionConstants.LEFT));
}

From source file:org.eclipse.wb.internal.swt.model.layout.form.LayoutAssistantPageClassic.java

License:Open Source License

private void fillAlignmentActions(ArrayList<Object> actions, IContributionManager manager) {
    for (Object action : actions) {
        if (action instanceof IContributionItem) {
            manager.add((IContributionItem) action);
        } else if (action instanceof IAction) {
            manager.add((IAction) action);
        }//from w w  w .  j a  va  2 s . com
    }
}

From source file:org.eclipse.wst.dtd.ui.tests.viewer.ViewerTestDTD.java

License:Open Source License

protected void addActions(IContributionManager mgr) {
    if (mgr != null) {
        mgr.add(new Action() {
            public String getText() {
                return getToolTipText();
            }//from   w  ww  .j  a  v  a 2 s.com

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

            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 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 fInput 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.eclipse.wst.html.ui.tests.viewer.ViewerTestHTML.java

License:Open Source License

protected void addActions(IContributionManager mgr) {
    if (mgr != null) {
        mgr.add(new Action() {
            public String getText() {
                return getToolTipText();
            }// w w w. jav a  2s.c om

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

            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.eclipse.wst.server.ui.internal.cnf.ServerActionProvider.java

License:Open Source License

public void fillActionBars(IActionBars actionBars) {
    actionBars.setGlobalActionHandler("org.eclipse.wst.server.debug", actions[0]);
    actionBars.setGlobalActionHandler("org.eclipse.wst.server.run", actions[1]);
    actionBars.setGlobalActionHandler("org.eclipse.wst.server.stop", actions[3]);
    actionBars.setGlobalActionHandler("org.eclipse.wst.server.publish", actions[4]);
    actionBars.setGlobalActionHandler("org.eclipse.ui.navigator.Open", openAction);
    actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), propertiesAction);
    actionBars.updateActionBars();/*from   w ww .  ja  v a2s. c  o m*/
    actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction);
    actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), pasteAction);
    actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), globalDeleteAction);
    actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), renameAction);

    IContributionManager cm = actionBars.getToolBarManager();
    IContributionItem[] cis = cm.getItems();
    List<IAction> existingActions = new ArrayList<IAction>();
    for (IContributionItem ci : cis) {
        if (ci instanceof ActionContributionItem) {
            ActionContributionItem aci = (ActionContributionItem) ci;
            existingActions.add(aci.getAction());
        }
    }

    for (int i = 0; i < actions.length - 1; i++)
        if (!existingActions.contains(actions[i]))
            cm.add(actions[i]);

}

From source file:org.eclipse.wst.server.ui.internal.view.servers.ServersView.java

License:Open Source License

/**
 * Initialize actions/*from   w ww .j  a va  2  s . c om*/
 * 
 * @param provider a selection provider
 */
public void initializeActions(ISelectionProvider provider) {
    Shell shell = getSite().getShell();
    IActionBars actionBars = getViewSite().getActionBars();

    actions = new Action[6];
    // create the start actions
    actions[0] = new StartAction(shell, provider, ILaunchManager.DEBUG_MODE);
    actionBars.setGlobalActionHandler("org.eclipse.wst.server.debug", actions[0]);
    actions[1] = new StartAction(shell, provider, ILaunchManager.RUN_MODE);
    actionBars.setGlobalActionHandler("org.eclipse.wst.server.run", actions[1]);
    actions[2] = new StartAction(shell, provider, ILaunchManager.PROFILE_MODE);

    // create the stop action
    actions[3] = new StopAction(shell, provider);
    actionBars.setGlobalActionHandler("org.eclipse.wst.server.stop", actions[3]);

    // create the publish actions
    actions[4] = new PublishAction(shell, provider);
    actionBars.setGlobalActionHandler("org.eclipse.wst.server.publish", actions[4]);
    actions[5] = new PublishCleanAction(shell, provider);

    // create the open action
    openAction = new OpenAction(provider);
    actionBars.setGlobalActionHandler("org.eclipse.ui.navigator.Open", openAction);

    // create copy, paste, and delete actions
    pasteAction = new PasteAction(shell, provider, tableViewer.clipboard);
    copyAction = new CopyAction(provider, tableViewer.clipboard, pasteAction);
    deleteAction = new DeleteAction(shell, provider);
    // Create a second delete action that can act in modules, when the delete key is pressed
    // the old DeleteAction only works for servers see bug# 286960
    globalDeleteAction = new GlobalDeleteAction(shell, provider);
    renameAction = new RenameAction(shell, tableViewer, provider);
    actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction);
    actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), pasteAction);
    actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), globalDeleteAction);
    actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), renameAction);

    // create the other actions
    actionModifyModules = new ModuleSloshAction(shell, provider);
    showInConsoleAction = new ShowInConsoleAction(provider);
    showInDebugAction = new ShowInDebugAction(provider);

    // create the properties action
    propertiesAction = new PropertiesAction(shell, provider);
    actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), propertiesAction);
    monitorPropertiesAction = new PropertiesAction(shell, "org.eclipse.wst.server.ui.properties.monitor",
            provider);

    // add toolbar buttons
    IContributionManager cm = actionBars.getToolBarManager();
    for (int i = 0; i < actions.length - 1; i++)
        cm.add(actions[i]);

    cm.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}