Search in sources :

Example 26 with SubFormReferenceType

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);
}
Also used : FieldUpdater(org.activityinfo.ui.client.component.form.field.FieldUpdater) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) Promise(org.activityinfo.promise.Promise) FormFieldWidget(org.activityinfo.ui.client.component.form.field.FormFieldWidget) FormClass(org.activityinfo.model.form.FormClass) FieldValue(org.activityinfo.model.type.FieldValue) FormField(org.activityinfo.model.form.FormField)

Example 27 with SubFormReferenceType

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()));
                }
            }
        }
    }
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormGroup(org.activityinfo.ui.client.widget.form.FormGroup) FlowPanel(com.google.gwt.user.client.ui.FlowPanel)

Example 28 with SubFormReferenceType

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()));
        }
    }
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) FieldValue(org.activityinfo.model.type.FieldValue)

Aggregations

SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)28 FormClass (org.activityinfo.model.form.FormClass)17 FormField (org.activityinfo.model.form.FormField)15 ResourceId (org.activityinfo.model.resource.ResourceId)9 QuantityType (org.activityinfo.model.type.number.QuantityType)5 Test (org.junit.Test)5 EnumType (org.activityinfo.model.type.enumerated.EnumType)4 FormFieldWidget (org.activityinfo.ui.client.component.form.field.FormFieldWidget)4 FormTree (org.activityinfo.model.formTree.FormTree)3 ReferenceType (org.activityinfo.model.type.ReferenceType)3 FormStorage (org.activityinfo.store.spi.FormStorage)3 FieldUpdater (org.activityinfo.ui.client.component.form.field.FieldUpdater)3 FieldWidgetContainer (org.activityinfo.ui.client.component.formdesigner.container.FieldWidgetContainer)3 LabelWidgetContainer (org.activityinfo.ui.client.component.formdesigner.container.LabelWidgetContainer)3 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 FormClassProvider (org.activityinfo.model.formTree.FormClassProvider)2 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)2 ColumnSet (org.activityinfo.model.query.ColumnSet)2 QueryModel (org.activityinfo.model.query.QueryModel)2