use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class BatchingFormTreeBuilder method fetchFormClasses.
private List<FormClass> fetchFormClasses(Iterable<ResourceId> formIds) {
List<FormClass> fetched = new ArrayList<>();
// Identify the forms that we don't already have in the cache
Set<ResourceId> toFetch = new HashSet<>();
for (ResourceId formClassId : formIds) {
if (!formCache.containsKey(formClassId)) {
toFetch.add(formClassId);
}
}
// Fetch from the store
Map<ResourceId, FormClass> formClasses = catalog.getFormClasses(toFetch);
// Store back to the cache
for (FormClass formClass : formClasses.values()) {
formCache.put(formClass.getId(), formClass);
fetched.add(formClass);
}
return fetched;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class FormForest method getReferencedForms.
public List<FormClass> getReferencedForms() {
Set<ResourceId> visited = new HashSet<>();
List<FormClass> list = new ArrayList<>();
// Depth-first search for natural ordering
for (FormTree formTree : trees.values()) {
collectReferenced(formTree, formTree.getRootFields(), visited, list);
}
return list;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class FormWidgetCreator method createWidgets.
public Promise<Void> createWidgets(final FormClass formClass, final FieldUpdated fieldUpdated) {
List<Promise<Void>> promises = Lists.newArrayList();
for (final FormField field : formClass.getFields()) {
if (field.getType() instanceof SubFormReferenceType) {
FormClass subForm = model.getSubFormByOwnerFieldId(field.getId());
if (subForm.getSubFormKind() != SubFormKind.REPEATING) {
// for repeating we create it internally in sub SimpleFormPanel
Promise<Void> subFormWidgetsPromise = createWidgets(subForm, fieldUpdated);
promises.add(subFormWidgetsPromise);
}
} else {
Promise<Void> promise = widgetFactory.createWidget(formClass, field, new FieldUpdater<FieldValue>() {
@Override
public void onInvalid(String errorMessage) {
containers.get(field.getId()).setInvalid(errorMessage);
}
@Override
public void update(FieldValue value) {
containers.get(field.getId()).setValid();
fieldUpdated.onFieldUpdated(field, value);
}
}).then(new Function<FormFieldWidget, Void>() {
@Override
public Void apply(FormFieldWidget widget) {
FieldContainer fieldContainer = containerFactory.createContainer(field, widget, 4);
containers.put(field.getId(), fieldContainer);
model.addContainerOfClass(formClass.getId(), fieldContainer);
return null;
}
});
promises.add(promise);
}
}
return Promise.waitAll(promises);
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class SimpleFormPanel method getSelectedKey.
/**
* Returns selected key/tab for given field or otherwise null if nothing is selected or it is root instance (no key).
*
* @return selected key/tab for given field or otherwise null if nothing is selected or it is root instance (no key).
*/
public String getSelectedKey(FormField field) {
FormClass formClass = model.getClassByField(field.getId());
if (formClass.isSubForm()) {
SubFormPanel subformPanel = widgetCreator.getSubformPanel(formClass);
if (subformPanel instanceof PeriodSubFormPanel) {
PeriodSubFormPanel periodSubFormPanel = (PeriodSubFormPanel) subformPanel;
Tab selectedTab = periodSubFormPanel.getSelectedTab();
if (selectedTab != null) {
return selectedTab.getId();
}
}
}
return null;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class SimpleFormPanel method validateBuiltinDates.
private Optional<Boolean> validateBuiltinDates(FieldContainer container, FormField field) {
if (BuiltinFields.isBuiltInDate(field.getId())) {
FormClass rootFormClass = getModel().getRootFormClass();
DateRange dateRange = BuiltinFields.getDateRange(getModel().getWorkingRootInstance(), rootFormClass);
if (!dateRange.isValidWithNull()) {
container.setInvalid(I18N.CONSTANTS.inconsistentDateRangeWarning());
return Optional.of(false);
} else {
if (dateRange.isValid()) {
getWidgetCreator().get(BuiltinFields.getStartDateField(rootFormClass).getId()).setValid();
getWidgetCreator().get(BuiltinFields.getEndDateField(rootFormClass).getId()).setValid();
return Optional.of(true);
}
}
}
return Optional.absent();
}
Aggregations