]> source.dussan.org Git - vaadin-framework.git/commitdiff
Update client side selection state when changing selection model (#20370)
authorArtur Signell <artur@vaadin.com>
Sat, 15 Oct 2016 20:02:15 +0000 (23:02 +0300)
committerArtur Signell <artur@vaadin.com>
Tue, 18 Oct 2016 05:15:30 +0000 (05:15 +0000)
Change-Id: I7fe8c160405a69140cac511c744d89a62c401cca

server/src/main/java/com/vaadin/ui/Grid.java
uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java

index 3f61dcd88fd60397c1397706bbaba149c7ff48ce..3bce7fcc394bd1ac6d470a6d73d4652ebacd948a 100644 (file)
@@ -5595,6 +5595,10 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
             if (!SharedUtil.equals(oldSelection, newSelection)) {
                 fireSelectionEvent(oldSelection, newSelection);
             }
+
+            // selection is included in the row data, so the client needs to be
+            // updated
+            datasourceExtension.refreshCache();
         }
     }
 
index bd2380ee454ee6c1c68a538b13ab7f605cc7999a..a1dc542250b2d44b8a21d8fbe67550871bbf9df6 100644 (file)
@@ -426,4 +426,44 @@ public class GridSelectionTest extends GridBasicFeaturesTest {
     private GridRowElement getRow(int i) {
         return getGridElement().getRow(i);
     }
+
+    @Test
+    public void changeSelectionModelSingleToNone() throws Exception {
+        openTestURL();
+
+        setSelectionModelSingle();
+        getGridElement().getCell(0, 0).click();
+        assertTrue("row should become selected", getRow(0).isSelected());
+        setSelectionModelNone();
+        assertFalse("row should become deselected", getRow(0).isSelected());
+        setSelectionModelSingle();
+        assertFalse("row should still be deselected", getRow(0).isSelected());
+        getGridElement().getCell(0, 0).click();
+        assertTrue("row should become selected", getRow(0).isSelected());
+    }
+
+    @Test
+    public void changeSelectionModelMultiToNone() throws Exception {
+        openTestURL();
+
+        setSelectionModelMulti();
+        getGridElement().getCell(0, 0).click();
+        getGridElement().getCell(1, 0).click();
+        getGridElement().getCell(2, 0).click();
+        assertTrue("row should become selected", getRow(0).isSelected());
+        assertTrue("row should become selected", getRow(1).isSelected());
+        assertTrue("row should become selected", getRow(2).isSelected());
+
+        setSelectionModelNone();
+        assertFalse("row should become deselected", getRow(0).isSelected());
+        assertFalse("row should become deselected", getRow(1).isSelected());
+        assertFalse("row should become deselected", getRow(2).isSelected());
+        setSelectionModelMulti();
+        assertFalse("row should still be deselected", getRow(0).isSelected());
+        assertFalse("row should still be deselected", getRow(1).isSelected());
+        assertFalse("row should still be deselected", getRow(2).isSelected());
+
+        getGridElement().getCell(0, 0).click();
+        assertTrue("row should become selected", getRow(0).isSelected());
+    }
 }