11 Replies Latest reply on Jan 16, 2007 7:14 AM by danFromBAH

    How to force repaint/render of mx:Tree

    danFromBAH
      Hello all:

      I am using an mx:Tree that gets populated dynamically from an mx:HTTPservice. When the new nodes are added I don't see the scroll bar change/move the reflect the exapnsion of the tree.

      Is there a way to force a tree to render itself? I have tried tree.invalidateList() and then tree.validateNow() ....

      Dan
        • 1. Re: How to force repaint/render of mx:Tree
          ntsiii Level 3
          Well, re-assigning the dataProvider should always force the tree to re-render.

          But that is surgery with a meat cleaver.

          Are you appending nodes to the dataprovider? What is the dataProvider? what is the resultFormat?

          Tracy
          • 2. Re: How to force repaint/render of mx:Tree
            danFromBAH Level 1
            Yes, I am appending to the data provider at runtime and my result format is e4x. Basically, anytime a tree node is expanded the following HTTPService gets invoked:

            <mx:HTTPService id="getChildrenTypesRPC"
            url="@ContextRoot()/niem-services/getChildrenTypes.do"
            resultFormat="e4x" showBusyCursor="true" method="post"
            fault="Alert.show(event.fault.faultString)"
            result="getChildrenTypesRPCHandler(event)">
            <mx:request>
            <localName>{selectedType.@name}</localName>
            <namespaceURI>{selectedType.@namespaceURI}</namespaceURI>
            </mx:request>
            </mx:HTTPService>
            <mx:XMLListCollection id="childrenTypes"
            source="{getChildrenTypesRPC.lastResult.type}" />


            The handler looks like this:

            private function getChildrenTypesRPCHandler(event:ResultEvent):void {

            for (var i:int = 0; i < childrenTypes.length; i++) {
            var newNode:XML = <type/>;
            var child:Object = childrenTypes.getItemAt(i);
            newNode.@name = child.@name;
            newNode.@type = child.@type;
            newNode.@annotation = child.@annotation;
            newNode.@isBranch = child.@isBranch;
            newNode.@namespaceURI = child.@namespaceURI;
            newNode.@isAttribute = child.@isAttribute;
            newNode.@isAbstract = child.@isAbstract;
            newNode.@isAttributeGroup = child.@isAttributeGroup;
            newNode.@isElement = child.@isElement;
            newNode.@isModelGroup = child.@isModelGroup;
            newNode.@isSimpleType = child.@isSimpleType;
            selectedNode.appendChild(newNode);
            }

            tree.validateNow();
            }


            and the Tree is:

            <mx:Tree id="tree" top="124" bottom="10" right="10" left="10"
            labelField="@name"
            itemOpen="itemOpen(event)"
            change="showDesc(event)"
            disclosureClosedIcon="@Embed(source='icons/expandall.gif')"
            disclosureOpenIcon="@Embed(source='icons/collapseall.gif')"
            itemRenderer="NIEMTreeItemRenderer" iconFunction="treeIconFunc"
            labelFunction="treeLabelFunc">
            </mx:Tree>


            • 3. Re: How to force repaint/render of mx:Tree
              ntsiii Level 3
              All that looks right. And my example uses almost the exact same code and it works. If you debug and look at the xml node itself, does it have the correct content?

              Below is the code I use.
              Tracy
              //run by toolbar button, adds the type of node specified by sNodeKind
              private function addNode(sNodeKind:String):void
              {
              var nodeParent:XML;
              var nodeNew:XML = <newnode />;
              switch (sNodeKind) {
              case "text": //NOT CURRENTLY USED
              var XMLdoc:XML = new XML();
              nodeNew = XMLdoc.appendChild("new text node");
              nodeParent = XML(_xmlNodeCurrent);
              break;
              case "sibling": //add a sibling node
              nodeParent = XML(_xmlNodeCurrent.parent()); //parent node of new node is this nodes parent
              break;
              case "child": //ad a child node
              nodeParent = XML(_xmlNodeCurrent); //parent node of new node is this node
              break;
              }
              nodeParent.appendChild(nodeNew); //append the new node
              treeData.expandItem(nodeParent, true);
              treeData.selectedItem = nodeNew; //select the new node
              showNodeDetail(); //show the detail
              }//addNode
              • 4. Re: How to force repaint/render of mx:Tree
                danFromBAH Level 1
                Tracy:

                The XML document that gets generated after appending a child is not well formatted. For example if the initial XMLListCollection looks like:

                <one/>
                <two/>

                and I want to add a child to <one/>, the resulting xml looks like:

                <one/>
                <childofOne/>
                <two/>

                It should look like:

                <one>
                <childofOne/>
                </one>
                <two/>

                Any suggestions on how I could rework this.

                Dan
                • 5. Re: How to force repaint/render of mx:Tree
                  danFromBAH Level 1
                  Disregard my last post. I got the XML to be formatted correctly. I check the structure of the XML after adding a child node and it is correct.

                  However, the tree is still not displaying the XMLListCollection correctly when I open the nodes near the bottom of the tree. No issues in the top portions of the tree.

                  For example if I add three children nodes to the last node of the tree below:

                  1
                  2
                  3
                  4
                  5

                  it should result in:

                  1
                  2
                  3
                  4
                  5
                  ***5.1
                  ***5.2
                  ***5.3

                  Instead I get,

                  1
                  5
                  ***5.1
                  ***5.2
                  ***5.3

                  The tree nodes disappear until I move the vertical scroll bar up and down!!
                  • 6. Re: How to force repaint/render of mx:Tree
                    ntsiii Level 3
                    Uh, that is bizarre. Maybe you should report a bug.

                    But first try the latest version 2.0.1, that was released today:
                    http://www.adobe.com/support/flex/downloads_updaters.html

                    Also, try re-assigning the dataProvider. See if that does work.

                    Tracy
                    • 7. Re: How to force repaint/render of mx:Tree
                      danFromBAH Level 1
                      I don't have a support plan. Can I still submit a bug report? where and how could i do that?
                      • 8. Re: How to force repaint/render of mx:Tree
                        modernistik
                        I'm having the same issue. Except it only refreshes when I close/reopen (thats when it finishes rendering correctly).
                        • 9. Re: How to force repaint/render of mx:Tree
                          danFromBAH Level 1
                          When you say "... close/reopen ...", do you mean minimizing and maximizing the application window?
                          • 10. Re: How to force repaint/render of mx:Tree
                            rkschulz
                            Some problem here when adding or removing nodes from a model.
                            Everthing is fine when after scrolling tree up or down and / or expanding node.
                            Basically anything that forces a redraw.

                            Trying a few things at the moment to work around this problem but no luck - this seem like a bug in the tree renderer - I can't find a "model change" event or something one could fire to force the tree to redraw ...

                            Robert.
                            • 11. Re: How to force repaint/render of mx:Tree
                              danFromBAH Level 1
                              I agree I believe it's a bug in the tree component. I have tried everything and nothing seems to work short of populating the tree dataProvider with all the nodes at tree creation time.

                              Dan