Search in sources :

Example 61 with FormIndex

use of org.javarosa.core.model.FormIndex in project collect by opendatakit.

the class FormEntryViewModel method canAddRepeat.

public boolean canAddRepeat() {
    if (formController != null && formController.indexContainsRepeatableGroup()) {
        FormDef formDef = formController.getFormDef();
        FormIndex repeatGroupIndex = getRepeatGroupIndex(formController.getFormIndex(), formDef);
        return !((GroupDef) formDef.getChild(repeatGroupIndex)).noAddRemove;
    } else {
        return false;
    }
}
Also used : FormDef(org.javarosa.core.model.FormDef) FormIndex(org.javarosa.core.model.FormIndex)

Example 62 with FormIndex

use of org.javarosa.core.model.FormIndex in project collect by opendatakit.

the class AuditEventCSVLine method getXPathPath.

/**
 * Get the XPath path of the node at a particular {@link FormIndex}.
 * <p>
 * Differs from {@link TreeReference#toString()} in that position predicates are only
 * included for repeats. For example, given a group named {@code my-group} that contains a
 * repeat named {@code my-repeat} which in turn contains a question named {@code my-question},
 * {@link TreeReference#toString()} would return paths that look like
 * {@code /my-group[1]/my-repeat[3]/my-question[1]}. In contrast, this method would return
 * {@code /my-group/my-repeat[3]/my-question}.
 * <p>
 * TODO: consider moving to {@link FormIndex}
 */
private static String getXPathPath(FormIndex formIndex) {
    List<String> nodeNames = new ArrayList<>();
    nodeNames.add(formIndex.getReference().getName(0));
    FormIndex walker = formIndex;
    int i = 1;
    while (walker != null) {
        try {
            String currentNodeName = formIndex.getReference().getName(i);
            if (walker.getInstanceIndex() != -1) {
                currentNodeName = currentNodeName + "[" + (walker.getInstanceIndex() + 1) + "]";
            }
            nodeNames.add(currentNodeName);
        } catch (IndexOutOfBoundsException e) {
            Timber.i(e);
        }
        walker = walker.getNextLevel();
        i++;
    }
    return "/" + StringUtils.join("/", nodeNames);
}
Also used : ArrayList(java.util.ArrayList) FormIndex(org.javarosa.core.model.FormIndex)

Example 63 with FormIndex

use of org.javarosa.core.model.FormIndex in project collect by opendatakit.

the class SaveFormIndexTask method loadFormIndexFromFile.

public static FormIndex loadFormIndexFromFile() {
    FormIndex formIndex = null;
    try {
        String instanceName = Collect.getInstance().getFormController().getInstanceFile().getName();
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(SaveFormToDisk.getFormIndexFile(instanceName)));
        formIndex = (FormIndex) ois.readObject();
        ois.close();
    } catch (Exception e) {
        Timber.e(e);
    }
    return formIndex;
}
Also used : FormIndex(org.javarosa.core.model.FormIndex) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

FormIndex (org.javarosa.core.model.FormIndex)63 GroupDef (org.javarosa.core.model.GroupDef)11 JavaRosaException (org.odk.collect.android.exception.JavaRosaException)11 FormController (org.odk.collect.android.javarosawrapper.FormController)11 ArrayList (java.util.ArrayList)10 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)10 Test (org.junit.Test)10 IFormElement (org.javarosa.core.model.IFormElement)6 TreeReference (org.javarosa.core.model.instance.TreeReference)6 FormEntryCaption (org.javarosa.form.api.FormEntryCaption)6 File (java.io.File)5 FormController (org.odk.collect.android.logic.FormController)5 HierarchyElement (org.odk.collect.android.logic.HierarchyElement)5 IAnswerData (org.javarosa.core.model.data.IAnswerData)4 HierarchyListAdapter (org.odk.collect.android.adapters.HierarchyListAdapter)4 FormDef (org.javarosa.core.model.FormDef)3 FormEntryModel (org.javarosa.form.api.FormEntryModel)3 Intent (android.content.Intent)2 ObjectInputStream (java.io.ObjectInputStream)2 HashMap (java.util.HashMap)2