Search in sources :

Example 6 with LayoutComponent

use of org.uberfire.ext.layout.editor.api.editor.LayoutComponent in project kie-wb-common by kiegroup.

the class FormLayoutTemplateGeneratorTest method testGeneratedLayout.

protected void testGeneratedLayout() {
    LayoutTemplate layout = form.getLayoutTemplate();
    assertNotNull(layout);
    assertNotNull(layout.getRows());
    assertEquals(form.getFields().size(), layout.getRows().size());
    for (LayoutRow row : layout.getRows()) {
        assertEquals(1, row.getLayoutColumns().size());
        for (LayoutColumn col : row.getLayoutColumns()) {
            assertEquals("12", col.getSpan());
            assertEquals(0, col.getRows().size());
            assertEquals(1, col.getLayoutComponents().size());
            for (LayoutComponent component : col.getLayoutComponents()) {
                assertEquals(templateGenerator.getDraggableType(), component.getDragTypeName());
                assertEquals(form.getId(), component.getProperties().get(FormLayoutComponent.FORM_ID));
                String fieldId = component.getProperties().get(FormLayoutComponent.FIELD_ID);
                assertNotNull(fieldId);
                assertNotNull(form.getFieldById(fieldId));
            }
        }
    }
}
Also used : LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) LayoutRow(org.uberfire.ext.layout.editor.api.editor.LayoutRow) LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn) FormLayoutComponent(org.kie.workbench.common.forms.model.FormLayoutComponent) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent)

Example 7 with LayoutComponent

use of org.uberfire.ext.layout.editor.api.editor.LayoutComponent 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 8 with LayoutComponent

use of org.uberfire.ext.layout.editor.api.editor.LayoutComponent in project kie-wb-common by kiegroup.

the class LayoutGeneratorTest method testTwoColumnsWithWraps.

@Test
public void testTwoColumnsWithWraps() {
    LayoutComponent component = mock(LayoutComponent.class);
    when(component.getDragTypeName()).thenReturn("wrap");
    LayoutSettings settings = new LayoutSettings();
    settings.setWrap(true);
    settingsMap.put(component, settings);
    component = mock(LayoutComponent.class);
    when(component.getDragTypeName()).thenReturn("wrap");
    settingsMap.put(component, settings);
    LayoutColumnDefinition[] structure = new LayoutColumnDefinition[] { new LayoutColumnDefinition(), new LayoutColumnDefinition() };
    generator.init(structure);
    settingsMap.entrySet().forEach(entry -> generator.addComponent(entry.getKey(), entry.getValue()));
    LayoutTemplate result = generator.build();
    assertNotNull(result);
    assertNotNull(result.getRows());
    assertEquals(settingsMap.size() / 2 + 1, result.getRows().size());
    result.getRows().forEach(row -> {
        assertNotNull(row);
        assertNotNull(row.getLayoutColumns());
        LayoutComponent layoutComponent = row.getLayoutColumns().get(0).getLayoutComponents().get(0);
        if ("wrap".equals(layoutComponent.getDragTypeName())) {
            checkTwoColumnsRowWraps(row);
        } else {
            checkTwoColumnsRow(row);
        }
    });
}
Also used : LayoutColumnDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition) LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) LayoutSettings(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) Test(org.junit.Test)

Example 9 with LayoutComponent

use of org.uberfire.ext.layout.editor.api.editor.LayoutComponent in project kie-wb-common by kiegroup.

the class LayoutGeneratorTest method testTwoColumnsLayoutWithSpans.

@Test
public void testTwoColumnsLayoutWithSpans() {
    LayoutComponent component = mock(LayoutComponent.class);
    when(component.getDragTypeName()).thenReturn("span");
    LayoutSettings settings = new LayoutSettings();
    settings.setHorizontalSpan(2);
    settingsMap.put(component, settings);
    component = mock(LayoutComponent.class);
    when(component.getDragTypeName()).thenReturn("span");
    settingsMap.put(component, settings);
    LayoutColumnDefinition[] structure = new LayoutColumnDefinition[] { new LayoutColumnDefinition(), new LayoutColumnDefinition() };
    generator.init(structure);
    settingsMap.entrySet().forEach(entry -> generator.addComponent(entry.getKey(), entry.getValue()));
    LayoutTemplate result = generator.build();
    assertNotNull(result);
    assertNotNull(result.getRows());
    assertEquals(settingsMap.size() / 2 + 1, result.getRows().size());
    result.getRows().forEach(row -> {
        assertNotNull(row);
        assertNotNull(row.getLayoutColumns());
        LayoutComponent layoutComponent = row.getLayoutColumns().get(0).getLayoutComponents().get(0);
        if ("span".equals(layoutComponent.getDragTypeName())) {
            checkSingleColumnRow(row);
        } else {
            checkTwoColumnsRow(row);
        }
    });
}
Also used : LayoutColumnDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition) LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) LayoutSettings(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) Test(org.junit.Test)

Example 10 with LayoutComponent

use of org.uberfire.ext.layout.editor.api.editor.LayoutComponent 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

LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)15 FormLayoutComponent (org.kie.workbench.common.forms.model.FormLayoutComponent)7 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)6 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)5 Test (org.junit.Test)4 LayoutColumn (org.uberfire.ext.layout.editor.api.editor.LayoutColumn)4 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)4 LayoutColumnDefinition (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition)3 LayoutSettings (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings)3 Formatter (java.util.Formatter)2 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)2 Field (org.kie.workbench.common.forms.migration.legacy.model.Field)2 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)2 FormMigrationSummary (org.kie.workbench.common.forms.migration.tool.FormMigrationSummary)2 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)2 Path (org.uberfire.backend.vfs.Path)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IntStream (java.util.stream.IntStream)1 Assertions (org.assertj.core.api.Assertions)1