private void gatherCommands(List<MCommand> commandList) { for (MCommand cmd : commandList) { commands.put(cmd.getElementId(), cmd); } }
public MCommand getCommand(String elementId) { if (elementIdToCommandMap == null) { Map<String, MCommand> result = new HashMap<String, MCommand>(); for (MCommand command : getCommands()) { MCommand otherCommand = result.put(command.getElementId(), command); if (otherCommand != null) { result.put(command.getElementId(), otherCommand); } } elementIdToCommandMap = result; } return elementIdToCommandMap.get(elementId); }
public MCommand getCommand(String elementId) { if (elementIdToCommandMap == null) { Map<String, MCommand> result = new HashMap<String, MCommand>(); for (MCommand command : getCommands()) { MCommand otherCommand = result.put(command.getElementId(), command); if (otherCommand != null) { result.put(command.getElementId(), otherCommand); } } elementIdToCommandMap = result; } return elementIdToCommandMap.get(elementId); }
protected MCommand findCommand(String commandId) { for (MCommand cmd : application.getCommands()) { if (commandId.equals(cmd.getElementId())) { return cmd; } } return null; }
public static MCommand getMCommand(MApplication application, CommandContributionItem contribution) { ParameterizedCommand command = contribution.getCommand(); if (command != null) { for (MCommand mcommand : application.getCommands()) { if (mcommand.getElementId().equals(command.getId())) { return mcommand; } } } return null; }
public static ParameterizedCommand generateParameterizedCommand( final MHandledItem item, final IEclipseContext lclContext) { ECommandService cmdService = (ECommandService) lclContext .get(ECommandService.class.getName()); Map<String, Object> parameters = null; List<MParameter> modelParms = item.getParameters(); if (modelParms != null && !modelParms.isEmpty()) { parameters = new HashMap<String, Object>(); for (MParameter mParm : modelParms) { parameters.put(mParm.getName(), mParm.getValue()); } } ParameterizedCommand cmd = cmdService.createCommand(item.getCommand() .getElementId(), parameters); item.setWbCommand(cmd); return cmd; } }
private ParameterizedCommand generateParameterizedCommand( final MHandledItem item, final IEclipseContext lclContext) { ECommandService cmdService = (ECommandService) lclContext .get(ECommandService.class.getName()); Map<String, Object> parameters = null; List<MParameter> modelParms = item.getParameters(); if (modelParms != null && !modelParms.isEmpty()) { parameters = new HashMap<String, Object>(); for (MParameter mParm : modelParms) { parameters.put(mParm.getName(), mParm.getValue()); } } ParameterizedCommand cmd = cmdService.createCommand(item.getCommand() .getElementId(), parameters); item.setWbCommand(cmd); return cmd; }
private static ParameterizedCommand generateParameterizedCommand(final MHandledItem item, final IEclipseContext lclContext) { ECommandService cmdService = lclContext.get(ECommandService.class); Map<String, Object> parameters = null; List<MParameter> modelParms = item.getParameters(); if (modelParms != null && !modelParms.isEmpty()) { parameters = new HashMap<>(); for (MParameter mParm : modelParms) { parameters.put(mParm.getName(), mParm.getValue()); } } ParameterizedCommand cmd = cmdService.createCommand(item.getCommand().getElementId(), parameters); item.setWbCommand(cmd); return cmd; }
if (Strings.isNullOrEmpty(item.getCommand().getElementId())) { getLogger().error("No command id assigned to " //$NON-NLS-1$ + item.getCommand().getElementId()); return null; ParameterizedCommand cmd = cmdService.createCommand(item.getCommand().getElementId(), parameters); return cmd;
/** * @param handler * @param context */ private void processActiveHandler(MHandler handler, IEclipseContext context) { MCommand command = handler.getCommand(); if (command != null) { String commandId = command.getElementId(); if (handler.getObject() == null) { IContributionFactory contributionFactory = (IContributionFactory) context .get(IContributionFactory.class.getName()); handler.setObject(contributionFactory.create(handler.getContributionURI(), context)); } EHandlerService handlerService = (EHandlerService) context.get(EHandlerService.class .getName()); handlerService.activateHandler(commandId, handler.getObject()); } }
&& curr.getCommand().getElementId().equals(commandId)) {
private void createCommand(MCommand cmdModel) { IParameter[] parms = null; String id = cmdModel.getElementId(); String name = localize(cmdModel.getCommandName(), cmdModel); String desc = localize(cmdModel.getDescription(), cmdModel); List<MCommandParameter> modelParms = cmdModel.getParameters(); if (modelParms != null && !modelParms.isEmpty()) { ArrayList<Parameter> parmList = new ArrayList<>(); for (MCommandParameter cmdParm : modelParms) { ParameterType parameterType = null; if (cmdParm.getTypeId() != null && cmdParm.getTypeId().length() > 0) { parameterType = commandManager.getParameterType(cmdParm.getTypeId()); } parmList.add(new Parameter(cmdParm.getElementId(), cmdParm.getName(), null, parameterType, cmdParm.isOptional())); } parms = parmList.toArray(new Parameter[parmList.size()]); } Category cat = undefinedCategory; if (cmdModel.getCategory() != null) { cat = commandService.getCategory(cmdModel.getCategory().getElementId()); } commandService.defineCommand(id, name, desc, cat, parms, cmdModel.getPersistedState().get("HelpContextId")); //$NON-NLS-1$ }
commands.put(command.getElementId(), command); } catch (NotDefinedException e) { WorkbenchPlugin.log(e);
@Override @SuppressWarnings("restriction") protected void handleHelpRequest() { if(helpService==null) return; String helpContextId = getModel().getPersistedState().get(EHelpService.HELP_CONTEXT_ID); if (helpContextId != null) { helpService.displayHelp(helpContextId); return; } MCommand command = getModel().getCommand(); if (command == null || commandHelpService == null) { return; } String contextHelpId = commandHelpService.getHelpContextId(command.getElementId(), getContext(getModel())); if (contextHelpId != null) { helpService.displayHelp(contextHelpId); } }
@Execute void process(MApplication application, IEclipseContext context, EModelService modelService) { this.modelService = modelService; for (MCategory catModel : application.getCategories()) { categories.put(catModel.getElementId(), catModel); } for (MCommand cmdModel : application.getCommands()) { commands.put(cmdModel.getElementId(), cmdModel); } CommandManager commandManager = context.get(CommandManager.class); if (commandManager == null) { HandlerServiceImpl.handlerGenerator = new ContextFunction() { @Override public Object compute(IEclipseContext context, String contextKey) { return new WorkbenchHandlerServiceHandler(contextKey); } }; commandManager = new CommandManager(); // setCommandFireEvents(commandManager, false); context.set(CommandManager.class, commandManager); } CommandPersistence cp = new CommandPersistence(commandManager); cp.reRead(); generateCategories(application, commandManager); generateCommands(application, commandManager); cp.dispose(); }
protected void setItemText(MMenuItem model, MenuItem item) { String text = model.getLocalizedLabel(); if (model instanceof MHandledItem) { MHandledItem handledItem = (MHandledItem) model; IEclipseContext context = getContext(model); EBindingService bs = (EBindingService) context .get(EBindingService.class.getName()); ParameterizedCommand cmd = handledItem.getWbCommand(); if (cmd != null && (text == null || text.length() == 0)) { try { text = cmd.getName(); } catch (NotDefinedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } TriggerSequence sequence = bs.getBestSequenceFor(handledItem .getWbCommand()); if (sequence != null) { text = text + '\t' + sequence.format(); } item.setText(text == null ? handledItem.getCommand().getElementId() : text); } else { super.setItemText(model, item); } }
MCommand command = handler.getCommand(); if (command != null) { String commandId = command.getElementId(); EHandlerService handlerService = (EHandlerService) context .get(EHandlerService.class.getName());
public static MMenuItem createItem(MApplication application, CommandContributionItem cci) { MCommand command = getMCommand(application, cci); if (command != null) { CommandContributionItemParameter data = cci.getData(); MHandledMenuItem menuItem = MenuFactoryImpl.eINSTANCE.createHandledMenuItem(); menuItem.setCommand(command); menuItem.setContributorURI(command.getContributorURI()); if (data.label != null) { menuItem.setLabel(data.label); } else { menuItem.setLabel(command.getCommandName()); } if (data.mnemonic != null) { menuItem.setMnemonics(data.mnemonic); } if (data.icon != null) { menuItem.setIconURI(getIconURI(data.icon, application.getContext())); } else { menuItem.setIconURI(getIconURI(command.getElementId(), application.getContext(), ICommandImageService.TYPE_DEFAULT)); } String itemId = cci.getId(); menuItem.setElementId(itemId == null ? command.getElementId() : itemId); return menuItem; } return null; }
String cmdId = model.getCommand().getElementId(); List<MParameter> modelParms = model.getParameters(); Map<String, String> parameters = new HashMap<String, String>(4);
String cmdId = getModel().getCommand().getElementId(); if (cmdId == null) { logger.error("Unable to generate parameterized command for " + getModel() //$NON-NLS-1$