protected MCategory findCategory(String id) { final List<MCategory> categories = application.getCategories(); for (MCategory cat : categories) { if (id.equals(cat.getElementId())) { return cat; } } return null; }
/** * @param commandManager */ private void generateCategories(MApplication application, CommandManager commandManager) { for (Category cat : commandManager.getDefinedCategories()) { if (categories.containsKey(cat.getId())) { continue; } try { MCategory catModel = modelService.createModelElement(MCategory.class); catModel.setElementId(cat.getId()); catModel.setName(cat.getName()); catModel.setDescription(cat.getDescription()); application.getCategories().add(catModel); categories.put(catModel.getElementId(), catModel); } catch (NotDefinedException e) { // Since we asked for defined commands, this shouldn't be an // issue WorkbenchPlugin.log(e); } } }
private void createCategory(MCategory catModel) { Category category = commandService.getCategory(catModel.getElementId()); if (!category.isDefined()) { category.define(localize(catModel.getName(), catModel), localize(catModel.getDescription(), catModel)); } }
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$ }
@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(); }