use of org.javarosa.core.model.IFormElement in project collect by opendatakit.
the class FileUtils method getFirstTopLevelBodyGeoPoint.
/**
* Returns the reference of the first child of the given element that is of type geopoint and
* is not contained in a repeat.
*/
private static TreeReference getFirstTopLevelBodyGeoPoint(IFormElement element, FormInstance primaryInstance) {
if (element instanceof QuestionDef) {
QuestionDef question = (QuestionDef) element;
int dataType = primaryInstance.resolveReference((TreeReference) element.getBind().getReference()).getDataType();
if (dataType == Constants.DATATYPE_GEOPOINT) {
return (TreeReference) question.getBind().getReference();
}
} else if (element instanceof FormDef || element instanceof GroupDef) {
if (element instanceof GroupDef && ((GroupDef) element).getRepeat()) {
return null;
} else {
for (IFormElement child : element.getChildren()) {
// perform recursive depth-first search
TreeReference geoRef = getFirstTopLevelBodyGeoPoint(child, primaryInstance);
if (geoRef != null) {
return geoRef;
}
}
}
}
return null;
}
use of org.javarosa.core.model.IFormElement in project collect by opendatakit.
the class DaylightSavingTest method prepareDateTimeWidget.
private DateTimeWidget prepareDateTimeWidget(int year, int month, int day, int hour, int minute) {
QuestionDef questionDefStub = mock(QuestionDef.class);
FormEntryPrompt formEntryPromptStub = new MockFormEntryPromptBuilder().withIndex("index").build();
IFormElement iformElementStub = formEntryPromptStub.getFormElement();
when(iformElementStub.getAdditionalAttribute(anyString(), anyString())).thenReturn(null);
when(formEntryPromptStub.getQuestion()).thenReturn(questionDefStub);
when(formEntryPromptStub.getFormElement()).thenReturn(iformElementStub);
when(formEntryPromptStub.getQuestion().getAppearanceAttr()).thenReturn("no-calendar");
DateTimeWidget dateTimeWidget = new DateTimeWidget(widgetActivity, new QuestionDetails(formEntryPromptStub), widgetUtils);
dateTimeWidget.setData(new LocalDateTime().withDate(year, month, day));
dateTimeWidget.setData(new DateTime().withTime(hour, minute, 0, 0));
return dateTimeWidget;
}
use of org.javarosa.core.model.IFormElement in project collect by opendatakit.
the class DaylightSavingTest method prepareDateWidget.
private DateWidget prepareDateWidget(int year, int month, int day) {
QuestionDef questionDefStub = mock(QuestionDef.class);
FormEntryPrompt formEntryPromptStub = new MockFormEntryPromptBuilder().withIndex("index").build();
IFormElement iformElementStub = formEntryPromptStub.getFormElement();
when(iformElementStub.getAdditionalAttribute(anyString(), anyString())).thenReturn(null);
when(formEntryPromptStub.getQuestion()).thenReturn(questionDefStub);
when(formEntryPromptStub.getFormElement()).thenReturn(iformElementStub);
when(formEntryPromptStub.getQuestion().getAppearanceAttr()).thenReturn("no-calendar");
DatePickerDialog datePickerDialog = mock(DatePickerDialog.class);
DatePicker datePicker = mock(DatePicker.class);
when(datePickerDialog.getDatePicker()).thenReturn(datePicker);
when(datePickerDialog.getDatePicker().getYear()).thenReturn(year);
when(datePickerDialog.getDatePicker().getMonth()).thenReturn(month);
when(datePickerDialog.getDatePicker().getDayOfMonth()).thenReturn(day);
return new DateWidget(widgetActivity, new QuestionDetails(formEntryPromptStub), widgetUtils);
}
use of org.javarosa.core.model.IFormElement in project collect by opendatakit.
the class FormController method repeatIsFieldList.
private boolean repeatIsFieldList(FormIndex index) {
// if this isn't a group, return right away
IFormElement element = formEntryController.getModel().getForm().getChild(index);
if (!(element instanceof GroupDef)) {
return false;
}
// exceptions?
GroupDef gd = (GroupDef) element;
return (ODKView.FIELD_LIST.equalsIgnoreCase(gd.getAppearanceAttr()));
}
use of org.javarosa.core.model.IFormElement in project collect by opendatakit.
the class FormController method stepToPreviousScreenEvent.
/**
* Move the current form index to the index of the previous question in the form.
* Step backward out of repeats and groups as needed. If the resulting question
* is itself within a field-list, move upward to the group or repeat defining that
* field-list.
*/
public int stepToPreviousScreenEvent() throws JavaRosaException {
try {
if (getEvent() != FormEntryController.EVENT_BEGINNING_OF_FORM) {
int event = stepToPreviousEvent();
while (event == FormEntryController.EVENT_REPEAT_JUNCTURE || event == FormEntryController.EVENT_PROMPT_NEW_REPEAT || (event == FormEntryController.EVENT_QUESTION && indexIsInFieldList()) || ((event == FormEntryController.EVENT_GROUP || event == FormEntryController.EVENT_REPEAT) && !indexIsInFieldList())) {
event = stepToPreviousEvent();
}
// Handle nested field-list group
if (getEvent() == FormEntryController.EVENT_GROUP) {
FormIndex currentIndex = getFormIndex();
IFormElement element = formEntryController.getModel().getForm().getChild(currentIndex);
if (element instanceof GroupDef) {
GroupDef gd = (GroupDef) element;
if (ODKView.FIELD_LIST.equalsIgnoreCase(gd.getAppearanceAttr())) {
// jump to outermost containing field-list
FormEntryCaption[] fclist = this.getCaptionHierarchy(currentIndex);
for (FormEntryCaption caption : fclist) {
if (groupIsFieldList(caption.getIndex())) {
formEntryController.jumpToIndex(caption.getIndex());
break;
}
}
}
}
}
}
return getEvent();
} catch (RuntimeException e) {
throw new JavaRosaException(e);
}
}
Aggregations