Search in sources :

Example 6 with LayoutColumnDefinition

use of org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition in project kie-wb-common by kiegroup.

the class LayoutGeneratorTest method testTwoColumnsLayout.

@Test
public void testTwoColumnsLayout() {
    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, result.getRows().size());
    result.getRows().forEach(row -> {
        checkTwoColumnsRow(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 7 with LayoutColumnDefinition

use of org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition in project kie-wb-common by kiegroup.

the class LayoutGenerator method init.

public void init(LayoutColumnDefinition[] structure) {
    currentRow = null;
    rows.clear();
    int autoCount = 0;
    int maxSpan = 0;
    for (LayoutColumnDefinition col : structure) {
        if (col.getSpan().equals(ColSpan.AUTO)) {
            autoCount++;
        } else {
            maxSpan += col.getSpan().getSpan();
        }
    }
    if (maxSpan > MAX_SPAN) {
        throw new IllegalArgumentException("Max SPAN allowed for all layout columns is 12.");
    }
    if (maxSpan < MAX_SPAN && autoCount == 0) {
        throw new IllegalArgumentException("Wrong layout definition, the columns total span must be 12");
    }
    if (maxSpan + autoCount > MAX_SPAN) {
        throw new IllegalArgumentException("There's not enough space for all columns in layout.");
    }
    int freeSpan = MAX_SPAN - maxSpan;
    int freeOffset = 0;
    int freeAVGSpan = 0;
    if (freeSpan > 0) {
        freeOffset = freeSpan % autoCount;
        freeAVGSpan = Math.floorDiv(freeSpan, autoCount);
    }
    List<ColSpan> spans = new ArrayList<>();
    for (LayoutColumnDefinition definition : structure) {
        if (definition.getSpan().equals(ColSpan.AUTO)) {
            int span = freeAVGSpan;
            if (freeOffset > 0) {
                span++;
                freeOffset--;
            }
            spans.add(ColSpan.calculateSpan(span));
        } else {
            spans.add(definition.getSpan());
        }
    }
    this.structure = spans.toArray(new ColSpan[spans.size()]);
}
Also used : LayoutColumnDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition) ArrayList(java.util.ArrayList) ColSpan(org.kie.workbench.common.forms.adf.definitions.settings.ColSpan)

Example 8 with LayoutColumnDefinition

use of org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition in project kie-wb-common by kiegroup.

the class LayoutGeneratorTest method testLayoutWithEmptyColumn.

@Test
public void testLayoutWithEmptyColumn() {
    LayoutColumnDefinition[] structure = new LayoutColumnDefinition[] { new LayoutColumnDefinition() };
    generator.init(structure);
    LayoutTemplate template = generator.build();
    assertNotNull(template);
    assertTrue(template.getRows().isEmpty());
}
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)

Aggregations

LayoutColumnDefinition (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition)8 Test (org.junit.Test)5 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)5 LayoutSettings (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings)3 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)3 ArrayList (java.util.ArrayList)1 ColSpan (org.kie.workbench.common.forms.adf.definitions.settings.ColSpan)1 LayoutGenerator (org.kie.workbench.common.forms.adf.engine.shared.formGeneration.layout.LayoutGenerator)1 LayoutDefinition (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutDefinition)1 TaskFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel)1 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)1 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)1 FormLayoutComponent (org.kie.workbench.common.forms.model.FormLayoutComponent)1