]> source.dussan.org Git - vaadin-framework.git/commitdiff
Handle generated empty string style names properly (#17335)
authorArtur Signell <artur@vaadin.com>
Mon, 18 May 2015 18:39:06 +0000 (21:39 +0300)
committerArtur Signell <artur@vaadin.com>
Tue, 19 May 2015 14:18:49 +0000 (14:18 +0000)
Change-Id: I1adce18f238fd4357b0eb1be68ebf7a3aaa6dd6e

server/src/com/vaadin/data/RpcDataProviderExtension.java
uitest/src/com/vaadin/tests/components/grid/GridHeaderStyleNames.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java

index cc1fbcf5e3c1abe9e6a088b34259bd812c057b42..9d18736ba8a1d0d1f4ff8b749cb01a5fbb5f75ab 100644 (file)
@@ -1134,7 +1134,7 @@ public class RpcDataProviderExtension extends AbstractExtension {
             Object propertyId = column.getPropertyId();
             cellReference.set(propertyId);
             String style = generator.getStyle(cellReference);
-            if (style != null) {
+            if (style != null && !style.isEmpty()) {
                 if (cellStyles == null) {
                     cellStyles = Json.createObject();
                 }
@@ -1152,7 +1152,7 @@ public class RpcDataProviderExtension extends AbstractExtension {
     private void setGeneratedRowStyles(RowStyleGenerator generator,
             JsonObject rowObject) {
         String rowStyle = generator.getStyle(rowReference);
-        if (rowStyle != null) {
+        if (rowStyle != null && !rowStyle.isEmpty()) {
             rowObject.put(GridState.JSONKEY_ROWSTYLE, rowStyle);
         }
     }
index 765cd0181243357fa2da93916678827f19b16763..019850dabb23fadf40f29984ee68b18c5501edb1 100644 (file)
@@ -46,7 +46,7 @@ public class GridHeaderStyleNames extends AbstractTestUIWithLog {
                 .createContainer(100));
 
         ageHeaderCell = grid.getDefaultHeaderRow().getCell("age");
-
+        grid.getDefaultHeaderRow().setStyleName("foo");
         headerRow = grid.prependHeaderRow();
         mergedCityCountryCell = headerRow.join("city", "country");
         mergedCityCountryCell.setText("Merged cell");
index 18f2d02e933e36e24c9ac5f89fb23172b5f64c57..ecf3d53385a57ed1dbd94f0fd3f49e2242271f9e 100644 (file)
@@ -83,9 +83,13 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
     public static final String ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4 = "Row numbers for 3/4";
     public static final String ROW_STYLE_GENERATOR_NONE = "None";
     public static final String ROW_STYLE_GENERATOR_ROW_NUMBERS = "Row numbers";
+    public static final String ROW_STYLE_GENERATOR_EMPTY = "Empty string";
+    public static final String ROW_STYLE_GENERATOR_NULL = "Null";
     public static final String CELL_STYLE_GENERATOR_NONE = "None";
     public static final String CELL_STYLE_GENERATOR_PROPERTY_TO_STRING = "Property to string";
     public static final String CELL_STYLE_GENERATOR_SPECIAL = "Special for 1/4 Column 1";
+    public static final String CELL_STYLE_GENERATOR_EMPTY = "Empty string";
+    public static final String CELL_STYLE_GENERATOR_NULL = "Null";
     private static final int MANUALLY_FORMATTED_COLUMNS = 5;
     public static final int COLUMNS = 12;
     public static final int EDITABLE_COLUMNS = COLUMNS - 1;
@@ -514,6 +518,22 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
                         }
                     }
                 });
+        rowStyleGenerators.put(ROW_STYLE_GENERATOR_EMPTY,
+                new RowStyleGenerator() {
+
+                    @Override
+                    public String getStyle(RowReference rowReference) {
+                        return "";
+                    }
+                });
+        rowStyleGenerators.put(ROW_STYLE_GENERATOR_NULL,
+                new RowStyleGenerator() {
+
+                    @Override
+                    public String getStyle(RowReference rowReference) {
+                        return null;
+                    }
+                });
         cellStyleGenerators.put(CELL_STYLE_GENERATOR_NONE, null);
         cellStyleGenerators.put(CELL_STYLE_GENERATOR_PROPERTY_TO_STRING,
                 new CellStyleGenerator() {
@@ -539,6 +559,20 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
                         return propertyId.toString().replace(' ', '_');
                     }
                 });
+        cellStyleGenerators.put(CELL_STYLE_GENERATOR_EMPTY,
+                new CellStyleGenerator() {
+                    @Override
+                    public String getStyle(CellReference cellReference) {
+                        return "";
+                    }
+                });
+        cellStyleGenerators.put(CELL_STYLE_GENERATOR_NULL,
+                new CellStyleGenerator() {
+                    @Override
+                    public String getStyle(CellReference cellReference) {
+                        return null;
+                    }
+                });
 
         createSelectAction("Row style generator", "State", rowStyleGenerators,
                 CELL_STYLE_GENERATOR_NONE,
index 643c61d90af1f0a12c702cbcb0a5e7c385b93e03..f013b760758f874763befb600eab91e903e99ffd 100644 (file)
@@ -118,4 +118,26 @@ public class GridCellStyleGeneratorTest extends GridBasicFeaturesTest {
     private void selectCellStyleNameGenerator(String name) {
         selectMenuPath("Component", "State", "Cell style generator", name);
     }
+
+    @Test
+    public void testEmptyStringStyleGenerator() {
+        setDebug(true);
+        openTestURL();
+        selectCellStyleNameGenerator(GridBasicFeatures.CELL_STYLE_GENERATOR_EMPTY);
+        selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_EMPTY);
+
+        assertFalse("Error notification was present",
+                isElementPresent(NotificationElement.class));
+    }
+
+    @Test
+    public void testNullStringStyleGenerator() {
+        setDebug(true);
+        openTestURL();
+        selectCellStyleNameGenerator(GridBasicFeatures.CELL_STYLE_GENERATOR_NULL);
+        selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_NULL);
+
+        assertFalse("Error notification was present",
+                isElementPresent(NotificationElement.class));
+    }
 }