Hi if You can use arrayCollection you can use this class
just change the MainChapterListVO, SubChapterListVO to your "Data Class"
waht I do here is I have a arraycollection called MainChapterListVO
this holds data and a arraycollection named SubChapterListVO, the
SubChapterListVO also holds data and a arrayColection to, whit files,
these classes all have in commen a 'name' property so I can read it
form the tree as label see botom for tre code..
package no.umbrellaCorp.customer.customerView.bp
{
import mx.collections.ICollectionView;
import mx.controls.treeClasses.ITreeDataDescriptor;
import no.umbrellaCorp.bp.MainChapterListVO;
import no.umbrellaCorp.bp.SubChapterListVO;
public class FileSystemBPTreeDataDescriptor implements
ITreeDataDescriptor
{
public function getData(node:Object, model:Object=null):Object
{
return node;
}
public function hasChildren(node:Object,
model:Object=null):Boolean
{
if(node is MainChapterListVO || node is SubChapterListVO){
return true;
}else{
return false;
}
}
public function addChildAt(parent:Object, newChild:Object,
index:int, model:Object=null):Boolean
{
return false;
}
public function isBranch(node:Object, model:Object=null):Boolean
{
try {
if (node is Object) {
if (node.subColl.length > 0) {
return true;
}
}
}
catch (e:Error) {
trace("[Descriptor] exception checking for isBranch");
}
return false;
//return !(node is FileNode) && hasChildren(node);
}
public function removeChildAt(parent:Object, child:Object,
index:int, model:Object=null):Boolean
{
//FileSystemBPTreeDataDescriptor(parent).Items.slice(index,index);
return false;
}
public function getChildren(node:Object,
model:Object=null):ICollectionView
{
if(node is MainChapterListVO){
return MainChapterListVO(node).subColl;
}else{
return SubChapterListVO(node).subColl;
}
}
}
}
mx:Tree
<mx:VBox label="Maler" width="100%"
height="100%">
<mx:Tree id="bpTree"
dataProvider="{LicenseVOSingleton.instance.bpTreeColl}"
click="onBpTreeSelected(event);" labelField="name"
dataDescriptor="{new FileSystemBPTreeDataDescriptor()}"
iconField="fileType" width="100%" height="100%" />
</mx:VBox>
Cato
--- In [email protected], franto <[EMAIL PROTECTED]> wrote:
>
> Hey all,
>
> it's long time I've posted something here :) But I can't find answer
for my
> help, so I hope someone will help me here...
>
> I'm creating custom component which extends Tree. Structure must support
> different levels, but I cant use ArrayCollection or XMLListCollection.
> I think best way is write own ICollectionView class, because each
item of
> this collection should be type of my class, let's call class Data();
>
> So I've create class Data
> and create property call children:ICollectionView (for dataDescriptor
> getChildren)
>
> Now I want create dataProvider for my customcomponent in MXML
>
> <model:MyModel id="myModel">
> <model:dataProvider>
> <data:Data name="Main Item" importance="100" progress="0
> level="0">
> <data:Data name="Subitem 1" importance="33" progress="0"
> level="1"/>
> <data:Data name="Subitem 2" importance="33" progress="0"
> level="1"/>
> <data:Data name="Subitem 3" importance="34" progress="0"
> level="1"/>
> </data:Goal>
> </model:dataProvider>
> </model:MyModel >
>
> but this give me compile error: In initializer for 'children': multiple
> initializer values for target type mx.collections.ICollectionView.
>
> Does any know, how can I write this in MXML. Btw i have
> [DefaultProperty("children")] so when it was array, MXML works, but
with
> ICollectionView do not.
>
>
> Or maybe if you have better idea how to implement such component
based on
> Tree let me know. I appreciate links to some tutorials or resources.
>
> Thank you very much
>
> --
> --
> Franto Kormanak ([EMAIL PROTECTED])
> Owner & Senior RIA Developer
> at Flexets (http://www.flexets.com)
>
> blog: http://www.franto.com
> profile: http://www.linkedin.com/in/franto
> skype: franto.kormanak
>