Exemplo n.º 1
0
  /**
   * The property is a simple value list. If property is a list property, the method will check to
   * see if the current element has the local list value, if it has, the method returns, otherwise,
   * a copy of the list value inherited from container or parent will be set locally on the element
   * itself.
   *
   * <p>This method is supposed to be used when we need to change the value of a composite property(
   * a simple list property ). These kind of property is inherited as a whole, so when the value
   * changed from a child element. This method will be called to ensure that a local copy will be
   * made, so change to the child won't affect the original value in the parent.
   *
   * @param ref a reference to a list property or member.
   */
  private DesignElement makeLocalCompositeValue(
      DesignElement topElement, ElementPropertyDefn prop, DesignElement content) {
    // Top level property is a list.

    Object localValue = topElement.getLocalProperty(module, prop);

    if (localValue != null) return content;

    // Make a local copy of the inherited list value.

    Object inherited = topElement.getProperty(module, prop);

    // if the action is add, the inherited can be null.

    if (inherited == null) return null;

    int index = -1;

    if (content != null && inherited instanceof List) index = ((List) inherited).indexOf(content);

    Object newValue = ModelUtil.copyValue(prop, inherited);
    ActivityStack activityStack = module.getActivityStack();

    ContainerContext context = new ContainerContext(topElement, prop.getName());

    if (newValue instanceof List) {
      List list = new ArrayList();
      PropertyRecord propRecord = new PropertyRecord(topElement, prop, list);
      activityStack.execute(propRecord);

      list = (List) newValue;
      for (int i = 0; i < list.size(); i++) {
        DesignElement tmpContent = (DesignElement) list.get(i);
        ContentRecord addRecord = new ContentRecord(module, context, tmpContent, i);
        activityStack.execute(addRecord);
      }
    } else {
      PropertyRecord propRecord = new PropertyRecord(topElement, prop, newValue);
      activityStack.execute(propRecord);
    }

    if (index != -1) return (DesignElement) ((List) newValue).get(index);

    return content;
  }
Exemplo n.º 2
0
  private DesignElement matchElement(DesignElement topElement) {
    List<Step> steps = eventTarget.stepIterator();

    DesignElement tmpElement = topElement;
    for (int i = steps.size() - 1; i >= 0; i--) {
      Step step = steps.get(i);
      PropertyDefn stepPropDefn = step.stepPropDefn;
      int index = step.index;

      Object stepValue = tmpElement.getLocalProperty(module, (ElementPropertyDefn) stepPropDefn);

      if (stepPropDefn.isListType()) {
        tmpElement = (DesignElement) ((List) stepValue).get(index);
      } else tmpElement = (DesignElement) stepValue;
    }

    return tmpElement;
  }