<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (c) 2007 FlexLib Contributors.  See:
     http://code.google.com/p/flexlib/wiki/ProjectContributors

     Permission is hereby granted, free of charge, to any person obtaining a copy of
     this software and associated documentation files (the "Software"), to deal in
     the Software without restriction, including without limitation the rights to
     use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
     of the Software, and to permit persons to whom the Software is furnished to do
     so, subject to the following conditions:

     The above copyright notice and this permission notice shall be included in all
     copies or substantial portions of the Software.

     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     SOFTWARE.
-->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               xmlns:flexlib="http://code.google.com/p/flexlib/"
               creationComplete="handleCreationComplete()">
  <s:layout>
    <s:HorizontalLayout />
  </s:layout>
  <fx:Style>
		.datagridStyle
		{
		   alternatingItemColors: #666666, #666666;
		   rollOverColor: #ff9933;
		   textRollOverColor: #000000;
		   selectionColor: #ff6600;
		   color: #ffffff;
		   textSelectedColor: #0b333c;
		}
		
		.dataGridHeader
		{
			color: #000000;
		}
	</fx:Style>

  <fx:Script>
    <![CDATA[
      import vo.TreeGridSampleVO;

      import mx.collections.ArrayCollection;

      [Bindable]
      private var dataProviderObject:TreeGridSampleVO;

      [Bindable]
      private var dataProviderArrayCollection:ArrayCollection;

      [Embed(source="assets/status.png")]
      public var statusIcon:Class;

      public function handleCreationComplete():void
      {
          dataProviderObject = new TreeGridSampleVO();

          var sampleVo1:TreeGridSampleVO = new TreeGridSampleVO();
          sampleVo1.id = 1;
          sampleVo1.name = "Companies";
          sampleVo1.type = "COMPANIES";
          sampleVo1.desc = "All companies";
          sampleVo1.statusIcon = "statusIcon";
          sampleVo1.children = new ArrayCollection();

          var sampleVo1_1:TreeGridSampleVO = new TreeGridSampleVO();
          sampleVo1_1.id = 2;
          sampleVo1_1.name = "Macromedia";
          sampleVo1_1.type = "COMPANY";
          sampleVo1_1.desc = "Flash, Flex, Director, ...";
          sampleVo1_1.statusIcon = "statusIcon";
          sampleVo1_1.children = new ArrayCollection();

          var sampleVo1_2:TreeGridSampleVO = new TreeGridSampleVO();
          sampleVo1_2.id = 3;
          sampleVo1_2.name = "Oracle";
          sampleVo1_2.type = "COMPANY";
          sampleVo1_2.desc = "Databases";
          sampleVo1_2.statusIcon = "statusIcon";
          sampleVo1_2.children = null;

          var sampleVo1_3:TreeGridSampleVO = new TreeGridSampleVO();
          sampleVo1_3.id = 4;
          sampleVo1_3.name = "Microsoft";
          sampleVo1_3.type = "COMPANY";
          sampleVo1_3.desc = "Windows, Office, Visual .NET, ...";
          sampleVo1_3.statusIcon = "statusIcon";
          sampleVo1_3.children = null;

          var sampleVo1_4:TreeGridSampleVO = new TreeGridSampleVO();
          sampleVo1_4.id = 5;
          sampleVo1_4.name = "Adobe";
          sampleVo1_4.type = "COMPANY";
          sampleVo1_4.desc = "Photoshop, Illustrator, LiveCycle, ...";
          sampleVo1_4.statusIcon = "statusIcon";
          sampleVo1_4.children = null;

          sampleVo1.children.addItem( sampleVo1_1 );
          sampleVo1.children.addItem( sampleVo1_2 );
          sampleVo1.children.addItem( sampleVo1_3 );
          sampleVo1.children.addItem( sampleVo1_4 );

          var sampleVo2_1:TreeGridSampleVO = new TreeGridSampleVO();
          sampleVo2_1.id = 6;
          sampleVo2_1.name = "Sector 01";
          sampleVo2_1.type = "SECTOR";
          sampleVo2_1.desc = "Description for sector 01";
          sampleVo2_1.statusIcon = "statusIcon";
          sampleVo2_1.children = null;

          var sampleVo2_2:TreeGridSampleVO = new TreeGridSampleVO();
          sampleVo2_2.id = 7;
          sampleVo2_2.name = "Sector 02";
          sampleVo2_2.desc = "Description for sector 02";
          sampleVo2_2.type = "SECTOR";
          sampleVo2_2.statusIcon = "statusIcon";
          sampleVo2_2.children = new ArrayCollection();

          var sampleVo2_3:TreeGridSampleVO = new TreeGridSampleVO();
          sampleVo2_3.id = 8;
          sampleVo2_3.name = "Sector 03";
          sampleVo2_3.type = "SECTOR";
          sampleVo2_3.desc = "Description for sector 03";
          sampleVo2_3.statusIcon = "statusIcon";
          sampleVo2_3.children = null;

          sampleVo1_1.children.addItem( sampleVo2_1 );
          sampleVo1_1.children.addItem( sampleVo2_2 );
          sampleVo1_1.children.addItem( sampleVo2_3 );

          var sampleVo3_1:TreeGridSampleVO = new TreeGridSampleVO();
          sampleVo3_1.id = 9;
          sampleVo3_1.name = "Class 01";
          sampleVo3_1.type = "CLASS";
          sampleVo3_1.desc = "Description for class 01";
          sampleVo3_1.statusIcon = "statusIcon";
          sampleVo3_1.children = new ArrayCollection();

          var sampleVo3_2:TreeGridSampleVO = new TreeGridSampleVO();
          sampleVo3_2.id = 10;
          sampleVo3_2.name = "Class 02";
          sampleVo3_2.type = "CLASS";
          sampleVo3_2.desc = "Description for class 02";
          sampleVo3_2.statusIcon = "statusIcon";
          sampleVo3_2.children = null;

          sampleVo2_2.children.addItem( sampleVo3_1 );
          sampleVo2_2.children.addItem( sampleVo3_2 );

          for ( var i:int = 0; i < 500; i++ )
          {
              var sampleVo4_3:TreeGridSampleVO = new TreeGridSampleVO();
              sampleVo4_3.id = 11 + i;
              sampleVo4_3.name = "Sub Class " + (1 + i);
              sampleVo4_3.type = "SUBCLASS";
              sampleVo4_3.desc = "Description for sub class " + (1 + i);
              sampleVo4_3.statusIcon = "statusIcon";
              sampleVo4_3.children = null;

              sampleVo3_1.children.addItem( sampleVo4_3 );
          }

          dataProviderObject = sampleVo1;

          sampleVo1_1 = new TreeGridSampleVO();
          sampleVo1_1.id = 2;
          sampleVo1_1.name = "Macromedia";
          sampleVo1_1.type = "COMPANY";
          sampleVo1_1.desc = "Flash, Flex, Director, ...";
          sampleVo1_1.statusIcon = "statusIcon";
          sampleVo1_1.children = new ArrayCollection();

          sampleVo1_2 = new TreeGridSampleVO();
          sampleVo1_2.id = 3;
          sampleVo1_2.name = "Oracle";
          sampleVo1_2.type = "COMPANY";
          sampleVo1_2.desc = "Databases";
          sampleVo1_2.statusIcon = "statusIcon";
          sampleVo1_2.children = null;

          sampleVo1_3 = new TreeGridSampleVO();
          sampleVo1_3.id = 4;
          sampleVo1_3.name = "Microsoft";
          sampleVo1_3.type = "COMPANY";
          sampleVo1_3.desc = "Windows, Office, Visual .NET, ...";
          sampleVo1_3.statusIcon = "statusIcon";
          sampleVo1_3.children = null;

          sampleVo1_4 = new TreeGridSampleVO();
          sampleVo1_4.id = 5;
          sampleVo1_4.name = "Adobe";
          sampleVo1_4.type = "COMPANY";
          sampleVo1_4.desc = "Photoshop, Illustrator, LiveCycle, ...";
          sampleVo1_4.statusIcon = "statusIcon";
          sampleVo1_4.children = null;

          dataProviderArrayCollection = new ArrayCollection();
          dataProviderArrayCollection.addItem( sampleVo1_1 );
          dataProviderArrayCollection.addItem( sampleVo1_2 );
          dataProviderArrayCollection.addItem( sampleVo1_3 );
          dataProviderArrayCollection.addItem( sampleVo1_4 );

          sampleVo2_1 = new TreeGridSampleVO();
          sampleVo2_1.id = 6;
          sampleVo2_1.name = "Sector 01";
          sampleVo2_1.type = "SECTOR";
          sampleVo2_1.desc = "Description for sector 01";
          sampleVo2_1.statusIcon = "statusIcon";
          sampleVo2_1.children = null;

          sampleVo2_2 = new TreeGridSampleVO();
          sampleVo2_2.id = 7;
          sampleVo2_2.name = "Sector 02";
          sampleVo2_2.desc = "Description for sector 02";
          sampleVo2_2.type = "SECTOR";
          sampleVo2_2.statusIcon = "statusIcon";
          sampleVo2_2.children = new ArrayCollection();

          sampleVo2_3 = new TreeGridSampleVO();
          sampleVo2_3.id = 8;
          sampleVo2_3.name = "Sector 03";
          sampleVo2_3.type = "SECTOR";
          sampleVo2_3.desc = "Description for sector 03";
          sampleVo2_3.statusIcon = "statusIcon";
          sampleVo2_3.children = null;

          sampleVo1_1.children.addItem( sampleVo2_1 );
          sampleVo1_1.children.addItem( sampleVo2_2 );
          sampleVo1_1.children.addItem( sampleVo2_3 );

          sampleVo3_1 = new TreeGridSampleVO();
          sampleVo3_1.id = 9;
          sampleVo3_1.name = "Class 01";
          sampleVo3_1.type = "CLASS";
          sampleVo3_1.desc = "Description for class 01";
          sampleVo3_1.statusIcon = "statusIcon";
          sampleVo3_1.children = new ArrayCollection();

          sampleVo3_2 = new TreeGridSampleVO();
          sampleVo3_2.id = 10;
          sampleVo3_2.name = "Class 02";
          sampleVo3_2.type = "CLASS";
          sampleVo3_2.desc = "Description for class 02";
          sampleVo3_2.statusIcon = "statusIcon";
          sampleVo3_2.children = null;

          sampleVo2_2.children.addItem( sampleVo3_1 );
          sampleVo2_2.children.addItem( sampleVo3_2 );

          for ( i = 0; i < 500; i++ )
          {
              sampleVo4_3 = new TreeGridSampleVO();
              sampleVo4_3.id = 11 + i;
              sampleVo4_3.name = "Sub Class " + (1 + i);
              sampleVo4_3.type = "SUBCLASS";
              sampleVo4_3.desc = "Description for sub class " + (1 + i);
              sampleVo4_3.statusIcon = "statusIcon";
              sampleVo4_3.children = null;

              sampleVo3_1.children.addItem( sampleVo4_3 );

          }
      }
      ]]>
  </fx:Script>

  <fx:Declarations>


    <fx:XML xmlns=""
            id="dataProviderXML"
            source="/test.xml" />

    <fx:XMLList id="dataProviderXMLList">
      <node id="1"
            name="Companies"
            type="COMPANIES"
            desc="All Companies"
            statusIcon="statusIcon">
        <node id="2"
              name="Adobe"
              type="COMPANY"
              desc="Adobe inc."
              statusIcon="statusIcon">
          <node id="5"
                name="Adobe Consulting"
                type="COMPANY"
                desc="Adobe (formerly macromedia)"
                statusIcon="statusIcon" />
          <node id="6"
                name="EDBU"
                type="COMPANY"
                desc="Database company"
                statusIcon="statusIcon" />
        </node>
        <node id="3"
              name="Macromedia"
              type="COMPANY"
              desc="Adobe (formerly macromedia)"
              statusIcon="statusIcon" />
        <node id="4"
              name="Oracle"
              type="COMPANY"
              desc="Database company"
              statusIcon="statusIcon" />
      </node>
    </fx:XMLList>
  </fx:Declarations>

  <s:VGroup width="100%" height="100%">
    <s:Label text="dataProvider: Nested Strong Typed Object, ShowRoot: false"
             fontSize="10"
             fontWeight="bold" />
    <flexlib:TreeGrid id="treeGrid1"
                      width="100%"
                      height="100%"
                      dataProvider="{ dataProviderObject }"
                      showRoot="false"
                      paddingLeft="25"
                      verticalTrunks="none"
                      disclosureClosedIcon="@Embed(source='assets/treeAssets.swf#TreeDisclosureClosed')"
                      disclosureOpenIcon="@Embed(source='assets/treeAssets.swf#TreeDisclosureOpen')">

      <flexlib:columns>
        <flexlib:TreeGridColumn dataField="name" />
        <mx:DataGridColumn dataField="desc" />
      </flexlib:columns>

    </flexlib:TreeGrid>
    <mx:Button label="Close All nodes" click="treeGrid1.closeAllItems();" />
  </s:VGroup>

  <s:VGroup width="100%" height="100%">
    <s:Label text="dataProvider: Nested Strong typed object, ShowRoot: true"
             fontSize="10"
             fontWeight="bold" />
    <flexlib:TreeGrid styleName="datagridStyle"
                      headerStyleName="dataGridHeader"
                      width="100%"
                      height="100%"
                      dataProvider="{ dataProviderObject }"
                      paddingLeft="25"
                      verticalTrunks="normal"
                      rowHeight="30"
                      disclosureClosedIcon="@Embed(source='assets/tree_openNode.png')"
                      disclosureOpenIcon="@Embed(source='assets/tree_closeNode.png')"
                      folderClosedIcon="@Embed(source='assets/status.png')"
                      folderOpenIcon="@Embed(source='assets/status.png')"
                      iconField="statusIcon">

      <flexlib:columns>
        <flexlib:TreeGridColumn dataField="name" />
        <mx:DataGridColumn dataField="desc" />
      </flexlib:columns>

    </flexlib:TreeGrid>
  </s:VGroup>

  <s:VGroup width="100%" height="100%">
    <s:Label text="dataProvider: External XML file"
             fontSize="10"
             fontWeight="bold" />
    <flexlib:TreeGrid styleName="datagridStyle"
                      headerStyleName="dataGridHeader"
                      width="100%"
                      height="100%"
                      dataProvider="{ dataProviderXML }"
                      paddingLeft="25"
                      verticalTrunks="normal"
                      disclosureClosedIcon="@Embed(source='assets/tree_openNode.png')"
                      disclosureOpenIcon="@Embed(source='assets/tree_closeNode.png')">

      <flexlib:columns>
        <flexlib:TreeGridColumn dataField="@name" headerText="name" />
        <mx:DataGridColumn dataField="@desc" headerText="desc" />
      </flexlib:columns>

    </flexlib:TreeGrid>
  </s:VGroup>

  <s:VGroup width="100%" height="100%">
    <s:Label text="dataProvider: ArrayCollection"
             fontSize="10"
             fontWeight="bold" />
    <flexlib:TreeGrid styleName="datagridStyle"
                      headerStyleName="dataGridHeader"
                      width="100%"
                      height="100%"
                      dataProvider="{ dataProviderArrayCollection }"
                      paddingLeft="25"
                      verticalTrunks="none"
                      disclosureClosedIcon="@Embed(source='assets/treeAssets.swf#Tree_folderClosedIcon')"
                      disclosureOpenIcon="@Embed(source='assets/treeAssets.swf#Tree_folderOpenIcon')">

      <flexlib:columns>
        <flexlib:TreeGridColumn dataField="name" />
        <mx:DataGridColumn dataField="desc" />
      </flexlib:columns>

    </flexlib:TreeGrid>
  </s:VGroup>

  <s:VGroup width="100%" height="100%">
    <s:Label text="dataProvider: XMLList "
             fontSize="10"
             fontWeight="bold" />
    <flexlib:TreeGrid styleName="datagridStyle"
                      headerStyleName="dataGridHeader"
                      width="100%"
                      height="100%"
                      dataProvider="{ dataProviderXMLList }"
                      paddingLeft="25"
                      verticalTrunks="none"
                      disclosureClosedIcon="@Embed(source='assets/tree_openNode.png')"
                      disclosureOpenIcon="@Embed(source='assets/tree_closeNode.png')">

      <flexlib:columns>
        <flexlib:TreeGridColumn dataField="@name" headerText="name" />
        <mx:DataGridColumn dataField="@desc" headerText="desc" />
      </flexlib:columns>

    </flexlib:TreeGrid>
  </s:VGroup>

</s:Application>
