]> source.dussan.org Git - vaadin-framework.git/commitdiff
Merged to 6.0 #2603 (a single select tree could show multiple items as selected)...
authorHenri Sara <henri.sara@itmill.com>
Mon, 6 Apr 2009 07:57:40 +0000 (07:57 +0000)
committerHenri Sara <henri.sara@itmill.com>
Mon, 6 Apr 2009 07:57:40 +0000 (07:57 +0000)
svn changeset:7313/svn branch:6.0

src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java
src/com/itmill/toolkit/ui/TextField.java
src/com/itmill/toolkit/ui/Tree.java

index dd11136aa41b1c84714e8ee526e7f487af16beb6..678f08a8869d01d8c2e36268f8802056ba47114b 100644 (file)
@@ -142,6 +142,11 @@ public class ITree 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) {
@@ -152,7 +157,7 @@ public class ITree extends FlowPanel implements Paintable {
                     final TreeNode oldSelection = keyToNode.get(id);
                     if (oldSelection != null) {
                         // can be null if the node is not visible (parent
-                        // expanded)
+                        // collapsed)
                         oldSelection.setSelected(false);
                     }
                     selectedIds.remove(id);
index dd8596f087a72e302758380795751d06b9f76595..0b7336e2155fe29b0be980eabc18f7bbf77de5e4 100644 (file)
@@ -409,7 +409,7 @@ public class TextField extends AbstractField {
      * 
      * <p>
      * If this property is true, writing null-representation string to text
-     * field allways sets the field value to real null. If this property is
+     * field always sets the field value to real null. If this property is
      * false, null setting is not made, but the null values are maintained.
      * Maintenance of null-values is made by only converting the textfield
      * contents to real null, if the text field matches the null-string
@@ -420,7 +420,7 @@ public class TextField extends AbstractField {
      * By default this setting is false
      * </p>
      * 
-     * @return boolean Should the null-string represenation be allways converted
+     * @return boolean Should the null-string represenation be always converted
      *         to null-values.
      * @see TextField#getNullRepresentation()
      */
@@ -454,7 +454,7 @@ public class TextField extends AbstractField {
      * 
      * <p>
      * If this property is true, writing null-representation string to text
-     * field allways sets the field value to real null. If this property is
+     * field always sets the field value to real null. If this property is
      * false, null setting is not made, but the null values are maintained.
      * Maintenance of null-values is made by only converting the textfield
      * contents to real null, if the text field matches the null-string
@@ -466,7 +466,7 @@ public class TextField extends AbstractField {
      * </p>
      * 
      * @param nullSettingAllowed
-     *            Should the null-string represenation be allways converted to
+     *            Should the null-string represenation be always converted to
      *            null-values.
      * @see TextField#getNullRepresentation()
      */
index 36b34ac50aa241aa9d46a4d1f9b73df7a9198d7a..20c7e03961c8ccd18e9d38f85eb2e852db28aac3 100644 (file)
@@ -32,8 +32,8 @@ import com.itmill.toolkit.terminal.Resource;
 import com.itmill.toolkit.terminal.gwt.client.MouseEventDetails;
 
 /**
- * MenuTree component. MenuTree can be used to select an item (or multiple
- * items) from a hierarchical set of items.
+ * Tree component. A Tree can be used to select an item (or multiple items) from
+ * a hierarchical set of items.
  * 
  * @author IT Mill Ltd.
  * @version
@@ -72,7 +72,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
     /**
      * List of action handlers.
      */
-    private LinkedList actionHandlers = null;
+    private LinkedList<Action.Handler> actionHandlers = null;
 
     /**
      * Action mapper.
@@ -396,10 +396,9 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
                 final Action action = (Action) actionMapper.get(st.nextToken());
                 if (action != null && containsId(itemId)
                         && actionHandlers != null) {
-                    for (final Iterator i = actionHandlers.iterator(); i
-                            .hasNext();) {
-                        ((Action.Handler) i.next()).handleAction(action, this,
-                                itemId);
+                    for (final Iterator<Action.Handler> i = actionHandlers
+                            .iterator(); i.hasNext();) {
+                        i.next().handleAction(action, this, itemId);
                     }
                 }
             }
@@ -448,7 +447,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
         }
 
         // Initialize variables
-        final Set actionSet = new LinkedHashSet();
+        final Set<Action> actionSet = new LinkedHashSet<Action>();
         String[] selectedKeys;
         if (isMultiSelect()) {
             selectedKeys = new String[((Set) getValue()).size()];
@@ -459,7 +458,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
         final LinkedList expandedKeys = new LinkedList();
 
         // Iterates through hierarchical tree using a stack of iterators
-        final Stack iteratorStack = new Stack();
+        final Stack<Iterator> iteratorStack = new Stack<Iterator>();
         Collection ids;
         if (partialUpdate) {
             ids = getChildren(expandedItemId);
@@ -474,7 +473,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
         while (!iteratorStack.isEmpty()) {
 
             // Gets the iterator for current tree level
-            final Iterator i = (Iterator) iteratorStack.peek();
+            final Iterator i = iteratorStack.peek();
 
             // If the level is finished, back to previous tree level
             if (!i.hasNext()) {
@@ -527,11 +526,11 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
 
                 // Actions
                 if (actionHandlers != null) {
-                    final ArrayList keys = new ArrayList();
-                    for (final Iterator ahi = actionHandlers.iterator(); ahi
-                            .hasNext();) {
-                        final Action[] aa = ((Action.Handler) ahi.next())
-                                .getActions(itemId, this);
+                    final ArrayList<String> keys = new ArrayList<String>();
+                    final Iterator<Action.Handler> ahi = actionHandlers
+                            .iterator();
+                    while (ahi.hasNext()) {
+                        final Action[] aa = ahi.next().getActions(itemId, this);
                         if (aa != null) {
                             for (int ai = 0; ai < aa.length; ai++) {
                                 final String akey = actionMapper.key(aa[ai]);
@@ -561,8 +560,9 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
         if (!actionSet.isEmpty()) {
             target.addVariable(this, "action", "");
             target.startTag("actions");
-            for (final Iterator i = actionSet.iterator(); i.hasNext();) {
-                final Action a = (Action) i.next();
+            final Iterator<Action> i = actionSet.iterator();
+            while (i.hasNext()) {
+                final Action a = i.next();
                 target.startTag("action");
                 if (a.getCaption() != null) {
                     target.addAttribute("caption", a.getCaption());
@@ -577,6 +577,10 @@ 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
@@ -899,7 +903,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
         if (actionHandler != null) {
 
             if (actionHandlers == null) {
-                actionHandlers = new LinkedList();
+                actionHandlers = new LinkedList<Action.Handler>();
                 actionMapper = new KeyMapper();
             }
 
@@ -941,7 +945,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
         final LinkedList visible = new LinkedList();
 
         // Iterates trough hierarchical tree using a stack of iterators
-        final Stack iteratorStack = new Stack();
+        final Stack<Iterator> iteratorStack = new Stack<Iterator>();
         final Collection ids = rootItemIds();
         if (ids != null) {
             iteratorStack.push(ids.iterator());
@@ -949,7 +953,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
         while (!iteratorStack.isEmpty()) {
 
             // Gets the iterator for current tree level
-            final Iterator i = (Iterator) iteratorStack.peek();
+            final Iterator i = iteratorStack.peek();
 
             // If the level is finished, back to previous tree level
             if (!i.hasNext()) {