Exemple #1
0
 public Observer clone() throws CloneNotSupportedException {
   SetAttribute clonedObserver = (SetAttribute) super.clone();
   List<SetAttributeObject> list = new ArrayList<SetAttributeObject>();
   for (SetAttributeObject obj : getSetAttributeObjects()) {
     list.add(obj.clone());
   }
   clonedObserver.setSetAttributeObjects(list);
   return clonedObserver;
 }
Exemple #2
0
  @Override
  public void check(Animation animation, BControl control) {

    this.setAttributes.clear();

    // Collect evaluate predicate objects in list
    for (SetAttributeObject obj : setAttributeObjects) {

      obj.setHasError(false);

      // First evaluate predicate (predicate field)
      String bolValue = "true";
      if (obj.getEval().length() > 0) {
        bolValue = parsePredicate(obj.getEval(), control, animation, obj);
      }

      if (!obj.hasError() && Boolean.valueOf(bolValue)) {

        String attributeID = obj.getAttribute();

        AbstractAttribute attributeObj = control.getAttribute(attributeID);

        Object attributeVal = obj.getValue();

        if (obj.isExpressionMode()) {
          String strAtrVal = parseExpression(attributeVal.toString(), control, animation, obj);
          String er = attributeObj.validateValue(strAtrVal, null);
          if (er != null) {
            addError(
                control,
                animation,
                "You selected "
                    + attributeObj.getName()
                    + " as attribute. There is a problem with your value: "
                    + strAtrVal
                    + " - Reason: "
                    + er);
            obj.setHasError(true);
          } else {
            attributeVal = attributeObj.unmarshal(strAtrVal);
          }
        }

        if (!obj.hasError()) {
          Object oldAttrVal = control.getAttributeValue(attributeID);
          if (!oldAttrVal.equals(attributeVal)) {
            control.setAttributeValue(attributeID, attributeVal);
          }
        }

        setAttributes.add(attributeID);
      }
    }

    // Restore attribute values
    for (SetAttributeObject obj : setAttributeObjects) {
      if (!setAttributes.contains(obj.getAttribute())) {
        AbstractAttribute attributeObj = control.getAttribute(obj.getAttribute());
        Object oldAttrVal = control.getAttributeValue(obj.getAttribute());
        if (!oldAttrVal.equals(attributeObj.getInitValue())) {
          control.restoreDefaultValue(attributeObj.getID());
        }
      }
    }
  }