/**
   * @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;
  }
  /**
   * Convert the parameter's value according to it's type.
   *
   * @param command
   * @param parameterId
   * @param value
   * @return converted value
   * @see org.eclipse.e4.ui.model.application.commands.MCommandParameter#getTypeId()
   */
  private Object convertParameterValue(Command command, String parameterId, String value) {
    try {
      ParameterType parameterType = command.getParameterType(parameterId);

      if (parameterType != null) {
        AbstractParameterValueConverter valueConverter = parameterType.getValueConverter();
        if (valueConverter != null) {
          return valueConverter.convertToObject(value);
        }
      }
    } catch (NotDefinedException e) {
    } catch (ParameterValueConversionException e) {
    }
    return value;
  }