From: Teemu Suo-Anttila Date: Mon, 1 Dec 2014 15:36:16 +0000 (+0200) Subject: Extend addColumn to support arbitrary data types (#13334) X-Git-Tag: 7.4.0.beta1~9^2~85 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d3cfb79c223a772d3baec8476a9d15716bade1ff;p=vaadin-framework.git Extend addColumn to support arbitrary data types (#13334) Change-Id: I3bd9d4b6fb6c4b289421c6982ba28d893a97908e --- diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index c307de84a5..c617917555 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -2333,22 +2333,27 @@ public class Grid extends AbstractComponent implements SelectionChangeNotifier, /** * Adds a new Column to Grid. This function makes sure that the property * with the given id and data type exists in the container. If property does - * not exists, it will be created. Default value for the new property is 0. + * not exists, it will be created. + *

+ * Default value for the new property is 0 if type is Integer, Double and + * Float. If type is String, default value is an empty string. For all other + * types the default value is null. *

* Note that adding a new property is only done for the default container * that Grid sets up with the default constructor. * * @param propertyId * the property id of the new column + * @param type + * the data type for the new property * @return the new column * * @throws IllegalStateException * if column for given property already exists in this grid or * property already exists in the container with wrong type */ - public Column addColumn(Object propertyId, Class type) - throws IllegalStateException { - addColumnProperty(propertyId, type, 0); + public Column addColumn(Object propertyId, Class type) { + addColumnProperty(propertyId, type, null); return getColumn(propertyId); } diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/GridColumnBuildTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/GridColumnBuildTest.java index 31b918f51e..5ac3b850b9 100644 --- a/server/tests/src/com/vaadin/tests/server/component/grid/GridColumnBuildTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/grid/GridColumnBuildTest.java @@ -65,6 +65,7 @@ public class GridColumnBuildTest { grid.addColumn("foo"); } + @Test public void testAddNumberColumns() { grid.addColumn("bar", Integer.class); grid.addColumn("baz", Double.class); @@ -72,9 +73,11 @@ public class GridColumnBuildTest { Property property = container.getContainerProperty( container.firstItemId(), "bar"); assertEquals(property.getType(), Integer.class); + assertEquals(null, property.getValue()); property = container.getContainerProperty(container.firstItemId(), "baz"); assertEquals(property.getType(), Double.class); + assertEquals(null, property.getValue()); } @Test(expected = IllegalStateException.class) @@ -113,4 +116,13 @@ public class GridColumnBuildTest { grid.removeAllColumns(); grid.addColumn("bar", Integer.class); } + + @Test + public void testAddBooleanColumnProperty() { + grid.addColumn("foo", Boolean.class); + Property property = container.getContainerProperty( + container.firstItemId(), "foo"); + assertEquals(property.getType(), Boolean.class); + assertEquals(property.getValue(), null); + } }