Esempio n. 1
0
  @Override
  @SuppressWarnings("unchecked")
  protected void evaluationRequest(Script script) {
    super.evaluationRequest(script);

    Object property = null;

    if (getValueOptions() != null) {

      if (getValueOptions().contains("endings")) {
        property = script.getProperty("endings");
      }

      if (property != null) {
        getFileFilter().setAcceptedEndings((ArrayList<String>) property);
      }

      property = null;

      if (getValueOptions().contains("description")) {
        property = script.getProperty("description");
      }

      if (property != null) {
        getFileFilter().setDescription((String) property);
      }
    }
  }
  /**
   * Constructor.
   *
   * <p>Creates an AbstractMethodRepresentation object from a method representation
   *
   * @param mRep the method representation
   */
  public AbstractMethodRepresentation(DefaultMethodRepresentation mRep) {
    valueData = new ArrayList<AbstractParameter>();
    parameterTypeNames = new ArrayList<String>();
    parameterGroup = new AbstractParameterGroups(mRep.getParameterGroup());

    String methodApiName = mRep.getDescription().getMethodName() + "(...)";

    for (TypeRepresentationBase t : mRep.getParameters()) {
      try {
        valueData.add(new AbstractParameter((TypeRepresentationBase) t));
      } catch (Exception ex) {

        ex.printStackTrace(System.err);

        String msgTitle = "Errors while saving Parameter(s):";
        String msg = ">> Cannot save Parameter(s) of method \"" + methodApiName + "\"";

        System.err.println(">> " + msgTitle);
        System.err.println(" --> " + msg);
        System.err.println(" --> still proceeding...");

        if (mRep.getMainCanvas() != null) {
          mRep.getMainCanvas()
              .getMessageBox()
              .addMessage(msgTitle, msg, t.getConnector(), MessageType.WARNING);
        }
      }
    }

    setReturnValueData(new AbstractParameter(mRep.getReturnValue()));

    setVisibility(mRep.isVisible());
    setMethodId(mRep.getID());
    setVisualMethodID(mRep.getVisualMethodID());
    setMethodName(mRep.getDescription().getMethodName());
    setMinimized(mRep.isMinimized());

    setParameterTypes(mRep.getDescription().getParameterTypes());

    for (Class<?> c : parameterTypes) {
      parameterTypeNames.add(c.getName());
    }
  }
  /**
   * Assigns properties to method representation. This method is used to assign properties loaded
   * from XML session file.
   *
   * @param m the method representation that is associated with this abstract method representation
   */
  public void assignProperties(DefaultMethodRepresentation m) {

    System.out.println("****METHOD: " + m.getName());

    for (TypeRepresentationBase t : m.getParameters()) {
      System.out.println(" --> Param: " + t.getValueName());
    }

    m.setVisualMethodID(getVisualMethodID());

    getParameterGroup().assignProperties(m.getParameterGroup());

    ArrayList<Object> values = new ArrayList<Object>();
    ArrayList<String> valueOptions = new ArrayList<String>();
    ArrayList<CustomParamData> customParamDataList = new ArrayList<CustomParamData>();

    for (AbstractParameter p : this.getValueData()) {
      values.add(p.getValueObject());
      valueOptions.add(p.getValueOptions());
      customParamDataList.add(p.getCustomData());
    }

    for (int i = 0; i < valueOptions.size(); i++) {
      m.getParameter(i).setValueOptions(valueOptions.get(i));
      m.getParameter(i).evaluateValueOptions();
    }

    m.setParameters(values);

    for (int i = 0; i < customParamDataList.size(); i++) {

      CustomParamData paramData = customParamDataList.get(i);

      // to support old versions (pre 3.8.11, 03.05.2010) we create an
      // empty custom paramDataObject to prevent null pointer exceptions
      if (paramData != null) {
        m.getParameter(i).setCustomData(paramData);
      }

      m.getParameter(i).setCustomData(customParamDataList.get(i));
      m.getParameter(i).evaluateCustomParamData();
    }

    m.getReturnValue().setValueOptions(returnValueData.getValueOptions());

    try {
      m.getReturnValue().evaluateValueOptions();
    } catch (Exception ex) {
      ex.printStackTrace(System.err);
    }

    Object returnValue = returnValueData.getValueObject();

    if (returnValue != null) {
      m.getReturnValue().setValue(returnValue);
      m.getReturnValue().setUpToDate(true);
    } else {
      m.getReturnValue().setUpToDate(false);
    }

    CustomParamData paramData = returnValueData.getCustomData();

    // to support old versions (pre 3.8.11, 03.05.2010) we create an
    // empty custom paramDataObject to prevent null pointer exceptions
    if (paramData != null) {
      m.getReturnValue().setCustomData(paramData);
    }

    try {
      m.getReturnValue().evaluateCustomParamData();
    } catch (Exception ex) {
      ex.printStackTrace(System.err);
    }

    if (getMinimized()) {
      m.minimize();
    }

    System.out.println(" --> DONE");
  }