]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix setSelected in MultiSelectionModel to update row data (#19302)
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Wed, 25 Nov 2015 10:20:24 +0000 (12:20 +0200)
committerVaadin Code Review <review@vaadin.com>
Wed, 25 Nov 2015 11:15:22 +0000 (11:15 +0000)
Change-Id: I32c980b2cae199ad2059701e4e04b4a7cb76bafa

server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java
server/src/com/vaadin/ui/Grid.java
uitest/src/com/vaadin/tests/components/grid/GridMultiSelectionOnInit.java
uitest/src/com/vaadin/tests/components/grid/GridMultiSelectionOnInitTest.java

index fed31646f43bfec9a8653fed3f059906a0dbbf00..55b486d4b69e029ba4e2b7a69890727967b0dfe3 100644 (file)
@@ -499,11 +499,12 @@ public class RpcDataProviderExtension extends AbstractExtension {
             return;
         }
 
+        Collection<Object> activeItemIds = activeItemHandler.getActiveItemIds();
         List<Column> columns = getGrid().getColumns();
         JsonArray rowData = Json.createArray();
         int i = 0;
         for (Object itemId : itemIds) {
-            if (activeItemHandler.getActiveItemIds().contains(itemId)) {
+            if (activeItemIds.contains(itemId)) {
                 Item item = container.getItem(itemId);
                 if (item != null) {
                     JsonObject row = getRowData(columns, itemId, item);
index 0f3e634ed385a4fe31ccbbd0d67202e2db1b0a7b..c75013b8c6d75afcf622b70294b34d800ca7f65c 100644 (file)
@@ -1810,12 +1810,18 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
             if (!added.isEmpty()) {
                 changed = true;
                 selection.addAll(added);
+                for (Object id : added) {
+                    refreshRow(id);
+                }
             }
 
             Set<Object> removed = getDifference(selection, selectedRows);
             if (!removed.isEmpty()) {
                 changed = true;
                 selection.removeAll(removed);
+                for (Object id : removed) {
+                    refreshRow(id);
+                }
             }
 
             if (changed) {
@@ -5826,8 +5832,7 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
     }
 
     /**
-     * Gets the
-     * {@link KeyMapper } being used by the data source.
+     * Gets the {@link KeyMapper } being used by the data source.
      * 
      * @return the key mapper being used by the data source
      */
index 10d49776234eee5f1887c14958381642dd071a48..4a11c19242c9490027b45658501e4be47b3bd17f 100644 (file)
@@ -17,18 +17,30 @@ package com.vaadin.tests.components.grid;
 
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
 import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.MultiSelectionModel;
 import com.vaadin.ui.Grid.SelectionMode;
 
 public class GridMultiSelectionOnInit extends AbstractTestUI {
 
     @Override
     protected void setup(VaadinRequest request) {
-        Grid grid = new Grid();
+        final Grid grid = new Grid();
         grid.addColumn("foo", String.class);
         grid.addRow("Foo 1");
         grid.addRow("Foo 2");
         grid.setSelectionMode(SelectionMode.MULTI);
         addComponent(grid);
+
+        addComponent(new Button("Select rows", new Button.ClickListener() {
+
+            @Override
+            public void buttonClick(ClickEvent event) {
+                ((MultiSelectionModel) grid.getSelectionModel())
+                        .setSelected(grid.getContainerDataSource().getItemIds());
+            }
+        }));
     }
 }
index d5eedae824d0d0a6f92262dbe09431434ce3923c..1818baa4c92b973f2a3fbccd2d455dce2a7ab1fb 100644 (file)
  */
 package com.vaadin.tests.components.grid;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
 import org.openqa.selenium.By;
 
+import com.vaadin.testbench.elements.ButtonElement;
 import com.vaadin.testbench.elements.GridElement;
 import com.vaadin.testbench.parallel.TestCategory;
 import com.vaadin.tests.tb3.MultiBrowserTest;
@@ -34,4 +36,14 @@ public class GridMultiSelectionOnInitTest extends MultiBrowserTest {
                 $(GridElement.class).first().getHeaderCell(0, 0)
                         .isElementPresent(By.tagName("input")));
     }
+
+    @Test
+    public void testSetSelectedUpdatesClient() {
+        openTestURL();
+        assertFalse("Rows should not be selected initially.",
+                $(GridElement.class).first().getRow(0).isSelected());
+        $(ButtonElement.class).first().click();
+        assertTrue("Rows should be selected after button click.",
+                $(GridElement.class).first().getRow(0).isSelected());
+    }
 }