7 Replies Latest reply on Oct 20, 2010 3:57 AM by Esfera Critica

    Refresh a Tree XML dataProvider

    Esfera Critica Level 1



      I have a problem with refreshing a Tree dataProvider. This is what I use:



      private var xmlFontes: XML;


      I then use it to put some php/sql generated xml. And then I make it a Tree dataProvider.

      So far so good... But I need to refresh the xml, and I use xmlFontes.refresh; and it works great. But I need to know when the refresh is complete, and I can't. Is it possible?


      Thank you so much for your help!


        • 1. Re: Refresh a Tree XML dataProvider
          Esfera Critica Level 1



          Just to make a correction:


          xmlFontes.refresh; wasn't doing anything so I removed it... It refreshed beacuse when I make changes I call the xml again and rebuild the tree. But I need to know when the tree ends rebuilding so I can open the node that was previously selected.


          Thanks again!

          • 2. Re: Refresh a Tree XML dataProvider
            Devtron Level 3

            I really dont understand your problem.


            I work with dynamic extended tree controls and dynamic XMLList data in my application, so I can probably help you a bit.


            how exactly do you "rebuild" the tree? I think that will explain how you can reset the tree node selection...

            • 3. Re: Refresh a Tree XML dataProvider
              Esfera Critica Level 1

              Well... I don't know if I can explain mutch better... My english is not great!


              I'm using a SpringLoadedTree, that I believe is some kind of tree but with more functions.

              When my application initializes it makes this:


              <mx:HTTPService id="treeF" showBusyCursor="true" url="php/treeFontes.php" resultFormat="e4x"  result="onResultFontes(event)" />


              My treeFontes.php file queries a sql database and gives back some xml code. And then:


              xmlFontes = XML(event.result);


              And xmlFontes is the dataProvider of my tree. This tree I'm using lets me drag and drop items between the tree nodes. When I do that I call another HTTPService to update the node position on the database. When it finishes updating the database I call the <mx:HTTPService id="treeF"... again and it updates the tree.


              What I wanted to do is this:


              When I drag the node on the tree I save that nodes parent id and when I drop it I save the new parent node id - confusing. With this I was hopping to be able to open the tree nodes from where I dragged and droped the child node. I can do this, but only with the click of a button...

              In my onResultFontes function I call another function that does what I want, but it's not working, beacause I don't know if it has finished generating the tree, and it probably tries to open the nodes before they are created.


              The function to open the nodes previously opened does something like this:


              expandParents(node[0]); - This is the original node - saved on drag
              expandParents(node[1]); - This is the destination node - saved on drop


              It's quite confusing... But I can't think of a better way.


              Thanks and sorry for all the confusing explanation!

              • 4. Re: Refresh a Tree XML dataProvider
                Devtron Level 3

                Your English is fine. Do not apologize for your English! You did fine explaining your problem, good job.


                I think what you need to do is re-set the selected node in your result event, which would be: OnResult.


                Do you have that function available to you? If so, you need to obtain the tree's open node ID (before the XML refresh happens) and then re-apply that at the end of OnResult.


                Hopefully that helps?

                • 5. Re: Refresh a Tree XML dataProvider
                  Esfera Critica Level 1

                  Hello again!


                  That's what I'm doing. I have the function to open the nodes in the result function, but it seems to me that it calls that function before it ends loading all the data in the tree... If I call the function from a button it opens the nodes correctly - maybe beacause of the delay of moving the mouse, and clicking it.


                  I believe my problem is related with the fact that I populate(?) the tree in the result function. I call the httpservice and then, on result I do this xmlFontes = XML(event.result); and then I immediatly call the function to open the nodes. Is there a way to know if the tree has ended beeing filled?


                  Thanks again for your help!

                  • 6. Re: Refresh a Tree XML dataProvider
                    Devtron Level 3

                    ^ That's strange, I would think it would work...maybe the XML is very large?


                    Maybe try using the creationComplete attribute of the tree control. You can specify a function for "creationComplete" and set the open node there. Give it a try....

                    • 7. Re: Refresh a Tree XML dataProvider
                      Esfera Critica Level 1



                      Tried what you said, but it didn't work... I believe the creationComplete handler, only runs when the tree is first created...


                      Anyway, thank's for the help...