Search in sources :

Example 6 with LayoutTemplate

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

the class AbstractFormDefinitionGeneratorTest method verifyUserForm.

protected void verifyUserForm(FormMigrationSummary summary) {
    Form originalForm = summary.getOriginalForm().get();
    Assertions.assertThat(originalForm.getFormFields()).isNotEmpty().hasSize(2);
    FormDefinition newForm = summary.getNewForm().get();
    Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(2);
    Assertions.assertThat(newForm.getModel()).isNotNull().hasFieldOrPropertyWithValue("className", USER_MODEL).isInstanceOf(DataObjectFormModel.class);
    IntStream indexStream = IntStream.range(0, newForm.getFields().size());
    LayoutTemplate formLayout = newForm.getLayoutTemplate();
    assertNotNull(formLayout);
    Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(2);
    indexStream.forEach(index -> {
        FieldDefinition fieldDefinition = newForm.getFields().get(index);
        switch(index) {
            case 0:
                checkFieldDefinition(fieldDefinition, USER_LOGIN, "login", "login", TextBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
                break;
            case 1:
                checkFieldDefinition(fieldDefinition, USER_PASSWORD, "password", "password", TextBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
                break;
        }
        LayoutRow fieldRow = formLayout.getRows().get(index);
        assertNotNull(fieldRow);
        Assertions.assertThat(fieldRow.getLayoutColumns()).isNotEmpty().hasSize(1);
        LayoutColumn fieldColumn = fieldRow.getLayoutColumns().get(0);
        assertNotNull(fieldColumn);
        assertEquals("12", fieldColumn.getSpan());
        Assertions.assertThat(fieldColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
        checkLayoutFormField(fieldColumn.getLayoutComponents().get(0), fieldDefinition, newForm);
    });
}
Also used : LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) LayoutRow(org.uberfire.ext.layout.editor.api.editor.LayoutRow) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) IntStream(java.util.stream.IntStream)

Example 7 with LayoutTemplate

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

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

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

the class LayoutGeneratorTest method testSimpleVerticalLayout.

@Test
public void testSimpleVerticalLayout() {
    LayoutColumnDefinition[] structure = 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(), result.getRows().size());
    result.getRows().forEach(row -> {
        checkSingleColumnRow(row);
    });
}
Also used : LayoutColumnDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition) LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) Test(org.junit.Test)

Example 10 with LayoutTemplate

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

Aggregations

LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)20 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)9 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)8 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)8 LayoutColumn (org.uberfire.ext.layout.editor.api.editor.LayoutColumn)8 Test (org.junit.Test)7 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)7 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)7 LayoutColumnDefinition (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition)6 DecimalBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)6 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)6 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)6 IntStream (java.util.stream.IntStream)5 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)5 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)4 LayoutSettings (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings)3 Field (org.kie.workbench.common.forms.migration.legacy.model.Field)3 FormMigrationSummary (org.kie.workbench.common.forms.migration.tool.FormMigrationSummary)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2