aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2015-09-07 14:36:03 +0300
committerVaadin Code Review <review@vaadin.com>2015-09-07 14:28:10 +0000
commitc41cd67905bb621a0032a1fc5bed938629f76f77 (patch)
treeaac8acb8c8f535b1442335857d3e9648e0eb5d4e
parent8ffe48687ae367a765e3e54721c2821d8d773c2d (diff)
downloadvaadin-framework-c41cd67905bb621a0032a1fc5bed938629f76f77.tar.gz
vaadin-framework-c41cd67905bb621a0032a1fc5bed938629f76f77.zip
Save editor content on keyboard editor move (#18809)
Change-Id: I1bb3e352c87fac491269c1ca93f6acdff8bb97eb
-rw-r--r--client/src/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java22
-rw-r--r--client/src/com/vaadin/client/widgets/Grid.java19
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java22
3 files changed, 61 insertions, 2 deletions
diff --git a/client/src/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java b/client/src/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java
index 564b0f1a03..8270ea4b04 100644
--- a/client/src/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java
+++ b/client/src/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java
@@ -18,6 +18,7 @@ package com.vaadin.client.widget.grid;
import com.google.gwt.core.client.Duration;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.WidgetUtil;
import com.vaadin.client.ui.FocusUtil;
import com.vaadin.client.widget.grid.events.EditorMoveEvent;
@@ -204,9 +205,30 @@ public class DefaultEditorEventHandler<T> implements Editor.EventHandler<T> {
// Limit colIndex between 0 and colCount - 1
colIndex = Math.max(0, Math.min(colCount - 1, colIndex));
+ triggerValueChangeEvent(event);
+
event.getEditor().editRow(rowIndex, colIndex);
}
+ /**
+ * Triggers a value change event from the editor field if it has focus. This
+ * is based on the assumption that editor field will fire the value change
+ * when a blur event occurs.
+ *
+ * @param event
+ * the editor DOM event
+ */
+ private void triggerValueChangeEvent(EditorDomEvent<T> event) {
+ // Force a blur to cause a value change event
+ Widget editorWidget = event.getEditorWidget();
+ if (editorWidget != null) {
+ if (editorWidget.getElement().isOrHasChild(
+ WidgetUtil.getFocusedElement())) {
+ WidgetUtil.getFocusedElement().blur();
+ }
+ }
+ }
+
@Override
public boolean handleEvent(EditorDomEvent<T> event) {
final Editor<T> editor = event.getEditor();
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java
index fc8151272d..9204c905e3 100644
--- a/client/src/com/vaadin/client/widgets/Grid.java
+++ b/client/src/com/vaadin/client/widgets/Grid.java
@@ -1176,8 +1176,12 @@ public class Grid<T> extends ResizeComposite implements
*/
public static class EditorDomEvent<T> extends GridEvent<T> {
- protected EditorDomEvent(Event event, EventCellReference<T> cell) {
+ private final Widget editorWidget;
+
+ protected EditorDomEvent(Event event, EventCellReference<T> cell,
+ Widget editorWidget) {
super(event, cell);
+ this.editorWidget = editorWidget;
}
/**
@@ -1190,6 +1194,15 @@ public class Grid<T> extends ResizeComposite implements
}
/**
+ * Returns the currently focused editor widget.
+ *
+ * @return the focused editor widget or {@code null} if not editable
+ */
+ public Widget getEditorWidget() {
+ return editorWidget;
+ }
+
+ /**
* Returns the row index the editor is open at. If the editor is not
* open, returns -1.
*
@@ -3162,6 +3175,7 @@ public class Grid<T> extends ResizeComposite implements
// Set column sizes for expanding columns
setColumnSizes(columnSizes);
}
+
return;
}
@@ -6869,7 +6883,8 @@ public class Grid<T> extends ResizeComposite implements
private boolean handleEditorEvent(Event event, RowContainer container) {
return getEditor().getEventHandler().handleEvent(
- new EditorDomEvent<T>(event, getEventCell()));
+ new EditorDomEvent<T>(event, getEventCell(), editor
+ .getWidget(eventCell.getColumn())));
}
private boolean handleRendererEvent(Event event, RowContainer container) {
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java
index 08094b57e3..0b84d3470f 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java
@@ -26,6 +26,7 @@ import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
+import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.elements.GridElement.GridCellElement;
public class GridEditorUnbufferedTest extends GridEditorTest {
@@ -220,4 +221,25 @@ public class GridEditorUnbufferedTest extends GridEditorTest {
assertEditorClosed();
}
+
+ @Test
+ public void testEditorSaveOnRowChange() {
+ // Double click sets the focus programmatically
+ getGridElement().getCell(5, 2).doubleClick();
+
+ TestBenchElement editor = getGridElement().getEditor().getField(2);
+ editor.clear();
+ // Click to ensure IE focus...
+ editor.click(5, 5);
+ editor.sendKeys("Foo", Keys.ENTER);
+
+ assertEquals("Editor did not move.", "(6, 0)", getGridElement()
+ .getEditor().getField(0).getAttribute("value"));
+ assertEquals("Editor field value did not update from server.",
+ "(6, 2)", getGridElement().getEditor().getField(2)
+ .getAttribute("value"));
+
+ assertEquals("Edited value was not saved.", "Foo", getGridElement()
+ .getCell(5, 2).getText());
+ }
} \ No newline at end of file