示例#1
0
 /**
  * Creates a FormEntryPrompt for the element at the given index in the form.
  *
  * @param form
  * @param index
  */
 public FormEntryPrompt(FormDef form, FormIndex index)
     : base(form, index)
 {
     if (!(element is QuestionDef))
     {
         throw new ArgumentException("FormEntryPrompt can only be created for QuestionDef elements");
     }
     this.mTreeElement = form.Instance.resolveReference(index.getReference());
 }
示例#2
0
 /**
  * commitAnswer actually saves the data into the datamodel.
  *
  * @param element
  * @param index
  * @param data
  * @return true if saved successfully, false otherwise
  */
 private Boolean commitAnswer(TreeElement element, FormIndex index, IAnswerData data)
 {
     if (data != null || element.getValue() != 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.getForm().setValue(data, index.getReference(), element);
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#3
0
        /**
         * Attempts to save the answer at the specified FormIndex into the
         * datamodel.
         *
         * @param index
         * @param data
         * @return OK if save was successful, error if a constraint was violated.
         */
        public int answerQuestion(FormIndex index, IAnswerData data)
        {
            QuestionDef q = model.getQuestionPrompt(index).getQuestion();

            if (model.getEvent(index) != FormEntryController.EVENT_QUESTION)
            {
                throw new SystemException("Non-Question object at the form index.");
            }
            TreeElement element         = model.getTreeElement(index);
            Boolean     complexQuestion = q.isComplex();

            Boolean hasConstraints = false;

            if (element.required && data == null)
            {
                return(ANSWER_REQUIRED_BUT_EMPTY);
            }
            else if (!complexQuestion && !model.getForm().evaluateConstraint(index.getReference(), 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 SystemException("Itemsets do not currently evaluate constraints. Your constraint will not work, please remove it before proceeding.");
            }
            else
            {
                try
                {
                    model.getForm().copyItemsetAnswer(q, element, data);
                }
                catch (InvalidReferenceException ire)
                {
                    Console.WriteLine(ire.StackTrace);
                    throw new SystemException("Invalid reference while copying itemset answer: " + ire.Message);
                }
                return(ANSWER_OK);
            }
        }
示例#4
0
        private String getRepetitionText(String type, FormIndex index, Boolean newrep)
        {
            if (element is GroupDef && ((GroupDef)element).Repeat && index.getElementMultiplicity() >= 0)
            {
                GroupDef g = (GroupDef)element;

                String title = getLongText();
                int    ix    = index.getElementMultiplicity() + 1;
                int    count = getNumRepetitions();

                String caption = null;
                if ("header".Equals(type))
                {
                    caption = g.entryHeader;
                }
                else if ("choose".Equals(type))
                {
                    caption = g.chooseCaption;
                    if (caption == null)
                    {
                        caption = g.entryHeader;
                    }
                }
                if (caption == null)
                {
                    return(title + " " + ix + "/" + count);
                }

                IDictionary <String, Object> vars = new Dictionary <String, Object>();
                vars.Add("name", title);
                vars.Add("i", ix);
                vars.Add("n", count);
                vars.Add("new", newrep);
                return(form.fillTemplateString(caption, index.getReference(), vars));
            }
            else
            {
                return(null);
            }
        }
示例#5
0
 /**
  *
  * @param index
  * @return
  */
 public TreeElement getTreeElement(FormIndex index)
 {
     return(form.Instance.resolveReference(index.getReference()));
 }
示例#6
0
        //TODO: this is explicitly missing integration with the new multi-media support
        //TODO: localize the default captions
        public String getRepeatText(String typeKey)
        {
            GroupDef g = (GroupDef)element;

            if (!g.Repeat)
            {
                throw new SystemException("not a repeat");
            }

            String title = getLongText();
            int    count = getNumRepetitions();

            String caption = null;

            if ("mainheader".Equals(typeKey))
            {
                caption = g.mainHeader;
                if (caption == null)
                {
                    return(title);
                }
            }
            else if ("add".Equals(typeKey))
            {
                caption = g.addCaption;
                if (caption == null)
                {
                    return("Add another " + title);
                }
            }
            else if ("add-empty".Equals(typeKey))
            {
                caption = g.addEmptyCaption;
                if (caption == null)
                {
                    caption = g.addCaption;
                }
                if (caption == null)
                {
                    return("None - Add " + title);
                }
            }
            else if ("del".Equals(typeKey))
            {
                caption = g.delCaption;
                if (caption == null)
                {
                    return("Delete " + title);
                }
            }
            else if ("done".Equals(typeKey))
            {
                caption = g.doneCaption;
                if (caption == null)
                {
                    return("Done");
                }
            }
            else if ("done-empty".Equals(typeKey))
            {
                caption = g.doneEmptyCaption;
                if (caption == null)
                {
                    caption = g.doneCaption;
                }
                if (caption == null)
                {
                    return("Skip");
                }
            }
            else if ("delheader".Equals(typeKey))
            {
                caption = g.delHeader;
                if (caption == null)
                {
                    return("Delete which " + title + "?");
                }
            }

            IDictionary <String, Object> vars = new Dictionary <String, Object>();

            vars.Add("name", title);
            vars.Add("n", count);
            return(form.fillTemplateString(caption, index.getReference(), vars));
        }