0 Replies Latest reply on Feb 1, 2010 7:29 PM by haigopi

    Flex Tree - leaf object height is overlapping.

    haigopi

      Hello folks,

         I am trying to build a tree component with an item renderer as below: The Text Area what I am adding as leaf node is overlapping on the next item branch node. As Tree extends List, I sent VariableRowHeight property to true. Some how tree is not treating this object as a leaf node it seems.

      Could you please guide me ??

       

      package my.renderers

      {

      import flash.display.DisplayObject;

       

      import mx.controls.TextArea;

      import mx.controls.Tree;

      import mx.controls.listClasses.ListBase;

      import mx.controls.treeClasses.TreeItemRenderer;

      import mx.controls.treeClasses.TreeListData;

       

       

      public class MyTreeItemRenderer extends TreeItemRenderer

      {

       

      public function MyTreeItemRenderer()

      {

      super();

      }

      override protected function commitProperties():void

      {

      super.commitProperties();

      }

      var textArea = new TextArea();

      override protected function createChildren():void

      {

      super.createChildren();

      textArea.width=200;

      textArea.height= 80;

      textArea.includeInLayout = true;

      }

       

      override public function set data(value:Object):void

      {

      super.data = value;

       

      var _tree:Tree = Tree(this.parent.parent);

      var tld:TreeListData= TreeListData(listData)

       

       

      if(!_tree.dataDescriptor.isBranch(value))

      {

      ListBase(this.parent.parent.parent.parent).rowHeight = textArea.height;

      trace("This is a Leaf, and so adding the Child Element" + value.toString());

      this.parent.parent.addChild(textArea);

      }

       

      if(_tree.dataDescriptor.isBranch(value))

      {

      if(_tree.contains(textArea))

      {

      trace("This is not a Leaf and so remove the Child Element");

      removeChild(DisplayObject(textArea));

      }

      }

      }

       

       

      override protected function updateDisplayList(

      unscaledWidth:Number, unscaledHeight:Number):void

              {

      super.updateDisplayList(unscaledWidth, unscaledHeight);

       

      var tld:TreeListData= TreeListData(listData)

      var _tree:Tree = Tree(this.parent.parent);

       

      if(_tree.dataDescriptor.isBranch(tld.item))

      {

      if(super.icon) {

      super.icon.visible=true;

      }

      if(super.label){

      super.label.visible=true;

      }

      }

      else

      {

      if(super.icon)

      super.icon.visible=false;

      if(super.label)

      super.label.visible=false;

      }

      }

      }

      }

      ---------------------------------------------------------------------------

      <my:MyTree

      variableRowHeight="true"

      indentation="0"

      defaultLeafIcon="{null}"

      folderClosedIcon="{null}"

      folderOpenIcon="{null}"

      width="100%" height="100%"

      dataProvider="{treeData}"

      showRoot="false"

      labelField="@label" />

      ----------------------------------------------------------------------------

      package my.controls

      {

      import flash.events.MouseEvent;

       

      import mx.controls.Tree;

      import mx.controls.listClasses.IListItemRenderer;

      import mx.core.ClassFactory;

       

      import my.renderers.MyTreeItemRenderer;

       

      /**

      * This class extends the Tree adding separator node capability. 

      */

      public class MyTree extends Tree

      {

      //----------------------------------------------------------------------

      //

      //  Constructor

      //

      //----------------------------------------------------------------------

       

      /**

      * Constructor.

      */

      public function MyTree()

      {

      super();

       

      itemRenderer = new ClassFactory(MyTreeItemRenderer);

      }

       

      //----------------------------------------------------------------------

      //

      //  Overridden methods

      //

      //----------------------------------------------------------------------

       

              /**

               * Override to prevent separator to be visually highlighted.

               */

              override protected function mouseOverHandler(event:MouseEvent):void

              {

      return;

              var item:IListItemRenderer = mouseEventToItemRenderer(event);

              if (item != null && !MyTreeItemRenderer(item).isSeparator)

              {

                      super.mouseOverHandler(event);

              }

              }

       

              /**

               * Override to prevent separator to be selected.

               */

              override protected function mouseDownHandler(event:MouseEvent):void

              {

      return;

              var item:IListItemRenderer = mouseEventToItemRenderer(event);

              if (item != null && !MyTreeItemRenderer(item).isSeparator)

              {

                      super.mouseDownHandler(event);

              }

              }

      }

      }