Search in sources :

Example 21 with ActionContributionItem

use of org.eclipse.jface.action.ActionContributionItem in project bndtools by bndtools.

the class ProjectRunPage method createFormContent.

@Override
protected void createFormContent(IManagedForm managedForm) {
    managedForm.setInput(model);
    FormToolkit tk = managedForm.getToolkit();
    final ScrolledForm form = managedForm.getForm();
    form.setText("Resolve/Run");
    Central.onWorkspaceInit(new Success<Workspace, Void>() {

        @Override
        public Promise<Void> call(Promise<Workspace> resolved) throws Exception {
            final Deferred<Void> completion = new Deferred<>();
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        updateFormImage(form);
                        completion.resolve(null);
                    } catch (Exception e) {
                        completion.fail(e);
                    }
                }
            });
            return completion.getPromise();
        }
    });
    tk.decorateFormHeading(form.getForm());
    form.getForm().addMessageHyperlinkListener(new MessageHyperlinkAdapter(getEditor()));
    // Toolbar Actions
    RunAction runAction = new RunAction(this, "run");
    runAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/run.gif"));
    runAction.setText("Run OSGi");
    ActionContributionItem runContrib = new ActionContributionItem(runAction);
    runContrib.setMode(ActionContributionItem.MODE_FORCE_TEXT);
    form.getToolBarManager().add(runContrib);
    RunAction debugAction = new RunAction(this, "debug");
    debugAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/debug.gif"));
    debugAction.setText("Debug OSGi");
    ActionContributionItem debugContrib = new ActionContributionItem(debugAction);
    debugContrib.setMode(ActionContributionItem.MODE_FORCE_TEXT);
    form.getToolBarManager().add(debugContrib);
    ExportAction exportAction = new ExportAction(getEditorSite().getShell(), getEditor(), model);
    exportAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/run_export.png"));
    exportAction.setText("Export");
    ActionContributionItem exportContrib = new ActionContributionItem(exportAction);
    exportContrib.setMode(ActionContributionItem.MODE_FORCE_TEXT);
    if (exportAction.shouldEnable())
        form.getToolBarManager().add(exportContrib);
    form.getToolBarManager().update(true);
    GridLayout gl;
    GridData gd;
    // Create Controls
    final Composite body = form.getBody();
    MDSashForm sashForm = new MDSashForm(body, SWT.HORIZONTAL, managedForm);
    sashForm.setSashWidth(6);
    tk.adapt(sashForm);
    final Composite left = tk.createComposite(sashForm);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    left.setLayoutData(gd);
    gl = new GridLayout(1, true);
    left.setLayout(gl);
    final Composite right = tk.createComposite(sashForm);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    right.setLayoutData(gd);
    gl = new GridLayout(1, true);
    right.setLayout(gl);
    // First column
    RepositorySelectionPart reposPart = new RepositorySelectionPart(getEditor(), left, tk, Section.TITLE_BAR | Section.TWISTIE);
    managedForm.addPart(reposPart);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 50;
    gd.heightHint = 50;
    reposPart.getSection().setLayoutData(PageLayoutUtils.createCollapsed());
    AvailableBundlesPart availableBundlesPart = new AvailableBundlesPart(left, tk, Section.TITLE_BAR | Section.EXPANDED);
    managedForm.addPart(availableBundlesPart);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 50;
    gd.heightHint = 50;
    availableBundlesPart.getSection().setLayoutData(PageLayoutUtils.createExpanded());
    RunFrameworkPart runFwkPart = new RunFrameworkPart(left, tk, Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
    managedForm.addPart(runFwkPart);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    runFwkPart.getSection().setLayoutData(gd);
    RunPropertiesPart runPropertiesPart = new RunPropertiesPart(left, tk, Section.TITLE_BAR | Section.TWISTIE);
    managedForm.addPart(runPropertiesPart);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    runPropertiesPart.getSection().setLayoutData(gd);
    // SECOND COLUMN
    if (supportsResolve) {
        RunRequirementsPart requirementsPart = new RunRequirementsPart(right, tk, Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED | Section.DESCRIPTION);
        managedForm.addPart(requirementsPart);
        requirementsPart.getSection().setLayoutData(PageLayoutUtils.createExpanded());
        requirementsPart.getSection().addExpansionListener(new ResizeExpansionAdapter(requirementsPart.getSection()));
        RunBlacklistPart blacklistPart = new RunBlacklistPart(right, tk, Section.TITLE_BAR | Section.TWISTIE | Section.COMPACT | Section.DESCRIPTION);
        managedForm.addPart(blacklistPart);
        blacklistPart.getSection().setLayoutData(PageLayoutUtils.createCollapsed());
        blacklistPart.getSection().addExpansionListener(new ResizeExpansionAdapter(blacklistPart.getSection()));
        RunBundlesPart runBundlesPart = new RunBundlesPart(right, tk, Section.TITLE_BAR | Section.TWISTIE);
        managedForm.addPart(runBundlesPart);
        runBundlesPart.getSection().setLayoutData(PageLayoutUtils.createCollapsed());
        runBundlesPart.getSection().addExpansionListener(new ResizeExpansionAdapter(runBundlesPart.getSection()));
    } else {
        RunBundlesPart runBundlesPart = new RunBundlesPart(right, tk, Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
        managedForm.addPart(runBundlesPart);
        runBundlesPart.getSection().setLayoutData(PageLayoutUtils.createExpanded());
        runBundlesPart.getSection().addExpansionListener(new ResizeExpansionAdapter(runBundlesPart.getSection()));
    }
    // Listeners
    model.addPropertyChangeListener(BndEditModel.PROP_WORKSPACE, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    updateFormImage(form);
                }
            });
        }
    });
    sashForm.setWeights(new int[] { 1, 1 });
    sashForm.hookResizeListener();
    body.setLayout(new FillLayout());
}
Also used : RunBundlesPart(bndtools.editor.project.RunBundlesPart) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) RunPropertiesPart(bndtools.editor.project.RunPropertiesPart) PropertyChangeListener(java.beans.PropertyChangeListener) AvailableBundlesPart(bndtools.editor.project.AvailableBundlesPart) Deferred(org.osgi.util.promise.Deferred) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) GridLayout(org.eclipse.swt.layout.GridLayout) RunFrameworkPart(bndtools.editor.project.RunFrameworkPart) PropertyChangeEvent(java.beans.PropertyChangeEvent) MessageHyperlinkAdapter(bndtools.utils.MessageHyperlinkAdapter) Composite(org.eclipse.swt.widgets.Composite) MDSashForm(bndtools.editor.common.MDSashForm) RunBlacklistPart(bndtools.editor.project.RunBlacklistPart) FillLayout(org.eclipse.swt.layout.FillLayout) Promise(org.osgi.util.promise.Promise) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) GridData(org.eclipse.swt.layout.GridData) RepositorySelectionPart(bndtools.editor.project.RepositorySelectionPart) Workspace(aQute.bnd.build.Workspace) RunRequirementsPart(bndtools.editor.project.RunRequirementsPart)

Example 22 with ActionContributionItem

use of org.eclipse.jface.action.ActionContributionItem in project sling by apache.

the class ServersActionModeFiddlerActionDelegate method initToolbarContributedActions.

private void initToolbarContributedActions() {
    cleanAction = new Action("Clean Publish...", IAction.AS_PUSH_BUTTON) {

        public void run() {
            if (server == null) {
                MessageDialog.openInformation(view.getSite().getShell(), "No server selected", "A server must be selected");
                return;
            }
            int selection = 2;
            if (!doNotAskAgain) {
                MessageDialog dialog = new MessageDialog(view.getSite().getShell(), Messages.defaultDialogTitle, null, Messages.dialogPublishClean, MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Cancel", "OK (do not ask again)", "OK" }, 1) {

                    @Override
                    protected void configureShell(Shell shell) {
                        super.configureShell(shell);
                        setShellStyle(getShellStyle() | SWT.SHEET);
                    }
                };
                selection = dialog.open();
            }
            if (selection != 0) {
                if (selection == 1) {
                    doNotAskAgain = true;
                }
                IAdaptable info = new IAdaptable() {

                    public Object getAdapter(Class adapter) {
                        if (Shell.class.equals(adapter))
                            return view.getSite().getShell();
                        if (String.class.equals(adapter))
                            return "user";
                        return null;
                    }
                };
                server.publish(IServer.PUBLISH_CLEAN, modules, info, null);
            }
        }
    };
    cleanAction.setText("Clean Publish...");
    cleanAction.setToolTipText("Clean and Publish...");
    ImageDescriptor cleanAndPublishImageDesc = new DecorationOverlayIcon(ImageResource.getImageDescriptor(ImageResource.IMG_CLCL_PUBLISH).createImage(), ImageDescriptor.createFromFile(SharedImages.class, "refresh.gif"), IDecoration.BOTTOM_RIGHT);
    cleanAction.setImageDescriptor(cleanAndPublishImageDesc);
    cleanAction.setId("org.apache.sling.ide.eclipse.ui.actions.CleanPublishAction");
    publishAction = new Action("Publish", IAction.AS_PUSH_BUTTON) {

        public void run() {
            if (server == null) {
                MessageDialog.openInformation(view.getSite().getShell(), "No server selected", "A server must be selected");
                return;
            }
            IAdaptable info = new IAdaptable() {

                public Object getAdapter(Class adapter) {
                    if (Shell.class.equals(adapter))
                        return view.getSite().getShell();
                    if (String.class.equals(adapter))
                        return "user";
                    return null;
                }
            };
            server.publish(IServer.PUBLISH_INCREMENTAL, modules, info, null);
        }
    };
    publishAction.setText("Publish");
    publishAction.setToolTipText("Publish");
    publishAction.setImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_CLCL_PUBLISH));
    publishAction.setId("org.apache.sling.ide.eclipse.ui.actions.PublishAction");
    cleanAction.setEnabled(false);
    publishAction.setEnabled(false);
    cleanActionContributionItem = new ActionContributionItem(cleanAction);
    publishActionContributionItem = new ActionContributionItem(publishAction);
    appendedToolbarActionContributionItems.add(publishActionContributionItem);
    appendedToolbarActionContributionItems.add(cleanActionContributionItem);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) DecorationOverlayIcon(org.eclipse.jface.viewers.DecorationOverlayIcon) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) Shell(org.eclipse.swt.widgets.Shell) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 23 with ActionContributionItem

use of org.eclipse.jface.action.ActionContributionItem in project sling by apache.

the class ServersActionModeFiddlerActionDelegate method selectionChanged.

@Override
public void selectionChanged(IAction action, ISelection selection) {
    server = null;
    modules = null;
    if (selection != null && (selection instanceof IStructuredSelection)) {
        IStructuredSelection iss = (IStructuredSelection) selection;
        Object first = iss.getFirstElement();
        if (first instanceof IServer) {
            server = (IServer) first;
            modules = null;
            if (iss.size() > 1) {
                // verify that all selected elements are of type IServer
                Iterator<?> it = iss.iterator();
                // skip the first, we have that above already
                it.next();
                while (it.hasNext()) {
                    Object next = it.next();
                    if (!(next instanceof IServer)) {
                        server = null;
                        modules = null;
                        break;
                    }
                }
            }
        } else if (first instanceof IServerModule) {
            modules = new LinkedList<>();
            IServerModule module = (IServerModule) first;
            modules.add(module.getModule());
            server = module.getServer();
            if (iss.size() > 1) {
                // verify that all selected elements are of type IServerModule
                // plus add the module[] to the modules list
                Iterator<?> it = iss.iterator();
                // skip the first, we have that above already
                it.next();
                while (it.hasNext()) {
                    Object next = it.next();
                    if (!(next instanceof IServerModule)) {
                        server = null;
                        module = null;
                        break;
                    } else {
                        module = (IServerModule) next;
                        modules.add(module.getModule());
                    }
                }
            }
        }
    }
    if (server != null) {
        if (server.getServerState() != IServer.STATE_STARTED) {
            server = null;
            modules = null;
        }
    }
    cleanAction.setEnabled(server != null);
    publishAction.setEnabled(server != null);
    action.setEnabled(true);
    final IAction serverRunAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.run");
    final IAction serverDebugAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.debug");
    IAction stopRunAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.stop");
    if (serverRunAction == null || stopRunAction == null || serverDebugAction == null) {
        return;
    }
    //		serverRunAction.setHoverImageDescriptor(SharedImages.SLING_LOG);
    serverRunAction.setHoverImageDescriptor(SharedImages.RUN_CONNECT);
    serverDebugAction.setHoverImageDescriptor(SharedImages.DEBUG_CONNECT);
    stopRunAction.setHoverImageDescriptor(SharedImages.DISCONNECT);
    findWstPublishAction();
    for (ActionContributionItem appendedAction : appendedToolbarActionContributionItems) {
        if (!contributionAdded(appendedAction)) {
            actionBars.getToolBarManager().add(appendedAction);
        }
    }
    if (wstPublishAction != null) {
        wstPublishAction.setVisible(false);
        publishActionContributionItem.setVisible(true);
    } else {
        // otherwise hide it, as it is an unexpected situation
        publishActionContributionItem.setVisible(false);
    }
    final String runText = "Connect to server in run mode";
    if (runTooltipListener == null) {
        runTooltipListener = new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
                    if (!event.getNewValue().equals(runText)) {
                        serverRunAction.setToolTipText(runText);
                    }
                }
            }
        };
        serverRunAction.addPropertyChangeListener(runTooltipListener);
    }
    final String debugText = "Connect to server in debug mode";
    if (debugTooltipListener == null) {
        debugTooltipListener = new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
                    if (!event.getNewValue().equals(debugText)) {
                        serverDebugAction.setToolTipText(debugText);
                    }
                }
            }
        };
        serverDebugAction.addPropertyChangeListener(debugTooltipListener);
    }
    final String disconnectText = "Disconnect from server";
    if (disconnectTooltipListener == null) {
        disconnectTooltipListener = new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
                    if (!event.getNewValue().equals(disconnectText)) {
                        serverRunAction.setToolTipText(disconnectText);
                    }
                }
            }
        };
        stopRunAction.addPropertyChangeListener(disconnectTooltipListener);
    }
    serverRunAction.setToolTipText(runText);
    serverDebugAction.setToolTipText(debugText);
    stopRunAction.setToolTipText(disconnectText);
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) IServer(org.eclipse.wst.server.core.IServer) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) IAction(org.eclipse.jface.action.IAction) IServerModule(org.eclipse.wst.server.ui.IServerModule) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LinkedList(java.util.LinkedList) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) Iterator(java.util.Iterator)

Example 24 with ActionContributionItem

use of org.eclipse.jface.action.ActionContributionItem in project sling by apache.

the class ServersActionModeFiddlerActionDelegate method findWstPublishAction.

private void findWstPublishAction() {
    if (wstPublishAction != null) {
        return;
    }
    IContributionItem[] items = actionBars.getToolBarManager().getItems();
    for (IContributionItem item : items) {
        if (item instanceof ActionContributionItem) {
            ActionContributionItem actionItem = (ActionContributionItem) item;
            IAction a = actionItem.getAction();
            if ("org.eclipse.wst.server.publish".equals(a.getActionDefinitionId())) {
                wstPublishAction = actionItem;
            //                    item.setVisible(false);
            //                    actionBars.getToolBarManager().remove(item);
            }
        }
    }
}
Also used : ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) IAction(org.eclipse.jface.action.IAction) IContributionItem(org.eclipse.jface.action.IContributionItem)

Example 25 with ActionContributionItem

use of org.eclipse.jface.action.ActionContributionItem in project eclipse.platform.text by eclipse.

the class NextPreviousPulldownActionDelegate method fillMenu.

/**
 * Fills the given menu using marker
 * annotation preferences.
 *
 * @param menu the menu to fill
 */
private void fillMenu(Menu menu) {
    IAction[] actions = getActionsFromDescriptors();
    for (int i = 0; i < actions.length; i++) {
        ActionContributionItem item = new ActionContributionItem(actions[i]);
        item.fill(menu, -1);
    }
}
Also used : ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) IAction(org.eclipse.jface.action.IAction)

Aggregations

ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)30 IAction (org.eclipse.jface.action.IAction)14 IContributionItem (org.eclipse.jface.action.IContributionItem)8 IMenuManager (org.eclipse.jface.action.IMenuManager)8 IToolBarManager (org.eclipse.jface.action.IToolBarManager)8 ActionManager (com.cubrid.common.ui.spi.action.ActionManager)7 MenuManager (org.eclipse.jface.action.MenuManager)7 Separator (org.eclipse.jface.action.Separator)7 DropDownAction (com.cubrid.common.ui.common.action.DropDownAction)3 GroupMarker (org.eclipse.jface.action.GroupMarker)3 ArrayList (java.util.ArrayList)2 Action (org.eclipse.jface.action.Action)2 ToolBarManager (org.eclipse.jface.action.ToolBarManager)2 ValgrindViewPart (org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart)2 Menu (org.eclipse.swt.widgets.Menu)2 Shell (org.eclipse.swt.widgets.Shell)2 Workspace (aQute.bnd.build.Workspace)1 MDSashForm (bndtools.editor.common.MDSashForm)1 AvailableBundlesPart (bndtools.editor.project.AvailableBundlesPart)1 RepositorySelectionPart (bndtools.editor.project.RepositorySelectionPart)1