aboutsummaryrefslogtreecommitdiffstats
path: root/compatibility-server/src
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2016-10-13 22:40:03 +0300
committerPekka Hyvönen <pekka@vaadin.com>2016-12-09 09:39:00 +0200
commitc94312a0f8a2c4afc019da16092eabad92ab7f2b (patch)
treeb67d99e3d158fb69b24fb5f30a025f2cfb844e85 /compatibility-server/src
parentd20fc36768c9d2c74b40b34c931da8d842d0a67e (diff)
downloadvaadin-framework-c94312a0f8a2c4afc019da16092eabad92ab7f2b.tar.gz
vaadin-framework-c94312a0f8a2c4afc019da16092eabad92ab7f2b.zip
Never check the selectAll checkbox in an empty grid (#20301)
Change-Id: Ia15edb5a10de9bff047044161ffe83dd09f51098
Diffstat (limited to 'compatibility-server/src')
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java4
-rw-r--r--compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/MultiSelectionModelTest.java27
2 files changed, 26 insertions, 5 deletions
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
@@ -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);