org.eclipse.ui.menus.CommandContributionItem Java Examples

The following examples show how to use org.eclipse.ui.menus.CommandContributionItem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AboutDialog.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create the context menu for the text widget.
 * 
 * @since 3.4
 */
private void createTextMenu() {
	final MenuManager textManager = new MenuManager();
	textManager.add(new CommandContributionItem(
			new CommandContributionItemParameter(PlatformUI
					.getWorkbench(), null, IWorkbenchCommandConstants.EDIT_COPY,
					CommandContributionItem.STYLE_PUSH)));
	textManager.add(new CommandContributionItem(
			new CommandContributionItemParameter(PlatformUI
					.getWorkbench(), null, IWorkbenchCommandConstants.EDIT_SELECT_ALL,
					CommandContributionItem.STYLE_PUSH)));
	text.setMenu(textManager.createContextMenu(text));
	text.addDisposeListener(new DisposeListener() {

		public void widgetDisposed(DisposeEvent e) {
			textManager.dispose();
		}
	});
	
}
 
Example #2
Source File: OpenFileManagerContributionItem.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected IContributionItem[] getContributionItems()
{
	CommandContributionItemParameter ccip = new CommandContributionItemParameter(PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow(), null, "com.aptana.ui.command.ShowInFileManager", //$NON-NLS-1$
			CommandContributionItem.STYLE_PUSH);
	if (Platform.getOS().equals(Platform.OS_MACOSX))
	{
		ccip.label = Messages.OpenFileManagerContributionItem_FinderLabel;
		ccip.icon = UIPlugin.getImageDescriptor("icons/finder.png"); //$NON-NLS-1$
	}
	else if (Platform.getOS().equals(Platform.OS_WIN32))
	{
		ccip.label = Messages.OpenFileManagerContributionItem_WindowsExplorerLabel;
		ccip.icon = UIPlugin.getImageDescriptor("icons/windows_explorer.png"); //$NON-NLS-1$
	}
	else
	{
		ccip.label = Messages.OpenFileManagerContributionItem_FileBrowserLabel;
	}
	return new IContributionItem[] { new CommandContributionItem(ccip) };
}
 
Example #3
Source File: CleanupHelper.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private static void changeIcon(final IMenuManager menu, final IContributionItem item,
		final ImageDescriptor image) {
	if (item instanceof ActionContributionItem) {
		((ActionContributionItem) item).getAction().setImageDescriptor(image);
	} else if (item instanceof CommandContributionItem) {
		final CommandContributionItemParameter data = ((CommandContributionItem) item).getData();
		data.commandId = ((CommandContributionItem) item).getCommand().getId();
		data.icon = image;
		final CommandContributionItem newItem = new CommandContributionItem(data);
		newItem.setId(item.getId());
		menu.insertAfter(item.getId(), newItem);
		menu.remove(item);
		item.dispose();
	} else if (item instanceof ActionSetContributionItem) {
		changeIcon(menu, ((ActionSetContributionItem) item).getInnerItem(), image);
	} else if (item instanceof MenuManager) {
		((MenuManager) item).setImageDescriptor(image);
	}
}
 
Example #4
Source File: SelectElementTypeContributionItem.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public int compare(IContributionItem o1, IContributionItem o2) {
    if (o1 instanceof MenuManager) {
        if (o2 instanceof MenuManager) {
            MenuManager m1 = (MenuManager) o1;
            MenuManager m2 = (MenuManager) o2;
            return m1.getMenuText().compareTo(m2.getMenuText());
        }
        return -1;
    }
    if (o2 instanceof MenuManager) {
        return 1;
    }
    CommandContributionItem c1 = (CommandContributionItem) o1;
    CommandContributionItem c2 = (CommandContributionItem) o2;
    return c1.getData().label.compareTo(c2.getData().label);
}
 
Example #5
Source File: SelectElementTypeContributionItem.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void addContributionItem(List<IContributionItem> list,
        String traceTypeId, String label, boolean selected, MenuManager subMenu) {
    Map<String, String> params = new HashMap<>();
    params.put(TYPE_PARAMETER, traceTypeId);

    ImageDescriptor icon = null;
    if (selected) {
        icon = SELECTED_ICON;
    }

    CommandContributionItemParameter param = new CommandContributionItemParameter(
            PlatformUI.getWorkbench().getActiveWorkbenchWindow(), // serviceLocator
            "my.parameterid", // id //$NON-NLS-1$
            getContributionItemCommandId(), // commandId
            CommandContributionItem.STYLE_PUSH // style
    );
    param.parameters = params;
    param.icon = icon;
    param.disabledIcon = icon;
    param.hoverIcon = icon;
    param.label = label;
    param.visibleEnabled = true;

    if (subMenu != null) {
        CommandContributionItem item = new CommandContributionItem(param);
        int i = Collections.binarySearch(Arrays.asList(subMenu.getItems()), item, ITEM_COMPARATOR);
        i = (i >= 0) ? i : -i - 1;
        subMenu.insert(i, item);
    } else {
        list.add(new CommandContributionItem(param));
    }
}
 
Example #6
Source File: WizardMenuContributions.java    From depan with Apache License 2.0 5 votes vote down vote up
private IContributionItem buildWizardItem(
    IServiceLocator srvcLocator, String planId,
    LayoutPlanDocument<? extends LayoutPlan> planDoc) {
  String name = planDoc.getName();
  String id = MessageFormat.format("{0}.{1}", MENU_ROOT, name); 
  int style = CommandContributionItem.STYLE_PUSH;

  Map<String, String> parameters = LayoutNodesHandler.buildParameters(planId);
  IContributionItem result = new CommandContributionItem(
      new CommandContributionItemParameter(srvcLocator, id,
          LayoutNodesHandler.LAYOUT_COMMAND, parameters, null, null, null, name,
          null, null, style, null, false));

  return result;
}
 
Example #7
Source File: DefineCommands.java    From EasyShell with Eclipse Public License 2.0 5 votes vote down vote up
private void addItem(IServiceLocator serviceLocator, IContributionRoot additions, String commandLabel,
        String commandId, Map<String, Object> commandParamametersMap, String commandImageId, boolean visible) {
    CommandContributionItemParameter param = new CommandContributionItemParameter(serviceLocator, "", commandId,
            SWT.PUSH);
    param.label = commandLabel;
    param.icon = Activator.getImageDescriptor(commandImageId);
    param.parameters = commandParamametersMap;
    CommandContributionItem item = new CommandContributionItem(param);
    item.setVisible(visible);
    additions.addContributionItem(item, null);
}
 
Example #8
Source File: GamaActionBarAdvisor.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private IContributionItem getItem(final String actionId, final String commandId, final String image,
	final String disabledImage, final String label, final String tooltip, final String helpContextId) {

	final IActionCommandMappingService acms = getWindow().getService(IActionCommandMappingService.class);
	acms.map(actionId, commandId);

	final CommandContributionItemParameter commandParm = new CommandContributionItemParameter(getWindow(), actionId,
		commandId, null, image != null ? icons.desc(image) : null, null, null, label, null, tooltip,
		CommandContributionItem.STYLE_PUSH, null, false);
	return new CommandContributionItem(commandParm);
}
 
Example #9
Source File: BodyMenuConfiguration.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private void createBodyMenu() {
	MenuManager menuMgr = new MenuManager();
	bodyMenu = menuMgr.createContextMenu(table.getShell());
	menuMgr.add(new CommandContributionItem(new CommandContributionItemParameter(PlatformUI.getWorkbench(), null,
			ActionFactory.CUT.getCommandId(), Collections.EMPTY_MAP, null, null, null, Messages
					.getString("tmxedtior.bodyMenuConfiguration.cut"), null, null,
			CommandContributionItem.STYLE_PUSH, null, false)));
	menuMgr.add(new CommandContributionItem(new CommandContributionItemParameter(PlatformUI.getWorkbench(), null,
			ActionFactory.COPY.getCommandId(), Collections.EMPTY_MAP, null, null, null, Messages
					.getString("tmxedtior.bodyMenuConfiguration.copy"), null, null,
			CommandContributionItem.STYLE_PUSH, null, false)));
	menuMgr.add(new CommandContributionItem(new CommandContributionItemParameter(PlatformUI.getWorkbench(), null,
			ActionFactory.PASTE.getCommandId(), Collections.EMPTY_MAP, null, null, null, Messages
					.getString("tmxedtior.bodyMenuConfiguration.paste"), null, null,
			CommandContributionItem.STYLE_PUSH, null, false)));
	menuMgr.add(new Separator());

	menuMgr.add(new CommandContributionItem(new CommandContributionItemParameter(PlatformUI.getWorkbench(), null,
			"net.heartsome.cat.te.tmxeditor.command.addtu", Collections.EMPTY_MAP, null, null, null, null, null,
			null, CommandContributionItem.STYLE_PUSH, null, false)));
	menuMgr.add(new CommandContributionItem(new CommandContributionItemParameter(PlatformUI.getWorkbench(), null,
			"net.heartsome.cat.te.tmxeditor.command.deletetu", Collections.EMPTY_MAP, null, null, null, null, null,
			null, CommandContributionItem.STYLE_PUSH, null, false)));
	
	menuMgr.add(new Separator());
	menuMgr.add(new CommandContributionItem(new CommandContributionItemParameter(PlatformUI.getWorkbench(), null,
			"net.heartsome.cat.te.ui.command.cleanSelectInnerTag", Collections.EMPTY_MAP, null, null, null, null, null,
			null, CommandContributionItem.STYLE_PUSH, null, false)));
}
 
Example #10
Source File: ModelContributionItem.java    From tlaplus with MIT License 5 votes vote down vote up
/**
   * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
   */
  protected IContributionItem[] getContributionItems()
  {
      final Vector<CommandContributionItem> modelContributions = new Vector<CommandContributionItem>();

      Spec currentSpec = ToolboxHandle.getCurrentSpec();
      if (currentSpec == null) {
      	return new IContributionItem[0];
      }
// First, search for all models for the given spec.
final Set<String> modelNames = currentSpec.getAdapter(TLCSpec.class).getModels().keySet();
for (String modelName : modelNames) {

          Map<String, String> parameters = new HashMap<String, String>();

          // fill the model name for the handler
          parameters.put(OpenModelHandler.PARAM_MODEL_NAME, modelName);

          // create the contribution item
          CommandContributionItemParameter param = new CommandContributionItemParameter(UIHelper
                  .getActiveWindow(), "toolbox.command.model.open." + modelName, OpenModelHandler.COMMAND_ID,
                  parameters, modelIcon, null, null, modelName, null, "Opens " + modelName,
                  CommandContributionItem.STYLE_PUSH, null, true);

          // add contribution item to the list
          modelContributions.add(new CommandContributionItem(param));
      }
      return modelContributions.toArray(new IContributionItem[modelContributions.size()]);
  }
 
Example #11
Source File: ListSubprocessContributionItem.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected IContributionItem[] getContributionItems() {
    final List<IContributionItem> res = new ArrayList<IContributionItem>();
    IRepository repository = RepositoryManager.getInstance().getCurrentRepository() ;
    diagramSotre = (DiagramRepositoryStore) repository.getRepositoryStore(DiagramRepositoryStore.class) ;
    try {
        for(AbstractProcess process : diagramSotre.getAllProcesses()){
            if (process.getName().equals(subprocessName)) {
                Map<String, String> params = new HashMap<String, String>();
                params.put(OpenSpecificProcessCommand.PARAMETER_PROCESS_NAME, process.getName());
                params.put(OpenSpecificProcessCommand.PARAMETER_PROCESS_VERSION, process.getVersion());
                CommandContributionItemParameter param = new CommandContributionItemParameter(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), null, OpenSpecificProcessCommand.ID, CommandContributionItem.STYLE_PUSH);
                param.parameters = params;
                param.label = process.getVersion();
                param.visibleEnabled = true;
                param.commandId = OpenSpecificProcessCommand.ID;
                CommandContributionItem commandContributionItem = new CommandContributionItem(param);
                commandContributionItem.setVisible(true);
                res.add(commandContributionItem);
            }
        }


    } catch (Exception ex) {
        BonitaStudioLog.error(ex);
    }
    return res.toArray(new IContributionItem[res.size()]);
}
 
Example #12
Source File: CommandsHelper.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static CommandContributionItemParameter contribItemParameter(IServiceLocator svLocator, String commandId) {
	return new CommandContributionItemParameter(svLocator, 
		commandId, 
		commandId, 
		CommandContributionItem.STYLE_PUSH
	);
}
 
Example #13
Source File: CommandsHelper.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static CommandContributionItemParameter contribItemParameter2(IServiceLocator svLocator, String commandId,
		ImageDescriptor icon) {
	CommandContributionItemParameter cip = new CommandContributionItemParameter(svLocator, 
		commandId, 
		commandId, 
		CommandContributionItem.STYLE_PUSH
	);
	cip.icon = icon;
	return cip;
}
 
Example #14
Source File: CommandsHelper.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static CommandContributionItemParameter contribItemParameter(IServiceLocator svLocator, String commandId,
		String contribId) {
	return new CommandContributionItemParameter(svLocator, 
		contribId, 
		commandId, 
		CommandContributionItem.STYLE_PUSH
	);
}
 
Example #15
Source File: LangEditorContextMenuContributor.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public void editorContextMenuAboutToShow(IMenuManager ctxMenu) {
	ctxMenu.prependToGroup(ICommonMenuConstants.GROUP_OPEN, new CommandContributionItem(
		createCommandContrib_OpenDefinitionContrib()));
	
	ctxMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN, new CommandContributionItem(
		createCommandContrib_QuickOutline()));
	
	prepareSourceMenu(ctxMenu);
}
 
Example #16
Source File: CommandsHelper.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public static CommandContributionItem pushItem(IServiceLocator svLocator, String commandId) {
	return new CommandContributionItem(contribItemParameter(svLocator, commandId));
}
 
Example #17
Source File: LangEditorActionContributorHelper.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
protected CommandContributionItem pushItem(String commandId) {
	return CommandsHelper.pushItem(getServiceLocator(), commandId, commandId);
}
 
Example #18
Source File: LangEditorActionContributorHelper.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
protected CommandContributionItem pushItem(String commandId, String contribId) {
	return CommandsHelper.pushItem(getServiceLocator(), commandId, contribId);
}
 
Example #19
Source File: CommandsHelper.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public static CommandContributionItem pushItem(IServiceLocator svLocator, String commandId, String contribId) {
	return new CommandContributionItem(contribItemParameter(svLocator, commandId, contribId));
}
 
Example #20
Source File: SavedModuleContributionItem.java    From tlaplus with MIT License 4 votes vote down vote up
protected IContributionItem[] getContributionItems()
{
    /*
     * Does nothing if the active editor is not a model editor. The
     * following code gets the config file for the active model editor (if
     * it is the active editor), gets the model folder for that config,
     * iterates through all members of the model folder, adding a
     * contribution item for each member that has extension .tla and is not
     * TE.tla or MC.tla.
     */
    IEditorPart editor = UIHelper.getActiveEditor();
    if (editor instanceof ModelEditor)
    {
        IFolder modelFolder = ((ModelEditor) editor).getModel().getTargetDirectory();
        if (modelFolder != null && modelFolder.exists())
        {
            try
            {
                /*
                 * The collection of command contribution items that will
                 * populate the menu and contain the command to be run when
                 * selected.
                 */
                final List<IContributionItem> contributions = new ArrayList<IContributionItem>();

                // get all resources in the model folder
                IResource[] members = modelFolder.members();
                for (int i = 0; i < members.length; i++)
                {
                    /*
                     * We add to the menu an option to open every file that
                     * has exists, has extension .tla, and is not the TE or
                     * MC file.
                     * 
                     * On Nov 2011, DR added a null check to members[i].getFileExtension() which
                     * can return null for directories.
                     */
                    if (members[i].exists() && members[i].getFileExtension() != null
                            && members[i].getFileExtension().equals(ResourceHelper.TLA_EXTENSION)
                            && !members[i].getName().equals(TLAConstants.Files.MODEL_CHECK_TLA_FILE)
                            && !members[i].getName().equals(ModelHelper.TE_FILE_TLA))
                    {
                        Map<String, String> parameters = new HashMap<String, String>(1);
                        parameters.put(OpenSavedModuleHandler.PARAM_MODULE_PATH, members[i].getRawLocation()
                                .toPortableString());
                        contributions.add(new CommandContributionItem(new CommandContributionItemParameter(UIHelper
                                .getActiveWindow(), "toolbox.command.model.open.savedModule.",
                                OpenSavedModuleHandler.COMMAND_ID, parameters, null, null, null, members[i]
                                        .getName(), null, "Opens the version saved in the last run of TLC.",
                                SWT.PUSH, null, true)));
                    }
                }

                return (IContributionItem[]) contributions.toArray(new IContributionItem[contributions.size()]);
            } catch (CoreException e)
            {
                TLCUIActivator.getDefault().logError("Error getting members of model folder " + modelFolder, e);
            }
        }
    }
    return new IContributionItem[0];
}