/** * @param cmd * @param modelService * @param categoryModel * @return a command model element * @throws NotDefinedException */ public static MCommand createCommand( Command cmd, EModelService modelService, final MCategory categoryModel) throws NotDefinedException { MCommand command = modelService.createModelElement(MCommand.class); command.setElementId(cmd.getId()); command.setCategory(categoryModel); command.setCommandName(cmd.getName()); command.setDescription(cmd.getDescription()); // deal with parameters // command.getParameters().addAll(parameters); IParameter[] cmdParms = cmd.getParameters(); if (cmdParms != null) { for (IParameter cmdParm : cmdParms) { MCommandParameter parmModel = modelService.createModelElement(MCommandParameter.class); parmModel.setElementId(cmdParm.getId()); parmModel.setName(cmdParm.getName()); parmModel.setOptional(cmdParm.isOptional()); ParameterType parmType = cmd.getParameterType(cmdParm.getId()); if (parmType != null) { parmModel.setTypeId(parmType.getId()); } command.getParameters().add(parmModel); } } return command; }
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); }