From: Artur Signell Date: Mon, 25 May 2015 17:27:46 +0000 (+0300) Subject: Select all checkbox when pressing space on the cell (#16685) X-Git-Tag: 7.5.0.beta2~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7ff6cc3fe73b43ba0ed5603a85bc5e40dafac2ca;p=vaadin-framework.git Select all checkbox when pressing space on the cell (#16685) Change-Id: I71ca4d7d390bdaf42cf3d9317564e6ad8f96cc25 --- diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index 274daeacb4..383139135e 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -2299,8 +2299,26 @@ public class Grid extends ResizeComposite implements } }); checkBox.setValue(selected); - selectionCell.setWidget(checkBox); + // Select all with space when "select all" cell is active + addHeaderKeyUpHandler(new HeaderKeyUpHandler() { + @Override + public void onKeyUp(GridKeyUpEvent event) { + if (event.getNativeKeyCode() != KeyCodes.KEY_SPACE) { + return; + } + HeaderRow targetHeaderRow = getHeader().getRow( + event.getFocusedCell().getRowIndex()); + if (!targetHeaderRow.isDefault()) { + return; + } + if (event.getFocusedCell().getColumn() == SelectionColumn.this) { + // Send events to ensure row selection state is + // updated + checkBox.setValue(!checkBox.getValue(), true); + } + } + }); } } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java index 5d15e53a20..0a1b1735fa 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java @@ -87,4 +87,28 @@ public abstract class GridBasicClientFeaturesTest extends GridBasicFeaturesTest selectMenuPath("Component", "State", "Column Reordering"); } + protected boolean isRowSelected(int index) { + boolean selected = getGridElement().getRow(index).isSelected(); + return selected; + } + + protected void setSelectionModelMulti() { + setSelectionModel("multi"); + } + + protected void setSelectionModelSingle(boolean deselectAllowed) { + String mode = "single"; + if (!deselectAllowed) { + mode += " (no deselect)"; + } + setSelectionModel(mode); + } + + protected void setSelectionModelNone() { + setSelectionModel("none"); + } + + protected void setSelectionModel(String model) { + selectMenuPath("Component", "State", "Selection mode", model); + } } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientKeyEventsTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientKeyEventsTest.java index dc4dedd3a0..bb8edee4b5 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientKeyEventsTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientKeyEventsTest.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; +import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.Keys; import org.openqa.selenium.interactions.Actions; @@ -84,6 +85,36 @@ public class GridClientKeyEventsTest extends GridBasicClientFeaturesTest { } } + @Test + public void selectAllUsingKeyboard() { + openTestURL(); + + selectMenuPath("Component", "Header", "Prepend row"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "State", "Selection mode", "multi"); + + // Focus cell above select all checkbox + getGridElement().getHeaderCell(0, 0).click(); + Assert.assertFalse(isRowSelected(1)); + new Actions(getDriver()).sendKeys(" ").perform(); + Assert.assertFalse(isRowSelected(1)); + + // Move down to select all checkbox cell + new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); + Assert.assertFalse(isRowSelected(1)); + new Actions(getDriver()).sendKeys(" ").perform(); // select all + Assert.assertTrue(isRowSelected(1)); + new Actions(getDriver()).sendKeys(" ").perform(); // deselect all + Assert.assertFalse(isRowSelected(1)); + + // Move down to header below select all checkbox cell + new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); + Assert.assertFalse(isRowSelected(1)); + new Actions(getDriver()).sendKeys(" ").perform(); // deselect all + Assert.assertFalse(isRowSelected(1)); + + } + @Test public void testFooterKeyEvents() throws IOException { openTestURL(); diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java index 57950de5e2..a341e39b74 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java @@ -195,28 +195,4 @@ public class GridClientSelectionTest extends GridBasicClientFeaturesTest { isRowSelected(1)); } - private boolean isRowSelected(int index) { - boolean selected = getGridElement().getRow(index).isSelected(); - return selected; - } - - private void setSelectionModelMulti() { - setSelectionModel("multi"); - } - - private void setSelectionModelSingle(boolean deselectAllowed) { - String mode = "single"; - if (!deselectAllowed) { - mode += " (no deselect)"; - } - setSelectionModel(mode); - } - - private void setSelectionModelNone() { - setSelectionModel("none"); - } - - private void setSelectionModel(String model) { - selectMenuPath("Component", "State", "Selection mode", model); - } }