}
});
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);
+ }
+ }
+ });
}
}
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);
+ }
}
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;
}
}
+ @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();
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);
- }
}