0 Replies Latest reply on Jun 3, 2011 7:39 AM by YordanYanakiev

    Flex TreeItemRenderer issue with Height

    YordanYanakiev

      Hello.

      I went trought alot of nightmare nights with this TreeItemRenderer in forums, Stack Overflow, Expert-Exchange and etc., and i left without actually help on my issue. I hope i got it here finally.

       

      The idea is basically create an item for a Tree , and this item can have some buttons if it is not a branch, and theese buttons is destributed vertically within the item, just below the label.

       

      Here the piece of code making my days and nights nightmares.

       

      override protected function commitProperties():void

      {

      super.commitProperties();

       

       

      if( data.@idNode != null )

      isNode = data.@isNode == "true";

      else

      isNode = false;

       

      if( isNode )

      {

      if( data.@rooming != null )

      allowedB1 = data.@b1 == "true";

      else

      allowedB1 = false;

       

      if( data.@engineControl != null )

      allowedB1B2 = data.@b1b2 == "true";

      else

      allowedB1B2 = false;

       

      }

       

      if( isNode )

      {

      // color box

      var _color : uint = 0x000000;

      if( data.@busColor )

      _color = uint( data.@busColor );

       

      colorBox.graphics.beginFill( _color, 0.9 );

      colorBox.graphics.drawRect( 0, 0, 12, 6 );

      colorBox.graphics.endFill();

       

       

      var _buttonStackHeight : Number = 0;

       

       

      if( allowedB1 )

      _buttonStackHeight += 22;

       

      /*

      if( allowedB1B2 )

      _buttonStackHeight += 44;

      */

      _buttonStackHeight += 15;

      //buttonsHolder.visible        = _buttonStackHeight > 1;

       

      this.measuredHeight          = _buttonStackHeight +20;

      this.measuredMinHeight       = _buttonStackHeight +20;

      this.minHeight               = _buttonStackHeight +20;

      }

      else

      {

       

      //buttonsHolder.visible = false;

      this.measuredHeight          = 20;

      this.measuredMinHeight       = 20;

      this.minHeight               = 20;

       

      }

      }

       

      override protected function createChildren() : void

      {

      super.createChildren();

       

      mainCheckBox = new CheckBox();

      mainCheckBox.setStyle( "verticalAlign", "top" );

      mainCheckBox.addEventListener( MouseEvent.CLICK, checkBoxToggleHandler );

      addChild( mainCheckBox );

       

      unknownStateImage        = new Image();

      unknownStateImage.source = inner;

      unknownStateImage.addEventListener( MouseEvent.CLICK, imageToggleHandler );

      unknownStateImage.setStyle( "verticalAlign", "top" );

      addChild( unknownStateImage );

       

      colorBox = new UIComponent();

      addChild( colorBox );

       

      buttonsHolder = new VBox();

      addChild( buttonsHolder );

       

      btn1       = new Button();

      btn1.label = "b1";

      buttonsHolder.addChild( btn1 );

       

      btn2       = new Button();

      btn2.label = "b2";

      buttonsHolder.addChild( btn2 );

       

      btn3       = new Button();

      btn3.label = "b3";

      buttonsHolder.addChild( btn3 );

       

      }

       

      override protected function updateDisplayList( unscaledWidth : Number, unscaledHeight : Number ) : void

          {

      super.updateDisplayList( unscaledWidth, unscaledHeight );

       

              if( super.data )

              {

       

      if( data.@state == STATE_UNKNOWN )

      {

      unknownStateImage.x      = mainCheckBox.x +1;

      unknownStateImage.y      = mainCheckBox.y - ( imageHeight/2 );

      unknownStateImage.width  = imageWidth;

      unknownStateImage.height = imageHeight;

      }

      else

      {

      unknownStateImage.x      = 0;

      unknownStateImage.y      = 0;

      unknownStateImage.width  = 0;

      unknownStateImage.height = 0;

      }

       

      applyStandartObjectsProperties();

       

      buttonsHolder.visible = isNode;

      colorBox.visible      = isNode;

       

      if( isNode )

      {

      btn1.visible = allowedB1;

      //btn2.visible    = btn3.visible = allowedB1B2;

       

      var _buttonStackHeight : Number = 0;

      var _buttonsWidth      : Number = unscaledWidth - ( this.icon.x +6 );

       

      colorBox.x = super.icon.x + super.icon.width + 4;

      colorBox.y = 7;

       

      if( allowedB1 )

      {

      btn1.x      = 1;

      btn1.y      = _buttonStackHeight +1;

      btn1.height = 20;

      btn1.width  = _buttonsWidth;

       

      _buttonStackHeight += 21;

      }

       

      if( allowedB1B2 )

      {

      btn2.x      = 1;

      btn2.y      = _buttonStackHeight +1;

      btn2.height = 20;

      btn2.width  = _buttonsWidth;

       

      _buttonStackHeight += 21;

       

      btn3.x      = 1;

      btn3.y      = _buttonStackHeight +1;

      btn3.height = 20;

      btn3.width  = _buttonsWidth;

       

      _buttonStackHeight += 21;

      }

       

      _buttonStackHeight += 10;

       

      buttonsHolder.x       = this.icon.x;

      buttonsHolder.y       = 20 +1;

      buttonsHolder.height  = _buttonStackHeight +2;

      buttonsHolder.width   = _buttonsWidth +2;

      buttonsHolder.visible = true;

       

      }

      else

      {

      buttonsHolder.visible = false;

      }

      }

          }