diff options
author | Ahmed Ashour <asashour@yahoo.com> | 2017-10-20 14:17:32 +0200 |
---|---|---|
committer | Péter Török <31210544+torok-peter@users.noreply.github.com> | 2017-10-20 15:17:32 +0300 |
commit | b394dec430792e6514992f651d1f512bdf32b914 (patch) | |
tree | 4acf6bffd5d9cf0b7f6cdcf0c163cee5c472d69b /server/src/main/java/com/vaadin/ui/Grid.java | |
parent | f706837fbfdafef24839184c487e975afaa7cfc3 (diff) | |
download | vaadin-framework-b394dec430792e6514992f651d1f512bdf32b914.tar.gz vaadin-framework-b394dec430792e6514992f651d1f512bdf32b914.zip |
Grid.removeColumn() not to fail silently (Fixes #8056) (#10215)
* Grid.removeColumn() not to fail silently (Fixes #8056)
* Compilation with JDK
* Fix removeColumnByColumn_alreadyRemoved test
* Use ExpectedException
Diffstat (limited to 'server/src/main/java/com/vaadin/ui/Grid.java')
-rw-r--r-- | server/src/main/java/com/vaadin/ui/Grid.java | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index de8f66ee58..50361528a7 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -976,10 +976,9 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, private static int compareMaybeComparables(Object a, Object b) { if (hasCommonComparableBaseType(a, b)) { return compareComparables(a, b); - } else { - return compareComparables(Objects.toString(a, ""), - Objects.toString(b, "")); } + return compareComparables(Objects.toString(a, ""), + Objects.toString(b, "")); } private static boolean hasCommonComparableBaseType(Object a, Object b) { @@ -1005,7 +1004,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, return false; } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) private static int compareComparables(Object a, Object b) { return ((Comparator) Comparator .nullsLast(Comparator.naturalOrder())).compare(a, b); @@ -1019,20 +1018,19 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, if (valueA instanceof Comparable && valueA.getClass().isInstance(valueB)) { return ((Comparable<Number>) valueA).compareTo(valueB); - } else if (valueA.equals(valueB)) { + } + if (valueA.equals(valueB)) { return 0; - } else { - // Fall back to comparing based on potentially truncated values - int compare = Long.compare(valueA.longValue(), - valueB.longValue()); - if (compare == 0) { - // This might still produce 0 even though the values are not - // equals, but there's nothing more we can do about that - compare = Double.compare(valueA.doubleValue(), - valueB.doubleValue()); - } - return compare; } + // Fall back to comparing based on potentially truncated values + int compare = Long.compare(valueA.longValue(), valueB.longValue()); + if (compare == 0) { + // This might still produce 0 even though the values are not + // equals, but there's nothing more we can do about that + compare = Double.compare(valueA.doubleValue(), + valueB.doubleValue()); + } + return compare; } @SuppressWarnings("unchecked") @@ -2720,6 +2718,9 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, * * @param column * the column to remove + * + * @throws IllegalArgumentException + * if the column is not a valid one */ public void removeColumn(Column<T, ?> column) { if (columnSet.remove(column)) { @@ -2737,6 +2738,9 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, if (displayIndex < getFrozenColumnCount()) { setFrozenColumnCount(getFrozenColumnCount() - 1); } + } else { + throw new IllegalArgumentException("Column with id " + + column.getId() + " cannot be removed from the grid"); } } @@ -2934,10 +2938,12 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, if (rows <= 0.0d) { throw new IllegalArgumentException( "More than zero rows must be shown."); - } else if (Double.isInfinite(rows)) { + } + if (Double.isInfinite(rows)) { throw new IllegalArgumentException( "Grid doesn't support infinite heights"); - } else if (Double.isNaN(rows)) { + } + if (Double.isNaN(rows)) { throw new IllegalArgumentException("NaN is not a valid row count"); } getState().heightMode = HeightMode.ROW; @@ -3761,7 +3767,6 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, } else { addExtension(selectionModel); } - } /** @@ -4267,7 +4272,8 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, SelectionMode selectionMode = getSelectionMode(); if (SelectionMode.SINGLE.equals(selectionMode)) { return asSingleSelect().isReadOnly(); - } else if (SelectionMode.MULTI.equals(selectionMode)) { + } + if (SelectionMode.MULTI.equals(selectionMode)) { return asMultiSelect().isReadOnly(); } return false; |