Search in sources :

Example 26 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FormValuesProcessorImpl method readFormValues.

@Override
public Map<String, Object> readFormValues(FormDefinition form, Map<String, Object> rawValues, BackendFormRenderingContext context) {
    final Map<String, Object> result = new HashMap<>();
    rawValues.forEach((String key, final Object value) -> {
        FieldDefinition field = form.getFieldByBinding(key);
        Object fieldValue = value;
        if (field != null) {
            if (value != null) {
                FieldValueProcessor processor = fieldValueProcessors.get(field.getClass());
                if (processor != null) {
                    fieldValue = processor.toFlatValue(field, value, context);
                }
            }
            result.put(key, fieldValue);
        }
    });
    return result;
}
Also used : NestedFormFieldValueProcessor(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.fieldProcessors.NestedFormFieldValueProcessor) FieldValueProcessor(org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.FieldValueProcessor) HashMap(java.util.HashMap) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition)

Example 27 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FormValuesProcessorImpl method writeFormValues.

@Override
public Map<String, Object> writeFormValues(FormDefinition form, Map<String, Object> formValues, Map<String, Object> rawValues, BackendFormRenderingContext context) {
    final Map<String, Object> result = new HashMap<>();
    formValues.forEach((key, value) -> {
        FieldDefinition field = form.getFieldByBinding(key);
        if (field != null) {
            if (value != null) {
                FieldValueProcessor processor = fieldValueProcessors.get(field.getClass());
                if (processor != null) {
                    value = processor.toRawValue(field, value, rawValues.get(key), context);
                }
            }
        }
        result.put(key, value);
    });
    return result;
}
Also used : NestedFormFieldValueProcessor(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.fieldProcessors.NestedFormFieldValueProcessor) FieldValueProcessor(org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.FieldValueProcessor) HashMap(java.util.HashMap) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition)

Example 28 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class MultipleSubformBackendFormRenderingContextManagerTest method getNestedForms.

@Override
protected FormDefinition[] getNestedForms() {
    JavaFormModel model = new PortableJavaModel(Person.class.getName());
    FormDefinition creationForm = new FormDefinition(model);
    creationForm.setId("person-creation");
    FieldDefinition field = fieldManager.getDefinitionByDataType(new TypeInfoImpl(Long.class.getName()));
    field.setName("id");
    field.setBinding("id");
    creationForm.getFields().add(field);
    field = fieldManager.getDefinitionByDataType(new TypeInfoImpl(String.class.getName()));
    field.setName("name");
    field.setBinding("name");
    creationForm.getFields().add(field);
    field = fieldManager.getDefinitionByDataType(new TypeInfoImpl(String.class.getName()));
    field.setName("lastName");
    field.setBinding("lastName");
    creationForm.getFields().add(field);
    field = fieldManager.getDefinitionByDataType(new TypeInfoImpl(Date.class.getName()));
    field.setName("birthday");
    field.setBinding("birthday");
    creationForm.getFields().add(field);
    FormDefinition editionForm = new FormDefinition(model);
    editionForm.setId("person-edition");
    field = fieldManager.getDefinitionByDataType(new TypeInfoImpl(Long.class.getName()));
    field.setName("id");
    field.setBinding("id");
    editionForm.getFields().add(field);
    field = fieldManager.getDefinitionByDataType(new TypeInfoImpl(String.class.getName()));
    field.setName("name");
    field.setBinding("name");
    editionForm.getFields().add(field);
    field = fieldManager.getDefinitionByDataType(new TypeInfoImpl(String.class.getName()));
    field.setName("lastName");
    field.setBinding("lastName");
    editionForm.getFields().add(field);
    field = fieldManager.getDefinitionByDataType(new TypeInfoImpl(Date.class.getName()));
    field.setName("birthday");
    field.setBinding("birthday");
    editionForm.getFields().add(field);
    return new FormDefinition[] { creationForm, editionForm };
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) PortableJavaModel(org.kie.workbench.common.forms.model.impl.PortableJavaModel) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) JavaFormModel(org.kie.workbench.common.forms.model.JavaFormModel) Person(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.model.Person) Date(java.util.Date)

Example 29 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class NestedFormBackendFormRenderingContextManagerTest method getNestedForms.

@Override
protected FormDefinition[] getNestedForms() {
    FormDefinition form = new FormDefinition(new PortableJavaModel(Person.class.getName()));
    form.setId(Person.class.getName());
    FieldDefinition field = fieldManager.getDefinitionByDataType(new TypeInfoImpl(String.class.getName()));
    field.setName("name");
    field.setBinding("name");
    form.getFields().add(field);
    field = fieldManager.getDefinitionByDataType(new TypeInfoImpl(String.class.getName()));
    field.setName("lastName");
    field.setBinding("lastName");
    form.getFields().add(field);
    field = fieldManager.getDefinitionByDataType(new TypeInfoImpl(Date.class.getName()));
    field.setName("birthday");
    field.setBinding("birthday");
    form.getFields().add(field);
    return new FormDefinition[] { form };
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) PortableJavaModel(org.kie.workbench.common.forms.model.impl.PortableJavaModel) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) Person(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.model.Person) Date(java.util.Date)

Example 30 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class NestedFormBackendFormRenderingContextManagerTest method getRootForm.

@Override
protected FormDefinition getRootForm() {
    FormDefinition form = new FormDefinition(new PortableJavaModel(Person.class.getName()));
    FieldDefinition field = fieldManager.getDefinitionByDataType(new TypeInfoImpl(TypeKind.OBJECT, Person.class.getName(), false));
    field.setName("person");
    field.setBinding("person");
    SubFormFieldDefinition subForm = (SubFormFieldDefinition) field;
    subForm.setNestedForm(Person.class.getName());
    form.getFields().add(field);
    return form;
}
Also used : SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) PortableJavaModel(org.kie.workbench.common.forms.model.impl.PortableJavaModel) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) Person(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.model.Person)

Aggregations

FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)85 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)42 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)29 Test (org.junit.Test)27 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)24 TextAreaFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition)22 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)21 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)20 CheckBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition)18 DecimalBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)17 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)14 DatePickerFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition)13 ArrayList (java.util.ArrayList)11 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)9 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)8 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)7 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)7 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)7 LayoutColumn (org.uberfire.ext.layout.editor.api.editor.LayoutColumn)7 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)7