]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix Grid header default row cell setup when adding properties (#13334)
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Mon, 22 Sep 2014 12:24:16 +0000 (15:24 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 24 Sep 2014 08:15:10 +0000 (08:15 +0000)
Change-Id: Ia4a36d433c5a48ae8aebf0c7fcf04d4cec2447b4

server/src/com/vaadin/ui/components/grid/Grid.java
server/src/com/vaadin/ui/components/grid/GridColumn.java
server/src/com/vaadin/ui/components/grid/GridStaticSection.java
server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java
shared/src/com/vaadin/shared/ui/grid/GridColumnState.java

index 77773e7743ab7f93a1417525e5b68d6140df8603..81a4598097e799582df862c99ea07360c35ebb09 100644 (file)
@@ -513,9 +513,6 @@ public class Grid extends AbstractComponent implements SelectionChangeNotifier,
                             .getSortableContainerPropertyIds().contains(
                                     propertyId));
                 }
-
-                // Add by default property id as column header
-                row.getCell(propertyId).setText(String.valueOf(propertyId));
             }
         }
     }
@@ -605,6 +602,7 @@ public class Grid extends AbstractComponent implements SelectionChangeNotifier,
 
         GridColumn column = new GridColumn(this, columnState);
         columns.put(datasourcePropertyId, column);
+        column.setHeaderCaption(String.valueOf(datasourcePropertyId));
 
         return column;
     }
index 0ef805eb2ed6fd8f8c985a3a74e6ddeba041ee48..0d7a8dc395ca7ef3105047cc14376428096b48d1 100644 (file)
@@ -22,8 +22,8 @@ import com.vaadin.data.util.converter.Converter;
 import com.vaadin.data.util.converter.ConverterUtil;
 import com.vaadin.server.VaadinSession;
 import com.vaadin.shared.ui.grid.GridColumnState;
-import com.vaadin.shared.ui.grid.GridStaticSectionState.CellState;
 import com.vaadin.ui.UI;
+import com.vaadin.ui.components.grid.GridHeader.HeaderRow;
 import com.vaadin.ui.components.grid.renderers.TextRenderer;
 
 /**
@@ -87,10 +87,14 @@ public class GridColumn implements Serializable {
      * @throws IllegalStateException
      *             if the column no longer is attached to the grid
      */
-    @Deprecated
     public String getHeaderCaption() throws IllegalStateException {
         checkColumnIsAttached();
-        return state.header;
+        HeaderRow row = grid.getHeader().getDefaultRow();
+        if (row != null) {
+            return row.getCell(grid.getPropertyIdByColumnId(state.id))
+                    .getText();
+        }
+        return null;
     }
 
     /**
@@ -102,46 +106,13 @@ public class GridColumn implements Serializable {
      * @throws IllegalStateException
      *             if the column is no longer attached to any grid
      */
-    @Deprecated
     public void setHeaderCaption(String caption) throws IllegalStateException {
         checkColumnIsAttached();
-        state.header = caption;
-    }
-
-    /**
-     * Returns the caption of the footer. By default the captions are
-     * <code>null</code>.
-     * 
-     * @return the text in the footer
-     * @throws IllegalStateException
-     *             if the column is no longer attached to any grid
-     */
-    @Deprecated
-    public String getFooterCaption() throws IllegalStateException {
-        checkColumnIsAttached();
-        return getFooterCellState().text;
-    }
-
-    /**
-     * Sets the caption of the footer.
-     * 
-     * @param caption
-     *            the text to show in the caption
-     * 
-     * @throws IllegalStateException
-     *             if the column is no longer attached to any grid
-     */
-    @Deprecated
-    public void setFooterCaption(String caption) throws IllegalStateException {
-        checkColumnIsAttached();
-        getFooterCellState().text = caption;
-        state.footer = caption;
-        grid.markAsDirty();
-    }
-
-    private CellState getFooterCellState() {
-        int index = grid.getState().columns.indexOf(state);
-        return grid.getState().footer.rows.get(0).cells.get(index);
+        HeaderRow row = grid.getHeader().getDefaultRow();
+        if (row != null) {
+            row.getCell(grid.getPropertyIdByColumnId(state.id))
+                    .setText(caption);
+        }
     }
 
     /**
index eb098d0d4ec6b0fc3b453fb438d33ef563f501f4..80a39022e96710f83b68d215e01d291a81e46894 100644 (file)
@@ -79,13 +79,11 @@ abstract class GridStaticSection<ROWTYPE extends GridStaticSection.StaticRow<?>>
         }
 
         /**
-         * Returns the cell at the given position in this row.
+         * Returns the cell for the given property id on this row.
          * 
          * @param propertyId
-         *            the itemId of column
-         * @return the cell on given column
-         * @throws IndexOutOfBoundsException
-         *             if the index is out of bounds
+         *            the property id of the column
+         * @return the cell for the given property or null if not found
          */
         public CELLTYPE getCell(Object propertyId) {
             return cells.get(propertyId);
index d7f29b8014372dbfc19c267290e5405917ea5314..413a31be8172ffa13080746a7d0ab9e274b8f0aa 100644 (file)
@@ -91,8 +91,8 @@ public class GridColumns {
 
         column.setHeaderCaption("CustomHeader");
         assertEquals("CustomHeader", column.getHeaderCaption());
-        assertEquals(column.getHeaderCaption(),
-                getColumnState("column1").header);
+        assertEquals(column.getHeaderCaption(), grid.getHeader()
+                .getDefaultRow().getCell("column1").getText());
 
         column.setVisible(false);
         assertFalse(column.isVisible());
@@ -134,13 +134,6 @@ public class GridColumns {
             // Detached state should throw exception
         }
 
-        try {
-            column.setFooterCaption("asd");
-            fail("Succeeded in modifying a detached column");
-        } catch (IllegalStateException ise) {
-            // Detached state should throw exception
-        }
-
         try {
             column.setVisible(false);
             fail("Succeeded in modifying a detached column");
index d9c72d5ebde59e8ae8e9576275085dc0a4f72ea6..89e7791dbb76d2b26c97fe7331e27c5cd28867c1 100644 (file)
@@ -34,18 +34,6 @@ public class GridColumnState implements Serializable {
      */
     public String id;
 
-    /**
-     * Header caption for the column
-     */
-    @Deprecated
-    public String header;
-
-    /**
-     * Footer caption for the column
-     */
-    @Deprecated
-    public String footer;
-
     /**
      * Has the column been hidden. By default the column is visible.
      */