summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeppo Kurki <teppo.kurki@vaadin.com>2015-06-02 16:29:57 +0300
committerTeppo Kurki <teppo.kurki@vaadin.com>2015-06-03 11:36:03 +0000
commiteed4059ca05483f7874f45bfbd876b6c2dfe4bb0 (patch)
treee892946c76f931637b0fe7a820f68a9e498cba1b
parentf861a2dfe4a64e696fe5f70fc7ae4c7c1b1612ef (diff)
downloadvaadin-framework-eed4059ca05483f7874f45bfbd876b6c2dfe4bb0.tar.gz
vaadin-framework-eed4059ca05483f7874f45bfbd876b6c2dfe4bb0.zip
On progr. editor open, focus target cell if Grid had focus prior7.6.0.alpha1
Change-Id: I8ad9100356a309309e1f8964d6bc293981b2a827
-rw-r--r--client/src/com/vaadin/client/widgets/Grid.java18
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java21
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java14
3 files changed, 51 insertions, 2 deletions
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java
index 2717dc3580..db3cea58dc 100644
--- a/client/src/com/vaadin/client/widgets/Grid.java
+++ b/client/src/com/vaadin/client/widgets/Grid.java
@@ -1280,12 +1280,26 @@ public class Grid<T> extends ResizeComposite implements
}
/**
- * Equivalent to {@code editRow(rowIndex, -1)}.
+ * If a cell of this Grid had focus once this editRow call was
+ * triggered, the editor component at the previously focused column
+ * index will be focused.
+ *
+ * If a Grid cell was not focused prior to calling this method, it will
+ * be equivalent to {@code editRow(rowIndex, -1)}.
*
* @see #editRow(int, int)
*/
public void editRow(int rowIndex) {
- editRow(rowIndex, -1);
+ // Focus the last focused column in the editor iff grid or its child
+ // was focused before the edit request
+ Cell focusedCell = grid.cellFocusHandler.getFocusedCell();
+ if (focusedCell != null
+ && grid.getElement().isOrHasChild(
+ WidgetUtil.getFocusedElement())) {
+ editRow(rowIndex, focusedCell.getColumn());
+ } else {
+ editRow(rowIndex, -1);
+ }
}
/**
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
index c98ee5c53b..a9cc528ac0 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
@@ -127,6 +127,14 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
};
+ private ItemClickListener editorOpeningItemClickListener = new ItemClickListener() {
+
+ @Override
+ public void itemClick(ItemClickEvent event) {
+ grid.editItem(event.getItemId());
+ }
+ };
+
private ColumnReorderListener columnReorderListener = new ColumnReorderListener() {
@Override
@@ -643,6 +651,19 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
});
+ createBooleanAction("EditorOpeningItemClickListener", "State", false,
+ new Command<Grid, Boolean>() {
+
+ @Override
+ public void execute(Grid c, Boolean value, Object data) {
+ if (!value) {
+ c.removeItemClickListener(editorOpeningItemClickListener);
+ } else {
+ c.addItemClickListener(editorOpeningItemClickListener);
+ }
+ }
+
+ });
createBooleanAction("ColumnReorderListener", "State", false,
new Command<Grid, Boolean>() {
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java
index 0a6d884251..ba6c29522b 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java
@@ -162,6 +162,20 @@ public abstract class GridEditorTest extends GridBasicFeaturesTest {
}
@Test
+ public void testFocusOnProgrammaticOpenOnItemClick() {
+ selectMenuPath("Component", "State", "EditorOpeningItemClickListener");
+
+ GridCellElement cell = getGridElement().getCell(4, 2);
+
+ cell.click();
+
+ WebElement focused = getFocusedElement();
+
+ assertEquals("", "input", focused.getTagName());
+ assertEquals("", cell.getText(), focused.getAttribute("value"));
+ }
+
+ @Test
public void testNoFocusOnProgrammaticOpen() {
selectMenuPath(EDIT_ITEM_5);