1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| package manageCheckBox
{
import flash.events.Event;
import flash.events.MouseEvent;
import mx.collections.IViewCursor;
import mx.controls.Alert;
import mx.controls.CheckBox;
import mx.controls.DataGrid;
import mx.controls.treeClasses.*;
import mx.controls.treeClasses.TreeItemRenderer;
public class DisplayCheckBox extends TreeItemRenderer{
public var chk:CheckBox;
public var itemXml:XML; // Fichier xml initial
public var dg:DataGrid; // datagrid à alimenter
public var myFields:XML; // second fichier
public function DisplayCheckBox(){
super();
mouseEnabled = false;
}
override public function set data(value:Object):void{
if(value != null){
super.data = value;
this.itemXml = XML(value);
if(this.itemXml.@checked == "1"){
this.chk.selected = true;
}else{
this.chk.selected = false;
}
}
}
override protected function createChildren():void{
super.createChildren();
chk = new CheckBox();
chk.addEventListener(MouseEvent.CLICK, handleChkClick);
addChild(chk);
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
super.updateDisplayList(unscaledWidth,unscaledHeight);
if(super.data){
var tld:TreeListData = TreeListData(super.listData);
if(tld.hasChildren){
this.chk.visible = false;
}else{
this.chk.visible = true;
}
if(chk.visible){
this.chk.x = super.label.x
super.label.x = this.chk.x + 17;
this.chk.y = super.label.y+8;
}
}
}
private function handleChkClick(evt:MouseEvent):void{
if(this.chk.selected){
this.itemXml.@checked = "1";
// alimentation de la datagrid
dg.dataProvider.addItem(
{
"col1": this.itemXml.@label,
"col2": this.itemXml.@label,
"col3": this.itemXml.@resourceId
}
);
}else{
//this.checked = false;
this.itemXml.@checked = "0";
var vObject:Object = dg.dataProvider ;
var cursor:IViewCursor=vObject.createCursor();
while( !cursor.afterLast )
{
if(cursor.current.col1 == this.itemXml.@label) {
cursor.remove() ;
}
cursor.moveNext();
}
}
}
}
} |
Partager