Search in sources :

Example 11 with IFormElement

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;
}
Also used : IFormElement(org.javarosa.core.model.IFormElement) TreeReference(org.javarosa.core.model.instance.TreeReference) FormDef(org.javarosa.core.model.FormDef) QuestionDef(org.javarosa.core.model.QuestionDef) GroupDef(org.javarosa.core.model.GroupDef)

Example 12 with IFormElement

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;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) IFormElement(org.javarosa.core.model.IFormElement) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) DateTimeWidget(org.odk.collect.android.widgets.DateTimeWidget) QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) QuestionDef(org.javarosa.core.model.QuestionDef) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime)

Example 13 with IFormElement

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);
}
Also used : IFormElement(org.javarosa.core.model.IFormElement) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) DatePickerDialog(android.app.DatePickerDialog) DateWidget(org.odk.collect.android.widgets.DateWidget) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) DatePicker(android.widget.DatePicker) QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) QuestionDef(org.javarosa.core.model.QuestionDef)

Example 14 with IFormElement

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()));
}
Also used : IFormElement(org.javarosa.core.model.IFormElement) GroupDef(org.javarosa.core.model.GroupDef)

Example 15 with IFormElement

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);
    }
}
Also used : IFormElement(org.javarosa.core.model.IFormElement) FormEntryCaption(org.javarosa.form.api.FormEntryCaption) FormIndex(org.javarosa.core.model.FormIndex) GroupDef(org.javarosa.core.model.GroupDef) JavaRosaException(org.odk.collect.android.exception.JavaRosaException)

Aggregations

IFormElement (org.javarosa.core.model.IFormElement)26 GroupDef (org.javarosa.core.model.GroupDef)19 QuestionDef (org.javarosa.core.model.QuestionDef)10 ArrayList (java.util.ArrayList)9 TreeReference (org.javarosa.core.model.instance.TreeReference)8 FormIndex (org.javarosa.core.model.FormIndex)6 TreeElement (org.javarosa.core.model.instance.TreeElement)6 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)5 IDataReference (org.javarosa.core.model.IDataReference)4 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)3 XPathReference (org.javarosa.model.xform.XPathReference)3 Element (org.kxml2.kdom.Element)3 DataBinding (org.javarosa.core.model.DataBinding)2 Constraint (org.javarosa.core.model.condition.Constraint)2 IAnswerData (org.javarosa.core.model.data.IAnswerData)2 FormEntryModel (org.javarosa.form.api.FormEntryModel)2 Test (org.junit.Test)2 QuestionDetails (org.odk.collect.android.formentry.questions.QuestionDetails)2 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)2 Activity (android.app.Activity)1