use of org.javarosa.form.api.FormEntryCaption in project collect by opendatakit.
the class FormController method stepToPreviousEvent.
/**
* Navigates backward in the form.
*
* @return the event that should be handled by a view.
*/
public int stepToPreviousEvent() {
/*
* Right now this will always skip to the beginning of a group if that group is represented
* as a 'field-list'. Should a need ever arise to step backwards by only one step in a
* 'field-list', this method will have to be updated.
*/
formEntryController.stepToPreviousEvent();
if (indexIsInFieldList() && getEvent() == FormEntryController.EVENT_QUESTION) {
// caption[0..len-1]
// caption[len-1] == the question itself
// caption[len-2] == the first group it is contained in.
FormEntryCaption[] captions = getCaptionHierarchy();
FormEntryCaption grp = captions[captions.length - 2];
int event = formEntryController.jumpToIndex(grp.getIndex());
// and test if this group or at least one of its children is relevant...
FormIndex idx = grp.getIndex();
if (!formEntryController.getModel().isIndexRelevant(idx)) {
return stepToPreviousEvent();
}
idx = formEntryController.getModel().incrementIndex(idx, true);
while (FormIndex.isSubElement(grp.getIndex(), idx)) {
if (formEntryController.getModel().isIndexRelevant(idx)) {
return event;
}
idx = formEntryController.getModel().incrementIndex(idx, true);
}
return stepToPreviousEvent();
} else if (indexIsInFieldList() && getEvent() == FormEntryController.EVENT_GROUP) {
FormIndex grpidx = formEntryController.getModel().getFormIndex();
int event = formEntryController.getModel().getEvent();
// and test if this group or at least one of its children is relevant...
if (!formEntryController.getModel().isIndexRelevant(grpidx)) {
// shouldn't happen?
return stepToPreviousEvent();
}
FormIndex idx = formEntryController.getModel().incrementIndex(grpidx, true);
while (FormIndex.isSubElement(grpidx, idx)) {
if (formEntryController.getModel().isIndexRelevant(idx)) {
return event;
}
idx = formEntryController.getModel().incrementIndex(idx, true);
}
return stepToPreviousEvent();
}
return getEvent();
}
use of org.javarosa.form.api.FormEntryCaption in project javarosa by opendatakit.
the class FormParseInit method printStuff.
/*
* Makes an 'extremely basic' print out of the xform model.
*/
public String printStuff() {
String stuff = "";
// go to the beginning of the form
fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
do {
FormEntryCaption fep = femodel.getCaptionPrompt();
boolean choiceFlag = false;
if (fep.getFormElement() instanceof QuestionDef) {
stuff += "\t[Type:QuestionDef, ";
List<SelectChoice> s = ((QuestionDef) fep.getFormElement()).getChoices();
stuff += "ContainsChoices: " + ((s != null && s.size() > 0) ? "true " : "false") + ", ";
if (s != null && s.size() > 0)
choiceFlag = true;
} else if (fep.getFormElement() instanceof FormDef) {
stuff += "\t[Type:FormDef, ";
} else if (fep.getFormElement() instanceof GroupDef) {
stuff += "\t[Type:GroupDef, ";
} else {
stuff += "\t[Type:Unknown]\n";
continue;
}
stuff += "ID:" + fep.getFormElement().getID() + ", TextID:" + fep.getFormElement().getTextID() + ",InnerText:" + fep.getFormElement().getLabelInnerText();
if (choiceFlag) {
stuff += "] \n\t\t---Choices:" + ((QuestionDef) fep.getFormElement()).getChoices().toString() + "\n";
} else {
stuff += "]\n";
}
} while (fec.stepToNextEvent() != fec.EVENT_END_OF_FORM);
return stuff;
}
Aggregations