diff options
author | John Ahlroos <john@vaadin.com> | 2013-12-10 16:35:50 +0200 |
---|---|---|
committer | John Ahlroos <john@vaadin.com> | 2013-12-10 16:35:50 +0200 |
commit | eb75c09574249687d9ea3899791c8daa3fcec314 (patch) | |
tree | 867b3fb40d55533a8d7cde2effd137cbe4b8bd1b /client/src | |
parent | b7dddff607f70d6f27104d98a086e7541a32aded (diff) | |
download | vaadin-framework-eb75c09574249687d9ea3899791c8daa3fcec314.tar.gz vaadin-framework-eb75c09574249687d9ea3899791c8daa3fcec314.zip |
Validate column group boundaries #12907
Change-Id: I5078d97c5a6bc92f59d0d04eca2a2cfc27c973b4
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/com/vaadin/client/ui/grid/ColumnGroupRow.java | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/client/src/com/vaadin/client/ui/grid/ColumnGroupRow.java b/client/src/com/vaadin/client/ui/grid/ColumnGroupRow.java index 113e0b34c6..0ced616f3f 100644 --- a/client/src/com/vaadin/client/ui/grid/ColumnGroupRow.java +++ b/client/src/com/vaadin/client/ui/grid/ColumnGroupRow.java @@ -18,6 +18,7 @@ package com.vaadin.client.ui.grid; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -73,7 +74,8 @@ public class ColumnGroupRow<T> { * @return a column group representing the collection of columns added to * the group. */ - public ColumnGroup<T> addGroup(GridColumn<?, T>... columns) { + public ColumnGroup<T> addGroup(GridColumn<?, T>... columns) + throws IllegalArgumentException { for (GridColumn<?, T> column : columns) { if (isColumnGrouped(column)) { @@ -83,6 +85,8 @@ public class ColumnGroupRow<T> { } } + validateNewGroupProperties(Arrays.asList(columns)); + ColumnGroup<T> group = new ColumnGroup<T>(grid, Arrays.asList(columns)); groups.add(group); grid.refreshHeader(); @@ -90,6 +94,52 @@ public class ColumnGroupRow<T> { return group; } + private void validateNewGroupProperties(Collection<GridColumn<?, T>> columns) { + + int rowIndex = grid.getColumnGroupRows().indexOf(this); + int parentRowIndex = rowIndex - 1; + + // Get the parent row of this row. + ColumnGroupRow<T> parentRow = null; + if (parentRowIndex > -1) { + parentRow = grid.getColumnGroupRows().get(parentRowIndex); + } + + if (parentRow == null) { + // A parentless row is always valid and is usually the first row + // added to the grid + return; + } + + for (GridColumn<?, T> column : columns) { + if (parentRow.hasColumnBeenGrouped(column)) { + /* + * If a property has been grouped in the parent row then all of + * the properties in the parent group also needs to be included + * in the child group for the groups to be valid + */ + ColumnGroup parentGroup = parentRow.getGroupForColumn(column); + if (!columns.containsAll(parentGroup.getColumns())) { + throw new IllegalArgumentException( + "Grouped properties overlaps previous grouping bounderies"); + } + } + } + } + + private boolean hasColumnBeenGrouped(GridColumn<?, T> column) { + return getGroupForColumn(column) != null; + } + + private ColumnGroup<T> getGroupForColumn(GridColumn<?, T> column) { + for (ColumnGroup<T> group : groups) { + if (group.getColumns().contains(column)) { + return group; + } + } + return null; + } + /** * Add a new group to the row by using other already greated groups * @@ -99,7 +149,8 @@ public class ColumnGroupRow<T> { * the group. * */ - public ColumnGroup<T> addGroup(ColumnGroup<T>... groups) { + public ColumnGroup<T> addGroup(ColumnGroup<T>... groups) + throws IllegalArgumentException { assert groups != null : "groups cannot be null"; Set<GridColumn<?, T>> columns = new HashSet<GridColumn<?, T>>(); @@ -107,6 +158,8 @@ public class ColumnGroupRow<T> { columns.addAll(group.getColumns()); } + validateNewGroupProperties(columns); + ColumnGroup<T> group = new ColumnGroup<T>(grid, columns); this.groups.add(group); grid.refreshHeader(); |