aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2014-08-13 16:39:40 +0300
committerTeemu Suo-Anttila <teemusa@vaadin.com>2014-08-20 15:30:26 +0300
commitc532e42ec703079eb024ca8e1f03442d493a40e7 (patch)
treeb7878c7373af58ae9f48703ba999c2da6410b20e /uitest/src
parent36b8edd18b8b0096d00e572783c04a1fa827063f (diff)
downloadvaadin-framework-c532e42ec703079eb024ca8e1f03442d493a40e7.tar.gz
vaadin-framework-c532e42ec703079eb024ca8e1f03442d493a40e7.zip
Implement KeyEvents for Grid (#13334)
Change-Id: Ida7a358aa23a4c96232a01bed0b4810fb91dd832
Diffstat (limited to 'uitest/src')
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientKeyEventsTest.java108
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java127
2 files changed, 233 insertions, 2 deletions
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
new file mode 100644
index 0000000000..fe81380296
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientKeyEventsTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid.basicfeatures.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
+
+public class GridClientKeyEventsTest extends GridBasicClientFeaturesTest {
+
+ private List<String> eventOrder = Arrays.asList("keydown", "keyup",
+ "keypress");
+
+ @Test
+ public void testBodyKeyEvents() throws IOException {
+ openTestURL();
+
+ getGridElement().getCell(2, 2).click();
+
+ new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
+
+ for (int i = 0; i < 3; ++i) {
+ assertEquals("Body key event handler was not called.", "(2, 2) "
+ + eventOrder.get(i) + " 13",
+ findElements(By.className("v-label")).get(i * 3).getText());
+
+ assertTrue("Header key event handler got called unexpectedly.",
+ findElements(By.className("v-label")).get(i * 3 + 1)
+ .getText().isEmpty());
+ assertTrue("Footer key event handler got called unexpectedly.",
+ findElements(By.className("v-label")).get(i * 3 + 2)
+ .getText().isEmpty());
+ }
+
+ }
+
+ @Test
+ public void testHeaderKeyEvents() throws IOException {
+ openTestURL();
+
+ getGridElement().getHeaderCell(0, 2).click();
+
+ new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
+
+ for (int i = 0; i < 3; ++i) {
+ assertEquals("Header key event handler was not called.", "(0, 2) "
+ + eventOrder.get(i) + " 13",
+ findElements(By.className("v-label")).get(i * 3 + 1)
+ .getText());
+
+ assertTrue("Body key event handler got called unexpectedly.",
+ findElements(By.className("v-label")).get(i * 3).getText()
+ .isEmpty());
+ assertTrue("Footer key event handler got called unexpectedly.",
+ findElements(By.className("v-label")).get(i * 3 + 2)
+ .getText().isEmpty());
+ }
+ }
+
+ @Test
+ public void testFooterKeyEvents() throws IOException {
+ openTestURL();
+
+ selectMenuPath("Component", "Footer", "Append row");
+ getGridElement().getFooterCell(0, 2).click();
+
+ new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
+
+ for (int i = 0; i < 3; ++i) {
+ assertEquals("Footer key event handler was not called.", "(0, 2) "
+ + eventOrder.get(i) + " 13",
+ findElements(By.className("v-label")).get(i * 3 + 2)
+ .getText());
+
+ assertTrue("Body key event handler got called unexpectedly.",
+ findElements(By.className("v-label")).get(i * 3).getText()
+ .isEmpty());
+ assertTrue("Header key event handler got called unexpectedly.",
+ findElements(By.className("v-label")).get(i * 3 + 1)
+ .getText().isEmpty());
+
+ }
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java
index 8a5a75da38..a7210236d4 100644
--- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java
+++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java
@@ -25,8 +25,11 @@ import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
+import com.vaadin.client.ui.VLabel;
+import com.vaadin.client.ui.grid.Cell;
import com.vaadin.client.ui.grid.FlyweightCell;
import com.vaadin.client.ui.grid.Grid;
+import com.vaadin.client.ui.grid.Grid.AbstractGridKeyEvent;
import com.vaadin.client.ui.grid.Grid.SelectionMode;
import com.vaadin.client.ui.grid.GridColumn;
import com.vaadin.client.ui.grid.GridFooter;
@@ -36,6 +39,18 @@ import com.vaadin.client.ui.grid.GridHeader.HeaderRow;
import com.vaadin.client.ui.grid.Renderer;
import com.vaadin.client.ui.grid.datasources.ListDataSource;
import com.vaadin.client.ui.grid.datasources.ListSorter;
+import com.vaadin.client.ui.grid.keyevents.BodyKeyDownHandler;
+import com.vaadin.client.ui.grid.keyevents.BodyKeyPressHandler;
+import com.vaadin.client.ui.grid.keyevents.BodyKeyUpHandler;
+import com.vaadin.client.ui.grid.keyevents.FooterKeyDownHandler;
+import com.vaadin.client.ui.grid.keyevents.FooterKeyPressHandler;
+import com.vaadin.client.ui.grid.keyevents.FooterKeyUpHandler;
+import com.vaadin.client.ui.grid.keyevents.GridKeyDownEvent;
+import com.vaadin.client.ui.grid.keyevents.GridKeyPressEvent;
+import com.vaadin.client.ui.grid.keyevents.GridKeyUpEvent;
+import com.vaadin.client.ui.grid.keyevents.HeaderKeyDownHandler;
+import com.vaadin.client.ui.grid.keyevents.HeaderKeyPressHandler;
+import com.vaadin.client.ui.grid.keyevents.HeaderKeyUpHandler;
import com.vaadin.client.ui.grid.renderers.DateRenderer;
import com.vaadin.client.ui.grid.renderers.HtmlRenderer;
import com.vaadin.client.ui.grid.renderers.NumberRenderer;
@@ -236,7 +251,9 @@ public class GridBasicClientFeaturesWidget extends
createFooterMenu();
grid.getElement().getStyle().setZIndex(0);
- add(grid);
+ addNorth(grid, 400);
+
+ createKeyHandlers();
}
private void createStateMenu() {
@@ -602,7 +619,7 @@ public class GridBasicClientFeaturesWidget extends
}
/**
- * Creates a a renderer for a {@link Renderers}
+ * Creates a renderer for a {@link Renderers}
*/
@SuppressWarnings("rawtypes")
private final Renderer createRenderer(Renderers renderer) {
@@ -629,4 +646,110 @@ public class GridBasicClientFeaturesWidget extends
return new TextRenderer();
}
}
+
+ /**
+ * Creates a collection of handlers for all the grid key events
+ */
+ private void createKeyHandlers() {
+ final List<VLabel> labels = new ArrayList<VLabel>();
+ for (int i = 0; i < 9; ++i) {
+ VLabel tmp = new VLabel();
+ addNorth(tmp, 20);
+ labels.add(tmp);
+ }
+
+ // Key Down Events
+ grid.addKeyDownHandler(new BodyKeyDownHandler<List<Data>>() {
+ private final VLabel label = labels.get(0);
+
+ @Override
+ public void onKeyDown(GridKeyDownEvent<List<Data>> event) {
+ updateLabel(label, event);
+ }
+ });
+
+ grid.addKeyDownHandler(new HeaderKeyDownHandler<List<Data>>() {
+ private final VLabel label = labels.get(1);
+
+ @Override
+ public void onKeyDown(GridKeyDownEvent<List<Data>> event) {
+ updateLabel(label, event);
+ }
+ });
+
+ grid.addKeyDownHandler(new FooterKeyDownHandler<List<Data>>() {
+ private final VLabel label = labels.get(2);
+
+ @Override
+ public void onKeyDown(GridKeyDownEvent<List<Data>> event) {
+ updateLabel(label, event);
+ }
+ });
+
+ // Key Up Events
+ grid.addKeyUpHandler(new BodyKeyUpHandler<List<Data>>() {
+ private final VLabel label = labels.get(3);
+
+ @Override
+ public void onKeyUp(GridKeyUpEvent<List<Data>> event) {
+ updateLabel(label, event);
+ }
+ });
+
+ grid.addKeyUpHandler(new HeaderKeyUpHandler<List<Data>>() {
+ private final VLabel label = labels.get(4);
+
+ @Override
+ public void onKeyUp(GridKeyUpEvent<List<Data>> event) {
+ updateLabel(label, event);
+ }
+ });
+
+ grid.addKeyUpHandler(new FooterKeyUpHandler<List<Data>>() {
+ private final VLabel label = labels.get(5);
+
+ @Override
+ public void onKeyUp(GridKeyUpEvent<List<Data>> event) {
+ updateLabel(label, event);
+ }
+ });
+
+ // Key Press Events
+ grid.addKeyPressHandler(new BodyKeyPressHandler<List<Data>>() {
+ private final VLabel label = labels.get(6);
+
+ @Override
+ public void onKeyPress(GridKeyPressEvent<List<Data>> event) {
+ updateLabel(label, event);
+ }
+ });
+
+ grid.addKeyPressHandler(new HeaderKeyPressHandler<List<Data>>() {
+ private final VLabel label = labels.get(7);
+
+ @Override
+ public void onKeyPress(GridKeyPressEvent<List<Data>> event) {
+ updateLabel(label, event);
+ }
+ });
+
+ grid.addKeyPressHandler(new FooterKeyPressHandler<List<Data>>() {
+ private final VLabel label = labels.get(8);
+
+ @Override
+ public void onKeyPress(GridKeyPressEvent<List<Data>> event) {
+ updateLabel(label, event);
+ }
+ });
+
+ }
+
+ private void updateLabel(VLabel label,
+ AbstractGridKeyEvent<List<Data>, ?> event) {
+ String type = event.getNativeEvent().getType();
+ Cell active = event.getActiveCell();
+ String coords = "(" + active.getRow() + ", " + active.getColumn() + ")";
+ String keyCode = "" + event.getNativeKeyCode();
+ label.setText(coords + " " + type + " " + keyCode);
+ }
}