`
k1280000
  • 浏览: 202558 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

FLEX TREE +右键菜单 +过滤+拖拽(待完成)

    博客分类:
  • Flex
 
阅读更多
  • 主页面
<?xml version="1.0" encoding="utf-8"?>
<!-- working_with_tree_controls/TreeAddRemoveNodes.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx"
			   xmlns:mycomponent="com.treeList.*"
			   creationComplete="app_onCreate()" 
			   >
	
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	
	<fx:Script>
		<![CDATA[
			import com.treeList.event.GetTextContentEvent;
			
			import flash.events.*;
			import flash.ui.*;
			
			import mx.collections.ArrayCollection;
			import mx.collections.XMLListCollection;
			import mx.controls.Alert;
			import mx.events.ListEvent;
			import mx.managers.PopUpManager;
			
			public static const DELETE_NODE :String = " - Del ";
			public static const ADD_NODE :String = " + Add a Ndde";
			public static const ADD_FOLDER :String = " + Add a Folder";
			public static const EDIT :String = " @ Edit";
			
			[Bindable]
			private var cm :ContextMenu ;
			[Bindable]
			private var company : XML = 
				<list>
					  <department label="Finance" code="200">
						  <manage label="Manager">
 							<employee label="John H"/>
						    <employee label="Sam K"/>
						  </manage>
						  <employee label="John H"/>
						  <employee label="Sam K"/>
					  </department>
					  <department label="Operations" code="400">
						  <employee label="Bill C"/>
						  <employee label="Jill W"/>
					  </department>                   
					  <department label="Engineering1111" code="300">
						  <employee label="Erin M11111111111111111"/>
						  <employee label="Ann B"/>
					  </department>   
				</list>;
			
			[Bindable]
			private var xmlData : XMLListCollection = new XMLListCollection (company.department);
			[Bindable]
			private var arrData : ArrayCollection = 
				new ArrayCollection ([{children:new ArrayCollection ([{children:"",label:"child1A"},{children:"cNode1B",label:"child1B"}]),label:"ROOT"}]);
			
			protected function app_onCreate():void{
				var childArrData : ArrayCollection = 
					new ArrayCollection ([{children:"NODEb1",label:"child2A"},{children:"NODEb2",label:"child2A"}]);
				arrData.getItemAt(0).children[0].children = childArrData;
				init();
			}
			
			/* protected function labelF (item:Object):String{
				var node :XML = XML (item);
				if(node.localName()=="department")
					return node.@title;
				
				return node.@name;
			} */
			
			
			//for the right-click
			// 为鼠标右键添加关闭当前浏览器窗口的菜单
			protected function init():void {
				cm= new ContextMenu();
				cm.addEventListener(ContextMenuEvent.MENU_SELECT,right_click);
				cm.hideBuiltInItems(); // 隐藏一些内建的鼠标右键菜单项
//				var contextMenuItem : ContextMenuItem = new ContextMenuItem("关闭本窗口");
//				cm.customItems.push(contextMenuItem);
//				contextMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, 
//					function(event : ContextMenuEvent) : void{
//					navigateToURL(new URLRequest("javascript:window.close()"), "_self");
//				});
//				this.contextMenu = contextMenu; 
			}
			
			protected function right_click(event:ContextMenuEvent):void {
				cm.customItems=null;
				var customItemList :Array =  new Array ();
				var isFolder :Boolean = tree.dataDescriptor.isBranch(tree.selectedItem);
				if(isFolder){
					 var addButton:ContextMenuItem= new ContextMenuItem(ADD_NODE);
					 addButton.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,add_childNode);
					 customItemList.push(addButton);
					 
					 var addFolder:ContextMenuItem=new ContextMenuItem(ADD_FOLDER);
					 addFolder.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,add_childFolder);
					 customItemList.push(addFolder);
				} 
				var delButton:ContextMenuItem=new ContextMenuItem(DELETE_NODE);
				delButton.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,del_Node);
				customItemList.push(delButton);
				
				//for edit pop-up window
				var editButton :ContextMenuItem = new ContextMenuItem (EDIT);
				editButton.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,edit_popUp);
				customItemList.push(editButton);
				
				//regist all the menu item
				cm.customItems = customItemList;
			}
			
			protected function add_childNode(event:ContextMenuEvent):void {
				var node :XML = tree.selectedItem as XML;
					node.appendChild(new XML ("<employee label='new nodes'/>"));
				expandNode();
			}
			
			protected function add_childFolder(event:ContextMenuEvent):void {
				
				var node :XML = tree.selectedItem as XML;
				if(node.localName() == "department"){
					node.appendChild(new XML ("<manager label='Manager'><employee label='employee'></employee></manager>"));
				}else{
					node.appendChild(new XML ("<employee label='Employee'><new label='New'></new></employee>"));
				}
				expandNode();
				// close all the expand node 
//				tree.openItems = [];
			}
			
			protected function del_Node(event:ContextMenuEvent):void {
				tree.dataDescriptor.removeChildAt(tree.selectedItem.parent(),tree.selectedItem,
											      tree.selectedItem.childIndex(),tree.dataProvider);
			}
			
			protected function tree_doubleClick(event:ListEvent):void {
				tree.editable = true;
				Tree(event.target).editedItemPosition= {columnIndex:0,rowIndex:event.rowIndex};
			}
			
			protected function tree_editBegining(event:ListEvent):void {
				//due to the single-click event will auto make the tree is editable
				//use this function to prevent the single-click to edit
				event.preventDefault();
			}
			
			protected function expandNode():void {
			    tree.expandItem(tree.selectedItem,true,true);	
			}
			
			private var popView :PopUpView ;
			protected function edit_popUp(event:ContextMenuEvent):void {
				popView = new PopUpView ();
				popView = PopUpManager.createPopUp(this,PopUpView,true) as PopUpView;
				popView.title = "Please input the Lable ";
				PopUpManager.centerPopUp(popView);
				
				popView.addEventListener(GetTextContentEvent.GET_INPUT_CONTENT,getInputData);
			}
			
			// events 
			public function getInputData(event:GetTextContentEvent):void{
				PopUpManager.removePopUp(popView);
				var node :XML = tree.selectedItem as XML;
				node.@label = event.inputContent;
			}
			
		]]>
	</fx:Script>
	
	<s:Scroller>
		<s:VGroup>
			<mx:Grid>
				<mx:GridRow>
					<mx:GridItem>
						<mx:Tree id="tree" 
								 dataProvider="{xmlData}" 
								 contextMenu="{cm}"
								 labelField="@label"
								 doubleClickEnabled="true" 
								 itemDoubleClick="tree_doubleClick(event)"
								 itemEditBeginning="tree_editBegining(event)" 
								 width="300" height="500"
								 horizontalScrollPolicy="auto" 
								 horizontalScrollPosition="500" 
								 dataTipField="" showDataTips="true" 
								 dragEnabled="true" 
								 dragMoveEnabled="true"
								 dropEnabled="true" 
								 >
						</mx:Tree>
					</mx:GridItem>
				</mx:GridRow>
			</mx:Grid>
			
		</s:VGroup>
	</s:Scroller>
	
</s:Application>
 





  • pup window

<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
			   close="titlewindow1_closeHandler(event)" 
			   width="300" 
			   height="100" 
			   >
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import com.treeList.event.GetTextContentEvent;
			import mx.controls.Alert;
			import mx.events.CloseEvent;
			import mx.managers.PopUpManager;

			protected function titlewindow1_closeHandler(event:CloseEvent):void
			{	
				trace(inputData.text.length);
				if(inputData.text.length != 0){
					Alert.show("You want to save the informaition ?","Confirm",Alert.YES|Alert.NO|Alert.CANCEL,this,pop_select);	
				}else{
					PopUpManager.removePopUp(this);
				}
			}


			protected function pop_Ok_clickHandler(event:MouseEvent):void
			{
				if(inputData.text.length != 0){
					Alert.show("You want to save the informaition ?","Confirm",Alert.YES|Alert.NO|Alert.CANCEL,this,pop_select);	
				}else{
					PopUpManager.removePopUp(this);
				}
				
			}
			
			private var _getContentEvent :GetTextContentEvent = new GetTextContentEvent (GetTextContentEvent.GET_INPUT_CONTENT,true); ;
			protected function pop_select(event:CloseEvent):void{
				if(event.detail == Alert.YES){
					_getContentEvent.inputContent = inputData.text ;
					dispatchEvent(_getContentEvent);
				}else if(event.detail == Alert.NO)
				{
					PopUpManager.removePopUp(this);
				}
			}
		]]>
	</fx:Script>
	<s:layout>
		<s:VerticalLayout  horizontalAlign="center" verticalAlign="middle"/>
	</s:layout>
	<s:Scroller>
	
		<s:VGroup>
			<mx:Grid>
				<mx:GridRow> 
						<mx:GridItem verticalAlign="middle">
							<s:Label text="Label : "/>
						</mx:GridItem>
						<mx:GridItem>
							<s:TextInput id="inputData" />
						</mx:GridItem>
				</mx:GridRow>
			</mx:Grid>
			<s:Button id="pop_Ok" label="OK" click="pop_Ok_clickHandler(event)"/>
		</s:VGroup>
		
	</s:Scroller>
</s:TitleWindow >
 




  • 过滤

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" 
			   minWidth="955" minHeight="600"
			   creationComplete="init()" 
			   >

	<fx:Declarations>
		
	</fx:Declarations>
	
	<fx:Script>
		<![CDATA[
			import com.treeList.model.MyTree;
			
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			import mx.utils.ObjectUtil;
			
			import spark.events.TextOperationEvent;
			
			[Bindable]
			private var dta:ArrayCollection = new ArrayCollection ();
			private var dtaa:ArrayCollection = new ArrayCollection ();
			
			private var dta1 :ArrayCollection = new ArrayCollection ();
			
			protected function init():void{
				for(var l:int = 0; l<350;l++){
					var d:MyTree = new MyTree ();
					d.label = "Node--"+l ;
					d.children = null;
					dta1.addItem(d);
				}
				
				//
				var dd:MyTree = new MyTree ();
				dd.label = "Node--77" ;
				dd.children = null;
				
				//
				var tem2:ArrayCollection = new ArrayCollection ();
				for(var k:int = 100; k<3500;k++){
					tem2.addItem(dta1.getItemAt(6));
					tem2.addItem(dta1.getItemAt(7));
				}
				dta1.getItemAt(2).children = tem2 ;
				//------------
				var tem0:ArrayCollection = new ArrayCollection ();
				tem0.addItem(dta1.getItemAt(2));
				tem0.addItem(dta1.getItemAt(3));
				tem0.addItem(dta1.getItemAt(4));
				dta1.getItemAt(0).children = tem0 ;
				
				dtaa.addItem(dta1.getItemAt(0));
				//-------------
				var tem1:ArrayCollection = new ArrayCollection ();
				tem1.addItem(dta1.getItemAt(5));
				tem1.addItem(dd);
				dta1.getItemAt(1).children = tem1 ;
				dtaa.addItem(dta1.getItemAt(1));
				
				//
				dtaa.addItem(dta1.getItemAt(8));
				
				//root
				var rd:MyTree = new MyTree ();
				rd.label = "" ;
				rd.children = dtaa;
				dta.addItem(rd);
			}
			
			protected function filterText_Handler(event:TextOperationEvent):void{
				var tempDataProvider :ArrayCollection = new ArrayCollection ();
				for (var k:uint = 0; k < dta.length; k++) {
					tempDataProvider.addItem(mx.utils.ObjectUtil.copy(dta.getItemAt(k)));
				}
				
				if(filterText.text.length !=0){
					/* for(var i:int= 0 ;i<tempDataProvider.length;i++){
						 if(tempDataProvider.getItemAt(i).children!=null){*/
							filterTextRecursion(tempDataProvider.source[0]);
						/* }
						
					} */
					tree1.dataProvider = tempDataProvider;
				}else{
					tree1.dataProvider = dta;
				}
				tree1.invalidateList();
			}
			
			protected function filterTextRecursion(object:Object):void{
				if(object.children!=null){
					for each (var obj:Object in object.children){
						filterTextRecursion(obj);
					}
					object.children = new ArrayCollection (object.children.source);
					object.children.filterFunction = filterData;
					object.children.refresh();
					
					//for the expand tree 
					tree1.callLater(expandTree);
				}
				
			}
			
			protected function expandTree():void{
				expandTree1(tree1.dataProvider as ArrayCollection);
			}
			
			protected function expandTree1(dtas:ArrayCollection):void{
				for each (var o:Object in dtas)
				{
					tree1.expandItem(o, true);
					if (o.children && o.children.length)
						expandTree1(o.children);
				}
			} 
			
			protected function filterData(item:Object):Boolean{
				var temLabel:String = item.label;
				if(temLabel.indexOf(filterText.text)>=0 || item.children){
					if(item.children!=null && item.children.length ==0 && temLabel.indexOf(filterText.text)<0){
						return false;
					}
					return true;
				}
				return false;
			}
			
			protected function filterData1(item:Object):Boolean{
				var temLabel:String = item.label;
				if(temLabel.indexOf(filterText.text)==-1){
					return false;
				}
				return true;
			}
			
			protected function button1_clickHandler(event:MouseEvent):void
			{
//				expandTree(dta);
			}
		]]>
	</fx:Script>
	

	<s:VGroup>
		<s:TextInput id="filterText" change="filterText_Handler(event)"/>
		<mx:Tree id="tree1" dataProvider="{dta}" width="300" height="200"/>
		<s:Button click="button1_clickHandler(event)" label="order" />
	</s:VGroup>
		
	
</s:Application>
 


分享到:
评论

相关推荐

    Flex Tree 的右键菜单事件

    另外,需要注意的是,由于Flex默认不支持Tree组件的右键菜单,所以可能需要对Tree组件进行一些自定义设置,例如禁用默认的上下文菜单: ```actionscript tree.contextMenuEnabled = false; ``` 这可以防止系统级的...

    Flex右键菜单 flex tree 右键菜单 源码

    在Flex中,右键菜单是用户交互的重要组成部分,特别是在数据可视化和树形结构的数据展示中,如Flex Tree组件。本文将深入探讨如何在Flex中实现右键菜单,并结合提供的源码进行分析。 1. Flex右键菜单: Flex中的...

    flex3 Tree右键菜单

    总的来说,Flex3 Tree右键菜单的实现涉及到对ContextMenu类、MenuItem类以及相关事件的理解和使用。通过自定义菜单项和事件处理,我们可以创建符合应用需求的交互式右键菜单,提高用户操作的便捷性。同时,灵活的...

    flex tree+checkbox级联勾选

    在IT行业中,Flex Tree是一种常用于数据展示和交互的组件,尤其在构建用户界面时,它能够以树形结构清晰地展示层次数据。配合Checkbox(复选框)功能,可以提供用户选择或过滤数据的便利操作。"Flex Tree + Checkbox...

    flex屏蔽系统右键菜单 & 自定义菜单

    "flex屏蔽系统右键菜单 & 自定义菜单"这个主题聚焦于如何禁用默认的系统右键菜单并创建自定义的右键菜单,以提供更个性化的用户体验。下面将详细介绍这个过程涉及的关键知识点。 1. Flex环境:Flex是Adobe开发的一...

    flex 自定义右键菜单 多级右键菜单

    在Flex开发中,自定义右键菜单和实现多级右键菜单是一项常见的需求,它能够为用户界面提供更丰富的交互体验。Flex是一个基于ActionScript 3.0的开放源代码框架,用于构建富互联网应用程序(RIA)。下面我们将深入...

    Flex自定义右键菜单

    在Flex开发中,自定义右键菜单是一项常见的需求,它能为用户界面提供更丰富的交互体验。Flex是一款基于ActionScript 3.0的开源框架,主要用于构建富互联网应用程序(RIA)。在这里,我们将深入探讨如何在Flex中实现...

    flex添加右键菜单实例

    在Flex编程中,右键菜单(ContextMenu)是一个重要的交互元素,它可以为用户提供额外的操作选项。在给定的实例中,我们看到如何在Flex应用中创建并添加自定义的右键菜单。下面将详细解释这个实例中的关键知识点。 ...

    Flex添加右键菜单

    在Flex开发中,有时我们需要为用户界面添加自定义的右键菜单,以便提供更多的交互功能。本教程将指导你如何在Flex项目中实现这一功能,主要涉及以下知识点: 1. **右键菜单库的引入**: 首先,你需要下载一个名为`...

    flex实现右键菜单

    本话题我们将探讨如何使用Flex技术来实现一个自定义的右键菜单。Flex是一种基于ActionScript 3.0的开放源码框架,主要用于构建富互联网应用程序(RIA)。 首先,我们需要理解Flex的基本架构。Flex使用MXML和...

    flex自定义右键菜单 完全屏蔽

    标题提到的"flex自定义右键菜单 完全屏蔽"是指在Flex应用程序中,不仅实现对默认右键菜单的完全屏蔽,还允许开发者根据自己的需求创建并应用自定义的右键菜单。这种方法避免了使用JavaScript进行跨域通信来实现屏蔽...

    Flex4自定义右键菜单源码.rar

    标题中的“Flex4自定义右键菜单源码”意味着这个压缩包包含了实现自定义右键菜单功能的源代码。这对于初学者来说是一份宝贵的学习资源,他们可以通过阅读和理解代码来学习如何在Flex4项目中创建和管理自定义的右键...

    Flex tree+checkbox可实现级联勾选 修改

    flex tree+checkbox可实现级联勾选 修改后 修改CheckTreeDemoRenderer.as这个文件中 while (!cursor.afterLast){ if (cursor.current.@state == STATE_CHECKED) { noChecks++; }else if (cursor.current.@state =...

    Flex++ & Bison++ for windows

    Flex++ 和 Bison++ 是两个强大的工具,主要用于在编程领域创建解析器和词法分析器,尤其在构建编译器和解释器时非常有用。这两个工具的Windows版本使得开发者能够在Windows平台上进行类似的工作,而无需依赖于Unix或...

    Flex 实现右键菜单

    本文将深入探讨如何在Flex环境中实现自定义的右键菜单,包括屏蔽浏览器的默认右键菜单,创建XML格式的多级菜单,以及设置菜单出现位置的自适应策略。 首先,我们需要了解Flex屏蔽浏览器系统右键的基本方法。在...

    flex自制右键菜单

    本项目标题为"flex自制右键菜单",描述中提到作者从网上获取了相关代码并进行改写,实现了屏蔽Flex默认的右键菜单以及动态生成右键菜单的功能。下面我们将详细探讨Flex中如何实现这一目标。 首先,Flex是由Adobe...

    FLEX 完全屏蔽系统默认右键菜单,实现自定义菜单

    完全屏蔽flex自带的右键菜单,实现自定义右键菜单,附件有完整可运行的例子。 这个问题折腾了一天多,在网上搜了很多资料,几乎都是一样的,转来转去,且讲的不明不白。这里我提供了可运行的全部代码,让你轻松搞定...

    Flex右键菜单例子

    "Flex右键菜单例子"是一个专门针对Flex技术的右键菜单自定义解决方案。Flex是一种用于构建富互联网应用程序(RIA)的开放源代码框架,由Adobe公司开发。它基于ActionScript编程语言和MXML标记语言,主要用于创建交互式...

    flex自定义右键菜单

    在Flex应用中,用户界面的交互性是关键,而右键菜单作为常见的用户交互元素,能够提供额外的功能选项,增强用户体验。本篇文章将深入探讨如何在Flex中自定义右键菜单。 一、Flex中的上下文菜单(Context Menu) ...

    flex 自定义右键菜单

    本文将深入探讨两种实现Flex自定义右键菜单的方法:系统右键菜单的扩展以及完全自定义的右键菜单。 1. **系统右键菜单** 系统右键菜单是在Flex应用中利用ActionScript 3.0直接添加到UI组件上的菜单项。这种实现...

Global site tag (gtag.js) - Google Analytics