diff options
author | Pekka Hyvönen <pekka@vaadin.com> | 2015-03-26 21:23:16 +0200 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2015-03-31 13:52:31 +0000 |
commit | 849c92d431ca2d4d591b2ca61c541aa40f754e83 (patch) | |
tree | 2bb224d58e583093de5f6dcf9f754aba7a8219a6 /client | |
parent | 0e7755958b46434185cb1e6e2ec8aa6932b32f34 (diff) | |
download | vaadin-framework-849c92d431ca2d4d591b2ca61c541aa40f754e83.tar.gz vaadin-framework-849c92d431ca2d4d591b2ca61c541aa40f754e83.zip |
Take hidden columns into account with spanned cells #17287
Change-Id: I595c6b7da061ebfa495c7f9f649c935a48190b66
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/widgets/Grid.java | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index f9c6ed28fe..73dcccfd1e 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -453,6 +453,8 @@ public class Grid<T> extends ResizeComposite implements } HashSet<Column<?, ?>> columnGroup = new HashSet<Column<?, ?>>(); + // NOTE: this doesn't care about hidden columns, those are + // filtered in calculateColspans() for (Column<?, ?> column : columns) { if (!cells.containsKey(column)) { throw new IllegalArgumentException( @@ -516,39 +518,46 @@ public class Grid<T> extends ResizeComposite implements } void calculateColspans() { - // Reset all cells for (CELLTYPE cell : this.cells.values()) { cell.setColspan(1); } - - List<Column<?, ?>> columnOrder = new ArrayList<Column<?, ?>>( - section.grid.getColumns()); // Set colspan for grouped cells for (Set<Column<?, ?>> group : cellGroups.keySet()) { - if (!checkCellGroupAndOrder(columnOrder, group)) { + if (!checkMergedCellIsContinuous(group)) { + // on error simply break the merged cell cellGroups.get(group).setColspan(1); } else { - int colSpan = group.size(); - cellGroups.get(group).setColspan(colSpan); + int colSpan = 0; + for (Column<?, ?> column : group) { + if (!column.isHidden()) { + colSpan++; + } + } + // colspan can't be 0 + cellGroups.get(group).setColspan(Math.max(1, colSpan)); } } } - private boolean checkCellGroupAndOrder( - List<Column<?, ?>> columnOrder, Set<Column<?, ?>> cellGroup) { - if (!columnOrder.containsAll(cellGroup)) { + private boolean checkMergedCellIsContinuous( + Set<Column<?, ?>> mergedCell) { + // no matter if hidden or not, just check for continuous order + final List<Column<?, ?>> columnOrder = new ArrayList<Column<?, ?>>( + section.grid.getColumns()); + + if (!columnOrder.containsAll(mergedCell)) { return false; } for (int i = 0; i < columnOrder.size(); ++i) { - if (!cellGroup.contains(columnOrder.get(i))) { + if (!mergedCell.contains(columnOrder.get(i))) { continue; } - for (int j = 1; j < cellGroup.size(); ++j) { - if (!cellGroup.contains(columnOrder.get(i + j))) { + for (int j = 1; j < mergedCell.size(); ++j) { + if (!mergedCell.contains(columnOrder.get(i + j))) { return false; } } @@ -791,6 +800,14 @@ public class Grid<T> extends ResizeComposite implements assert grid != null; return grid; } + + protected void updateColSpans() { + for (ROWTYPE row : rows) { + if (row.hasSpannedCells()) { + row.calculateColspans(); + } + } + } } /** @@ -4092,6 +4109,8 @@ public class Grid<T> extends ResizeComposite implements } } grid.columnHider.updateToggleValue(this); + grid.header.updateColSpans(); + grid.footer.updateColSpans(); scheduleColumnWidthRecalculator(); this.grid.fireEvent(new ColumnVisibilityChangeEvent<T>(this, hidden, userOriginated)); |