@Override
  protected String conditionedApply(
      Operator operator, String operatorTypeName, XMLImporter importer) {
    if (operator.getParameters().isSpecified(parameterName)) {
      try {
        String attributeName = operator.getParameterAsString(parameterName);

        ChangeAttributeRole setRoleOp = OperatorService.createOperator(ChangeAttributeRole.class);

        // inserting operator into process
        ExecutionUnit process = operator.getExecutionUnit();
        int operatorIndex = process.getOperators().indexOf(operator);
        process.addOperator(setRoleOp, operatorIndex + 1);

        // setting parameter
        setRoleOp.setParameter(ChangeAttributeRole.PARAMETER_NAME, attributeName);
        setRoleOp.setParameter(ChangeAttributeRole.PARAMETER_TARGET_ROLE, targetRole);
        return "Inserted operator for explicitly setting attribute <code>"
            + attributeName
            + "</code> to role <code>"
            + targetRole
            + "</code>";
      } catch (UndefinedParameterError e) {
        return null;
      } catch (OperatorCreationException e) {
        return null;
      }
    }
    return null;
  }
  /**
   * Clones operators contained in <code>original</code>, adds them to this execution unit and wires
   * them as they were originally.
   *
   * @param forParallelExecution Indicates whether this clone is supposed to be executed in
   *     parallel. If yes, the clone will not be registered with the parent process and will share
   *     its {@link Operator#applyCount} with the original.
   */
  public void cloneExecutionUnitFrom(ExecutionUnit original, boolean forParallelExecution) {
    // Clone operators
    Map<String, Operator> clonedOperatorsByName = new HashMap<String, Operator>();
    for (Operator originalChild : original.operators) {
      Operator clonedOperator =
          originalChild.cloneOperator(originalChild.getName(), forParallelExecution);
      addOperator(clonedOperator, !forParallelExecution);
      clonedOperatorsByName.put(originalChild.getName(), clonedOperator);
    }

    // Restore connections
    cloneConnections(original.getInnerSources(), original, clonedOperatorsByName);
    for (Operator op : original.operators) {
      cloneConnections(op.getOutputPorts(), original, clonedOperatorsByName);
    }

    // Unlock
    original.getInnerSources().unlockPortExtenders();
    original.getInnerSinks().unlockPortExtenders();
    for (Operator op : this.operators) {
      op.getInputPorts().unlockPortExtenders();
      op.getOutputPorts().unlockPortExtenders();
    }

    // Other:
    this.expanded = original.expanded;
  }
  @Override
  public void apply() {
    try {
      Operator oldOperator = inputPort.getPorts().getOwner().getOperator();
      Operator newOperator =
          NewOperatorDialog.selectMatchingOperator(
              RapidMinerGUI.getMainFrame().getActions(), null, neededClass, null, null);

      if (newOperator != null) {
        ExecutionUnit unit = inputPort.getPorts().getOwner().getConnectionContext();
        int index = unit.getIndexOfOperator(oldOperator);
        if (index == -1) {
          unit.addOperator(newOperator);
        } else {
          unit.addOperator(newOperator, unit.getIndexOfOperator(oldOperator));
        }
        if (RapidMinerGUI.getMainFrame().VALIDATE_AUTOMATICALLY_ACTION.isSelected()) {
          unit.autoWireSingle(newOperator, CompatibilityLevel.VERSION_5, true, true);
        }
      }
    } catch (OperatorCreationException e) {
    }
  }
Exemplo n.º 4
0
  /**
   * The given operators will be inserted at the last position of the currently selected operator
   * chain.
   */
  public void insert(List<Operator> newOperators) {
    Object selectedNode = getSelectedOperator();
    if (selectedNode == null) {
      SwingTools.showVerySimpleErrorMessage("cannot_insert_operator");
      return;
    } else if (mainFrame.getProcessPanel().getProcessRenderer().getModel().getDisplayedChain()
        == selectedNode) {
      for (Operator newOperator : newOperators) {
        int index =
            mainFrame
                .getProcessPanel()
                .getProcessRenderer()
                .getProcessIndexUnder(
                    mainFrame
                        .getProcessPanel()
                        .getProcessRenderer()
                        .getModel()
                        .getCurrentMousePosition());
        if (index == -1) {
          index = 0;
        }
        ((OperatorChain) selectedNode).getSubprocess(index).addOperator(newOperator);
      }
    } else {
      int i = 0;
      Operator selectedOperator = (Operator) selectedNode;
      ExecutionUnit process = selectedOperator.getExecutionUnit();
      int parentIndex = process.getOperators().indexOf(selectedOperator) + 1;
      for (Operator newOperator : newOperators) {
        process.addOperator(newOperator, parentIndex + i);
        i++;
      }
    }

    AutoWireThread.autoWireInBackground(newOperators, true);
    mainFrame.selectOperators(newOperators);
  }