]> source.dussan.org Git - vaadin-framework.git/commitdiff
Use headerCaption as default hidingToggleCaption (#18028)
authorTeppo Kurki <teppo.kurki@vaadin.com>
Wed, 3 Jun 2015 11:26:35 +0000 (14:26 +0300)
committerVaadin Code Review <review@vaadin.com>
Fri, 5 Jun 2015 09:58:51 +0000 (09:58 +0000)
Change-Id: Ifaf288da98d6d1d1c02760784b832cb5b5d93c07

client/src/com/vaadin/client/connectors/GridConnector.java
client/src/com/vaadin/client/widgets/Grid.java
server/src/com/vaadin/ui/Grid.java
server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java
shared/src/com/vaadin/shared/ui/grid/GridColumnState.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnVisibilityTest.java

index d3fa678c3e9d24e9a7c42dc53708872105bbca8f..f2246b1e5f6753eb5f7c0392f1a61971058add68 100644 (file)
@@ -1198,6 +1198,8 @@ public class GridConnector extends AbstractHasComponentsConnector implements
 
         column.setSortable(state.sortable);
 
+        column.setHeaderCaption(state.headerCaption);
+
         column.setHidden(state.hidden);
         column.setHidable(state.hidable);
         column.setHidingToggleCaption(state.hidingToggleCaption);
index 9393ffb48cda6cbcb7998cb8248ef0f232401b39..fa74b16317d6c74e75e9458651817fa53d9e4bbb 100644 (file)
@@ -4390,8 +4390,8 @@ public class Grid<T> extends ResizeComposite implements
          * for this column in the grid's sidebar when the column is
          * {@link #isHidable() hidable}.
          * <p>
-         * Defaults to <code>null</code>, when will use whatever is set with
-         * {@link #setHeaderCaption(String)}.
+         * The default value is <code>null</code>. In this case the header
+         * caption is used, see {@link #setHeaderCaption(String)}.
          * 
          * @since 7.5.0
          * @param hidingToggleCaption
index c061a81b7390d1c706d599c5461f4b8a98b223f5..96884d7fd5c734ef79ac360f8f26c837ae4f00d5 100644 (file)
@@ -2441,9 +2441,10 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
         private Converter<?, Object> converter;
 
         /**
-         * A check for allowing the {@link #Column(Grid, GridColumnState, Object)
-         * constructor} to call {@link #setConverter(Converter)} with a
-         * <code>null</code>, even if model and renderer aren't compatible.
+         * A check for allowing the
+         * {@link #Column(Grid, GridColumnState, Object) constructor} to call
+         * {@link #setConverter(Converter)} with a <code>null</code>, even if
+         * model and renderer aren't compatible.
          */
         private boolean isFirstConverterAssignment = true;
 
@@ -2503,7 +2504,9 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
         }
 
         /**
-         * Sets the caption of the header.
+         * Sets the caption of the header. This caption is also used as the
+         * hiding toggle caption, unless it is explicitly set via
+         * {@link #setHidingToggleCaption(String)}.
          * 
          * @param caption
          *            the text to show in the caption
@@ -2515,6 +2518,9 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
         public Column setHeaderCaption(String caption)
                 throws IllegalStateException {
             checkColumnIsAttached();
+
+            state.headerCaption = caption;
+
             HeaderRow row = grid.getHeader().getDefaultRow();
             if (row != null) {
                 row.getCell(grid.getPropertyIdByColumnId(state.id)).setText(
@@ -2542,11 +2548,11 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
          * toggle for this column in the grid's sidebar when the column is
          * {@link #isHidable() hidable}.
          * <p>
-         * By default, before triggering this setter, a user friendly version of
-         * the column's {@link #getPropertyId() property id} is used.
+         * The default value is <code>null</code>, and in that case the column's
+         * {@link #getHeaderCaption() header caption} is used.
          * <p>
-         * <em>NOTE:</em> setting this to <code>null</code> or empty string
-         * might cause the hiding toggle to not render correctly.
+         * <em>NOTE:</em> setting this to empty string might cause the hiding
+         * toggle to not render correctly.
          * 
          * @since 7.5.0
          * @param hidingToggleCaption
@@ -3207,9 +3213,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
             DesignAttributeHandler.writeAttribute("hidden", attributes,
                     isHidden(), def.hidden, boolean.class);
             DesignAttributeHandler.writeAttribute("hiding-toggle-caption",
-                    attributes, getHidingToggleCaption(),
-                    SharedUtil.propertyIdToHumanFriendly(getPropertyId()),
-                    String.class);
+                    attributes, getHidingToggleCaption(), null, String.class);
             DesignAttributeHandler.writeAttribute("property-id", attributes,
                     getPropertyId(), null, Object.class);
         }
@@ -3288,7 +3292,8 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
 
         private final String nullRepresentation;
 
-        protected AbstractRenderer(Class<T> presentationType, String nullRepresentation) {
+        protected AbstractRenderer(Class<T> presentationType,
+                String nullRepresentation) {
             this.presentationType = presentationType;
             this.nullRepresentation = nullRepresentation;
         }
@@ -3333,6 +3338,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
 
         /**
          * Null representation for the renderer
+         * 
          * @return a textual representation of {@code null}
          */
         protected String getNullRepresentation() {
@@ -4303,7 +4309,6 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
         String humanFriendlyPropertyId = SharedUtil
                 .propertyIdToHumanFriendly(String.valueOf(datasourcePropertyId));
         column.setHeaderCaption(humanFriendlyPropertyId);
-        column.setHidingToggleCaption(humanFriendlyPropertyId);
 
         if (datasource instanceof Sortable
                 && ((Sortable) datasource).getSortableContainerPropertyIds()
@@ -4513,8 +4518,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
      * @throws IllegalArgumentException
      *             if {@code rows} is zero or less
      * @throws IllegalArgumentException
-     *             if {@code rows} is {@link Double#isInfinite(double)
-     *             infinite}
+     *             if {@code rows} is {@link Double#isInfinite(double) infinite}
      * @throws IllegalArgumentException
      *             if {@code rows} is {@link Double#isNaN(double) NaN}
      */
index 35553bb406bccc185d1816379d7c80e75afc43b3..2b960d26a0e49008ed2250ca2e4081a9f54b15cf 100644 (file)
@@ -338,4 +338,20 @@ public class GridColumns {
     public void testAddingColumnsWithSetColumnsNonDefaultContainer() {
         grid.setColumns("column1", "column2", "column50");
     }
+
+    @Test
+    public void testDefaultColumnHidingToggleCaption() {
+        Column firstColumn = grid.getColumns().get(0);
+        firstColumn.setHeaderCaption("headerCaption");
+        assertEquals(null, firstColumn.getHidingToggleCaption());
+    }
+
+    @Test
+    public void testOverriddenColumnHidingToggleCaption() {
+        Column firstColumn = grid.getColumns().get(0);
+        firstColumn.setHidingToggleCaption("hidingToggleCaption");
+        firstColumn.setHeaderCaption("headerCaption");
+        assertEquals("hidingToggleCaption",
+                firstColumn.getHidingToggleCaption());
+    }
 }
index 5aa9ea9b659810f7be2ec5d332f04b6a572cca99..547a4a84cae9b35ebacbd5b9103688331d14b27f 100644 (file)
@@ -85,4 +85,7 @@ public class GridColumnState implements Serializable {
 
     /** The caption for the column hiding toggle. */
     public String hidingToggleCaption;
+
+    /** Column header caption */
+    public String headerCaption;
 }
index ecf3d53385a57ed1dbd94f0fd3f49e2242271f9e..ef51cdf44659b8fc8946348700781013afb86515 100644 (file)
@@ -908,6 +908,18 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
                         }
                     }, null, c);
 
+            createClickAction("Change header caption", getColumnProperty(c),
+                    new Command<Grid, String>() {
+                        int count = 0;
+
+                        @Override
+                        public void execute(Grid grid, String value, Object data) {
+                            final String columnProperty = getColumnProperty((Integer) data);
+                            grid.getColumn(columnProperty).setHeaderCaption(
+                                    columnProperty + " header " + count++);
+                        }
+                    }, null, c);
+
             createCategory("Column " + c + " Width", getColumnProperty(c));
 
             createClickAction("Auto", "Column " + c + " Width",
index d01e689b7230ccc9a3123da66f7a1154157ed8d9..e2d7468d08d13501cff303559d45cf2eca780283 100644 (file)
@@ -195,6 +195,34 @@ public class GridColumnVisibilityTest extends GridBasicFeaturesTest {
         assertEquals("Column 1", getColumnHidingToggle(1).getText());
     }
 
+    @Test
+    public void testColumnHidingToggleCaption_settingColumnHeaderCaption_toggleCaptionIsEqual() {
+        toggleColumnHidable(1);
+
+        selectMenuPath("Component", "Columns", "Column 1",
+                "Change header caption");
+
+        getSidebarOpenButton().click();
+        assertEquals("column 1 header 0", getGridElement().getHeaderCell(0, 1)
+                .getText().toLowerCase());
+        assertEquals("Column 1 header 0", getColumnHidingToggle(1).getText());
+    }
+
+    @Test
+    public void testColumnHidingToggleCaption_explicitlySet_toggleCaptionIsNotOverridden() {
+        toggleColumnHidable(1);
+
+        selectMenuPath("Component", "Columns", "Column 1",
+                "Change hiding toggle caption");
+        selectMenuPath("Component", "Columns", "Column 1",
+                "Change header caption");
+
+        getSidebarOpenButton().click();
+        assertEquals("column 1 header 0", getGridElement().getHeaderCell(0, 1)
+                .getText().toLowerCase());
+        assertEquals("Column 1 caption 0", getColumnHidingToggle(1).getText());
+    }
+
     private void toggleColumnHidingToggleCaptionChange(int index) {
         selectMenuPath("Component", "Columns", "Column " + index,
                 "Change hiding toggle caption");