From c94312a0f8a2c4afc019da16092eabad92ab7f2b Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 13 Oct 2016 22:40:03 +0300 Subject: Never check the selectAll checkbox in an empty grid (#20301) Change-Id: Ia15edb5a10de9bff047044161ffe83dd09f51098 --- .../src/main/java/com/vaadin/v7/ui/Grid.java | 4 +++- .../component/grid/MultiSelectionModelTest.java | 27 ++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'compatibility-server') diff --git a/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java b/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java index 627b4cf25c..e47294d440 100644 --- a/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java +++ b/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java @@ -1918,7 +1918,9 @@ public class Grid extends AbstractComponent 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/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/MultiSelectionModelTest.java b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/MultiSelectionModelTest.java index f30b5ea141..044124bc8a 100644 --- a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/MultiSelectionModelTest.java +++ b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/MultiSelectionModelTest.java @@ -28,12 +28,20 @@ import com.vaadin.v7.data.Container; import com.vaadin.v7.data.util.IndexedContainer; import com.vaadin.v7.event.SelectionEvent; import com.vaadin.v7.event.SelectionEvent.SelectionListener; +import com.vaadin.v7.shared.ui.grid.selection.MultiSelectionModelState; import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.MultiSelectionModel; -import com.vaadin.v7.ui.Grid.SelectionMode; public class MultiSelectionModelTest { + private static class MultiSelectionModel + extends com.vaadin.v7.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 @@ -104,6 +112,17 @@ public class MultiSelectionModelTest { verifyCurrentSelection(itemId1Present, itemId2Present); } + @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 { -- cgit v1.2.3