use of com.haulmont.cuba.gui.components.form.ComponentArea in project cuba by cuba-platform.
the class WebForm method getComponent.
@Override
public Component getComponent(int column, int row) {
checkArgument(column >= 0 && column < component.getColumns() && row >= 0 && row < component.getRows(), "Illegal coordinates for the component: [%s, %s]. Must be between [0, 0] - [%s, %s]", column, row, component.getColumns() - 1, component.getRows() - 1);
List<ComponentArea> componentAreas = calculateComponentAreas();
for (ComponentArea area : componentAreas) {
if (area.getStartColumn() <= column && column <= area.getEndColumn() && area.getStartRow() <= row && row <= area.getEndRow()) {
return area.getComponent();
}
}
throw new IllegalStateException(String.format("Can't find a component for the given coordinates: [%s, %s]", column, row));
}
use of com.haulmont.cuba.gui.components.form.ComponentArea in project cuba by cuba-platform.
the class WebForm method reattachColumnFields.
protected void reattachColumnFields() {
List<ComponentArea> componentAreas = calculateComponentAreas();
this.component.removeAllComponents();
for (ComponentArea componentArea : componentAreas) {
com.vaadin.ui.Component composition = WebComponentsHelper.getComposition(componentArea.getComponent());
this.component.addComponent(composition, componentArea.getStartColumn(), componentArea.getStartRow(), componentArea.getEndColumn(), componentArea.getEndRow());
}
}
use of com.haulmont.cuba.gui.components.form.ComponentArea in project cuba by cuba-platform.
the class WebForm method calculateComponentAreas.
protected List<ComponentArea> calculateComponentAreas() {
List<ComponentArea> componentAreas = new ArrayList<>();
// Inspired by GridLayoutLoader logic
boolean[][] spanMatrix = new boolean[this.component.getColumns()][this.component.getRows()];
for (int col = 0; col < columnComponentMapping.size(); col++) {
int row = 0;
List<ComponentPosition> columnFields = columnComponentMapping.get(col);
for (ComponentPosition componentPosition : columnFields) {
while (spanMatrix[col][row]) {
row++;
}
Component component = componentPosition.getComponent();
int colSpan = componentPosition.getColSpan();
int rowSpan = componentPosition.getRowSpan();
if (colSpan == 1 && rowSpan == 1) {
componentAreas.add(new ComponentArea(component, col, row, col, row));
} else {
fillSpanMatrix(spanMatrix, col, row, colSpan, rowSpan);
int endColumn = col + colSpan - 1;
int endRow = row + rowSpan - 1;
componentAreas.add(new ComponentArea(component, col, row, endColumn, endRow));
}
row++;
}
}
return componentAreas;
}
use of com.haulmont.cuba.gui.components.form.ComponentArea in project cuba by cuba-platform.
the class WebForm method checkExistingOverlaps.
protected void checkExistingOverlaps(int startColumn, int startRow, int colSpan, int rowSpan) {
int endColumn = startColumn + colSpan - 1;
int endRow = startRow + rowSpan - 1;
List<ComponentArea> componentAreas = calculateComponentAreas();
for (ComponentArea area : componentAreas) {
// Check that a component isn't inserted to the existing component area excluding top left point.
if (area.getStartColumn() < startColumn && startColumn <= area.getEndColumn() && area.getStartRow() <= startRow && startRow <= area.getEndRow() || area.getStartRow() < startRow && startRow <= area.getEndRow() && area.getStartColumn() <= startColumn && startColumn <= area.getEndColumn()) {
throw new IllegalArgumentException(String.format("Given coordinates [%s, %s] - [%s, %s] overlap existing component: [%s, %s] - [%s, %s]", startColumn, startRow, endColumn, endRow, area.getStartColumn(), area.getStartRow(), area.getEndColumn(), area.getEndRow()));
}
}
}
use of com.haulmont.cuba.gui.components.form.ComponentArea in project cuba by cuba-platform.
the class WebForm method detectRowsCount.
protected int detectRowsCount(int column, boolean isCheckAreas) {
List<ComponentPosition> componentPositions = columnComponentMapping.get(column);
// Calculate rows count considering row spans
int rowsCount = componentPositions.stream().map(ComponentPosition::getRowSpan).reduce(Integer::sum).orElse(0);
List<ComponentArea> componentAreas = isCheckAreas ? calculateComponentAreas() : Collections.emptyList();
// then increase rows count by its row span value
for (int i = 0; i < column; i++) {
List<ComponentPosition> positions = columnComponentMapping.get(i);
for (ComponentPosition position : positions) {
if (i + position.getColSpan() > column) {
// Even though a component from a previous column overlaps current column
// it still can be above a current component
ComponentArea area = findComponentArea(componentAreas, position);
if (area == null || rowsCount >= area.getStartRow()) {
rowsCount += position.getRowSpan();
}
}
}
}
return rowsCount;
}
Aggregations