/**
   * @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;
  }
Exemplo n.º 2
0
  @Test
  public void controlModelTestWithoutDialog() throws NotDefinedException, ParameterValuesException {
    IParameter dialogParameter =
        HandlerUtils.getCommand(this.COMMAND_ID)
            .getParameter(ControlCommandHandler.CONTROLMODE_USE_DIALOG_PARAMETER);
    ControlModeCommandParameterValues controlModePlatformValues =
        (ControlModeCommandParameterValues) dialogParameter.getValues();
    controlModePlatformValues.put("showDialog", false);
    RunnableWithResult<?> runnableWithResult =
        new RunnableWithResult.Impl<Object>() {

          @Override
          public void run() {
            List<PackageableElement> elements = selectElementToControl();
            Assert.assertTrue(
                Messages.ControlModelTest_4,
                HandlerUtils.getActiveHandlerFor(COMMAND_ID).isEnabled());

            controlAndSave(editor, model, elements, HandlerUtils.getCommand(COMMAND_ID));
          }
        };
    Display.getDefault().syncExec(runnableWithResult);
  }