Search in sources :

Example 1 with MCommand

use of org.eclipse.e4.ui.model.application.commands.MCommand 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 2 with MCommand

use of org.eclipse.e4.ui.model.application.commands.MCommand in project whole by wholeplatform.

the class CommandFactory method createActionCallCommand.

@Override
public MCommand createActionCallCommand() {
    MCommandParameter functionUri = createMCommandParameter(FUNCTION_URI_PARAMETER_ID, "function uri to unparse to apply transformation", false);
    MCommandParameter predicate = createMCommandParameter(PREDICATE_XWL_PARAMETER_ID, "xwl fragment to unparse for predicate", false);
    MCommandParameter analyzing = createMCommandParameter(ANALYSING_PARAMETER_ID, "enables results view update", true);
    MCommandParameter description = createMCommandParameter(DESCRIPTION_PARAMETER_ID, "action description", true);
    return createMCommand(ACTION_CALL_COMMAND_ID, "action call", functionUri, predicate, analyzing, description);
}
Also used : MCommandParameter(org.eclipse.e4.ui.model.application.commands.MCommandParameter)

Example 3 with MCommand

use of org.eclipse.e4.ui.model.application.commands.MCommand in project whole by wholeplatform.

the class CommandFactory method createMCommand.

protected MCommand createMCommand(String elementId, String commandName, MCommandParameter... parameters) {
    MCommand command = MCommandsFactory.INSTANCE.createCommand();
    command.setElementId(elementId);
    command.setCommandName(commandName);
    for (MCommandParameter parameter : parameters) command.getParameters().add(parameter);
    return command;
}
Also used : MCommand(org.eclipse.e4.ui.model.application.commands.MCommand) MCommandParameter(org.eclipse.e4.ui.model.application.commands.MCommandParameter)

Example 4 with MCommand

use of org.eclipse.e4.ui.model.application.commands.MCommand in project portfolio by buchen.

the class CSVConfigurationsMenuContribution method aboutToShow.

@AboutToShow
public void aboutToShow(List<MMenuElement> items) {
    if (mCommand == null || mParameter == null)
        return;
    // problem: we must pass a string as parameter to the command, but
    // there is no unique identifier for a CSVConfig. Instead of
    // introducing one, we use the index within the list. As the menu is
    // created dynamically, the index should not be different between
    // showing the menu and opening the wizard page.
    int index = 0;
    for (CSVConfig config : configManager.getBuiltInConfigurations()) createMenu(items, index++, config);
    items.add(MMenuFactory.INSTANCE.createMenuSeparator());
    for (CSVConfig config : configManager.getUserSpecificConfigurations()) createMenu(items, index++, config);
}
Also used : CSVConfig(name.abuchen.portfolio.datatransfer.csv.CSVConfig) AboutToShow(org.eclipse.e4.ui.di.AboutToShow)

Example 5 with MCommand

use of org.eclipse.e4.ui.model.application.commands.MCommand in project aero.minova.rcp by minova-afis.

the class MenuProcessor method createMenuEntry.

/**
 * Diese Methode erstellt einen Eintrag für ein MMenu aus dem übergebenen MDI-Eintrag
 *
 * @param entryMDI
 * @param actionMDI
 * @param modelService
 * @param mApplication
 * @return
 */
private MHandledMenuItem createMenuEntry(Entry entryMDI, Action actionMDI, EModelService modelService, MApplication mApplication) {
    MHandledMenuItem handledMenuItem = modelService.createModelElement(MHandledMenuItem.class);
    handledMenuItem.getPersistedState().put("persistState", String.valueOf(false));
    MCommand command = mApplication.getCommand("aero.minova.rcp.rcp.command.openform");
    handledMenuItem.setCommand(command);
    // set the form name as parameter
    MParameter mParameterForm = modelService.createModelElement(MParameter.class);
    // not used
    mParameterForm.setElementId("parameter.formName." + entryMDI.getId());
    mParameterForm.setName(Constants.FORM_NAME);
    mParameterForm.setValue(actionMDI.getAction());
    handledMenuItem.getParameters().add(mParameterForm);
    // set the perspective id as parameter
    MParameter mParameterId = modelService.createModelElement(MParameter.class);
    // not used
    mParameterId.setElementId("parameter.formId." + entryMDI.getId());
    mParameterId.setName(Constants.FORM_ID);
    mParameterId.setValue(actionMDI.getId());
    handledMenuItem.getParameters().add(mParameterId);
    // set the perspective name as parameter
    MParameter mParameterPerspectiveName = modelService.createModelElement(MParameter.class);
    // not used
    mParameterPerspectiveName.setElementId("parameter.PerspectiveLabel." + entryMDI.getId());
    mParameterPerspectiveName.setName(Constants.FORM_LABEL);
    mParameterPerspectiveName.setValue(actionMDI.getText());
    handledMenuItem.getParameters().add(mParameterPerspectiveName);
    // set the perspective icon as parameter
    MParameter mParameterPerspectiveIcon = modelService.createModelElement(MParameter.class);
    // not used
    mParameterPerspectiveIcon.setElementId("parameter.PerspectiveIcon." + entryMDI.getId());
    mParameterPerspectiveIcon.setName(Constants.FORM_ICON);
    mParameterPerspectiveIcon.setValue(actionMDI.getIcon());
    handledMenuItem.getParameters().add(mParameterPerspectiveIcon);
    handledMenuItem.setElementId("menuItemFor." + actionMDI.getId());
    handledMenuItem.setLabel(actionMDI.getText());
    String retrieveIcon = ImageUtil.retrieveIcon(actionMDI.getIcon(), false);
    handledMenuItem.setIconURI(retrieveIcon);
    return handledMenuItem;
}
Also used : MCommand(org.eclipse.e4.ui.model.application.commands.MCommand) MHandledMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem) MParameter(org.eclipse.e4.ui.model.application.commands.MParameter)

Aggregations

MCommand (org.eclipse.e4.ui.model.application.commands.MCommand)41 MParameter (org.eclipse.e4.ui.model.application.commands.MParameter)14 MHandledMenuItem (org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem)11 MCommandParameter (org.eclipse.e4.ui.model.application.commands.MCommandParameter)9 MApplication (org.eclipse.e4.ui.model.application.MApplication)8 Test (org.junit.Test)8 MWindow (org.eclipse.e4.ui.model.application.ui.basic.MWindow)6 MMenu (org.eclipse.e4.ui.model.application.ui.menu.MMenu)6 HashMap (java.util.HashMap)5 MKeyBinding (org.eclipse.e4.ui.model.application.commands.MKeyBinding)5 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)5 Map (java.util.Map)4 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)4 Execute (org.eclipse.e4.core.di.annotations.Execute)4 MCategory (org.eclipse.e4.ui.model.application.commands.MCategory)4 ArrayList (java.util.ArrayList)3 Inject (javax.inject.Inject)3 AboutToShow (org.eclipse.e4.ui.di.AboutToShow)3 MHandler (org.eclipse.e4.ui.model.application.commands.MHandler)3 MHandledToolItem (org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem)3