6 Replies Latest reply on Aug 27, 2009 7:00 AM by sonrosado

    Spark DataGroup and Hierarchical Data

    sonrosado

      Can the Spark DataGroup be used with Hierarchical Data such as with XMLList?

       

      Thank you.

        • 1. Re: Spark DataGroup and Hierarchical Data
          Shongrunden Adobe Employee

          DataGroup requires that the dataProvider be an IList.  You can wrap an XMLList in an XMLListCollection to bring this data in to a spark DataGroup.

           

          Here is an example of working with XML/XMLList/XMLListCollection in DataGroup with a simple custom item renderer:

           

          <s:Application 
              xmlns:fx="http://ns.adobe.com/mxml/2009" 
              xmlns:s="library://ns.adobe.com/flex/spark" 
              creationComplete="init()">
              <fx:Script>
                  <![CDATA[
                      import mx.collections.XMLListCollection;
          
                      private var books:XML = 
                          <books>
                          <book publisher="Addison-Wesley" name="Design Patterns" />
                          <book publisher="Addison-Wesley" name="Test Driven Development" />
                          <book publisher="O'Reilly Media" name="The Cathedral & the Bazaar" />
                          <book publisher="O'Reilly Media" name="Unit Test Frameworks" />
                          </books>;
                        
                        public function init():void {
                            // books.book is an XMLList, but DataGroup requires the dataProvider
                            // to be an IList so we wrap it in an XMLListCollection
                            dg.dataProvider = new XMLListCollection(books.book);
                        }
                  ]]>
              </fx:Script>
              
              <s:DataGroup id="dg">
                  <s:layout>
                      <s:VerticalLayout />
                  </s:layout>
                  <s:itemRenderer>
                      <fx:Component>
                          <s:ItemRenderer>
                              <s:states>
                                  <s:State name="normal" />
                                  <s:State name="disabled" />
                              </s:states>
                              
                              <s:SimpleText text="Name: {data.@name}" />
                          </s:ItemRenderer>
                      </fx:Component>
                  </s:itemRenderer>
              </s:DataGroup>
          
          </s:Application>
          
          
          
          1 person found this helpful
          • 2. Re: Spark DataGroup and Hierarchical Data
            sonrosado Level 1

            Great example. Thank you!

             

            Now, my question was more related to the hierarchical data management capability in DataGroup.

            I need to manage branches and nodes, to reproduce part of the Halo Menu functionality, in a new SparkMenu component.

            Do you think DataGroup might be a good staring point?

            Thank you again.

            • 3. Re: Spark DataGroup and Hierarchical Data
              Shongrunden Adobe Employee

              I believe you might find this post a good place to start: http://forums.adobe.com/message/2160631

              • 4. Re: Spark DataGroup and Hierarchical Data
                rfrishbe Level 3

                I do think DataGroup is a great starting place. However, there are some mismatches with the type of object expected.  DataGroup works on IList which is an index based approach.  What you're going to end up with is a heirarchal collection view.  There are really two ways we've solved this in the past.  One is to create a new data-type instead of IList, something like IHierarchicalCollectionView.  The other is to create a "data descriptor" (like IMenuDataDescriptor) that can interpret the "heirarchal nature" of a particular node.  You could do something like that for a Spark menu--create a data descriptor similar to our DefaultDataDescriptor--but rather than working off and returning ICollectionViews, use ILists.

                 

                Hope that helps,

                Ryan

                • 5. Re: Spark DataGroup and Hierarchical Data
                  Flex harUI Adobe Employee

                  IMenuDataDescriptor and IHierarchicalCollectionView are there for "utmost generality".  If you make assumptions about the data set, the job gets much easier, although someone may end up unhappy because you can't handle their particular data set.

                   

                  In Spark, the List class takes an IList instead of the ICollectionView that Halo List takes because we rarely, if ever, saw anyone's data set leverage the power of ICollectionView (non-random-access data sets) and it made our code simple and fast if we didn't have to worry about ICollectionView.

                   

                  I have yet to see a Menu use a DataProvider that isn't a simple object graph or XML tree.  If you restrict yourself to one or both of those two things, you may not need IMenuDataDescriptor and IHeirarchicalCollection constructs in your code.  Note that I wouldn't make the same recommendation for Tree because I have seen folks need to "unwind" a single data object as a hierarchy, but I haven't seen it for menu

                   

                  Alex Harui

                  Flex SDK Developer

                  Adobe Systems Inc.

                  Blog: http://blogs.adobe.com/aharui

                  1 person found this helpful
                  • 6. Re: Spark DataGroup and Hierarchical Data
                    sonrosado Level 1

                    Thank you very much for your answer!!