diff options
author | Artur Signell <artur@vaadin.com> | 2016-10-13 22:40:03 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2016-10-13 22:41:23 +0300 |
commit | 9c90ed78a137ba919a9b90f285a6b7e5dd5efb2b (patch) | |
tree | 3f477cdb8bf95948e788d407264d14490e9be96c /server | |
parent | 57a2eef0d141b779c35e520ffdcc7709f124fff1 (diff) | |
download | vaadin-framework-9c90ed78a137ba919a9b90f285a6b7e5dd5efb2b.tar.gz vaadin-framework-9c90ed78a137ba919a9b90f285a6b7e5dd5efb2b.zip |
Never check the selectAll checkbox in an empty grid (#20301)
Change-Id: Ia15edb5a10de9bff047044161ffe83dd09f51098
Diffstat (limited to 'server')
-rw-r--r-- | server/src/main/java/com/vaadin/ui/Grid.java | 4 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/component/grid/MultiSelectionModelTest.java | 27 |
2 files changed, 26 insertions, 5 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index 5e1d44244b..8ca1a3de11 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -1878,7 +1878,9 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, private void updateAllSelectedState() { int totalRowCount = getParentGrid().datasource.size(); int rows = Math.min(totalRowCount, selectionLimit); - if (getState().allSelected != selection.size() >= rows) { + if (totalRowCount == 0) { + getState().allSelected = false; + } else { getState().allSelected = selection.size() >= rows; } } diff --git a/server/src/test/java/com/vaadin/tests/server/component/grid/MultiSelectionModelTest.java b/server/src/test/java/com/vaadin/tests/server/component/grid/MultiSelectionModelTest.java index d901cfbd5d..f07c740b6c 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/grid/MultiSelectionModelTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/grid/MultiSelectionModelTest.java @@ -28,12 +28,20 @@ import com.vaadin.data.Container; import com.vaadin.data.util.IndexedContainer; import com.vaadin.event.SelectionEvent; import com.vaadin.event.SelectionEvent.SelectionListener; +import com.vaadin.shared.ui.grid.selection.MultiSelectionModelState; import com.vaadin.ui.Grid; -import com.vaadin.ui.Grid.MultiSelectionModel; -import com.vaadin.ui.Grid.SelectionMode; public class MultiSelectionModelTest { + private static class MultiSelectionModel + extends com.vaadin.ui.Grid.MultiSelectionModel { + @Override + protected MultiSelectionModelState getState() { + // Overridden to be accessible from test + return super.getState(); + } + } + private Object itemId1Present = "itemId1Present"; private Object itemId2Present = "itemId2Present"; private Object itemId3Present = "itemId3Present"; @@ -52,8 +60,8 @@ public class MultiSelectionModelTest { public void setUp() { dataSource = createDataSource(); grid = new Grid(dataSource); - grid.setSelectionMode(SelectionMode.MULTI); - model = (MultiSelectionModel) grid.getSelectionModel(); + model = new MultiSelectionModel(); + grid.setSelectionModel(model); } @After @@ -105,6 +113,17 @@ public class MultiSelectionModelTest { } @Test + public void testSelectAllWithoutItems() throws Throwable { + Assert.assertFalse(model.getState().allSelected); + dataSource.removeAllItems(); + Assert.assertFalse(model.getState().allSelected); + model.select(); + Assert.assertFalse(model.getState().allSelected); + model.deselect(); + Assert.assertFalse(model.getState().allSelected); + } + + @Test public void testSettingSelection() throws Throwable { try { expectSelectEvent(itemId2Present, itemId1Present); |