/// <summary> Creates a FormEntryPrompt for the element at the given index in the form. /// /// </summary> /// <param name="form"> /// </param> /// <param name="index"> /// </param> public FormEntryPrompt(FormDef form, FormIndex index) : base(form, index) { InitBlock(); if (!(element is QuestionDef)) { throw new System.ArgumentException("FormEntryPrompt can only be created for QuestionDef elements"); } this.mTreeElement = form.MainInstance.resolveReference(index.Reference); }
/// <summary> saveAnswer attempts to save the current answer into the data model /// without doing any constraint checking. Only use this if you know what /// you're doing. For normal form filling you should always use /// answerQuestion or answerCurrentQuestion. /// /// </summary> /// <param name="index"> /// </param> /// <param name="data"> /// </param> /// <returns> true if saved successfully, false otherwise. /// </returns> public virtual bool saveAnswer(FormIndex index, IAnswerData data) { if (model.getEvent(index) != FormEntryController.EVENT_QUESTION) { throw new System.SystemException("Non-Question object at the form index."); } TreeElement element = model.getTreeElement(index); return(commitAnswer(element, index, data)); }
/// <summary> Creates a new repeated instance of the group referenced by the specified /// FormIndex. /// /// </summary> /// <param name="questionIndex"> /// </param> public virtual void newRepeat(FormIndex questionIndex) { try { model.Form.createNewRepeat(questionIndex); } catch (InvalidReferenceException ire) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" throw new System.SystemException("Invalid reference while copying itemset answer: " + ire.Message); } }
/// <summary> commitAnswer actually saves the data into the datamodel. /// /// </summary> /// <param name="element"> /// </param> /// <param name="index"> /// </param> /// <param name="data"> /// </param> /// <returns> true if saved successfully, false otherwise /// </returns> private bool commitAnswer(TreeElement element, FormIndex index, IAnswerData data) { if (data != null || element.Value != null) { // we should check if the data to be saved is already the same as // the data in the model, but we can't (no IAnswerData.equals()) model.Form.setValue(data, index.Reference, element); return(true); } else { return(false); } }
/// <summary> Attempts to save the answer at the specified FormIndex into the /// datamodel. /// /// </summary> /// <param name="index"> /// </param> /// <param name="data"> /// </param> /// <returns> OK if save was successful, error if a constraint was violated. /// </returns> public virtual int answerQuestion(FormIndex index, IAnswerData data) { QuestionDef q = model.getQuestionPrompt(index).Question; if (model.getEvent(index) != FormEntryController.EVENT_QUESTION) { throw new System.SystemException("Non-Question object at the form index."); } TreeElement element = model.getTreeElement(index); bool complexQuestion = q.Complex; bool hasConstraints = false; if (element.Required && data == null) { return(ANSWER_REQUIRED_BUT_EMPTY); } else if (!complexQuestion && !model.Form.evaluateConstraint(index.Reference, data)) { return(ANSWER_CONSTRAINT_VIOLATED); } else if (!complexQuestion) { commitAnswer(element, index, data); return(ANSWER_OK); } else if (complexQuestion && hasConstraints) { //TODO: itemsets: don't currently evaluate constraints for itemset/copy -- haven't figured out how handle it yet throw new System.SystemException("Itemsets do not currently evaluate constraints. Your constraint will not work, please remove it before proceeding."); } else { try { model.Form.copyItemsetAnswer(q, element, data); } catch (InvalidReferenceException ire) { SupportClass.WriteStackTrace(ire, Console.Error); //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" throw new System.SystemException("Invalid reference while copying itemset answer: " + ire.Message); } return(ANSWER_OK); } }
/// <summary> Moves the current FormIndex to the next/previous relevant position. /// /// </summary> /// <param name="forward"> /// </param> /// <returns> /// </returns> private int stepEvent(bool forward) { FormIndex index = model.FormIndex; do { if (forward) { index = model.incrementIndex(index); } else { index = model.decrementIndex(index); } }while (index.InForm && !model.isIndexRelevant(index)); return(jumpToIndex(index)); }
/// <summary> Deletes a repeated instance of a group referenced by the specified /// FormIndex. /// /// </summary> /// <param name="questionIndex"> /// </param> /// <returns> /// </returns> public virtual FormIndex deleteRepeat(FormIndex questionIndex) { return(model.Form.deleteRepeat(questionIndex)); }
/// <summary> Jumps to a given FormIndex. /// /// </summary> /// <param name="index"> /// </param> /// <returns> EVENT for the specified Index. /// </returns> public virtual int jumpToIndex(FormIndex index) { model.QuestionIndex = index; return(model.getEvent(index)); }