/** * Determine if the current FormIndex is relevant. Only relevant indexes * should be returned when filling out a form. * * @param index * @return true if current element at FormIndex is relevant */ public Boolean isIndexRelevant(FormIndex index) { TreeReference ref_ = form.getChildInstanceRef(index); Boolean isAskNewRepeat = (getEvent(index) == FormEntryController.EVENT_PROMPT_NEW_REPEAT); Boolean isRepeatJuncture = (getEvent(index) == FormEntryController.EVENT_REPEAT_JUNCTURE); Boolean relevant; if (isAskNewRepeat) { relevant = form.isRepeatRelevant(ref_) && form.canCreateRepeat(ref_, index); //repeat junctures are still relevant if no new repeat can be created; that option //is simply missing from the menu } else if (isRepeatJuncture) { relevant = form.isRepeatRelevant(ref_); } else { TreeElement node = form.Instance.resolveReference(ref_); relevant = node.isRelevant(); // check instance flag first } if (relevant) { // if instance flag/condition says relevant, we still // have to check the <group>/<repeat> hierarchy FormIndex ancestorIndex = index; while (!ancestorIndex.isTerminal()) { // This should be safe now that the TreeReference is contained // in the ancestor index itself TreeElement ancestorNode = form.Instance.resolveReference(ancestorIndex.getLocalReference()); if (!ancestorNode.isRelevant()) { relevant = false; break; } ancestorIndex = ancestorIndex.getNextLevel(); } } return(relevant); }