]> source.dussan.org Git - vaadin-framework.git/commitdiff
Change Grid default selection model to Single (#15435)
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Wed, 7 Jan 2015 14:17:00 +0000 (16:17 +0200)
committerJohannes Dahlström <johannesd@vaadin.com>
Thu, 8 Jan 2015 09:15:23 +0000 (09:15 +0000)
Change-Id: Iba651c043fa47125b12d17371947042cbb03a589

client/src/com/vaadin/client/connectors/GridConnector.java
client/src/com/vaadin/client/widgets/Grid.java
server/src/com/vaadin/ui/Grid.java
server/tests/src/com/vaadin/tests/server/component/grid/GridSelection.java
uitest/src/com/vaadin/tests/components/grid/GridAddAndRemoveDataOnInitTest.java
uitest/src/com/vaadin/tests/components/grid/GridAddRow.java
uitest/src/com/vaadin/tests/components/grid/GridColspans.java
uitest/src/com/vaadin/tests/components/grid/GridGeneratedPropertiesTest.java
uitest/src/com/vaadin/tests/components/grid/GridHeaderStyleNames.java

index 31bc2ac67350a6d932f327e458dd602c7c54f18e..c3d46a4295d6cbdacc706000d6599036d4282b92 100644 (file)
@@ -326,7 +326,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
      */
     private Map<String, CustomGridColumn> columnIdToColumn = new HashMap<String, CustomGridColumn>();
 
-    private AbstractRowHandleSelectionModel<JsonObject> selectionModel = createSelectionModel(SharedSelectionMode.NONE);
+    private AbstractRowHandleSelectionModel<JsonObject> selectionModel;
     private Set<String> selectedKeys = new LinkedHashSet<String>();
     private List<String> columnOrder = new ArrayList<String>();
 
@@ -396,8 +396,6 @@ public class GridConnector extends AbstractHasComponentsConnector implements
             }
         });
 
-        getWidget().setSelectionModel(selectionModel);
-
         getWidget().addSelectionHandler(internalSelectionChangeHandler);
 
         getWidget().addSortHandler(new SortHandler<JsonObject>() {
@@ -751,7 +749,8 @@ public class GridConnector extends AbstractHasComponentsConnector implements
         }
 
         AbstractRowHandleSelectionModel<JsonObject> model = createSelectionModel(mode);
-        if (!model.getClass().equals(selectionModel.getClass())) {
+        if (selectionModel == null
+                || !model.getClass().equals(selectionModel.getClass())) {
             selectionModel = model;
             getWidget().setSelectionModel(model);
             selectedKeys.clear();
index 28cc1000ce0be5abaaa263a0fb1aa74d6b8f8eae..8c1b833acc9c82257af2546071aa885366bd5bb8 100644 (file)
@@ -3398,7 +3398,7 @@ public class Grid<T> extends ResizeComposite implements
 
         editor.setGrid(this);
 
-        setSelectionMode(SelectionMode.MULTI);
+        setSelectionMode(SelectionMode.SINGLE);
 
         escalator.addScrollHandler(new ScrollHandler() {
             @Override
index 5b29d1f10b8557a842c25134c0bcb38150ff38f3..d9f1b266a282e019bcb953a3b3fd4b88676d1504 100644 (file)
@@ -2578,7 +2578,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
      * Grid initial setup
      */
     private void initGrid() {
-        setSelectionMode(SelectionMode.MULTI);
+        setSelectionMode(SelectionMode.SINGLE);
         addSelectionListener(new SelectionListener() {
             @Override
             public void select(SelectionEvent event) {
index 07a138c6cad03e88d047c079792dcf3222b30799..7f09677b506f831ab8decc07f4788742473a2bd5 100644 (file)
@@ -99,8 +99,8 @@ public class GridSelection {
     }
 
     @Test
-    public void defaultSelectionModeIsMulti() {
-        assertTrue(grid.getSelectionModel() instanceof SelectionModel.Multi);
+    public void defaultSelectionModeIsSingle() {
+        assertTrue(grid.getSelectionModel() instanceof SelectionModel.Single);
     }
 
     @Test(expected = IllegalStateException.class)
index 38ce49b6226e9dc8264ceb7d45fc0065b3b68262..ceaceb661df73854ca5ebba9648cb8d6ab5ab498 100644 (file)
@@ -31,14 +31,14 @@ public class GridAddAndRemoveDataOnInitTest extends MultiBrowserTest {
         openTestURL();
 
         GridElement gridAdd = $(GridElement.class).first();
-        if (!gridAdd.isElementPresent(By.vaadin("#cell[9][1]"))
-                || gridAdd.isElementPresent(By.vaadin("#cell[10][1]"))) {
+        if (!gridAdd.isElementPresent(By.vaadin("#cell[9][0]"))
+                || gridAdd.isElementPresent(By.vaadin("#cell[10][0]"))) {
             Assert.fail("Grid with added data contained incorrect rows");
         }
 
         GridElement gridRemove = $(GridElement.class).get(1);
-        if (!gridRemove.isElementPresent(By.vaadin("#cell[4][1]"))
-                || gridRemove.isElementPresent(By.vaadin("#cell[5][1]"))) {
+        if (!gridRemove.isElementPresent(By.vaadin("#cell[4][0]"))
+                || gridRemove.isElementPresent(By.vaadin("#cell[5][0]"))) {
             Assert.fail("Grid with removed data contained incorrect rows");
         }
     }
index 74beb20914eb82eab40e93d21eb1faeec1b096c8..fa2d7b5399f1716079f79aa0620c72f0eb1e7846 100644 (file)
@@ -20,6 +20,7 @@ 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.SelectionMode;
 
 public class GridAddRow extends AbstractTestUI {
 
@@ -27,6 +28,7 @@ public class GridAddRow extends AbstractTestUI {
     protected void setup(VaadinRequest request) {
 
         final Grid grid = new Grid();
+        grid.setSelectionMode(SelectionMode.MULTI);
         grid.addColumn("firstName");
         grid.addColumn("age", Integer.class);
 
index f61a39a1f27fb779cd502cdfb6562f3a98cd60b8..80337971b65f14e85a2b2c39be735e5fa04f6542 100644 (file)
@@ -25,6 +25,7 @@ import com.vaadin.ui.Button.ClickEvent;
 import com.vaadin.ui.Grid;
 import com.vaadin.ui.Grid.FooterRow;
 import com.vaadin.ui.Grid.HeaderRow;
+import com.vaadin.ui.Grid.SelectionMode;
 import com.vaadin.ui.renderer.NumberRenderer;
 
 public class GridColspans extends AbstractTestUI {
@@ -48,6 +49,7 @@ public class GridColspans extends AbstractTestUI {
         grid = new Grid(dataSource);
         grid.setWidth("600px");
         grid.getColumn("zipCode").setRenderer(new NumberRenderer());
+        grid.setSelectionMode(SelectionMode.MULTI);
         addComponent(grid);
 
         HeaderRow row = grid.prependHeaderRow();
index af9aa3aad3706c7df1d805924afad506e2041c27..c71dd8036009f5c8d05c5d890e1315d478fe4ed6 100644 (file)
@@ -34,7 +34,7 @@ public class GridGeneratedPropertiesTest extends MultiBrowserTest {
         openTestURL();
         GridElement grid = $(GridElement.class).first();
         assertEquals("Miles header wasn't present.", "miles", grid
-                .getHeaderCell(0, 3).getText().toLowerCase());
+                .getHeaderCell(0, 2).getText().toLowerCase());
     }
 
     @Test
@@ -43,13 +43,13 @@ public class GridGeneratedPropertiesTest extends MultiBrowserTest {
         GridElement grid = $(GridElement.class).first();
 
         // Overwritten foo property should not be sortable
-        GridCellElement fooHeader = grid.getHeaderCell(0, 1);
+        GridCellElement fooHeader = grid.getHeaderCell(0, 0);
         fooHeader.click();
         assertFalse("Column foo was unexpectedly sorted.", fooHeader
                 .getAttribute("class").contains("sort"));
 
         // Generated property miles is not sortable
-        GridCellElement milesHeader = grid.getHeaderCell(0, 3);
+        GridCellElement milesHeader = grid.getHeaderCell(0, 2);
         milesHeader.click();
         assertFalse("Column miles was unexpectedly sorted.", milesHeader
                 .getAttribute("class").contains("sort"));
@@ -61,7 +61,7 @@ public class GridGeneratedPropertiesTest extends MultiBrowserTest {
         GridElement grid = $(GridElement.class).first();
 
         // Generated property baz is sortable
-        GridCellElement bazHeader = grid.getHeaderCell(0, 4);
+        GridCellElement bazHeader = grid.getHeaderCell(0, 3);
         bazHeader.click();
         assertTrue("Column baz was not sorted ascending", bazHeader
                 .getAttribute("class").contains("sort-asc"));
index 7c9eb6601201bef89daa8c921c0a820ca46b5b52..765cd0181243357fa2da93916678827f19b16763 100644 (file)
@@ -27,6 +27,7 @@ import com.vaadin.ui.Grid.FooterCell;
 import com.vaadin.ui.Grid.FooterRow;
 import com.vaadin.ui.Grid.HeaderCell;
 import com.vaadin.ui.Grid.HeaderRow;
+import com.vaadin.ui.Grid.SelectionMode;
 
 @Theme("valo")
 public class GridHeaderStyleNames extends AbstractTestUIWithLog {
@@ -40,6 +41,7 @@ public class GridHeaderStyleNames extends AbstractTestUIWithLog {
     @Override
     protected void setup(VaadinRequest request) {
         Grid grid = new Grid();
+        grid.setSelectionMode(SelectionMode.MULTI);
         grid.setContainerDataSource(BeanItemContainerGenerator
                 .createContainer(100));