]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix for #5008
authorJohn Alhroos <john.ahlroos@itmill.com>
Fri, 18 Jun 2010 13:39:26 +0000 (13:39 +0000)
committerJohn Alhroos <john.ahlroos@itmill.com>
Fri, 18 Jun 2010 13:39:26 +0000 (13:39 +0000)
svn changeset:13779/svn branch:6.4

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

index 108a68be145c01430fba17d151a2d0fd4c2d6631..22d10f13c9f1b61fe978f3066b8a0092021f98a9 100644 (file)
@@ -252,6 +252,11 @@ public class VTree extends SimpleFocusablePanel implements Paintable,
 
         selectedIds = uidl.getStringArrayVariableAsSet("selected");
 
+        if (lastSelection == null && focusedNode == null) {
+            setFocusedNode(keyToNode.get(selectedIds.iterator().next()));
+            focusedNode.setFocused(false);
+        }
+
         rendering = false;
 
     }
@@ -1012,6 +1017,13 @@ public class VTree extends SimpleFocusablePanel implements Paintable,
             }
         }
 
+        /**
+         * Scrolls the caption into view
+         */
+        public void scrollIntoView() {
+            nodeCaptionDiv.scrollIntoView();
+        }
+
     }
 
     public VDropHandler getDropHandler() {
@@ -1413,6 +1425,7 @@ public class VTree extends SimpleFocusablePanel implements Paintable,
 
         if (node != null) {
             node.setFocused(true);
+            node.scrollIntoView();
         }
 
         focusedNode = node;
@@ -1427,10 +1440,12 @@ public class VTree extends SimpleFocusablePanel implements Paintable,
      */
     public void onFocus(FocusEvent event) {
         // If no node has focus, focus the first item in the tree
-        if (focusedNode == null && selectable) {
+        if (focusedNode == null && lastSelection == null && selectable) {
             setFocusedNode((TreeNode) body.getWidget(0));
-        } else if (selectable) {
+        } else if (focusedNode != null && selectable) {
             setFocusedNode(focusedNode);
+        } else if (lastSelection != null && selectable) {
+            setFocusedNode(lastSelection);
         }
     }