예제 #1
0
  public void createNewRepeat(FormIndex index) throws InvalidReferenceException {
    TreeReference destRef = getChildInstanceRef(index);
    TreeElement template = instance.getTemplate(destRef);

    instance.copyNode(template, destRef);

    preloadInstance(instance.resolveReference(destRef));
    triggerTriggerables(destRef); // trigger conditions that depend on the creation of this new node
    initializeTriggerables(destRef); // initialize conditions for the node (and sub-nodes)
  }
예제 #2
0
  /**
   * meant to be called after deserialization and initialization of handlers
   *
   * @param newInstance true if the form is to be used for a new entry interaction, false if it is
   *     using an existing IDataModel
   */
  public void initialize(boolean newInstance) {
    if (newInstance) { // only preload new forms (we may have to revisit
      // this)
      preloadInstance(instance.getRoot());
    }

    if (getLocalizer() != null && getLocalizer().getLocale() == null) {
      getLocalizer().setToDefault();
    }

    initializeTriggerables();
  }
예제 #3
0
 public void initializeTriggerables() {
   initializeTriggerables(TreeReference.rootRef());
 }
예제 #4
0
  public void copyItemsetAnswer(QuestionDef q, TreeElement targetNode, IAnswerData data)
      throws InvalidReferenceException {
    ItemsetBinding itemset = q.getDynamicChoices();
    TreeReference targetRef = targetNode.getRef();
    TreeReference destRef = itemset.getDestRef().contextualize(targetRef);

    Vector<Selection> selections = null;
    Vector<String> selectedValues = new Vector<String>();
    if (data instanceof SelectMultiData) {
      selections = (Vector<Selection>) data.getValue();
    } else if (data instanceof SelectOneData) {
      selections = new Vector<Selection>();
      selections.addElement((Selection) data.getValue());
    }
    if (itemset.valueRef != null) {
      for (int i = 0; i < selections.size(); i++) {
        selectedValues.addElement(selections.elementAt(i).choice.getValue());
      }
    }

    // delete existing dest nodes that are not in the answer selection
    Hashtable<String, TreeElement> existingValues = new Hashtable<String, TreeElement>();
    Vector<TreeReference> existingNodes = getInstance().expandReference(destRef);
    for (int i = 0; i < existingNodes.size(); i++) {
      TreeElement node = getInstance().resolveReference(existingNodes.elementAt(i));

      if (itemset.valueRef != null) {
        String value =
            itemset
                .getRelativeValue()
                .evalReadable(
                    this.getInstance(), new EvaluationContext(exprEvalContext, node.getRef()));
        if (selectedValues.contains(value)) {
          existingValues.put(value, node); // cache node if in selection and already exists
        }
      }

      // delete from target
      targetNode.removeChild(node);
    }

    // copy in nodes for new answer; preserve ordering in answer
    for (int i = 0; i < selections.size(); i++) {
      Selection s = selections.elementAt(i);
      SelectChoice ch = s.choice;

      TreeElement cachedNode = null;
      if (itemset.valueRef != null) {
        String value = ch.getValue();
        if (existingValues.containsKey(value)) {
          cachedNode = existingValues.get(value);
        }
      }

      if (cachedNode != null) {
        cachedNode.setMult(i);
        targetNode.addChild(cachedNode);
      } else {
        getInstance().copyItemsetNode(ch.copyNode, destRef, this);
      }
    }

    triggerTriggerables(
        destRef); // trigger conditions that depend on the creation of these new nodes
    initializeTriggerables(destRef); // initialize conditions for the node (and sub-nodes)
    // not 100% sure this will work since destRef is ambiguous as the last step, but i think it's
    // supposed to work
  }