自定义flex tree的DataDescriptor

public class EnvironmentDataDescriptor extends DefaultDataDescriptor
	{
		private var logger:org.as3commons.logging.ILogger=LoggerFactory.getClassLogger(EnvironmentDataDescriptor);
				
		public function EnvironmentDataDescriptor()
		{
			super();
		}
				
		override public function getChildren(node:Object, model:Object=null):ICollectionView{
			if(node==null)
				return null;
			//logger.debug("getChildren:"+node.toString());
			if(!(node is IEnvTreeBase))
				throw new Error("EnvironmentDataDescriptor:getChildren error");
			if(node is EnvironmentGroupVO){
				return (node as EnvironmentGroupVO).envSet;
			}else if(node is EnvironmentVO){
				return (node as EnvironmentVO).portfolioSet;
			}else if(node is PortfolioVO){
				return (node as PortfolioVO).tradeSet;
			}else{
				return null;
			}
		}
		
		override public function hasChildren(node:Object, model:Object=null):Boolean{
			if(node==null)
				return false;
			if(!(node is IEnvTreeBase))
				throw new Error("EnvironmentDataDescriptor:hasChildren error");
			if(node is EnvironmentGroupVO){
				return (node as EnvironmentGroupVO).envSet != null;
			}else if(node is EnvironmentVO){
				return (node as EnvironmentVO).portfolioSet!=null&&(node as EnvironmentVO).portfolioSet.length>0;
			}else if(node is PortfolioVO){
				return (node as PortfolioVO).tradeSet!=null&&(node as PortfolioVO).tradeSet.length>0;
			}else{
				return false;
			}
		}
		
		override public function isBranch(node:Object, model:Object=null):Boolean{
			return hasChildren(node,model);
		}
		
		override public function getData(node:Object, model:Object=null):Object{
			if(node==null)
				return null;
			//logger.debug("getData:"+node.toString());
			if(!(node is IEnvTreeBase))
				throw new Error("EnvironmentDataDescriptor:getData error");
			if(node is EnvironmentGroupVO){
				return node;
			}else if(node is EnvironmentVO){
				return node;
			}else if(node is PortfolioVO){
				return node;
			}else if(node is Trade4TreeVO){
				return node;
			}else{
				return null;
			}
		}
	}
}

你可能感兴趣的:(tree,datadescriptor)