/**
   * @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;
  }
    @Override
    public boolean performFinish() {

      MCommand command = CommandsFactoryImpl.eINSTANCE.createCommand();
      MHandler handler = CommandsFactoryImpl.eINSTANCE.createHandler();
      MKeyBinding keyBinding = null;

      String parentId = application.getElementId();

      String prefix =
          parentId != null && parentId.trim().length() > 0
              ? parentId + "."
              : ""; //$NON-NLS-1$ //$NON-NLS-2$

      if (handlerPage.idField.getText().trim().length() > 0) {
        command.setElementId(
            prefix + "commands." + handlerPage.idField.getText().trim()); // $NON-NLS-1$
        handler.setElementId(
            prefix + "handlers." + handlerPage.idField.getText().trim()); // $NON-NLS-1$
      }

      if (application.getBindingTables().size() != 0) {
        if (keyPage.keyField.getText().trim().length() > 0
            && !keyPage.bindtableViewer.getSelection().isEmpty()) {
          keyBinding = CommandsFactoryImpl.eINSTANCE.createKeyBinding();
          keyBinding.setKeySequence(keyPage.keyField.getText().trim());
          keyBinding.setCommand(command);
        }
      }

      command.setCommandName(handlerPage.nameField.getText());
      handler.setCommand(command);

      CompoundCommand cmd = new CompoundCommand();
      cmd.append(
          AddCommand.create(
              getEditingDomain(),
              application,
              ApplicationPackageImpl.Literals.APPLICATION__COMMANDS,
              command));
      cmd.append(
          AddCommand.create(
              getEditingDomain(),
              application,
              CommandsPackageImpl.Literals.HANDLER_CONTAINER__HANDLERS,
              handler));

      if (keyBinding != null) {
        cmd.append(
            AddCommand.create(
                getEditingDomain(),
                ((IStructuredSelection) keyPage.bindtableViewer.getSelection()).getFirstElement(),
                CommandsPackageImpl.Literals.BINDING_TABLE__BINDINGS,
                keyBinding));
      }

      if (cmd.canExecute()) {
        getEditingDomain().getCommandStack().execute(cmd);
        return true;
      }

      return false;
    }