/** * Returns a hierarchical list of FormEntryCaption objects for the given * FormIndex * * @param index * @return list of FormEntryCaptions in hierarchical order */ public FormEntryCaption[] getCaptionHierarchy(FormIndex index) { List <FormEntryCaption> captions = new List <FormEntryCaption>(); FormIndex remaining = index; while (remaining != null) { remaining = remaining.getNextLevel(); FormIndex localIndex = index.diff(remaining); IFormElement element = form.getChild(localIndex); if (element != null) { FormEntryCaption caption = null; if (element is GroupDef) { caption = new FormEntryCaption(getForm(), localIndex); } else if (element is QuestionDef) { caption = new FormEntryPrompt(getForm(), localIndex); } if (caption != null) { captions.Add(caption); } } } FormEntryCaption[] captionArray = new FormEntryCaption[captions.Count]; captions.CopyTo(captionArray); return(captionArray); }
/** * 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); }