]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix lost focus in Table when refreshing row cache (#12231)
authorTapio Aali <tapio@vaadin.com>
Tue, 16 Jul 2013 13:15:01 +0000 (16:15 +0300)
committerLeif Åstrand <leif@vaadin.com>
Tue, 16 Jul 2013 13:42:06 +0000 (16:42 +0300)
svn changeset:25991/svn branch:6.8
svn changeset:26075/svn branch:6.8
svn changeset:26091/svn branch:6.8

Change-Id: Ia4a6ab4cc6ff98795a6d1f9b1701a345dc3f4dc4

client/src/com/vaadin/client/ui/VScrollTable.java
client/src/com/vaadin/client/ui/table/TableConnector.java
tests/testbench/com/vaadin/tests/components/table/TableFocusOnRefreshRowCache.html [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/table/TableFocusOnRefreshRowCache.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/table/MultiSelectWithRemovedRow.html

index e2e82a1959efeb075804baa60681b739729e2565..2d177f29b5362cbebc1c9cef8f94b327333b0342 100644 (file)
@@ -194,7 +194,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
 
     private SelectMode selectMode = SelectMode.NONE;
 
-    private final HashSet<String> selectedRowKeys = new HashSet<String>();
+    public final HashSet<String> selectedRowKeys = new HashSet<String>();
 
     /*
      * When scrolling and selecting at the same time, the selections are not in
@@ -568,7 +568,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
             this.rowKey = rowKey;
             this.left = left;
             this.top = top;
-            this.closeRegistration = menu.addCloseHandler(this);
+            closeRegistration = menu.addCloseHandler(this);
         }
 
         @Override
index 36587ffe4d09e14e6cae6ac36cda5df978ed8fd5..47229dc9c7e867532b2a0bf48c4a3b3fd29a7258 100644 (file)
@@ -266,7 +266,23 @@ public class TableConnector extends AbstractHasComponentsConnector implements
             if (!getWidget().focusedRow.isAttached()
                     && !getWidget().rowRequestHandler.isRunning()) {
                 // focused row has been orphaned, can't focus
-                getWidget().focusRowFromBody();
+                if (getWidget().selectedRowKeys.contains(getWidget().focusedRow
+                        .getKey())) {
+                    // if row cache was refreshed, focused row should be
+                    // in selection and exists with same index
+                    getWidget().setRowFocus(
+                            getWidget().getRenderedRowByKey(
+                                    getWidget().focusedRow.getKey()));
+                } else if (getWidget().selectedRowKeys.size() > 0) {
+                    // try to focus any row in selection
+                    getWidget().setRowFocus(
+                            getWidget().getRenderedRowByKey(
+                                    getWidget().selectedRowKeys.iterator()
+                                            .next()));
+                } else {
+                    // try to focus any row
+                    getWidget().focusRowFromBody();
+                }
             }
         }
 
diff --git a/tests/testbench/com/vaadin/tests/components/table/TableFocusOnRefreshRowCache.html b/tests/testbench/com/vaadin/tests/components/table/TableFocusOnRefreshRowCache.html
new file mode 100644 (file)
index 0000000..b5f4d9b
--- /dev/null
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8888/" />
+<title>TableFocusOnRefreshRowCache</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">TableFocusOnRefreshRowCache</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.table.TableFocusOnRefreshRowCache?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>scroll</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableFocusOnRefreshRowCache::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]</td>
+       <td>3161</td>
+</tr>
+<tr>
+       <td>pause</td>
+       <td>500</td>
+       <td></td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableFocusOnRefreshRowCache::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[42]/domChild[0]/domChild[0]</td>
+       <td>186,-3151</td>
+</tr>
+<!-- Opera does some funky stuff with the row indices when this is run in
+     testbench, making it impossible to reliably test that the stylenames are
+     in the right location. Must instead just test that the stylename is not in
+     the position it was prior to fixing the bug, although that could never
+     fail in Opera since it looks at the wrong row
+-->
+<!-- 
+<tr>
+       <td>assertCSSClass</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableFocusOnRefreshRowCache::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[35]</td>
+       <td>v-selected</td>
+</tr>
+<tr>
+       <td>assertCSSClass</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableFocusOnRefreshRowCache::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[35]</td>
+       <td>v-table-focus</td>
+</tr>
+-->
+<!-- Test that the first row in the view does not get focus -->
+<tr>
+       <td>assertNotCSSClass</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableFocusOnRefreshRowCache::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[23]</td>
+       <td>v-table-focus</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/testbench/com/vaadin/tests/components/table/TableFocusOnRefreshRowCache.java b/tests/testbench/com/vaadin/tests/components/table/TableFocusOnRefreshRowCache.java
new file mode 100644 (file)
index 0000000..a4bd11c
--- /dev/null
@@ -0,0 +1,37 @@
+package com.vaadin.tests.components.table;
+
+import com.vaadin.event.ItemClickEvent;
+import com.vaadin.event.ItemClickEvent.ItemClickListener;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Table;
+
+public class TableFocusOnRefreshRowCache extends TestBase {
+
+    @Override
+    protected void setup() {
+        final Table table = new Table();
+        table.setSizeFull();
+        table.addContainerProperty("Name", String.class, null);
+        for (int i = 0; i < 200; i++) {
+            table.addItem(new Object[] { "Item " + i }, i);
+        }
+
+        table.setSelectable(true);
+        table.addListener(new ItemClickListener() {
+            public void itemClick(ItemClickEvent event) {
+                table.refreshRowCache();
+            }
+        });
+        addComponent(table);
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Calling Table#refreshRowCache() loses cell focus";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 11797;
+    }
+}
index c41f3fbfddbc79f50475e8942b74686407a3bab7..670736127b2feabc19b54cdadfe535ca793caf33 100644 (file)
@@ -91,7 +91,7 @@
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestscomponentstableMultiSelectWithRemovedRow::PID_SLog_row_0</td>
-       <td>4. Selection: [William, Averell, Bob, Grat]</td>
+       <td>4. Selection: [Averell, Bob, Grat]</td>
 </tr>
 <!--Sort + shift select down-->
 <tr>