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);
});
}
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()]);
}
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());
}
Aggregations