use of org.eclipse.ui.menus.CommandContributionItem in project yamcs-studio by yamcs.
the class SwitchProcessorCompoundContributionItem method createProcessorItem.
private CommandContributionItem createProcessorItem(ProcessorInfo processor) {
CommandContributionItemParameter itemParameter = new CommandContributionItemParameter(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), null, SWITCH_PROCESSOR_COMMAND, CommandContributionItem.STYLE_RADIO);
HashMap<String, String> params = new HashMap<>();
params.put(RadioState.PARAMETER_ID, processor.getName());
itemParameter.label = processor.getName();
itemParameter.parameters = params;
return new CommandContributionItem(itemParameter);
}
use of org.eclipse.ui.menus.CommandContributionItem in project vorto by eclipse.
the class PopulateGeneratorsMenu method getContributionItems.
@Override
protected IContributionItem[] getContributionItems() {
List<CommandContributionItem> contributionItems = new ArrayList<CommandContributionItem>();
List<IConfigurationElement> registeredGenerators = getAllRegisteredGeneratorNames();
for (IConfigurationElement aGenerator : registeredGenerators) {
CommandContributionItem commandForGenerator = constructCommandForGenerator(aGenerator);
if (commandForGenerator != null) {
contributionItems.add(commandForGenerator);
}
}
Collections.sort(contributionItems, new Comparator<CommandContributionItem>() {
@Override
public int compare(CommandContributionItem a, CommandContributionItem b) {
return a.getData().label.compareTo(b.getData().label);
}
});
return contributionItems.toArray(new IContributionItem[contributionItems.size()]);
}
use of org.eclipse.ui.menus.CommandContributionItem in project core by jcryptool.
the class FileExplorerView method init.
@Override
public void init(IViewSite site, IMemento memento) throws PartInitException {
super.init(site, memento);
if (memento != null && memento.getBoolean(MEMENTOKEY_INVISIBLE_FILES_HIDDEN) != null) {
boolean invis_files_hidden = memento.getBoolean(MEMENTOKEY_INVISIBLE_FILES_HIDDEN);
this.setHideInvisible(invis_files_hidden);
} else {
setHideInvisible(getDefaultForHideInvisibleFiles());
}
getViewSite().getActionBars().getMenuManager().addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
if (!menuButtonInitialized) {
try {
IContributionItem[] items = getViewSite().getActionBars().getMenuManager().getItems();
for (IContributionItem item : items) {
if ("org.jcryptool.fileexplorer.invisibleToggle".equals(item.getId())) {
if (item instanceof CommandContributionItem) {
CommandContributionItem invisibleToggle = (CommandContributionItem) item;
State state = invisibleToggle.getCommand().getCommand().getState(RegistryToggleState.STATE_ID);
if (state == null)
throw new UnsupportedOperationException(// $NON-NLS-1$
"The 'show invisible files' command does not have a toggle state");
else if (!(state.getValue() instanceof Boolean))
throw new UnsupportedOperationException(// $NON-NLS-1$
"The 'show invisible files' command's toggle state doesn't contain a boolean value");
else {
state.setValue(!isHideInvisible());
}
} else if (item instanceof HandledContributionItem) {
HandledContributionItem invisibleToggle = (HandledContributionItem) item;
// The MCommand's element ID seems to be the command ID
// Knowing the command ID, we can retrieve the Command (not
// MCommand!)
// from the ECommandService
String commandId = invisibleToggle.getModel().getCommand().getElementId();
ECommandService commandService = (ECommandService) PlatformUI.getWorkbench().getService(ECommandService.class);
State state = commandService.getCommand(commandId).getState(RegistryToggleState.STATE_ID);
if (state == null)
throw new UnsupportedOperationException(// $NON-NLS-1$
"The 'show invisible files' command does not have a toggle state");
else if (!(state.getValue() instanceof Boolean))
throw new UnsupportedOperationException(// $NON-NLS-1$
"The 'show invisible files' command's toggle state doesn't contain a boolean value");
else {
state.setValue(!isHideInvisible());
}
}
}
}
menuButtonInitialized = true;
} catch (UnsupportedOperationException e) {
LogUtil.logError(e.getMessage());
}
}
}
});
}
use of org.eclipse.ui.menus.CommandContributionItem in project core by jcryptool.
the class FlexiProviderOperationsView 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);
}
use of org.eclipse.ui.menus.CommandContributionItem in project egit by eclipse.
the class ResetMenu method getCommandContributionItem.
private static CommandContributionItem getCommandContributionItem(String commandId, String menuLabel, Map<String, String> parameters, IWorkbenchSite site) {
CommandContributionItemParameter parameter = new CommandContributionItemParameter(site, commandId, commandId, CommandContributionItem.STYLE_PUSH);
parameter.label = menuLabel;
parameter.parameters = parameters;
return new CommandContributionItem(parameter);
}
Aggregations