Search in sources :

Example 1 with CommandContributionItem

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);
}
Also used : HashMap(java.util.HashMap) CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Example 2 with CommandContributionItem

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()]);
}
Also used : ArrayList(java.util.ArrayList) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 3 with CommandContributionItem

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());
                }
            }
        }
    });
}
Also used : IContributionItem(org.eclipse.jface.action.IContributionItem) State(org.eclipse.core.commands.State) RegistryToggleState(org.eclipse.ui.handlers.RegistryToggleState) IMenuManager(org.eclipse.jface.action.IMenuManager) HandledContributionItem(org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem) IMenuListener(org.eclipse.jface.action.IMenuListener) ECommandService(org.eclipse.e4.core.commands.ECommandService)

Example 4 with CommandContributionItem

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);
}
Also used : CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Example 5 with CommandContributionItem

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);
}
Also used : CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Aggregations

CommandContributionItem (org.eclipse.ui.menus.CommandContributionItem)37 CommandContributionItemParameter (org.eclipse.ui.menus.CommandContributionItemParameter)30 IContributionItem (org.eclipse.jface.action.IContributionItem)11 HashMap (java.util.HashMap)8 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)4 ResultSetPanelDescriptor (org.jkiss.dbeaver.ui.controls.resultset.panel.ResultSetPanelDescriptor)4 ArrayList (java.util.ArrayList)3 DataTransferNodeDescriptor (org.jkiss.dbeaver.tools.transfer.registry.DataTransferNodeDescriptor)3 DataTransferProcessorDescriptor (org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 DecimalFormat (java.text.DecimalFormat)2 java.util (java.util)2 List (java.util.List)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 org.eclipse.jface.action (org.eclipse.jface.action)2 MenuManager (org.eclipse.jface.action.MenuManager)2