Search in sources :

Example 1 with FormField

use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.

the class NewDimensionDialog method onForestUpdated.

private void onForestUpdated(Observable<FormForest> forest) {
    store.clear();
    if (forest.isLoaded()) {
        // The Form Name can be a dimension
        store.add(new FormNode());
        // Add root fields...
        for (FormTree.Node node : forest.get().getRootNodes()) {
            if (isEligible(node.getType())) {
                store.add(new RootFieldNode(node.getDefiningFormClass().getId(), node.getField()));
            }
        }
        // Add reference forms with eligible fields
        for (FormClass formClass : forest.get().getReferencedForms()) {
            List<DimensionNode> children = new ArrayList<>();
            for (FormField field : formClass.getFields()) {
                if (isEligible(field.getType())) {
                    children.add(new ReferencedNode(formClass, field));
                }
            }
            if (!children.isEmpty()) {
                ReferenceFormNode refNode = new ReferenceFormNode(formClass, children.get(0));
                store.add(refNode);
                store.add(refNode, children);
            }
        }
    }
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) FormClass(org.activityinfo.model.form.FormClass) ArrayList(java.util.ArrayList) FormField(org.activityinfo.model.form.FormField)

Example 2 with FormField

use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.

the class LookupKeySetTest method multipleTextKeysTest.

@Test
public void multipleTextKeysTest() {
    TestingStorageProvider catalog = setup.getCatalog();
    SimpleReferenceForm refForm = catalog.getSimpleReferenceForm();
    MultipleTextKeysForm multTextKeyForm = catalog.getMultipleTextKeysForm();
    FormField refField = refForm.getRefField();
    CompoundExpr pathToKey1 = new CompoundExpr(refField.getId(), MultipleTextKeysForm.FIRST_TEXT_KEY_ID.asString());
    CompoundExpr pathToKey2 = new CompoundExpr(refField.getId(), MultipleTextKeysForm.SECOND_TEXT_KEY_ID.asString());
    FormTree formTree = catalog.getFormTree(multTextKeyForm.getFormId());
    LookupKeySet lookupKeySet = new LookupKeySet(formTree, refField);
    Map<LookupKey, FormulaNode> formulas = lookupKeySet.getKeyFormulas(refField.getId());
    assertThat(formulas.values(), containsInAnyOrder(pathToKey1, pathToKey2));
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) LookupKeySet(org.activityinfo.model.formTree.LookupKeySet) FormulaNode(org.activityinfo.model.formula.FormulaNode) FormTree(org.activityinfo.model.formTree.FormTree) LookupKey(org.activityinfo.model.formTree.LookupKey) FormField(org.activityinfo.model.form.FormField) Test(org.junit.Test)

Example 3 with FormField

use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.

the class QueryRunner method addField.

@Override
public void addField(ResourceId fieldId, CursorObserver<FieldValue> observer) {
    if (fieldId.asString().equals("@parent")) {
        recordObservers.add(new ParentObserver(formClass.getParentFormId().get(), observer));
    } else {
        FormField field = formClass.getField(fieldId);
        FieldObserver fieldObserver = new FieldObserver(field.getName(), field.getType(), observer);
        recordObservers.add(fieldObserver);
    }
}
Also used : FormField(org.activityinfo.model.form.FormField)

Example 4 with FormField

use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.

the class SimpleFormPanel method setValue.

public Promise<Void> setValue(FormInstance instance) {
    model.setWorkingRootInstance(instance);
    List<Promise<Void>> tasks = Lists.newArrayList();
    for (FieldContainer container : widgetCreator.getContainers().values()) {
        FormField field = container.getField();
        FieldValue value = model.getWorkingRootInstance().get(field.getId(), field.getType());
        if (value != null && value.getTypeClass() == field.getType().getTypeClass()) {
            tasks.add(container.getFieldWidget().setValue(value));
        } else {
            container.getFieldWidget().clearValue();
        }
        container.setValid();
    }
    return Promise.waitAll(tasks).then(new Function<Void, Void>() {

        @Override
        public Void apply(Void input) {
            // invoke relevance handler once values are set
            relevanceHandler.onValueChange();
            return null;
        }
    });
}
Also used : Promise(org.activityinfo.promise.Promise) FieldValue(org.activityinfo.model.type.FieldValue) FormField(org.activityinfo.model.form.FormField)

Example 5 with FormField

use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.

the class ColumnMappingPage method collectNotMappedMandatoryColumns.

/**
 * @param mandatory if true - then only mandatory, if false then ALL
 * @return
 */
public List<ImportTarget> collectNotMappedMandatoryColumns(boolean mandatory) {
    List<ImportTarget> list = Lists.newArrayList();
    for (final MapExistingAction action : actions) {
        final FormField formField = action.getTarget().getFormField();
        if (mandatory && !formField.isRequired()) {
            continue;
        }
        final Map<TargetSiteId, ColumnAccessor> mappedColumns = importModel.getMappedColumns(formField.getId());
        if (mappedColumns.isEmpty()) {
            list.add(action.getTarget());
        }
    }
    return list;
}
Also used : ImportTarget(org.activityinfo.ui.client.component.importDialog.model.strategy.ImportTarget) ColumnAccessor(org.activityinfo.ui.client.component.importDialog.model.strategy.ColumnAccessor) MapExistingAction(org.activityinfo.ui.client.component.importDialog.model.MapExistingAction) TargetSiteId(org.activityinfo.ui.client.component.importDialog.model.strategy.TargetSiteId) FormField(org.activityinfo.model.form.FormField)

Aggregations

FormField (org.activityinfo.model.form.FormField)119 FormClass (org.activityinfo.model.form.FormClass)48 ResourceId (org.activityinfo.model.resource.ResourceId)32 Test (org.junit.Test)30 QuantityType (org.activityinfo.model.type.number.QuantityType)18 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)17 ReferenceType (org.activityinfo.model.type.ReferenceType)16 EnumType (org.activityinfo.model.type.enumerated.EnumType)14 FieldValue (org.activityinfo.model.type.FieldValue)12 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)11 JsonValue (org.activityinfo.json.JsonValue)9 FormTree (org.activityinfo.model.formTree.FormTree)9 FormInstance (org.activityinfo.model.form.FormInstance)8 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)8 ColumnSet (org.activityinfo.model.query.ColumnSet)6 QueryModel (org.activityinfo.model.query.QueryModel)6 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)5 Quantity (org.activityinfo.model.type.number.Quantity)5 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)5 ArrayList (java.util.ArrayList)4