/** * @param elements * @param multiplicities * @return */ public TreeReference getChildInstanceRef(Vector elements, Vector multiplicities) { if (elements.size() == 0) return null; // get reference for target element TreeReference ref = FormInstance.unpackReference(((IFormElement) elements.lastElement()).getBind()).clone(); for (int i = 0; i < ref.size(); i++) { // There has to be a better way to encapsulate this if (ref.getMultiplicity(i) != TreeReference.INDEX_ATTRIBUTE) { ref.setMultiplicity(i, 0); } } // fill in multiplicities for repeats along the way for (int i = 0; i < elements.size(); i++) { IFormElement temp = (IFormElement) elements.elementAt(i); if (temp instanceof GroupDef && ((GroupDef) temp).getRepeat()) { TreeReference repRef = FormInstance.unpackReference(temp.getBind()); if (repRef.isParentOf(ref, false)) { int repMult = ((Integer) multiplicities.elementAt(i)).intValue(); ref.setMultiplicity(repRef.size() - 1, repMult); } else { return null; // question/repeat hierarchy is not consistent // with instance instance and bindings } } } return ref; }
public IFormElement getChild(FormIndex index) { IFormElement element = this; while (index != null && index.isInForm()) { element = element.getChild(index.getLocalIndex()); index = index.getNextLevel(); } return element; }
public static QuestionDef findQuestionByRef(TreeReference ref, IFormElement fe) { if (fe instanceof FormDef) { ref = ref.genericize(); } if (fe instanceof QuestionDef) { QuestionDef q = (QuestionDef) fe; TreeReference bind = FormInstance.unpackReference(q.getBind()); return (ref.equals(bind) ? q : null); } else { for (int i = 0; i < fe.getChildren().size(); i++) { QuestionDef ret = findQuestionByRef(ref, fe.getChild(i)); if (ret != null) return ret; } return null; } }
public void collapseIndex( FormIndex index, Vector indexes, Vector multiplicities, Vector elements) { if (!index.isInForm()) { return; } IFormElement element = this; while (index != null) { int i = index.getLocalIndex(); element = element.getChild(i); indexes.addElement(new Integer(i)); multiplicities.addElement( new Integer(index.getInstanceIndex() == -1 ? 0 : index.getInstanceIndex())); elements.addElement(element); index = index.getNextLevel(); } }
public IFormElement getElement(String varName) { if (questions == null) return null; for (int i = 0; i < questions.size(); i++) { IFormElement def = (IFormElement) questions.get(i); if (varName.equals(def.getBinding())) return def; // Without this, then we have not validation and skip rules in repeat questions. if (def instanceof GroupDef) { IFormElement elem = ((GroupDef) def).getElement(varName); if (elem != null) return elem; } if (def.getDataType() == QuestionDef.QTN_TYPE_REPEAT && ((QuestionDef) def).getRepeatQtnsDef() != null) { def = ((QuestionDef) def).getRepeatQtnsDef().getElement(varName); if (def != null) return def; } } return null; }
@Override public void writeToXML( Document doc, Element instanceNode, Element bindNode, List<Element> iTextNodes, Element UINode) { // first lets handle the instance stuff instanceNode = writeToXmlInstance(doc, instanceNode); // next the iTextNode writeToXmliText(doc, iTextNodes); // now the UI UINode = writeToXmlUi(doc, UINode); // now that our work is done, lets call the kids // what if the kids are null, those are the worst if (getChildren() != null) { for (IFormElement element : getChildren()) { element.writeToXML(doc, instanceNode, bindNode, iTextNodes, UINode); } } }
/** * Attempts to return question text for this element. Will check for text in the following order: * <br> * Localized Text (long form) -> Localized Text (no special form) <br> * If no textID is specified, method will return THIS element's labelInnerText. * * @param textID - The textID of the text you're trying to retrieve. if <code>textID == null * </code> will get LabelInnerText for current element * @return Question Text. <code>null</code> if no text for this element exists (after all * fallbacks). * @throws RunTimeException if this method is called on an element that is NOT a QuestionDef */ public String getQuestionText(String textID) { String tid = textID; if (tid == "") tid = null; // to make things look clean // check for the null id case and return labelInnerText if it is so. if (tid == null) return substituteStringArgs(element.getLabelInnerText()); // otherwise check for 'long' form of the textID, then for the default form and return String returnText; returnText = getIText(tid, "long"); if (returnText == null) returnText = getIText(tid, null); return substituteStringArgs(returnText); }
/** Used to find out what the index of this element is */ public int getIndex() { IFormElement element = getParent(); return element.getIndexOfChild(this); }
public FormDef getFormDef() { IFormElement element = getParent(); if (parent instanceof FormDef) return (FormDef) element; return element.getFormDef(); }
public void unregister() { this.viewWidget = null; element.unregisterStateObserver(this); }
public void register(IQuestionWidget viewWidget) { this.viewWidget = viewWidget; element.registerStateObserver(this); }
public String getAppearanceHint() { return element.getAppearanceAttr(); }