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());
}
}
}
});
}
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);
}
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;
}
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);
}
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;
}
Aggregations