3 Replies Latest reply on Oct 8, 2009 9:28 AM by leybniz

    Please Help!!!

    aretap

      I'm trying to create a general component LevelTree which will inherit from mx.controls.Tree and will have a new public property itemRenderers:Array, where renderer with an index 0 will be used for showing the first level of the tree, renderer with an index 1 for the second level of the tree etc. Using of such a tree will than look like this:

      <view:LevelTree
      dataProvider="{collection}"
      itemRenderers="{
      [
      DeliveryWaysRenderer,
      DepartmentsRenderer,
      EmployeesRenderer
      ]}" />
      As a dataProvider for the tree I'm using a collection from a file collection.txt assuming, that listed structure is coming from an external system and can't be changed. The EmployeesRenderer is DataGrid representing one node of the tree. The result should not be much different from the attached picture.

      Can anyone help me please?

        • 1. Re: Please Help!!!
          leybniz Level 4

          Unfortunately, your way it will be too complicated to implement, since itemRenderer pattern assumes only one renderer class to be used, the only feasable way for you to implement your need is to have one renderer class incapsulating behaviour of your three classes, via states for example, each role for your item renderer could be defined as a separate state of your ItemRendererClass.

          • 2. Re: Please Help!!!
            aretap Level 1

            Thank you Alex, I've got this assignment as an entry level programmer so maybe I explained it differently. Was I clear on what I was trying to do? Because what you suggested to do is a little advanced and like you said unnecessarily complicated although that assignment was a practical example.

            David

            • 3. Re: Please Help!!!
              leybniz Level 4

              Ahoj!

               

              Your intention is clear, but implementation approach somewhat strange..

              the only way I see this thing working is to have one ItemRendererClass instead of 3 of them. I see your difficulty to change data structure you have

              in your txt file, in order to ease the use of it you'll have to produce XML structure based on it and pass that XML tree as dataProvider to the mx:Tree.

               

              Another important point is to have clear evidence for each node which level it belongs to, say you might have an attribute called level, having tree

              of them "firm", "department", "employee". And then inside your ItemRendererClass switch visuals depending on that level attribute value.

               

              I'd recommend you to digg into itemRenderer concept from the Flex help, and master it's usage via overriding it's data property like:

               

              override public function set data(value:*):void {

                   super.data = value;

               

                   switch (String(data.@level)) {

                        case "firm" : // Show visuals set #1

                        break;

               

                        case "department" : // Show visuals set #2

                        break;

               

                        case "employee" : // Show visuals set #3

                        break;

                   }

               

              }