Example #1
0
 /**
  * For the current index: Checks whether the index represents a node which
  * should exist given a non-interactive repeat, along with a count for that
  * repeat which is beneath the dynamic level specified.
  *
  * If this index does represent such a node, the new model for the repeat is
  * created behind the scenes and the index for the initial question is
  * returned.
  *
  * Note: This method will not prevent the addition of new repeat elements in
  * the interface, it will merely use the xforms repeat hint to create new
  * nodes that are assumed to exist
  *
  * @param The index to be evaluated as to whether the underlying model is
  *        hinted to exist
  */
 private void createModelIfNecessary(FormIndex index)
 {
     if (index.isInForm())
     {
         IFormElement e = getForm().getChild(index);
         if (e is GroupDef)
         {
             GroupDef g = (GroupDef)e;
             if (g.Repeat && g.CountReference != null)
             {
                 IAnswerData count = getForm().Instance.getDataValue(g.CountReference);
                 if (count != null)
                 {
                     long          fullcount = ((int)count.Value);
                     TreeReference ref_      = getForm().getChildInstanceRef(index);
                     TreeElement   element   = getForm().Instance.resolveReference(ref_);
                     if (element == null)
                     {
                         if (index.getInstanceIndex() < fullcount)
                         {
                             try
                             {
                                 getForm().createNewRepeat(index);
                             }
                             catch (InvalidReferenceException ire)
                             {
                                 Console.WriteLine(ire.StackTrace);
                                 throw new SystemException("Invalid Reference while creting new repeat!" + ire.Message);
                             }
                         }
                     }
                 }
             }
         }
     }
 }