public Object run(ExecutionEvent event) throws ExecutionException {

    DBSelection dbSel =
        event == null ? null : new DBSelection(HandlerUtil.getCurrentSelection(event));

    if (model == null) {
      ElementDBNode sel = dbSel.getSel();

      if (sel instanceof InstanceDBNode)
        model = addSibling ? ((InstanceDBNode) sel).getInstDB().modelRoot() : dbSel.getModel();
      else if (sel instanceof ModelDBNode) model = ((ModelDBNode) sel).model();
    }

    if (model == null) {
      ViewUtils.setErrorMessage("no model selected to add the instance to, request ignored");
      return null;
    }

    Shell activeShell = ViewUtils.getTopShellActivePage();

    if (!ToolsDesignLib.isEditable(model.getDb())) {
      MessageDialog.openError(
          activeShell,
          "Add model",
          "Attempting to add a new model to the library "
              + model.getDb().getName()
              + ". Only the work library is editable, all others are read-only");
      return null;
    }

    SelectionDialogModel dialog = new SelectionDialogModel(activeShell, model.techno());

    if (dialog.open() == Window.OK) {
      for (ModelDB m : dialog.getDataModel().getSelectedModels()) {
        DBJobParam param = new DBJobParam();
        param.setSrcModel(m);
        param.setDstModel(model);

        InstanceAddDBJob job = new InstanceAddDBJob(param);

        job.launch();
      }
    }
    model = null;

    return null;
  }
  public Object execute(List<String> argList) throws TclShellException {
    JSAPResult argv = parse(argList);
    if (argv == null) {
      return false;
    }

    if (argv.getBoolean(SmOptionPM.LIST_ATTR_OPTION)) {
      for (PWR_SRC_ATTR e : PWR_SRC_ATTR.values())
        System.out.println(
            " =>  "
                + e.arg
                + " :\n         "
                + e.help
                + (e.allowed == null ? "" : " = " + StringUtilities.join(", ", e.allowed) + ")"));

      return true;
    }

    String modelID = argv.getString(SmOption.MODEL_OPTION);
    ModelDB model =
        (modelID != null) ? ToolsDesign.getModel(modelID) : UnwCore.getDBProject().model();

    if (model == null) {
      Logger.error(ErrorList.DB3.errorName(), ErrorList.DB3.getMessage(modelID));
      throw new TclShellException("");
    }

    PMConfig cfg = PMResourceManager.instance.getPmconfig(model, null);

    String pwrsrcName = argv.getString(SmOptionPM.PWRSRC_OPTION);

    PowerSourceInstance powerSource = PMFindVDomainTools.findPowerSource(cfg, pwrsrcName);

    if (powerSource == null) {
      Logger.error(
          ErrorListPM.PM22.errorName(),
          ErrorListPM.PM22.getMessage(pwrsrcName + "in model " + model.getModelName()));
      throw new TclShellException("");
    }

    if (!argv.contains(SmOption.NAME_VALUE_OPTION)) {
      Logger.error("TCL", "no attribute specified");
      throw new TclShellException("");
    }

    String[] tokens = argv.getStringArray(SmOption.NAME_VALUE_OPTION);
    if (tokens.length % 2 != 0) {
      Logger.error(ErrorListPM.PM_TCL1.errorName(), ErrorListPM.PM_TCL1.getMessage());
      throw new TclShellException("");
    }

    String attrName;
    String attrValue;
    boolean error = false;

    for (int i = 0; i < tokens.length; i += 2) {
      attrName = tokens[i];
      attrValue = tokens[i + 1];

      PWR_SRC_ATTR id = PWR_SRC_ATTR.findAttr(attrName);

      if (id == null) {
        Logger.error(ErrorListPM.PM_TCL3.errorName(), ErrorListPM.PM_TCL3.getMessage(attrName));
        throw new TclShellException("");

      } else {

        CONNECT_DIRECTIVE direct = null;

        switch (id) {
          case CONNECT_IVOLT:
            try {
              direct = CONNECT_DIRECTIVE.valueOf(attrValue);
              powerSource.setConnectInputVoltage(direct);
            } catch (Exception e) {
              error = true;
            }
            break;

          case CONNECT_CTRL:
            try {
              direct = CONNECT_DIRECTIVE.valueOf(attrValue);
              powerSource.setConnectControl(direct);
            } catch (Exception e) {
              error = true;
            }
            break;

          case NAME:
            if (FormatValidation.isAlphaNumeric(attrValue, false)) {
              powerSource.setName(attrValue);
            } else error = true;

          default:
            break;
        }

        if (error) {
          Logger.error(
              ErrorListPM.PM_TCL2.errorName(),
              ErrorListPM.PM_TCL2.getMessage(attrValue + " for attribute " + attrName));
          throw new TclShellException("");
        }
      }
    }

    return true;
  }
  public Object execute(List<String> argList) throws TclShellException {

    JSAPResult argv = parse(argList);
    if (argv == null) {
      return false;
    }
    InstanceDB inst;
    boolean hasError = false;
    String modelID = argv.getString(SmOption.MODEL_OPTION);

    ModelDB model = SmOption.getModel(modelID);
    if (model == null) throw new TclShellException("");

    boolean createPort = argv.getBoolean(SmOption.CREATE_PORT_OPTION);
    /*
     * Set Parameters
     */
    String[] instances = argv.getStringArray(SmOption.INSTANCE_OPTION);

    Collection<InstanceDB> instToConnect = new ArrayList<InstanceDB>();

    if (instances == null || instances.length == 0) instToConnect = model.instances();

    for (String instName : instances) {
      inst = model.instance(instName);

      if (inst == null) {
        Logger.error(
            ErrorList.DB15.errorName(),
            ErrorList.DB15.getMessage(instName + " in model " + model.getModelName()));
        hasError = true;
        continue;
      }
      instToConnect.add(inst);
    }

    DBJobParam param = new DBJobParam();
    param.setSrcData(
        ConnectByNameDBJob.CONNECT_INSTANCES,
        instToConnect.toArray(new InstanceDB[instToConnect.size()]));
    param.setSrcData(ConnectByNameDBJob.CREATE_PORT, createPort);
    param.setSrcData(ConnectByNameDBJob.LEAKAGE_PORT, argv.getBoolean(SmOption.LEAKAGE_OPTION));
    param.setSrcData(
        ConnectByNameDBJob.PROPAGATE_UP,
        SmOption.UP_OPTION.equals(argv.getString(SmOption.PROPAGATE_OPTION)));

    if (argv.contains(SmOption.DIRECTION_OPTION)) {
      String dir = argv.getString(SmOption.DIRECTION_OPTION);

      if ("in".equals(dir)) param.setSrcData(ConnectByNameDBJob.DIRECTION, PortInDB.class);
      else if ("out".equals(dir)) param.setSrcData(ConnectByNameDBJob.DIRECTION, PortOutDB.class);
    }

    if (argv.getBoolean(SmOption.HIER_OPTION))
      param.setSrcData(ConnectByNameDBJob.HIER_OPTION, true);

    param.setSrcData(ConnectByNameDBJob.KEEPCONNECTION, !argv.getBoolean(SmOption.FORCE_OPTION));

    DBJob job = new ConnectByNameDBJob(param);
    job.launch();

    if (hasError || !job.isSuccessful())
      throw new TclShellException("error with " + getCommandText());

    return null;
  }