use of org.kie.workbench.common.forms.adf.definitions.settings.ColSpan 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.definitions.settings.ColSpan in project kie-wb-common by kiegroup.
the class LayoutGenerator method newRow.
protected void newRow() {
List<Cell> cells = new ArrayList<>();
for (ColSpan span : structure) {
cells.add(new Cell(span.getSpan()));
}
currentRow = new Row(cells);
rows.add(currentRow);
}
Aggregations