6 Replies Latest reply on Jan 10, 2009 7:17 AM by Newsgroup_User

    Tree drag and drop (move, copy to self)

    Erxar
      I've got a problem with drag and drop in a tree component.

      I'd like to send information about tree being rearranged to the server and for that I need "old" parent of the node that was moved and the "new" parent of this node.

      Anybody know how to get this data? Thanks.
        • 1. Re: Tree drag and drop (move, copy to self)
          ntsiii Level 3
          Store that information in an instance var assigned in the dragStart handler.

          Though as I recall, the drop handler is called before any rearrangement of the data actually happens so you could also get the data there.

          Tracy
          • 2. Re: Tree drag and drop (move, copy to self)
            Erxar Level 1
            quote:

            Originally posted by: ntsiii
            Though as I recall, the drop handler is called before any rearrangement of the data actually happens so you could also get the data there.



            Exactly! Even the dropComplete event is called before any rearrangement od the data (moved item is removed for previous place but it's not added to the selected one). "Old" father is doable. It's not as clean as i would like it to be but i managed. The "New" father is the real problem since i don't have access to the rearranged data. I tried to access updated data by calling callLater(fun, dragedItem) in dragDrop. In the fun function i'm calling getParentItem(dragedItem) but it dosn't always work :(. Sometimes it returns null .. as far as i know it's indeterministic.

            Do you maby have any other idea on how can i do it?
            • 3. Tree drag and drop (move, copy to self)
              Erxar Level 1
              Edit: Double post. Sorry.
              • 4. Re: Tree drag and drop (move, copy to self)
                Level 7

                "Erxar" <webforumsuser@macromedia.com> wrote in message
                news:gk4m5l$2pd$1@forums.macromedia.com...
                >
                quote:

                Originally posted by: ntsiii
                > Though as I recall, the drop handler is called before any rearrangement of
                > the
                > data actually happens so you could also get the data there.
                >

                >
                > Exactly! Even the dropComplete event is called before any rearrangement od
                > the
                > data (moved item is removed for previous place but it's not added to the
                > selected one). "Old" father is doable. It's not as clean as i would like
                > it to
                > be but i managed. The "New" father is the real problem since i don't have
                > access to the rearranged data. I tried to access updated data by calling
                > callLater(fun, dragedItem) in dragDrop. In the fun function i'm calling
                > getParentItem(dragedItem) but it dosn't always work :(. Sometimes it
                > returns
                > null .. as far as i know it's indeterministic.
                >
                > Do you maby have any other idea on how can i do it?

                add an Event Listener on drop that listens for the collection change event?


                • 5. Tree drag and drop (move, copy to self)
                  Erxar Level 1
                  quote:

                  Originally posted by: Newsgroup User
                  add an Event Listener on drop that listens for the collection change event?



                  Well, the collection is a custom tree structure. I may add event listener to dataProvider (which is ArrayCollection), but this dataProvider has one item - root. If somebody adds another root i'd be notified but if it adds node deeper in the tree i won't be.

                  I think, in order for it to work, i'd have to add this event listener to every node in the tree. What do you think about that? It's a bit messy and i'd rather look for something simpler.

                  Any more ideas?

                  Edit: I mean .. come on! I can't believe i even have this kind of a problem. Getting node that item is droped on is *pretty* basic stuff. This is embarasing for flex.
                  • 6. Re: Tree drag and drop (move, copy to self)
                    Level 7

                    "Erxar" <webforumsuser@macromedia.com> wrote in message
                    news:gk7d1j$orr$1@forums.macromedia.com...
                    >
                    quote:

                    Originally posted by: Newsgroup User
                    > add an Event Listener on drop that listens for the collection change
                    > event?
                    >

                    >
                    > Well, the collection is a custom tree structure. I may add event listener
                    > to
                    > dataProvider (which is ArrayCollection), but this dataProvider has one
                    > item -
                    > root. If somebody adds another root i'd be notified but if it adds node
                    > deeper
                    > in the tree i won't be.
                    >
                    > I think, in order for it to work, i'd have to add this event listener to
                    > every
                    > node in the tree. What do you think about that? It's a bit messy and i'd
                    > rather
                    > look for something simpler.
                    >
                    > Any more ideas?

                    You could add listeners on each of the openItems. You'd have to have logic
                    in your itemClose handler to remove listeners from closed collections.
                    Alternatively, you could set up your custom collection to fire an event when
                    any part of it changes.

                    You might also try the getParent method of the defaultDataDescriptor on the
                    node on something like updateComplete for the tree. I'm thinking the tree
                    will have to update itself after the drop happens. I'm thinking that based
                    on the ID of the node, the server should already know the old parent ID, so
                    all you should actually need is the new parent ID.

                    HTH;

                    Amy