]> source.dussan.org Git - vaadin-framework.git/commitdiff
Unify select all behavior with single row selection. (#17742)
authorSauli Tähkäpää <sauli@vaadin.com>
Sat, 29 Aug 2015 20:00:21 +0000 (23:00 +0300)
committerTeemu Suo-Anttila <teemusa@vaadin.com>
Mon, 30 Nov 2015 12:37:01 +0000 (14:37 +0200)
Change-Id: I2aec82d16b2508505e855f1ff3a1ca5de341821c

client/src/com/vaadin/client/widgets/Grid.java
uitest/src/com/vaadin/tests/components/grid/GridSelectAllCell.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/grid/GridSelectAllCellTest.java [new file with mode: 0644]

index 6145d69305c7ac2e177efefc987060c4caf3e510..abd5c91eeb3861f4fa00558e166ee157a6d0ef8d 100644 (file)
@@ -2429,6 +2429,18 @@ public class Grid<T> extends ResizeComposite implements
                         });
                 selectAllCheckBox.setValue(selected);
 
+                addHeaderClickHandler(new HeaderClickHandler() {
+                    @Override
+                    public void onClick(GridClickEvent event) {
+                        CellReference<?> targetCell = event.getTargetCell();
+                        int defaultRowIndex = getHeader().getRows().indexOf(getDefaultHeaderRow());
+
+                        if(targetCell.getColumnIndex() == 0 && targetCell.getRowIndex() == defaultRowIndex) {
+                            selectAllCheckBox.setValue(!selectAllCheckBox.getValue(), true);
+                        }
+                    }
+                });
+
                 // Select all with space when "select all" cell is active
                 addHeaderKeyUpHandler(new HeaderKeyUpHandler() {
                     @Override
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridSelectAllCell.java b/uitest/src/com/vaadin/tests/components/grid/GridSelectAllCell.java
new file mode 100644 (file)
index 0000000..1b31c38
--- /dev/null
@@ -0,0 +1,21 @@
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.annotations.Theme;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Grid;
+
+@Theme("valo")
+public class GridSelectAllCell extends AbstractTestUI {
+    @Override
+    protected void setup(VaadinRequest request) {
+        Grid grid = new Grid();
+
+        grid.addColumn("foo", String.class);
+        grid.addRow("bar");
+
+        grid.setSelectionMode(Grid.SelectionMode.MULTI);
+
+        addComponent(grid);
+    }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridSelectAllCellTest.java b/uitest/src/com/vaadin/tests/components/grid/GridSelectAllCellTest.java
new file mode 100644 (file)
index 0000000..423a9f4
--- /dev/null
@@ -0,0 +1,34 @@
+package com.vaadin.tests.components.grid;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class GridSelectAllCellTest extends MultiBrowserTest {
+
+    @Override
+    public void setup() throws Exception {
+        super.setup();
+
+        openTestURL();
+    }
+
+    @Test
+    public void selectAllCellCanBeClicked() throws IOException {
+        GridElement.GridCellElement selectAllCell = $(GridElement.class).first().getHeaderCell(0, 0);
+
+        new Actions(getDriver()).moveToElement(selectAllCell, 2, 2).click().perform();
+
+        WebElement selectAllCheckbox = selectAllCell.findElement(By.cssSelector("input"));
+        assertThat(selectAllCheckbox.isSelected(), is(true));
+    }
+}
\ No newline at end of file