]> source.dussan.org Git - vaadin-framework.git/commitdiff
collapsing events now handled
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 13 Nov 2007 10:02:27 +0000 (10:02 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 13 Nov 2007 10:02:27 +0000 (10:02 +0000)
svn changeset:2799/svn branch:trunk

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

index 91a12839a7972c70c999d8f32b6552a37802279c..f7a4998e70405f4586a3a09bd7f3d48ef5cb1a0d 100644 (file)
@@ -90,7 +90,7 @@ public class ITree extends FlowPanel implements Paintable {
                this.paintableId = uidl.getId();
 
                this.immediate = uidl.hasAttribute("immediate");
-               
+
                disabled = uidl.getBooleanAttribute("disabled");
 
                isNullSelectionAllowed = uidl.getBooleanAttribute("nullselect");
@@ -118,6 +118,10 @@ public class ITree extends FlowPanel implements Paintable {
                TreeNode rootNode = (TreeNode) keyToNode.get(uidl
                                .getStringAttribute("rootKey"));
                if (rootNode != null) {
+                       if (!rootNode.getState()) {
+                               // expanding node happened server side
+                               rootNode.setState(true, false);
+                       }
                        rootNode.renderChildNodes(uidl.getChildIterator());
                }
 
@@ -177,7 +181,7 @@ public class ITree extends FlowPanel implements Paintable {
 
                public void onBrowserEvent(Event event) {
                        super.onBrowserEvent(event);
-                       if(disabled)
+                       if (disabled)
                                return;
                        Element target = DOM.eventGetTarget(event);
                        if (DOM.compare(target, nodeCaptionSpan)) {
@@ -195,7 +199,7 @@ public class ITree extends FlowPanel implements Paintable {
                }
 
                private void toggleState() {
-                       this.setState(!getState());
+                       this.setState(!getState(), true);
                }
 
                protected void constructDom() {
@@ -234,7 +238,7 @@ public class ITree extends FlowPanel implements Paintable {
 
                        if (uidl.getTag().equals("node")) {
                                if (uidl.getChidlCount() == 0) {
-                                       // TODO "loading indicator"
+                                       childNodeContainer.setVisible(false);
                                } else {
                                        renderChildNodes(uidl.getChildIterator());
                                        childrenLoaded = true;
@@ -244,7 +248,7 @@ public class ITree extends FlowPanel implements Paintable {
                        }
 
                        if (uidl.getBooleanAttribute("expanded") && !getState()) {
-                               open = true;
+                               setState(true, false);
                        }
 
                        if (uidl.getBooleanAttribute("selected")) {
@@ -252,23 +256,28 @@ public class ITree extends FlowPanel implements Paintable {
                        }
                }
 
-               private void setState(boolean b) {
-                       if (open == b)
+               private void setState(boolean state, boolean notifyServer) {
+                       if (open == state)
                                return;
-                       if (b) {
-                               if (!childrenLoaded) {
-                                       ITree.this.client.updateVariable(paintableId, "expand",
-                                                       new String[] { key }, true);
+                       if (state) {
+                               if (!childrenLoaded && notifyServer) {
+                                       client.updateVariable(paintableId, "requestChildTree",
+                                                       true, false);
                                }
+                               if (notifyServer)
+                                       client.updateVariable(paintableId, "expand",
+                                                       new String[] { key }, true);
                                addStyleName(CLASSNAME + "-expanded");
                                childNodeContainer.setVisible(true);
                        } else {
                                removeStyleName(CLASSNAME + "-expanded");
                                childNodeContainer.setVisible(false);
-                               // TODO notify server
+                               if (notifyServer)
+                                       client.updateVariable(paintableId, "collapse",
+                                                       new String[] { key }, true);
                        }
 
-                       open = b;
+                       open = state;
                }
 
                private boolean getState() {
@@ -281,6 +290,7 @@ public class ITree extends FlowPanel implements Paintable {
 
                private void renderChildNodes(Iterator i) {
                        childNodeContainer.clear();
+                       childNodeContainer.setVisible(true);
                        while (i.hasNext()) {
                                UIDL childUidl = (UIDL) i.next();
                                // actions are in bit weird place, don't mix them with children,
index fb5bce08ca3f6fd18ee188c74cd113b78ab613f6..a86717eb8497e46dcfb31c308cd0dc2d8df38dac 100644 (file)
@@ -168,6 +168,19 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
         * @return True iff the expand operation succeeded
         */
        public boolean expandItem(Object itemId) {
+               return expandItem(itemId, true);
+       }
+
+       /**
+        * Expands an item.
+        * 
+        * @param itemId
+        *            the item id.
+        * @param sendChildTree
+        *              flag to indicate if client needs subtree or not (may be cached)
+        * @return True iff the expand operation succeeded
+        */
+       private boolean expandItem(Object itemId, boolean sendChildTree) {
 
                // Succeeds if the node is already expanded
                if (isExpanded(itemId)) {
@@ -185,7 +198,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
                this.expandedItemId = itemId;
                if (this.initialPaint) {
                        requestRepaint();
-               } else {
+               } else if(sendChildTree) {
                        requestPartialRepaint();
                }
                fireExpandEvent(itemId);
@@ -223,14 +236,14 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
                // Expands recursively
                while (!todo.isEmpty()) {
                        Object id = todo.pop();
-                       if (areChildrenAllowed(id) && !expandItem(id)) {
+                       if (areChildrenAllowed(id) && !expandItem(id, false)) {
                                result = false;
                        }
                        if (hasChildren(id)) {
                                todo.addAll(getChildren(id));
                        }
                }
-
+               requestRepaint();
                return result;
        }
 
@@ -358,11 +371,15 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
 
                // Expands the nodes
                if (variables.containsKey("expand")) {
+                       boolean sendChildTree = false;
+                       if(variables.containsKey("requestChildTree")) {
+                               sendChildTree = true;
+                       }
                        String[] keys = (String[]) variables.get("expand");
                        for (int i = 0; i < keys.length; i++) {
                                Object id = this.itemIdMapper.get(keys[i]);
                                if (id != null) {
-                                       expandItem(id);
+                                       expandItem(id, sendChildTree);
                                }
                        }
                }