]> source.dussan.org Git - vaadin-framework.git/commitdiff
Added some explaining comments to a bit of code introduced in the fix for #6841
authorJonatan Kronqvist <jonatan.kronqvist@itmill.com>
Mon, 2 May 2011 12:51:03 +0000 (12:51 +0000)
committerJonatan Kronqvist <jonatan.kronqvist@itmill.com>
Mon, 2 May 2011 12:51:03 +0000 (12:51 +0000)
svn changeset:18583/svn branch:6.6

src/com/vaadin/terminal/gwt/client/ui/VTree.java

index 53ca56aca9918de4f9d8f463fef4e184924a0197..dc60fdc0ad7c2683c5dda54c158f29d44e1e1969 100644 (file)
@@ -1804,10 +1804,7 @@ public class VTree extends FocusElementPanel implements Paintable,
                             focusedNode);
                     setFocusedNode(focusedNode.getParentNode());
                 } else {
-                    TreeNode oldFocusedNode = focusedNode;
-                    setFocusedNode(focusedNode.getParentNode());
-                    setSelected(focusedNode, true);
-                    setSelected(oldFocusedNode, false);
+                    focusAndSelectNode(focusedNode.getParentNode());
                 }
             }
             return true;
@@ -1825,10 +1822,7 @@ public class VTree extends FocusElementPanel implements Paintable,
                     setFocusedNode(focusedNode.getChildren().get(0));
                     setSelected(focusedNode, true);
                 } else {
-                    TreeNode oldFocusedNode = focusedNode;
-                    setFocusedNode(focusedNode.getChildren().get(0));
-                    setSelected(focusedNode, true);
-                    setSelected(oldFocusedNode, false);
+                    focusAndSelectNode(focusedNode.getChildren().get(0));
                 }
             }
             return true;
@@ -1879,6 +1873,24 @@ public class VTree extends FocusElementPanel implements Paintable,
         return false;
     }
 
+    private void focusAndSelectNode(TreeNode node) {
+        /*
+         * Keyboard navigation doesn't work reliably if the tree is in
+         * multiselect mode as well as isNullSelectionAllowed = false. It first
+         * tries to deselect the old focused node, which fails since there must
+         * be at least one selection. After this the newly focused node is
+         * selected and we've ended up with two selected nodes even though we
+         * only navigated with the arrow keys.
+         * 
+         * Because of this, we first select the next node and later de-select
+         * the old one.
+         */
+        TreeNode oldFocusedNode = focusedNode;
+        setFocusedNode(node);
+        setSelected(focusedNode, true);
+        setSelected(oldFocusedNode, false);
+    }
+
     /**
      * Traverses the tree to the bottom most child
      *