]> source.dussan.org Git - vaadin-framework.git/commitdiff
Never check the selectAll checkbox in an empty grid (#20301)
authorArtur Signell <artur@vaadin.com>
Thu, 13 Oct 2016 19:40:03 +0000 (22:40 +0300)
committerArtur Signell <artur@vaadin.com>
Thu, 13 Oct 2016 19:41:23 +0000 (22:41 +0300)
Change-Id: Ia15edb5a10de9bff047044161ffe83dd09f51098

server/src/main/java/com/vaadin/ui/Grid.java
server/src/test/java/com/vaadin/tests/server/component/grid/MultiSelectionModelTest.java

index 5e1d44244b1ff7ce8c2b4bb4754ae375f7b38ed9..8ca1a3de11e1cece9582c68966f6bc510ef43590 100644 (file)
@@ -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;
             }
         }
index d901cfbd5d4d16644e3f808f04ffcc0c7dcbe75f..f07c740b6ca2165bca22307f4a18c43e6fd73e36 100644 (file)
@@ -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
@@ -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 {