diff options
-rw-r--r-- | client/src/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java | 10 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java | 84 |
2 files changed, 72 insertions, 22 deletions
diff --git a/client/src/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java b/client/src/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java index 0fea7c37bd..e4a8783f54 100644 --- a/client/src/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java +++ b/client/src/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java @@ -38,7 +38,8 @@ public class DefaultEditorEventHandler<T> implements Editor.EventHandler<T> { public static final int KEYCODE_OPEN = KeyCodes.KEY_ENTER; public static final int KEYCODE_MOVE_VERTICAL = KeyCodes.KEY_ENTER; public static final int KEYCODE_CLOSE = KeyCodes.KEY_ESCAPE; - private static final int KEYCODE_MOVE_HORIZONTAL = KeyCodes.KEY_TAB; + public static final int KEYCODE_MOVE_HORIZONTAL = KeyCodes.KEY_TAB; + public static final int KEYCODE_BUFFERED_SAVE = KeyCodes.KEY_ENTER; private double lastTouchEventTime = 0; private int lastTouchEventX = -1; @@ -222,6 +223,13 @@ public class DefaultEditorEventHandler<T> implements Editor.EventHandler<T> { + (e.getShiftKey() ? -1 : +1)); return true; + } else if (e.getType().equals(BrowserEvents.KEYDOWN) + && e.getKeyCode() == KEYCODE_BUFFERED_SAVE) { + triggerValueChangeEvent(event); + + // Save and close. + event.getGrid().getEditor().save(); + return true; } return false; diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java index 69e2a09bc9..8340c40b4b 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java @@ -29,6 +29,7 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; import com.vaadin.shared.ui.grid.GridConstants; +import com.vaadin.testbench.TestBenchElement; import com.vaadin.testbench.elements.GridElement.GridCellElement; import com.vaadin.testbench.elements.GridElement.GridEditorElement; import com.vaadin.testbench.elements.NotificationElement; @@ -42,6 +43,52 @@ public class GridEditorBufferedTest extends GridEditorTest { } @Test + public void testKeyboardSave() { + selectMenuPath(EDIT_ITEM_100); + + WebElement textField = getEditorWidgets().get(0); + + textField.click(); + // without this, the click in the middle of the field might not be after + // the old text on some browsers + new Actions(getDriver()).sendKeys(Keys.END).perform(); + + textField.sendKeys(" changed"); + + // Save from keyboard + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + + assertEditorClosed(); + assertEquals("(100, 0) changed", getGridElement().getCell(100, 0) + .getText()); + } + + @Test + public void testKeyboardSaveWithInvalidEdition() { + makeInvalidEdition(); + + GridEditorElement editor = getGridElement().getEditor(); + TestBenchElement field = editor.getField(7); + + field.click(); + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + + assertEditorOpen(); + assertEquals("Column 7: Could not convert value to Integer", + editor.getErrorMessage()); + assertTrue("Field 7 should have been marked with an error after error", + editor.isFieldErrorMarked(7)); + + editor.cancel(); + + selectMenuPath(EDIT_ITEM_100); + assertFalse("Exception should not exist", + isElementPresent(NotificationElement.class)); + assertEquals("There should be no editor error message", null, + getGridElement().getEditor().getErrorMessage()); + } + + @Test public void testSave() { selectMenuPath(EDIT_ITEM_100); @@ -84,18 +131,9 @@ public class GridEditorBufferedTest extends GridEditorTest { @Test public void testInvalidEdition() { - selectMenuPath(EDIT_ITEM_5); - assertFalse(logContainsText("Exception occured, java.lang.IllegalStateException")); + makeInvalidEdition(); GridEditorElement editor = getGridElement().getEditor(); - - assertFalse( - "Field 7 should not have been marked with an error before error", - editor.isFieldErrorMarked(7)); - - WebElement intField = editor.getField(7); - intField.clear(); - intField.sendKeys("banana phone"); editor.save(); assertEquals("Column 7: Could not convert value to Integer", @@ -111,6 +149,21 @@ public class GridEditorBufferedTest extends GridEditorTest { getGridElement().getEditor().getErrorMessage()); } + private void makeInvalidEdition() { + selectMenuPath(EDIT_ITEM_5); + assertFalse(logContainsText("Exception occured, java.lang.IllegalStateException")); + + GridEditorElement editor = getGridElement().getEditor(); + + assertFalse( + "Field 7 should not have been marked with an error before error", + editor.isFieldErrorMarked(7)); + + WebElement intField = editor.getField(7); + intField.clear(); + intField.sendKeys("banana phone"); + } + @Test public void testEditorInDisabledGrid() { int originalScrollPos = getGridVerticalScrollPos(); @@ -232,17 +285,6 @@ public class GridEditorBufferedTest extends GridEditorTest { } @Test - public void testKeyboardOpeningDisabledWhenOpen() { - selectMenuPath(EDIT_ITEM_5); - - new Actions(getDriver()).click(getGridElement().getCell(4, 0)) - .sendKeys(Keys.ENTER).perform(); - - assertEquals("Editor should still edit row 5", "(5, 0)", - getEditorWidgets().get(0).getAttribute("value")); - } - - @Test public void testProgrammaticOpeningDisabledWhenOpen() { selectMenuPath(EDIT_ITEM_5); assertEditorOpen(); |