package com
{
import com.adobe.cairngorm.control.CairngormEventDispatcher;
import com.vzw.mpi.rss.events.DataReceiveEvent;
import com.vzw.mpi.rss.model.RdsModelLocator;
import com.vzw.mpi.rss.serverEvents.RdsEvent;
import com.vzw.mpi.rss.utils.RDSConstants;
import com.vzw.mpi.rss.utils.RssConstants;
import customComponents.ImageFocus;
import customComponents.datagrid.CheckBoxDataGrid;
import customComponents.popups.SingleSelectCustomPopup;
import flash.events.Event;
import flash.events.FocusEvent;
import mx.controls.TextInput;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.controls.listClasses.IListItemRenderer;
import mx.core.UIComponent;
import mx.managers.IFocusManagerComponent;
import mx.managers.PopUpManager;
public class SpyGlassFieldEditor extends UIComponent implements IListItemRenderer, IDropInListItemRenderer, IFocusManagerComponent
{
public function SpyGlassFieldEditor()
{
super();
addEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeHandler);
}
private var txtInputByUser:TextInput;
private var spyGlassImage:ImageFocus;
private var maxInputCharacters:int=20;
private var _data:Object;
public function get data():Object
{
return _data;
}
public function set data(value:Object):void
{
_data=value;
invalidateProperties();
}
private var _listData:BaseListData;
private var _dataGrid:CheckBoxDataGrid;
private var _dataField:String;
private var win:SingleSelectCustomPopup;
[Bindable]
protected var rdsModel:RdsModelLocator=RdsModelLocator.getInstance();
public function get listData():BaseListData
{
return _listData;
}
public function set listData(value:BaseListData):void
{
_listData=value;
_dataGrid=value.owner as CheckBoxDataGrid;
_dataField=(value as DataGridListData).dataField;
}
override public function setFocus():void
{
if (dgOwner.shiftKey)
{
spyGlassImage.setFocus();
}
else
txtInputByUser.setFocus();
}
private function onTextChange(event:Event):void
{
var textInput:TextInput=event.currentTarget as TextInput;
if(_dataField)
{
var properties:Array=_dataField.split(".");
if (properties.length >= 2)
{
var object:Object=data[properties[0]];
object[properties[1]]=textInput.text;
}
else
{
data[_dataField]=textInput.text;
}
_dataGrid.dataProvider.itemUpdated(data);
invalidateProperties();
}
}
override protected function createChildren():void
{
super.createChildren();
txtInputByUser=new TextInput();
txtInputByUser.maxChars=maxCharacters;
txtInputByUser.addEventListener("change", onTextChange, false, 0, true);
addChild(txtInputByUser);
spyGlassImage=new ImageFocus();
spyGlassImage.source="assets/images/spyglass.gif";
spyGlassImage.buttonMode = true;
spyGlassImage.addEventListener("click", onImageClick, false, 0, true);
addChild(spyGlassImage);
}
protected function onImageClick(evt:Event):void
{
}
public function get editValue():String
{
return txtInputByUser.text;
}
private var dgOwner:CheckBoxDataGrid;
override protected function commitProperties():void
{
dgOwner=owner as CheckBoxDataGrid;
super.commitProperties();
if (_dataField)
{
var properties:Array=_dataField.split(".");
if (properties.length >= 2)
{
var object:Object=data[properties[0]];
txtInputByUser.text=object[properties[1]];
}
else
{
txtInputByUser.text=data[_dataField];
}
}
}
public function onPopUpClose():void
{
var properties:Array=_dataField.split(".");
if (properties.length >= 2)
{
var object:Object=data[properties[0]];
object[properties[1]]=win.idSelected.text;
}
else
{
data[_dataField]=win.idSelected.text;
}
_dataGrid.dataProvider.itemUpdated(data);
invalidateProperties();
}
override protected function updateDisplayList(w:Number, h:Number):void
{
super.updateDisplayList(w, h);
txtInputByUser.move(0, 0);
txtInputByUser.setActualSize(w - 25, h);
spyGlassImage.move(w - 11, 0);
spyGlassImage.setActualSize(11, 11);
}
private function keyFocusChangeHandler(event:FocusEvent):void
{
//trace("Focus Manager " + focusManager.focusPane);
if (event.shiftKey)
{
//trace("Inside Shift Key");
if (spyGlassImage.contains(getFocus()))
{
event.preventDefault();
txtInputByUser.setFocus();
}
}
else
{
if (txtInputByUser.contains(getFocus()))
{
event.preventDefault();
spyGlassImage.setFocus();
}
}
}
public function set maxCharacters(max:int):void
{
maxInputCharacters=max;
if (txtInputByUser)
txtInputByUser.maxChars=max;
}
public function get maxCharacters():int
{
return maxInputCharacters;
}
}
}
Thursday, July 22, 2010
Code for PopUp
Subscribe to:
Posts (Atom)