itemRenderer获取DataGrid对象

package com.hundsun.job.view.jobManager.jobNet
{
	import flash.events.Event;
	import flash.events.MouseEvent;

	import mx.containers.HBox;
	import mx.controls.Button;
	import mx.controls.listClasses.IListItemRenderer;
	import mx.core.IDataRenderer;
	import mx.core.UIComponent;
	import mx.events.FlexEvent;
	import mx.resources.ResourceManager;

	/**
	 * 解决大数据量下作业网列表页面中,操作按钮显示隐藏的性能提升情况。
	 * ItemRenderer性能优化
	 * @author yaorui
	 *
	 */
	public class JobNetListBtnRenderer extends HBox implements IListItemRenderer, IDataRenderer
	{
		private var _data:Object;

		//查看
		private var viewByBtn:Button;

		//设计
		private var viewDescBtn:Button;

		//执行
		private var activeBtn:Button;

		//停止
		private var stopBtn:Button;

		//删除
		private var delBtn:Button;

		public function JobNetListBtnRenderer()
		{
			super();
		}

		override protected function createChildren():void
		{
			super.createChildren();
			this.setStyle("horizontalAlign", "center");
			this.setStyle("paddingTop", "0");
			this.setStyle("paddingBottom", "0");
			this.setStyle("horizontalScrollPolicy", "middle");
			viewByBtn=new Button();
			viewByBtn.label="查 看";
			viewByBtn.enabled=true;
			viewDescBtn=new Button();
			viewDescBtn.label="设 计";
			viewDescBtn.enabled=true;
			activeBtn=new Button();
			activeBtn.label="执 行";
			activeBtn.enabled=true;
			stopBtn=new Button();
			stopBtn.label="停 止";
			stopBtn.enabled=true;
			delBtn=new Button();
			delBtn.label="删 除";
			delBtn.enabled=true;
			viewByBtn.addEventListener(MouseEvent.CLICK, viewBy);
			viewDescBtn.addEventListener(MouseEvent.CLICK, view);
			activeBtn.addEventListener(MouseEvent.CLICK, active);
			stopBtn.addEventListener(MouseEvent.CLICK, stopHandler);
			delBtn.addEventListener(MouseEvent.CLICK, remove);
			this.addChild(viewByBtn);
			this.addChild(viewDescBtn);
			this.addChild(activeBtn);
			this.addChild(stopBtn);
			this.addChild(delBtn);
		}

		private function viewBy(e:Event):void
		{
			owner.document.viewBy();
		}

		private function view(e:Event):void
		{
			owner.document.view();
		}

		private function active(e:Event):void
		{
			owner.document.active();
		}

		private function stopHandler(e:Event):void
		{
			owner.document.stopHandler();
		}

		private function remove(e:Event):void
		{
			owner.document.remove();
		}

		override protected function commitProperties():void
		{
			super.commitProperties();
			if (data)
			{
				//作业网异常,停止按钮和执行灰,处于运行中的设计不能看
				var str:String=ResourceManager.getInstance().getString("status", "btnEnabled");
				var arr:Array=str.split("&");
				var ctlStatu:String=data.ctlStatu.toString();
				var isVisible:String=data.isVisible.toString();
				for each (var strOne:String in arr)
				{
					var strStatus:String=strOne.split("|")[0];
					var strValue:String=strOne.split("|")[1];
					var status:Array=strStatus.split(",");
					var index:int=status.indexOf(ctlStatu);
					if (index != -1)
					{
						//存在状态
						var btnValue:Array=strValue.split(",");
						viewDescBtn.enabled=btnValue[2] == "true";
						//非外部作业网的特殊处理
						if (isVisible == "true")
						{
							stopBtn.enabled=btnValue[0] == "true";
							delBtn.enabled=btnValue[1] == "true";
							activeBtn.enabled=btnValue[3] == "true";
						}
						else
						{
							delBtn.enabled=true;
							activeBtn.enabled=false;
							stopBtn.enabled=false;
						}
						break;
					}
				}
			}
		}

		[Bindable("dataChange")]
		override public function get data():Object
		{
			return _data;
		}

		override public function set data(value:Object):void
		{
			_data=value;
			invalidateProperties();
			dispatchEvent(new FlexEvent("dataChange"));
		}
	}
}


通过owner.document.stopHandler()调用上层中写好的应用。

你可能感兴趣的:(itemRenderer)