Parcourir la source

Save editor content on keyboard editor move (#18809)

Change-Id: I1bb3e352c87fac491269c1ca93f6acdff8bb97eb
tags/7.6.0.alpha5
Teemu Suo-Anttila il y a 8 ans
Parent
révision
c41cd67905

+ 22
- 0
client/src/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java Voir le fichier

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

+ 17
- 2
client/src/com/vaadin/client/widgets/Grid.java Voir le fichier

@@ -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;
}

/**
@@ -1189,6 +1193,15 @@ public class Grid<T> extends ResizeComposite implements
return getGrid().getEditor();
}

/**
* 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) {

+ 22
- 0
uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java Voir le fichier

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

Chargement…
Annuler
Enregistrer