Search in sources :

Example 21 with CommandContributionItem

use of org.eclipse.ui.menus.CommandContributionItem in project core by jcryptool.

the class KeystoreView method addContributionItem.

private void addContributionItem(IContributionManager manager, final String commandId, final ImageDescriptor icon, final String tooltip) {
    CommandContributionItemParameter param = new CommandContributionItemParameter(serviceLocator, null, commandId, SWT.PUSH);
    if (icon != null)
        param.icon = icon;
    if (tooltip != null && !tooltip.equals(""))
        param.tooltip = tooltip;
    CommandContributionItem item = new CommandContributionItem(param);
    manager.add(item);
}
Also used : CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Example 22 with CommandContributionItem

use of org.eclipse.ui.menus.CommandContributionItem in project egit by eclipse.

the class GitActionContributor method createItem.

private CommandContributionItem createItem(String itemAction) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    CommandContributionItemParameter itemParam = new CommandContributionItemParameter(workbench, null, itemAction, STYLE_PUSH);
    IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
    IHandlerService hsr = CommonUtils.getService(activeWorkbenchWindow, IHandlerService.class);
    IEvaluationContext ctx = hsr.getCurrentState();
    ctx.addVariable(ACTIVE_MENU_SELECTION_NAME, getContext().getSelection());
    return new CommandContributionItem(itemParam);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IHandlerService(org.eclipse.ui.handlers.IHandlerService) CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Example 23 with CommandContributionItem

use of org.eclipse.ui.menus.CommandContributionItem in project egit by eclipse.

the class PushMenu method getContributionItems.

@Override
protected IContributionItem[] getContributionItems() {
    List<IContributionItem> res = new ArrayList<>();
    if (this.handlerService != null) {
        Repository repository = SelectionUtils.getRepository(handlerService.getCurrentState());
        if (repository != null) {
            try {
                String ref = repository.getFullBranch();
                String menuLabel = UIText.PushMenu_PushHEAD;
                if (ref != null && ref.startsWith(Constants.R_HEADS)) {
                    menuLabel = NLS.bind(UIText.PushMenu_PushBranch, Repository.shortenRefName(ref));
                }
                CommandContributionItemParameter params = new CommandContributionItemParameter(this.serviceLocator, getClass().getName(), ActionCommands.PUSH_BRANCH_ACTION, CommandContributionItem.STYLE_PUSH);
                params.label = menuLabel;
                CommandContributionItem item = new CommandContributionItem(params);
                res.add(item);
            } catch (IOException ex) {
                Activator.handleError(ex.getLocalizedMessage(), ex, false);
            }
        }
    }
    return res.toArray(new IContributionItem[res.size()]);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IContributionItem(org.eclipse.jface.action.IContributionItem) CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Example 24 with CommandContributionItem

use of org.eclipse.ui.menus.CommandContributionItem in project mylyn.docs by eclipse.

the class WikiMarkupGenerationContribution method getContributionItems.

@Override
protected IContributionItem[] getContributionItems() {
    Map<String, IContributionItem> items = new TreeMap<>();
    for (MarkupLanguage markupLanguage : ServiceLocator.getInstance().getAllMarkupLanguages()) {
        try {
            // test to see if markup generation is supported
            markupLanguage.createDocumentBuilder(new StringWriter());
        } catch (UnsupportedOperationException e) {
            // markup langage doesn't provide document builder
            continue;
        }
        String commandId = ConvertMarkupToMarkup.COMMAND_ID;
        // $NON-NLS-1$ //$NON-NLS-2$
        String id = commandId + '.' + markupLanguage.getName().replaceAll("\\W", "_");
        HashMap<String, String> args = new HashMap<>();
        args.put(ConvertMarkupToMarkup.PARAM_MARKUP_LANGUAGE, markupLanguage.getName());
        CommandContributionItemParameter parameters = new CommandContributionItemParameter(serviceLocator, id, commandId, CommandContributionItem.STYLE_PUSH);
        parameters.label = NLS.bind(Messages.WikiMarkupGenerationContribution_generate_markup, markupLanguage.getName());
        parameters.parameters = args;
        items.put(markupLanguage.getName(), new CommandContributionItem(parameters));
    }
    return items.values().toArray(new IContributionItem[items.size()]);
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) IContributionItem(org.eclipse.jface.action.IContributionItem) CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) TreeMap(java.util.TreeMap) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Example 25 with CommandContributionItem

use of org.eclipse.ui.menus.CommandContributionItem in project ecf by eclipse.

the class AbstractRosterMenuContributionItem method createCommandContributionItemForEntry.

/**
 * Create a command contribution item for the given entry with the given commandId.
 *
 * @param commandId the commandId for the new CommandContributionItem.  Must not be <code>null</code>.
 * @param rosterEntry the IRosterEntry for the new CommandContributionItem.  Must not be <code>null</code>.
 * @return CommandContributionItem created.  Must not return <code>null</code>.
 */
protected CommandContributionItem createCommandContributionItemForEntry(String commandId, IRosterEntry rosterEntry) {
    CommandContributionItemParameter p = new CommandContributionItemParameter(serviceLocator, null, commandId, CommandContributionItem.STYLE_PUSH);
    p.icon = getRosterEntryImageDescriptor(rosterEntry);
    p.label = rosterEntry.getName();
    // 3.4 return new CommandContributionItem(serviceLocator, null, commandId, new HashMap(), getRosterEntryImageDescriptor(rosterEntry), null, null, rosterEntry.getName(), null, null, CommandContributionItem.STYLE_PUSH);
    return new CommandContributionItem(p);
}
Also used : CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Aggregations

CommandContributionItem (org.eclipse.ui.menus.CommandContributionItem)31 CommandContributionItemParameter (org.eclipse.ui.menus.CommandContributionItemParameter)25 IContributionItem (org.eclipse.jface.action.IContributionItem)10 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)4 Separator (org.eclipse.jface.action.Separator)3 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)2 MenuManager (org.eclipse.jface.action.MenuManager)2 IMenuService (org.eclipse.ui.menus.IMenuService)2 UserRefactoringInfo (org.erlide.wrangler.refactoring.backend.UserRefactoringInfo)2 DBException (org.jkiss.dbeaver.DBException)2 DatabaseLoadService (org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService)2 DataTransferNodeDescriptor (org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor)2 DataTransferProcessorDescriptor (org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 DecimalFormat (java.text.DecimalFormat)1 java.util (java.util)1 List (java.util.List)1