use of org.activityinfo.model.type.subform.SubFormReferenceType 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.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.
the class PanelFiller method add.
public void add(FormElementContainer container, final int depth, final FlowPanel panel) {
if (headingVisible) {
FormHeading heading = new FormHeading();
heading.setFormClass(model.getRootFormClass());
panel.add(heading);
}
for (FormElement element : container.getElements()) {
if (element instanceof FormLabel) {
FormLabel formLabel = (FormLabel) element;
panel.add(new FormGroup().label(formLabel.getLabel()));
} else if (element instanceof FormSection) {
panel.add(createHeader(depth, element.getLabel()));
add((FormElementContainer) element, depth + 1);
} else if (element instanceof FormField) {
FormField formField = (FormField) element;
if (formField.isVisible()) {
if (formField.getType() instanceof SubFormReferenceType) {
final FormClass subForm = model.getSubFormByOwnerFieldId(formField.getId());
final FlowPanel subFormFieldPanel = new FlowPanel();
subFormFieldPanel.addStyleName(FormPanelStyles.INSTANCE.subformPanel());
subFormFieldPanel.add(createHeader(depth + 1, subForm.getLabel()));
subFormFieldPanel.add(widgetCreator.createSubformPanel(subForm, depth + 1, relevanceHandler, this).getLoadingPanel());
panel.add(subFormFieldPanel);
} else {
panel.add(widgetCreator.get(formField.getId()));
}
}
}
}
}
use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.
the class RecordTreeLoader method findChildren.
private void findChildren(Set<NodeKey> children, FormClass schema, FormInstance record) {
// Add referenced records
for (FieldValue value : record.getFieldValueMap().values()) {
if (value instanceof ReferenceValue) {
for (RecordRef recordRef : ((ReferenceValue) value).getReferences()) {
children.add(new RecordKey(recordRef));
}
}
}
// Add sub forms
for (FormField formField : schema.getFields()) {
if (formField.getType() instanceof SubFormReferenceType) {
SubFormReferenceType subFormType = (SubFormReferenceType) formField.getType();
children.add(new SubFormKey(record.getRef(), subFormType.getClassId()));
}
}
}
Aggregations