« Bullet Point Characters Incorrect for Word Documents in OpenOffice MacRockstar to Offer Flash Game Counterpart to GTA for Money Laundering »

8 comments

  1. § Richard Leggett® Email said on :
    I mention ITreeDataDescriptor2 in the post, here's how I'd implement those extra 3 methods it defines:


    public function getParent(node:Object, collection:ICollectionView, model:Object = null):Object
    {
      return (node as FolderItem).parentFolder;
    }

    public function getNodeDepth(node:Object, iterator:IViewCursor, model:Object = null):int
    {
      var folderItem:FolderItem = node as FolderItem;

      var depth:int=0;
      var parentFolder:Folder = folderItem.parentFolder;

      while(parentFolder != null)
      {
        depth++;
        parentFolder = parentFolder.parentFolder;
      }

      return depth;
    }

    public function getHierarchicalCollectionAdaptor(hierarchicalData:ICollectionView,
    uidFunction:Function,
    openItems:Object,
    model:Object = null):ICollectionView
    {
      return new HierarchicalCollectionView(hierarchicalData,
    this,
    uidFunction,
    openItems);
    }
  2. § Brian Email said on :
    Can you review your ITreeDataDescriptor2 implementation (specifically getHierarchicalCollectionAdaptor())? The constructor for HierarchicalCollectionView takes only two parameters. IHierarchicalData is the first parameter, and ICollectionView does not extend IHierarchicalData.
  3. § Richard Leggett® Email said on :
    Hi Brian, I have mx.controls.treeClasses.HierarchicalCollectionView open in a text editor, I can see the constructor takes 4 parameters. You may be referring to the "other" HierarchicalCollectionView in the mx.collections package, yep, it's that crazy but it can be explained...

    As to which to use, the Tree class imports the (bundled) one that takes 4 parameters (you can find it in the mx.controls.treeClasses package.The other one in mx.collections.* does take 2 params but it is not part of the standard Flex SDK, it is found in Flex Builder Professional's "Data Visualisation Components" SWC, and I would guess that one is used when you are defining a DataDescriptor for the AdvancedDataGrid, not the Tree.

    You can see the notice about it being for the Data Visualization Components only at the top of the livedocs page for it:

    http://livedocs.adobe.com/flex/gumbo/langref/mx/collections/HierarchicalCollectionView.html

    It gets more confusing to the developer though because the "standard"/treeClasses HierarhicalCollectionView has an [ExcludeClass] meta-tag which I believe prevents FlexBuilder from "auto-importing" it, and also from it appearing in the Livedocs, even though you can import and use it manually. Presumably this is because you don't need to use it yourself, the Tree is the only thing that actually needs to use it.
  4. § Brian Email said on :
    Disregard previous comment; I did not realize that there are two HierarchicalCollectionView(s):

    mx.collections.HierarchicalCollectionView
    mx.controls.treeClasses.HierarchicalCollectionView

    I'm sure there is a good reason for naming a "collection" a "view", but that's a different question for a different day.

    Thanks.
  5. § Stu Email said on :
    Hey Richard,

    I have rewritten some of your code for use with an XMLList/XMLListCollection datasource.

    Below are the rewritten filterFunction, getChildren and hasChildren functions:

    public function filterFunction(node:XML):Boolean
    {
    //Set searchString
    searchString = searchString.toLowerCase();

    //Determine if node or a descendant node contains searchString
    if(node.@name.toString().toLowerCase().indexOf(searchString) != -1 ||
    node.*.(@name.toString().toLowerCase().indexOf(searchString) != -1).length() > 0) return true;

    //Walk up the tree to see if predecessors contain the search string
    var pre:XML = node.parent();
    while(pre != null){
    if(pre.@name.toString().toLowerCase().indexOf(searchString) != -1){
    return true;
    }
    pre = pre.parent();
    }
    return false;
    }

    public function getChildren(node:Object, model:Object=null):ICollectionView
    {
    var children:XMLListCollection = new XMLListCollection();
    if(filter == null || filter.searchString == null || filter.searchString == "")
    {
    var root:XML = node as XML;
    if(root.children().length() > 0) return new XMLListCollection(root.children());
    else return null;
    }
    else if(node is XML)
    {
    //Filter node
    var item:XML = node as XML;
    for each(var child:XML in item.children())
    {
    if(filter.filterFunction(child))
    children.addItem(child);
    }
    }
    return children;
    }

    public function hasChildren(node:Object, model:Object=null):Boolean
    {
    return XML(node).children().length() > 0;
    }

    When performing a search I'm using the following code:

    MyDescriptor(tree.dataDescriptor).filter.searchString=txtSearch.text;
    tree.invalidateList();
    expandAll(); //expands all tree nodes

    This seems to work fine when the search results contain only leaf nodes. If however a folder is included in the search results I get a stack overflow error at line 147 of XMLListAdapter.as which returns the source of an XMLList.

    I can only assume that something is screwed with respect to the HierarchicalCollectionView or ICollectionView.

    Have you got any idea what is going on here?

    Cheers,
    Stu.
  6. § Tom Email said on :
    How can I filter hierarchical datat multiple columns in an Advanced datagrid using the above?

    Where can i get the below imports from , i meand the code?
    thanks,
    Tom
  7. § Tom Email said on :
    import com.domain.app.model.Asset;
    import com.domain.app.model.Folder;
    import com.domain.app.model.FolderTypes;
    import com.domain.app.model.Slide;

    thanks,
    Tom
  8. § Rashmi Email said on :
    Hi.. Thanks for this.. A very good explanation about ITreeDataDescriptor.

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
Contact. ©2010 by Richard Leggett. blog software / UK hosts / blog ads.
Design & icons by N.Design Studio. Skin by Tender Feelings / Evo Factory.