Flex 针对Clob大字符数据块显示的ItemRender

在Flex的DataGrid中展示长字符串比如数据库中的Clob字段一般的做法都是在对应的列区域放入一个按钮如果用户需要查看的话就点进去弹出一个窗口或者编辑器,等不用的时候再关闭。
  在Flex中这个功能是用ItemRender来实现的。以下代码通过一个PopUpButton和RichTexEditor来实现的。在查看消息历史的应用中,有两个Clob字段需要展示,一个是消息本身,另一个是在消息出来出现异常的情况下查看异常信息。所以用到了PopUpButton,用RicheTexEditor主要是他功能较多,只为了好看吧。你可以用别的如TextArea等替换的。
   package message.utils
{
import flash.events.MouseEvent;

import mx.containers.TitleWindow;
import mx.controls.Button;
import mx.controls.Menu;
import mx.controls.PopUpButton;
import mx.controls.RichTextEditor;
import mx.events.CloseEvent;
import mx.events.MenuEvent;
import mx.managers.PopUpManager;

public class ClobColumnItemRender extends PopUpButton
{
private var menu:Menu;
private var rt:RichTextEditor;
private var titleWin:TitleWindow;

public function ClobColumnItemRender()
{
super();
menu = new Menu();
var dp:Object = [{label:"消息"},{label:"异常"}];
menu.dataProvider = dp;
menu.addEventListener(MenuEvent.ITEM_CLICK,changeHandler);
this.popUp = menu;
this.addEventListener(MouseEvent.CLICK, showMsg);
this.label = dp[0].label as String;

rt=new RichTextEditor();
rt.horizontalScrollPolicy="off";
rt.verticalScrollPolicy="off";
rt.visible=false;
}

override public function set data(value:Object):void{
super.data = value;
this.rt.text = value.message as String;
}

//Show The Message Or Error Log ,s Detail Information
private function showMsg(event:MouseEvent):void
{
this.titleWin=PopUpManager.createPopUp((event.currentTarget as Button).parent, TitleWindow, true) as TitleWindow;
this.titleWin.title="Messag Information";
this.titleWin.showCloseButton = true;
this.titleWin.addEventListener(CloseEvent.CLOSE, closeHandler);
this.titleWin.addChild(rt);
rt.visible=true;
PopUpManager.centerPopUp(titleWin);
}

//When Sub Pop-Up Button Change Event Is Despatched Decide Msg Or Log To Show
private function changeHandler(event:MenuEvent):void{
this.label = event.label;
if(data.hasOwnProperty("message") && label=="消息"){
this.rt.text = data.message;
}else if(data.hasOwnProperty("exception")&&label =="异常"){
this.rt.text = data.exception;
}
this.close();
}

//Close The Sub Poped  RicheTextEditor
private function closeHandler(event:CloseEvent):void
{
PopUpManager.removePopUp(this.titleWin);
this.rt.visible=false;
}

}
}

你可能感兴趣的:(Flex,Flash,UP)