Search in sources :

Example 6 with LayoutColumn

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

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

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

the class LayoutGeneratorTest method checkTwoColumnsRowWraps.

protected void checkTwoColumnsRowWraps(LayoutRow row) {
    assertNotNull(row);
    assertNotNull(row.getLayoutColumns());
    assertEquals(2, row.getLayoutColumns().size());
    LayoutColumn column = row.getLayoutColumns().get(0);
    assertNotNull(column);
    assertEquals("6", column.getSpan());
    assertNotNull(column.getLayoutComponents());
    assertEquals(1, column.getLayoutComponents().size());
    assertTrue(settingsMap.containsKey(column.getLayoutComponents().get(0)));
    // the first element is wrapped so check if the next column is empty
    column = row.getLayoutColumns().get(1);
    assertNotNull(column);
    assertEquals("6", column.getSpan());
    assertNotNull(column.getLayoutComponents());
    assertNotNull(column.getLayoutComponents());
    assertEquals(0, column.getLayoutComponents().size());
}
Also used : LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn)

Example 9 with LayoutColumn

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

Example 10 with LayoutColumn

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

the class AbstractFormLayoutTemplateGenerator method addFieldsToTemplate.

protected void addFieldsToTemplate(LayoutTemplate template, List<FieldDefinition> fields, String formId) {
    fields.forEach(field -> {
        LayoutComponent layoutComponent = new LayoutComponent(getDraggableType());
        layoutComponent.addProperty(FormLayoutComponent.FORM_ID, formId);
        layoutComponent.addProperty(FormLayoutComponent.FIELD_ID, field.getId());
        LayoutColumn column = new LayoutColumn("12");
        column.add(layoutComponent);
        LayoutRow row = new LayoutRow();
        row.add(column);
        template.addRow(row);
    });
}
Also used : 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)

Aggregations

LayoutColumn (org.uberfire.ext.layout.editor.api.editor.LayoutColumn)14 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)10 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)8 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)7 DecimalBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)5 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)5 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)5 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)5 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)5 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)5 IntStream (java.util.stream.IntStream)4 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)4 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)3 FormLayoutComponent (org.kie.workbench.common.forms.model.FormLayoutComponent)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Field (org.kie.workbench.common.forms.migration.legacy.model.Field)2 FormMigrationSummary (org.kie.workbench.common.forms.migration.tool.FormMigrationSummary)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Formatter (java.util.Formatter)1