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;
}
}
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);
}
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;
}
Aggregations