Search in sources :

Example 1 with FieldStatusModifier

use of org.kie.workbench.common.forms.adf.service.building.FieldStatusModifier 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)

Aggregations

FieldStatusModifier (org.kie.workbench.common.forms.adf.service.building.FieldStatusModifier)1 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)1 FormLayoutComponent (org.kie.workbench.common.forms.model.FormLayoutComponent)1 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)1