]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add method for refreshing all Grid rows (#8406)
authorArtur <artur@vaadin.com>
Wed, 1 Feb 2017 07:46:20 +0000 (09:46 +0200)
committerDenis <denis@vaadin.com>
Wed, 1 Feb 2017 07:46:20 +0000 (09:46 +0200)
* Add method for refreshing all Grid rows

Fixes #8350

server/src/main/java/com/vaadin/ui/Grid.java
uitest/src/main/java/com/vaadin/tests/components/grid/GridRefreshRow.java
uitest/src/test/java/com/vaadin/tests/components/grid/GridRefreshRowTest.java

index f96b485cc0db4f65414f72e1f0bc8f8e787c1488..4b7793893d3d9d02187493823f6a763fbd22df25 100644 (file)
@@ -6859,6 +6859,13 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
         }
     }
 
+    /**
+     * Refreshes, i.e. causes the client side to re-render all rows.
+     */
+    public void refreshAllRows() {
+        datasourceExtension.refreshCache();
+    }
+
     private static Logger getLogger() {
         return Logger.getLogger(Grid.class.getName());
     }
index 0084e33360cd2152f77511412e94c68f8ce4442b..2104218d9be0594c12298a3abafa9d014a9ff9cd 100644 (file)
@@ -70,13 +70,20 @@ public class GridRefreshRow extends AbstractTestUIWithLog {
             }
         });
         refresh10.setId("refresh10");
+        Button refreshAll = new Button("Refresh all", new ClickListener() {
+            @Override
+            public void buttonClick(ClickEvent event) {
+                grid.refreshAllRows();
+            }
+        });
+        refreshAll.setId("refreshAll");
         addComponents(new HorizontalLayout(refresh(0), refresh(1), refresh(2),
                 new Button("Refresh non-existant", new ClickListener() {
                     @Override
                     public void buttonClick(ClickEvent event) {
                         grid.refreshRows("foobar");
                     }
-                })), refresh10);
+                })), refresh10, refreshAll);
         addComponents(new HorizontalLayout(style(0), style(1), style(2)));
     }
 
index 3b1e2b9c888a9fd7c1b24d7cb38117f188d10e19..9ea393c7b990327dd0f89659aaf89c8eec8ff3bc 100644 (file)
@@ -55,6 +55,40 @@ public class GridRefreshRowTest extends SingleBrowserTest {
         Assert.assertEquals("!!Marge", grid.getCell(2, 1).getText());
     }
 
+    @Test
+    public void refreshAllRows() {
+        openTestURL();
+        grid = $(GridElement.class).first();
+        update(0);
+        update(1);
+        update(2);
+        style(1);
+        style(2);
+
+        Assert.assertEquals("Lisa", grid.getCell(0, 1).getText());
+        Assert.assertEquals("Joshua", grid.getCell(1, 1).getText());
+        Assert.assertEquals("Marge", grid.getCell(2, 1).getText());
+
+        Assert.assertFalse(hasCssClass(grid.getRow(0), "rowstyle"));
+        Assert.assertFalse(hasCssClass(grid.getRow(1), "rowstyle"));
+        Assert.assertFalse(hasCssClass(grid.getRow(2), "rowstyle"));
+        Assert.assertFalse(hasCssClass(grid.getCell(0, 0), "cellstyle"));
+        Assert.assertFalse(hasCssClass(grid.getCell(1, 0), "cellstyle"));
+        Assert.assertFalse(hasCssClass(grid.getCell(2, 0), "cellstyle"));
+
+        refreshAll();
+        Assert.assertEquals("!Lisa", grid.getCell(0, 1).getText());
+        Assert.assertEquals("!Joshua", grid.getCell(1, 1).getText());
+        Assert.assertEquals("!Marge", grid.getCell(2, 1).getText());
+
+        Assert.assertFalse(hasCssClass(grid.getRow(0), "rowstyle"));
+        Assert.assertTrue(hasCssClass(grid.getRow(1), "rowstyle"));
+        Assert.assertTrue(hasCssClass(grid.getRow(2), "rowstyle"));
+        Assert.assertFalse(hasCssClass(grid.getCell(0, 0), "cellstyle"));
+        Assert.assertTrue(hasCssClass(grid.getCell(1, 0), "cellstyle"));
+        Assert.assertTrue(hasCssClass(grid.getCell(2, 0), "cellstyle"));
+    }
+
     private void refresh10First() {
         $(ButtonElement.class).id("refresh10").click();
     }
@@ -70,4 +104,8 @@ public class GridRefreshRowTest extends SingleBrowserTest {
     private void refresh(int i) {
         $(ButtonElement.class).id("refresh" + i).click();
     }
+
+    private void refreshAll() {
+        $(ButtonElement.class).id("refreshAll").click();
+    }
 }