2 Replies Latest reply on Aug 13, 2007 11:00 AM by deepa subramaniam (adobe)

    Empty Tree Node

    Fidoogle
      I have a Tree in which a user can drag children and move them to another folder (). When a user drags the last child out of a folder, the folder instantly turns into a child, rather than remaining a folder. Then the user cannot drag an item back into this child (originally a folder) because that child is not longer a folder and children can't be dragged into other children. Does anyone know how to force a folder to remain a folder even when that folder is empty? Thank you.
        • 1. Empty Tree Node
          joan_lafferty Adobe Employee
          Yes, we see the need for this functionality and there is a bug logged for this specific use case.
          https://bugs.adobe.com/jira/browse/SDK-11281

          It's deferred for now, however. I"ll post more info if I can find some.

          Joan
          • 2. Empty Tree Node
            deepa subramaniam (adobe) Level 2
            Hello -

            If you take a look at the Tree property, dataDescriptor, you'll see that its a property that implements the ITreeDataDescriptor interface. This interface describes the contract that the Tree uses to parse the data bound to it. You'll notice there is a method called isBranch() which, given a node of data, returns whether that node should be treated as a branch node or a leaf node.

            In your example, when the last node is removed from a branch node via a successful drag and drop action, we want that node to still be treated as a branch. All you have to do is extend Tree and modify the dragCompleteHandler() event to do this. I'm copying and pasting my code below. You'll see that before I call super.dragCompleteHandler() I check to see if the parent of the item being dragged is dragging its last child, in which case we force that parent node to stay a branch by setting the isBranch attribute to true. I'm assuming the data is XML but if your data is in Array form, you can still do something similar.

            Cheers,
            Deepa Subramaniam
            Flex Framework

            // ActionScript file
            package
            {
            import mx.controls.Tree;
            import mx.events.DragEvent;
            import mx.collections.ICollectionView;

            public class myTree extends Tree
            {
            public function myTree()
            {
            super();
            }

            override protected function dragCompleteHandler(event:DragEvent):void
            {
            var parent:*;
            var childCollection:ICollectionView;
            var items:Array = event.dragSource.dataForFormat("treeItems") as Array;
            for (var i:int = 0; i < items.length; i++)
            {
            parent = getParentItem(items );
            if (parent)
            {
            childCollection = dataDescriptor.getChildren(parent);
            if (childCollection.length == 1)
            {
            //we are removing the last child of this parent folder,
            //we want to make sure it appears as a branch
            parent.@isBranch = true;
            }
            }
            }
            super.dragCompleteHandler(event);
            }
            }
            }