]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #3275 (regression from #2603, now solved in another way) + some minor cleaning...
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 3 Sep 2009 13:56:03 +0000 (13:56 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 3 Sep 2009 13:56:03 +0000 (13:56 +0000)
svn changeset:8658/svn branch:6.1

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

index 6f676441e72787277bd8bac7c49ec7fcea630daf..87b98526c56d74c07af2f53dc49afa5e4a9c3877 100644 (file)
@@ -141,12 +141,6 @@ public class VTree extends FlowPanel implements Paintable {
             }
             rootNode.renderChildNodes(uidl.getChildIterator());
         }
-
-        if (uidl.hasVariable("selected")) {
-            // update selection in case selected nodes were not visible
-            selectedIds = uidl.getStringArrayVariableAsSet("selected");
-        }
-
     }
 
     public void setSelected(TreeNode treeNode, boolean selected) {
@@ -309,6 +303,9 @@ public class VTree extends FlowPanel implements Paintable {
 
             if (uidl.getBooleanAttribute("selected")) {
                 setSelected(true);
+                // ensure that identifier is in selectedIds array (this may be a
+                // partial update)
+                selectedIds.add(key);
             }
 
             if (uidl.hasAttribute("icon")) {
index 0d563849942b405313744ec589f4332304b9b166..cb3f667a4f4e4cf4d0a938a8e1ee1f00d64d45d0 100644 (file)
@@ -331,8 +331,8 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
      * Called when one or more variables handled by the implementing class are
      * changed.
      * 
-     * @see com.vaadin.terminal.VariableOwner#changeVariables(Object
-     *      source, Map variables)
+     * @see com.vaadin.terminal.VariableOwner#changeVariables(Object source, Map
+     *      variables)
      */
     @Override
     public void changeVariables(Object source, Map variables) {
@@ -448,14 +448,11 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
 
         // Initialize variables
         final Set<Action> actionSet = new LinkedHashSet<Action>();
-        String[] selectedKeys;
-        if (isMultiSelect()) {
-            selectedKeys = new String[((Set) getValue()).size()];
-        } else {
-            selectedKeys = new String[(getValue() == null ? 0 : 1)];
-        }
-        int keyIndex = 0;
-        final LinkedList expandedKeys = new LinkedList();
+
+        // rendered selectedKeys
+        LinkedList<String> selectedKeys = new LinkedList<String>();
+
+        final LinkedList<String> expandedKeys = new LinkedList<String>();
 
         // Iterates through hierarchical tree using a stack of iterators
         final Stack<Iterator> iteratorStack = new Stack<Iterator>();
@@ -509,12 +506,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
                 target.addAttribute("key", key);
                 if (isSelected(itemId)) {
                     target.addAttribute("selected", true);
-                    try {
-                        selectedKeys[keyIndex++] = key;
-                    } catch (Exception e) {
-                        // TODO Fix, see TreeExample (featurebrowser)
-                        e.printStackTrace();
-                    }
+                    selectedKeys.add(key);
                 }
                 if (areChildrenAllowed(itemId) && isExpanded(itemId)) {
                     target.addAttribute("expanded", true);
@@ -577,14 +569,11 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
         }
 
         if (partialUpdate) {
-            // update tree-level selection information in case some selected
-            // node(s) were collapsed
-            target.addVariable(this, "selected", selectedKeys);
-
             partialUpdate = false;
         } else {
             // Selected
-            target.addVariable(this, "selected", selectedKeys);
+            target.addVariable(this, "selected", selectedKeys
+                    .toArray(new String[selectedKeys.size()]));
 
             // Expand and collapse
             target.addVariable(this, "expand", new String[] {});
@@ -669,9 +658,8 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
     /*
      * (non-Javadoc)
      * 
-     * @see
-     * com.vaadin.data.Container.Hierarchical#setParent(java.lang.Object
-     * , java.lang.Object)
+     * @see com.vaadin.data.Container.Hierarchical#setParent(java.lang.Object ,
+     * java.lang.Object)
      */
     public boolean setParent(Object itemId, Object newParentId) {
         final boolean success = ((Container.Hierarchical) items).setParent(