diff options
author | Artur <artur@vaadin.com> | 2017-02-01 09:46:20 +0200 |
---|---|---|
committer | Denis <denis@vaadin.com> | 2017-02-01 09:46:20 +0200 |
commit | 7be7afaa25e4dc05286cf98ccb35676e6e5c7b20 (patch) | |
tree | 521fa7aa35b001620f59c59b22de5d0287fc9f9d | |
parent | 8405496a7a6f6808fe829485c677bb73b4fa670c (diff) | |
download | vaadin-framework-7be7afaa25e4dc05286cf98ccb35676e6e5c7b20.tar.gz vaadin-framework-7be7afaa25e4dc05286cf98ccb35676e6e5c7b20.zip |
Add method for refreshing all Grid rows (#8406)
* Add method for refreshing all Grid rows
Fixes #8350
3 files changed, 53 insertions, 1 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index f96b485cc0..4b7793893d 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -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()); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridRefreshRow.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridRefreshRow.java index 0084e33360..2104218d9b 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridRefreshRow.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridRefreshRow.java @@ -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))); } diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridRefreshRowTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridRefreshRowTest.java index 3b1e2b9c88..9ea393c7b9 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridRefreshRowTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridRefreshRowTest.java @@ -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(); + } } |