]> source.dussan.org Git - vaadin-framework.git/commitdiff
Extend addColumn to support arbitrary data types (#13334)
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Mon, 1 Dec 2014 15:36:16 +0000 (17:36 +0200)
committerTeemu Suo-Anttila <teemusa@vaadin.com>
Thu, 4 Dec 2014 09:46:40 +0000 (09:46 +0000)
Change-Id: I3bd9d4b6fb6c4b289421c6982ba28d893a97908e

server/src/com/vaadin/ui/Grid.java
server/tests/src/com/vaadin/tests/server/component/grid/GridColumnBuildTest.java

index c307de84a51d770aa2025d0b4547f3fd4f71a1f5..c61791755590e348c113f7945e9bde20f156c688 100644 (file)
@@ -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.
+     * <p>
+     * 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.
      * <p>
      * 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 <T extends Number> Column addColumn(Object propertyId, Class<T> type)
-            throws IllegalStateException {
-        addColumnProperty(propertyId, type, 0);
+    public Column addColumn(Object propertyId, Class<?> type) {
+        addColumnProperty(propertyId, type, null);
         return getColumn(propertyId);
     }
 
index 31b918f51e321475203431dbdb6a85fb624e8a31..5ac3b850b928d436b100330ec0f88ac04112fde1 100644 (file)
@@ -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);
+    }
 }