protected MCommand findCommand(String commandId) {
   for (MCommand cmd : application.getCommands()) {
     if (commandId.equals(cmd.getElementId())) {
       return cmd;
     }
   }
   return null;
 }
 public static MCommand getCommandById(MApplication app, String cmdId) {
   final List<MCommand> cmds = app.getCommands();
   for (MCommand cmd : cmds) {
     if (cmdId.equals(cmd.getElementId())) {
       return cmd;
     }
   }
   return null;
 }
예제 #3
0
  @Override
  public String getDetailLabel(Object element) {
    MCommand cmd = (MCommand) element;
    if (cmd.getCommandName() != null && cmd.getCommandName().trim().length() > 0) {
      return cmd.getCommandName();
    }

    return null;
  }
  /**
   * @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);
 }
예제 #6
0
    @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;
    }