]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix for #7057
authorJonatan Kronqvist <jonatan.kronqvist@itmill.com>
Tue, 6 Sep 2011 08:40:15 +0000 (08:40 +0000)
committerJonatan Kronqvist <jonatan.kronqvist@itmill.com>
Tue, 6 Sep 2011 08:40:15 +0000 (08:40 +0000)
svn changeset:20874/svn branch:6.7

src/com/vaadin/terminal/gwt/client/ui/VTree.java
tests/src/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators [new file with mode: 0644]
tests/src/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators.java [new file with mode: 0644]

index d63ddc5e02c8ac72eb0d9051612a422049fb2c90..6a1c131944bf568a6b57517c16e3c5df66a87657 100644 (file)
@@ -265,6 +265,8 @@ public class VTree extends FocusElementPanel implements Paintable,
         }
 
         body.clear();
+        // clear out any references to nodes that no longer are attached
+        keyToNode.clear();
         TreeNode childTree = null;
         UIDL childUidl = null;
         for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {
@@ -302,6 +304,17 @@ public class VTree extends FocusElementPanel implements Paintable,
 
         selectedIds = uidl.getStringArrayVariableAsSet("selected");
 
+        // Update lastSelection and focusedNode to point to *actual* nodes again
+        // after the old ones have been cleared from the body. This fixes focus
+        // and keyboard navigation issues as described in #7057 and other
+        // tickets.
+        if (lastSelection != null) {
+            lastSelection = keyToNode.get(lastSelection.key);
+        }
+        if (focusedNode != null) {
+            setFocusedNode(keyToNode.get(focusedNode.key));
+        }
+
         if (lastSelection == null && focusedNode == null
                 && !selectedIds.isEmpty()) {
             setFocusedNode(keyToNode.get(selectedIds.iterator().next()));
@@ -1092,8 +1105,9 @@ public class VTree extends FocusElementPanel implements Paintable,
                     childNodeContainer.add(childTree);
                 }
                 if (!i.hasNext()) {
-                    childTree.addStyleDependentName(childTree.isLeaf()
-                            ? "leaf-last" : "last");
+                    childTree
+                            .addStyleDependentName(childTree.isLeaf() ? "leaf-last"
+                                    : "last");
                     childTree.childNodeContainer.addStyleDependentName("last");
                 }
             }
@@ -1794,7 +1808,6 @@ public class VTree extends FocusElementPanel implements Paintable,
      */
     protected boolean handleKeyNavigation(int keycode, boolean ctrl,
             boolean shift) {
-
         // Navigate down
         if (keycode == getNavigationDownKey()) {
             TreeNode node = null;
diff --git a/tests/src/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators b/tests/src/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators
new file mode 100644 (file)
index 0000000..8b9722d
--- /dev/null
@@ -0,0 +1,97 @@
+<?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="" />
+<title>TreeKeyboardNavigationValidators</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+    <td>open</td>
+    <td>/run/com.vaadin.tests.components.tree.TreeKeyboardNavigationValidators?restartApplication</td>
+    <td></td>
+</tr>
+<tr>
+    <td>mouseClick</td>
+    <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]#n[0]</td>
+    <td>7,10</td>
+</tr>
+<tr>
+    <td>pressSpecialKey</td>
+    <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+    <td>right</td>
+</tr>
+<tr>
+    <td>pressSpecialKey</td>
+    <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+    <td>down</td>
+</tr>
+<tr>
+    <td>pressSpecialKey</td>
+    <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+    <td>down</td>
+</tr>
+<tr>
+    <td>pressSpecialKey</td>
+    <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+    <td>down</td>
+</tr>
+<tr>
+    <td>pressSpecialKey</td>
+    <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+    <td>down</td>
+</tr>
+<tr>
+    <td>pressSpecialKey</td>
+    <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+    <td>right</td>
+</tr>
+<tr>
+    <td>pressSpecialKey</td>
+    <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+    <td>down</td>
+</tr>
+<tr>
+    <td>pressSpecialKey</td>
+    <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+    <td>down</td>
+</tr>
+<tr>
+    <td>pressSpecialKey</td>
+    <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+    <td>down</td>
+</tr>
+<tr>
+    <td>pressSpecialKey</td>
+    <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+    <td>down</td>
+</tr>
+<tr>
+    <td>pressSpecialKey</td>
+    <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+    <td>right</td>
+</tr>
+<tr>
+    <td>pressSpecialKey</td>
+    <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+    <td>down</td>
+</tr>
+<tr>
+    <td>pressSpecialKey</td>
+    <td>vaadin=runcomvaadintestscomponentstreeTreeKeyboardNavigationValidators::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]/domChild[1]</td>
+    <td>down</td>
+</tr>
+<tr>
+    <td>screenCapture</td>
+    <td></td>
+    <td>5-2-sel</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/src/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators.java b/tests/src/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators.java
new file mode 100644 (file)
index 0000000..2a54506
--- /dev/null
@@ -0,0 +1,54 @@
+package com.vaadin.tests.components.tree;
+
+import com.vaadin.data.Container;
+import com.vaadin.data.util.HierarchicalContainer;
+import com.vaadin.data.validator.AbstractValidator;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Tree;
+
+public class TreeKeyboardNavigationValidators extends TestBase {
+
+    @Override
+    protected void setup() {
+        addComponent(getTree());
+    }
+
+    private Tree getTree() {
+        Tree tree = new Tree();
+        tree.setSizeFull();
+        tree.setContainerDataSource(generateHierarchicalContainer());
+        tree.setImmediate(true);
+        tree.addValidator(new AbstractValidator("failed") {
+            public boolean isValid(Object value) {
+                return false;
+            }
+
+        });
+        return tree;
+    }
+
+    private Container generateHierarchicalContainer() {
+        HierarchicalContainer cont = new HierarchicalContainer();
+        for (int i = 1; i < 6; i++) {
+            cont.addItem(i);
+            for (int j = 1; j < 3; j++) {
+                String id = i + " -> " + j;
+                cont.addItem(id);
+                cont.setChildrenAllowed(id, false);
+                cont.setParent(id, i);
+            }
+        }
+        return cont;
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Keyboard navigation should still work in a tree with validators.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 7057;
+    }
+
+}