Показать сообщение отдельно
Старый 04.04.2009, 18:44
wvxvw вне форума Посмотреть профиль Отправить личное сообщение для wvxvw Найти все сообщения от wvxvw
  № 5  
Ответить с цитированием
wvxvw
Modus ponens
 
Аватар для wvxvw

модератор форума
Регистрация: Jul 2006
Адрес: #1=(list #1#)
Сообщений: 8,049
Записей в блоге: 38
А, хотя вот, собственно, сделал, но это не полная имплементация (курсор, сортировку и т.п. нужно доделать, но как подтверждение концепции - работает
Код:
<?xml version="1.0" encoding="utf-8"?>
<!-- Tree control example. -->
<mx:Application 
	xmlns:mx="http://www.adobe.com/2006/mxml"
	applicationComplete="filterTreeProvider()">

    <mx:Script>
        <![CDATA[
			import mx.collections.XMLListCollection;
			import CustomTreeDataDescriptor;
			
            [Bindable]
            public var selectedNode:XML;

            // Event handler for the Tree control change event.
            public function treeChanged(event:Event):void
			{
                selectedNode=Tree(event.target).selectedItem as XML;
            }
			
			public function filterTreeProvider():void
			{
				trace(myTree.dataDescriptor);
				(myTree.dataProvider as XMLListCollection).filterFunction = treeFilterFunction;
				(myTree.dataProvider as XMLListCollection).refresh();
			}
			
			private function treeFilterFunction(item:Object):Boolean
			{
				trace("treeFilterFunction", item is XML);
				if(item.hasOwnProperty("@label")) return true;
				return false;
			}
			
        ]]>
    </mx:Script>

    <mx:XMLList id="treeData">
        <node label="Mail Box">
            <node label="Inbox">
                <node label="Marketing"/>
                <node label="Product Management"/>
                <node label="Personal"/>
            </node>
            <node label="Outbox">
                <node label="Professional"/>
                <node label="Personal"/>
            </node>
            <node label="Spam"/>
            <node label="Sent"/>
<!-- этот узел не будет отображен т.как не пройдет валидацию у CustomTreeDataDescriptor -->
            <foo anotherAttribute="Sent"/>
        </node>    
    </mx:XMLList>

    <mx:Panel title="Tree Control Example" height="75%" width="75%" 
        paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">

        <mx:Label width="100%" color="blue" 
            text="Select a node in the Tree control."/>

        <mx:HDividedBox width="100%" height="100%">
            <mx:Tree id="myTree" width="50%" height="100%" labelField="@label" 
				dataDescriptor="{new CustomTreeDataDescriptor()}"
                showRoot="false" dataProvider="{treeData}" change="treeChanged(event)"/>
            <mx:TextArea height="100%" width="50%"
                text="Selected Item: {selectedNode.@label}"/>
        </mx:HDividedBox>
        
    </mx:Panel>
</mx:Application>
Код:
package  
{
	import mx.collections.ICollectionView;
	import mx.collections.ListCollectionView;
	import mx.collections.XMLListCollection;
	import mx.controls.treeClasses.ITreeDataDescriptor;
	
	/**
	* CustomTreeDataDescriptor class.
	* @author wvxvw
	* @langVersion 3.0
	* @playerVersion 10.0.12.36
	*/
	public class CustomTreeDataDescriptor implements ITreeDataDescriptor
	{
		//--------------------------------------------------------------------------
		//
		//  Public properties
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Protected properties
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Private properties
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Cunstructor
		//
		//--------------------------------------------------------------------------
		public function CustomTreeDataDescriptor() 
		{
			super();
			
		}
		
		/* INTERFACE mx.controls.treeClasses.ITreeDataDescriptor */
		
		public function getChildren(node:Object, model:Object = null):ICollectionView
		{
			return new ListCollectionView(validateList(node));
		}
		
		public function hasChildren(node:Object, model:Object = null):Boolean
		{
			if ((node as XML).*.length()) return true;
			return false;
		}
		
		public function isBranch(node:Object, model:Object = null):Boolean
		{
			if (validateNode(node) && (node as XML).*.length()) return true;
			return false;
		}
		
		public function getData(node:Object, model:Object = null):Object
		{
			//trace("getData", arguments);
			return node;
		}
		
		public function addChildAt(parent:Object, newChild:Object, index:int, 
												model:Object = null):Boolean
		{
			//trace("addChildAt", arguments);
			return false;
		}
		
		public function removeChildAt(parent:Object, child:Object, index:int, 
												model:Object = null):Boolean
		{
			//trace("removeChildAt", arguments);
			return false;
		}
		//--------------------------------------------------------------------------
		//
		//  Public methods
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Protected methods
		//
		//--------------------------------------------------------------------------
		
		protected function validateNode(node:Object):Boolean
		{
			if (node.hasOwnProperty("@label")) return true;
			return false;
		}
		
		protected function validateList(node:Object):XMLListCollection
		{
			var listCopy:XMLList = (node as XML).*.(validateNode(valueOf()));
			return new XMLListCollection(listCopy);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Private methods
		//
		//--------------------------------------------------------------------------
	}
}
__________________
Hell is the possibility of sanity