Search in sources :

Example 21 with FieldDefinition

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

the class AbstractBPMNFormGeneratorService method createModelFormDefinition.

protected FormDefinition createModelFormDefinition(String modelType, GenerationContext<SOURCE> context) {
    FormDefinition form = context.getContextForms().get(modelType);
    if (form == null) {
        String modelName = modelType.substring(modelType.lastIndexOf(".") + 1);
        String formModelName = modelName;
        formModelName = formModelName.substring(0, 1).toLowerCase() + formModelName.substring(1);
        DataObjectFormModel formModel = new DataObjectFormModel(formModelName, modelType);
        form = new FormDefinition(formModel);
        context.getContextForms().put(modelType, form);
        form.setId(UIDGenerator.generateUID());
        form.setName(modelName);
        // TODO: extract model properties & generate fields
        List<FieldDefinition> fields = extractModelFields(formModel, context);
        form.getFields().addAll(fields);
        createFormLayout(form);
        processFormDefinition(form, context);
    }
    return form;
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) DataObjectFormModel(org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel)

Example 22 with FieldDefinition

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

the class BPMNRuntimeFormGeneratorService method createRootFormDefinition.

@Override
protected FormDefinition createRootFormDefinition(GenerationContext<ClassLoader> context) {
    FormDefinition form = new FormDefinition(context.getFormModel());
    form.setId(context.getFormModel().getFormName());
    form.setName(context.getFormModel().getFormName());
    context.getFormModel().getProperties().forEach(property -> {
        if (!BPMNVariableUtils.isValidInputName(property.getName())) {
            return;
        }
        FieldDefinition field = generateFieldDefinition(property, context);
        if (field != null) {
            form.getFields().add(field);
        }
    });
    return form;
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 23 with FieldDefinition

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

the class BPMNRuntimeFormGeneratorService method generateFieldDefinition.

protected FieldDefinition generateFieldDefinition(ModelProperty property, GenerationContext<ClassLoader> context) {
    FieldDefinition field = fieldManager.getDefinitionByModelProperty(property);
    if (field == null) {
        return null;
    }
    processFieldDefinition(field, context);
    return field;
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition)

Example 24 with FieldDefinition

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

the class AbstractFieldElementProcessor method processFormElement.

@Override
public LayoutComponent processFormElement(FieldElement element, FormGenerationContext context) {
    FieldDefinition field;
    if (element.getPreferredType().equals(FieldType.class)) {
        field = fieldManager.getDefinitionByDataType(element.getTypeInfo());
    } else {
        field = fieldManager.getDefinitionByFieldType(element.getPreferredType(), element.getTypeInfo());
        if (field == null) {
            field = fieldManager.getDefinitionByDataType(element.getTypeInfo());
        }
    }
    if (field != null) {
        context.getFormDefinition().getFields().add(field);
        field.setId(element.getName());
        field.setName(element.getName());
        field.setBinding(element.getBinding());
        String label = context.getI18nHelper().getTranslation(element.getLabelKey());
        if (label == null || label.isEmpty()) {
            label = element.getName().substring(0, 1).toUpperCase() + element.getName().substring(1);
        }
        field.setLabel(label);
        String helpMessage = context.getI18nHelper().getTranslation(element.getHelpMessageKey());
        field.setHelpMessage(helpMessage);
        field.setRequired(element.isRequired());
        field.setReadOnly(element.isReadOnly());
        if (context.getModel() != null) {
            String fullFieldName = context.getFormDefinitionSettings().getModelType() + "." + element.getName();
            FieldStatusModifier initializer = context.getStatusModifierForFieldName(fullFieldName);
            if (initializer != null) {
                initializer.modifyFieldStatus(field, propertyValueExtractor.readPropertyValue(context.getModel(), element.getName()));
            }
        }
        for (FieldInitializer fieldInitializer : initializers) {
            if (fieldInitializer.supports(field)) {
                fieldInitializer.initialize(field, element, context);
            }
        }
        LayoutComponent component = new LayoutComponent("org.kie.workbench.common.forms.dynamic.client.rendering.FieldLayoutComponent");
        component.addProperty(FormLayoutComponent.FORM_ID, context.getFormDefinition().getId());
        component.addProperty(FormLayoutComponent.FIELD_ID, field.getId());
        return component;
    }
    return null;
}
Also used : FieldStatusModifier(org.kie.workbench.common.forms.adf.service.building.FieldStatusModifier) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) FormLayoutComponent(org.kie.workbench.common.forms.model.FormLayoutComponent) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent)

Example 25 with FieldDefinition

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

the class AbstractFormGenerationTest method testGeneratedForm.

protected void testGeneratedForm(FormDefinition form, String modelName) {
    assertNotNull(form);
    FormDefinitionSettings settings = resourcesProvider.getDefinitionSettings().get(modelName);
    assertEquals(settings.getModelType(), form.getId());
    assertEquals(settings.getModelType(), form.getName());
    assertEquals(settings.getFormElements().size(), form.getFields().size());
    settings.getFormElements().forEach(element -> {
        FieldElement fieldElement = (FieldElement) element;
        FieldDefinition field = form.getFieldByBinding(fieldElement.getBinding());
        assertNotNull(field);
        assertEquals(fieldElement.getName(), field.getName());
        if (!fieldElement.getPreferredType().equals(FieldType.class)) {
            assertEquals(fieldElement.getPreferredType(), field.getFieldType().getClass());
        }
        assertEquals(fieldElement.getTypeInfo().getClassName(), field.getStandaloneClassName());
        assertEquals(fieldElement.isReadOnly(), field.getReadOnly());
        assertEquals(fieldElement.isRequired(), field.getRequired());
        assertEquals(fieldElement.getBinding(), field.getBinding());
        verify(i18nHelper, atLeast(1)).getTranslation(field.getName() + ".label");
    });
    assertNotNull(form.getLayoutTemplate());
    assertEquals(settings.getFormElements().size(), form.getLayoutTemplate().getRows().size());
    form.getLayoutTemplate().getRows().forEach(row -> {
        assertNotNull(row);
        assertEquals(1, row.getLayoutColumns().size());
        LayoutColumn column = row.getLayoutColumns().get(0);
        assertNotNull(column);
        assertEquals("12", column.getSpan());
        assertEquals(1, column.getLayoutComponents().size());
        LayoutComponent layoutComponent = column.getLayoutComponents().get(0);
        String formId = layoutComponent.getProperties().get(FormLayoutComponent.FORM_ID);
        assertNotNull(formId);
        assertEquals(form.getId(), formId);
        String fieldId = layoutComponent.getProperties().get(FormLayoutComponent.FIELD_ID);
        assertNotNull(fieldId);
        FieldDefinition field = form.getFieldById(fieldId);
        assertNotNull(field);
    });
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn) FieldElement(org.kie.workbench.common.forms.adf.service.definitions.elements.FieldElement) FormLayoutComponent(org.kie.workbench.common.forms.model.FormLayoutComponent) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) FormDefinitionSettings(org.kie.workbench.common.forms.adf.service.definitions.FormDefinitionSettings) FieldType(org.kie.workbench.common.forms.model.FieldType)

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