Loading ...
Sorry, an error occurred while loading the content.

RE: [SPAM] Re: [flexcoders] Selecting xml nodes in a tree

Expand Messages
  • Tracy Spratt
    One thing I have considered trying is to put a reference to every node into an associative array Object), based on a string key. That would essentially give
    Message 1 of 7 , Jan 1, 2010
    • 0 Attachment

      One thing I have considered trying is to put a reference to every node into an associative array Object), based on a string key.  That would essentially give you random access to any node at hash table speeds.  Or maybe use a Dictionary, with the node as the key.

       

      I have not actually tried this.

       

      Tracy Spratt,

      Lariat Services, development services available


      From: flexcoders@yahoogroups.com [mailto: flexcoders@yahoogroups.com ] On Behalf Of Jeroen Beckers
      Sent: Thursday, December 31, 2009 8:34 AM
      To: flexcoders@yahoogroups.com
      Subject: [SPAM] Re: [flexcoders] Selecting xml nodes in a tree

       

       

      I fine-tuned it to the following (some lines are commented, just to give a complete example for future google-visitors)

      private function displayTreeNode( node:XML) :void
              {
                  var t:Number = getTimer();
                  //expand all the parents
                  expandToTop( node.parent( ));
                  //item is now selectable
                  tree.selectedItem = node;
                  //open the item itself
                  //tree.expandItem( node,true, false);
                 
                 
                  //make the node visible (=position scrollbar)
                  var idx:int = tree.getItemIndex( node);
                  tree.scrollToIndex( idx);
                  //tree.firstVisible Item = node;
                 
                  trace("Looking up the item in the tree took " + (getTimer() - t) + "ms");
              }
             
              private function expandToTop( node:XML) :void
              {
                  //open if it's not open yet
                  //if(!tree.isItemOp en(node)) tree.expandItem( node, true);
                  tree.expandItem( node, true);
                 
                  //if there's a parent, continue recursion
                  if(node.parent( )) expandToTop( node.parent( ));
              }

      The only problem now is that my treeData is really big and the E4X statement takes about 1200ms on average. Updating the tree takes up another 800ms. I'll have to optimize the crap out of this :).


      On Wed, Dec 30, 2009 at 5:21 PM, Jim Hayes <jim@primalpictures. com> wrote:

       

      It strikes me now that if it meets an open node on the way up the tree it will stop there (and probably shouldn't)
      You might want to allow for that / fix it.
      It's something that I put in as a feature request that was subsequently depreciated because when the client saw it in practice they decided they didn't like it after all!
      So it's not all that well tested I'm afraid.



      -----Original Message-----
      From: flexcoders@yahoogro ups.com on behalf of Jeroen Beckers
      Sent: Wed 12/30/2009 3:20 PM
      To: flexcoders@yahoogro ups.com

      Subject: Re: [flexcoders] Selecting xml nodes in a tree

      Hi Jim,

      I think that'll be enough to get me going, thanks! :).

      And if not, you'll hear from me soon enough :).

      Greets,
      Dauntless
      On Wed, Dec 30, 2009 at 3:36 PM, Jim Hayes <jim@primalpictures. com> wrote:

      >
      >
      > I've used something like this (which is possibly a bit flaky, I admit. I
      > wrote this a long time ago and haven't revisited it since).
      >
      > private function displayTreeNode( node:XML) :void
      > {
      > expandTreeParents( node);
      > movieTree.selectedI tem = node;
      > movieTree.expandIte m(node,true, false);
      > var idx:int = movieTree.getItemIn dex(node) ;
      > movieTree.scrollToI ndex(idx) ;
      > movieTree.firstVisi bleItem = node;
      > }
      >
      > private function expandTreeParents( node:XML) :void {
      > if (node && !movieTree.isItemOp en(node)) {
      > movieTree.expandIte m(node, true);
      > expandTreeParents( node.parent( ));
      > }
      > }
      >
      > where movieTree is my tree instance.
      > You need to traverse up the tree from the node you want to display and
      open
      > each item ( expandTreeParents( ) above ),
      > then select the node you want to display. This may not be visible even
      > then, hence the scroll to index stuff.
      >
      > Hope that's enough to get you going, in any case.
      >
      >
      > -----Original Message-----

      > From: flexcoders@yahoogro ups.com <flexcoders%40yahoogroups. com> on behalf

      > of thedauntless_ ff
      > Sent: Wed 12/30/2009 1:31 PM

      > To: flexcoders@yahoogro ups.com <flexcoders%40yahoogroups. com>

      > Subject: [flexcoders] Selecting xml nodes in a tree
      >
      > Hi,
      >
      > My situation:
      > - 1 Tree component (id=tree)
      > - 1 XMLListCollection as a dataprovider for the tree (id=treeData)
      > - 1 String, a url, that has to be found & selected.
      >
      > My XMLListCollection looks like this:
      > <page title="page1" href="url1">
      > <page title="subpage1" href="url2"/>
      > <page title="subpage2" href="url3">
      > <page title="subsubpage1" href="url4">
      > </page>
      > </page>
      > <page title="page2" href="url5">
      > <page .../>
      > <page .../>
      > </page>
      >
      > Etc. All nodes are named 'page' and have a href property.
      >
      > What I need now, is a way to select the node in the tree for the given
      url.
      > For example, all nodes are collapsed and I want to select the node with
      > href=url4. How can I do this?
      >
      > This is what I tried:
      >
      > var t:XMLListCollection = this.treeData;
      > var url:String = "myURL";
      > for(var i:Number = 0; i<t.length; i++)
      > {
      > //this works, nodes now contains a list of xml items with the correct url.
      > var nodes:XMLList = t[i]..page.( @href==url) ;
      > if(nodes.length( ) > 0)
      > {
      > //I only want to select the first occurence
      > tree.selectedItem = nodes[0];
      > break;
      > }
      > }
      >
      > This, however, gives me a weird error (probably not that helpfull):
      >
      > TypeError: Error #1010: A term is undefined and has no properties.
      > at
      > mx.controls. listClasses: :ListBase/ setSelectionData Loop()[E: \dev\beta1\ frameworks\ projects\ framework\ src\mx\controls\ listClasses\ ListBase. as:7360]
      > at
      > mx.controls. listClasses: :ListBase/ commitSelectedIt ems()[E:\ dev\beta1\ frameworks\ projects\ framework\ src\mx\controls\ listClasses\ ListBase. as:7251]
      > at
      > mx.controls. listClasses: :ListBase/ commitSelectedIt em()[E:\dev\ beta1\frameworks \projects\ framework\ src\mx\controls\ listClasses\ ListBase. as:7216]
      > at mx.controls. listClasses: :ListBase/ set
      > selectedItem( )[E:\dev\ beta1\frameworks \projects\ framework\ src\mx\controls\ listClasses\ ListBase. as:3474]
      > at classes::Logic/ onBrowserLocatio nChange() [C:\Users\ ser\Documents\ Flex
      > Builder 3\application\ src\classes\ Logic.as: 346]
      > at flash.events: :EventDispatcher /dispatchEventFu nction()
      > at flash.events: :EventDispatcher /dispatchEvent( )
      > at
      > mx.core::UIComponen t/dispatchEvent( )[E:\dev\ beta1\frameworks \projects\ framework\ src\mx\core\ UIComponent. as:11260]
      > at Classes::Logic/ onBrowserLocatio nChange() [C:\Users\ user\Documents\ Flex
      > Builder 3\application\ src\classes\ Logic.as: 73]
      > at flash.events: :EventDispatcher /dispatchEventFu nction()
      > at flash.events: :EventDispatcher /dispatchEvent( )
      > at
      > mx.core::UIComponen t/dispatchEvent( )[E:\dev\ beta1\frameworks \projects\ framework\ src\mx\core\ UIComponent. as:11260]
      > at
      > mx.controls: :HTML/htmlLoader _locationChangeH andler()[ E:\dev\beta1\ frameworks\ projects\ airframework\ src\mx\controls\ HTML.as:1438]
      > at flash.events: :EventDispatcher /dispatchEventFu nction()
      > at flash.events: :EventDispatcher /dispatchEvent( )
      > at flash.html:: HTMLLoader/ onLocationChange Timer()
      > at flash.utils: :Timer/_timerDis patch()
      > at flash.utils: :Timer/tick( )
      >
      > Greets,
      > Dauntless
      >
      > ____________ _________ _________ _________ _________ _________ _
      > This communication is from Primal Pictures Ltd., a company registered in
      > England and
      w:st="on"> Wales with registration No. 02622298 and registered office: 4th
      > Floor, Tennyson House, 159-165 Great Portland Street,
      London , W1W 5PA , UK .
      > VAT registration No. 648874577.
      >
      > This e-mail is confidential and may be privileged. It may be read, copied
      > and used only by the intended recipient. If you have received it in error,
      > please contact the sender immediately by return e-mail or by telephoning
      > +44(0)20 7637 1010. Please then delete the e-mail and do not disclose its
      > contents to any person.
      > This email has been scanned for Primal Pictures by the MessageLabs Email
      > Security System.
      > ____________ _________ _________ _________ _________ _________ _
      >
      >

      ____________ _________ _________ _________ _________ _________ _
      This communication is from Primal Pictures Ltd., a company registered in England and Wales with registration No. 02622298 and registered office: 4th Floor, Tennyson House, 159-165 Great Portland Street, London , W1W 5PA , UK . VAT registration No. 648874577.

      This e-mail is confidential and may be privileged. It may be read, copied and used only by the intended recipient. If you have received it in error, please contact the sender immediately by return e-mail or by telephoning +44(0)20 7637 1010. Please then delete the e-mail and do not disclose its contents to any person.
      This email has been scanned for Primal Pictures by the MessageLabs Email Security System.
      ____________ _________ _________ _________ _________ _________ _

       

    • Jeroen Beckers
      Thanks Tracy, I ll try that. I ll take some time @ startup to build the dictionary, but doing it once is of course better than doing it x times every minute
      Message 2 of 7 , Jan 1, 2010
      • 0 Attachment
        Thanks Tracy, I'll try that. I'll take some time @ startup to build the dictionary, but doing it once is of course better than doing it x times every minute :).

        On Fri, Jan 1, 2010 at 6:53 PM, Tracy Spratt <tracy@...> wrote:
         

        One thing I have considered trying is to put a reference to every node into an associative array Object), based on a string key.  That would essentially give you random access to any node at hash table speeds.  Or maybe use a Dictionary, with the node as the key.

         

        I have not actually tried this.

         

        Tracy Spratt,

        Lariat Services, development services available


        From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Jeroen Beckers
        Sent: Thursday, December 31, 2009 8:34 AM
        To: flexcoders@yahoogroups.com
        Subject: [SPAM] Re: [flexcoders] Selecting xml nodes in a tree

         

         

        I fine-tuned it to the following (some lines are commented, just to give a complete example for future google-visitors)

        private function displayTreeNode(node:XML):void
                {
                    var t:Number = getTimer();
                    //expand all the parents
                    expandToTop(node.parent());
                    //item is now selectable
                    tree.selectedItem = node;
                    //open the item itself
                    //tree.expandItem(node,true,false);
                   
                   
                    //make the node visible (=position scrollbar)
                    var idx:int = tree.getItemIndex(node);
                    tree.scrollToIndex(idx);
                    //tree.firstVisibleItem = node;
                   
                    trace("Looking up the item in the tree took " + (getTimer() - t) + "ms");
                }
               
                private function expandToTop(node:XML):void
                {
                    //open if it's not open yet
                    //if(!tree.isItemOpen(node)) tree.expandItem(node, true);
                    tree.expandItem(node, true);
                   
                    //if there's a parent, continue recursion
                    if(node.parent()) expandToTop(node.parent());
                }

        The only problem now is that my treeData is really big and the E4X statement takes about 1200ms on average. Updating the tree takes up another 800ms. I'll have to optimize the crap out of this :).


        On Wed, Dec 30, 2009 at 5:21 PM, Jim Hayes <jim@...> wrote:

         

        It strikes me now that if it meets an open node on the way up the tree it will stop there (and probably shouldn't)
        You might want to allow for that / fix it.
        It's something that I put in as a feature request that was subsequently depreciated because when the client saw it in practice they decided they didn't like it after all!
        So it's not all that well tested I'm afraid.



        -----Original Message-----
        From: flexcoders@yahoogroups.com on behalf of Jeroen Beckers
        Sent: Wed 12/30/2009 3:20 PM
        To: flexcoders@yahoogroups.com

        Subject: Re: [flexcoders] Selecting xml nodes in a tree

        Hi Jim,

        I think that'll be enough to get me going, thanks! :).

        And if not, you'll hear from me soon enough :).

        Greets,
        Dauntless
        On Wed, Dec 30, 2009 at 3:36 PM, Jim Hayes <jim@...> wrote:

        >
        >
        > I've used something like this (which is possibly a bit flaky, I admit. I
        > wrote this a long time ago and haven't revisited it since).
        >
        > private function displayTreeNode(node:XML):void
        > {
        > expandTreeParents(node);
        > movieTree.selectedItem = node;
        > movieTree.expandItem(node,true,false);
        > var idx:int = movieTree.getItemIndex(node);
        > movieTree.scrollToIndex(idx);
        > movieTree.firstVisibleItem = node;
        > }
        >
        > private function expandTreeParents(node:XML):void {
        > if (node && !movieTree.isItemOpen(node)) {
        > movieTree.expandItem(node, true);
        > expandTreeParents(node.parent());
        > }
        > }
        >
        > where movieTree is my tree instance.
        > You need to traverse up the tree from the node you want to display and open
        > each item ( expandTreeParents() above ),
        > then select the node you want to display. This may not be visible even
        > then, hence the scroll to index stuff.
        >
        > Hope that's enough to get you going, in any case.
        >
        >
        > -----Original Message-----

        > From: flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com> on behalf
        > of thedauntless_ff
        > Sent: Wed 12/30/2009 1:31 PM

        > To: flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>
        > Subject: [flexcoders] Selecting xml nodes in a tree
        >
        > Hi,
        >
        > My situation:
        > - 1 Tree component (id=tree)
        > - 1 XMLListCollection as a dataprovider for the tree (id=treeData)
        > - 1 String, a url, that has to be found & selected.
        >
        > My XMLListCollection looks like this:
        > <page title="page1" href="url1">
        > <page title="subpage1" href="url2"/>
        > <page title="subpage2" href="url3">
        > <page title="subsubpage1" href="url4">
        > </page>
        > </page>
        > <page title="page2" href="url5">
        > <page .../>
        > <page .../>
        > </page>
        >
        > Etc. All nodes are named 'page' and have a href property.
        >
        > What I need now, is a way to select the node in the tree for the given url.
        > For example, all nodes are collapsed and I want to select the node with
        > href=url4. How can I do this?
        >
        > This is what I tried:
        >
        > var t:XMLListCollection = this.treeData;
        > var url:String = "myURL";
        > for(var i:Number = 0; i<t.length; i++)
        > {
        > //this works, nodes now contains a list of xml items with the correct url.
        > var nodes:XMLList = t[i]..page.(@href==url);
        > if(nodes.length() > 0)
        > {
        > //I only want to select the first occurence
        > tree.selectedItem = nodes[0];
        > break;
        > }
        > }
        >
        > This, however, gives me a weird error (probably not that helpfull):
        >
        > TypeError: Error #1010: A term is undefined and has no properties.
        > at
        > mx.controls.listClasses::ListBase/setSelectionDataLoop()[E:\dev\beta1\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:7360]
        > at
        > mx.controls.listClasses::ListBase/commitSelectedItems()[E:\dev\beta1\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:7251]
        > at
        > mx.controls.listClasses::ListBase/commitSelectedItem()[E:\dev\beta1\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:7216]
        > at mx.controls.listClasses::ListBase/set
        > selectedItem()[E:\dev\beta1\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:3474]
        > at classes::Logic/onBrowserLocationChange()[C:\Users\ser\Documents\Flex
        > Builder 3\application\src\classes\Logic.as:346]
        > at flash.events::EventDispatcher/dispatchEventFunction()
        > at flash.events::EventDispatcher/dispatchEvent()
        > at
        > mx.core::UIComponent/dispatchEvent()[E:\dev\beta1\frameworks\projects\framework\src\mx\core\UIComponent.as:11260]
        > at Classes::Logic/onBrowserLocationChange()[C:\Users\user\Documents\Flex
        > Builder 3\application\src\classes\Logic.as:73]
        > at flash.events::EventDispatcher/dispatchEventFunction()
        > at flash.events::EventDispatcher/dispatchEvent()
        > at
        > mx.core::UIComponent/dispatchEvent()[E:\dev\beta1\frameworks\projects\framework\src\mx\core\UIComponent.as:11260]
        > at
        > mx.controls::HTML/htmlLoader_locationChangeHandler()[E:\dev\beta1\frameworks\projects\airframework\src\mx\controls\HTML.as:1438]
        > at flash.events::EventDispatcher/dispatchEventFunction()
        > at flash.events::EventDispatcher/dispatchEvent()
        > at flash.html::HTMLLoader/onLocationChangeTimer()
        > at flash.utils::Timer/_timerDispatch()
        > at flash.utils::Timer/tick()
        >
        > Greets,
        > Dauntless
        >
        > __________________________________________________________
        > This communication is from Primal Pictures Ltd., a company registered in
        > England and Wales with registration No. 02622298 and registered office: 4th
        > Floor, Tennyson House, 159-165 Great Portland Street, London, W1W 5PA, UK.
        > VAT registration No. 648874577.
        >
        > This e-mail is confidential and may be privileged. It may be read, copied
        > and used only by the intended recipient. If you have received it in error,
        > please contact the sender immediately by return e-mail or by telephoning
        > +44(0)20 7637 1010. Please then delete the e-mail and do not disclose its
        > contents to any person.
        > This email has been scanned for Primal Pictures by the MessageLabs Email
        > Security System.
        > __________________________________________________________
        >
        >

        __________________________________________________________
        This communication is from Primal Pictures Ltd., a company registered in England and Wales with registration No. 02622298 and registered office: 4th Floor, Tennyson House, 159-165 Great Portland Street, London, W1W 5PA, UK. VAT registration No. 648874577.

        This e-mail is confidential and may be privileged. It may be read, copied and used only by the intended recipient. If you have received it in error, please contact the sender immediately by return e-mail or by telephoning +44(0)20 7637 1010. Please then delete the e-mail and do not disclose its contents to any person.
        This email has been scanned for Primal Pictures by the MessageLabs Email Security System.
        __________________________________________________________

         


      Your message has been successfully submitted and would be delivered to recipients shortly.