<?xml version="1.0" encoding="utf-8"?>    

<TsAbstructTextInput xmlns="cls.com.ils.biz.component.*" 
		xmlns:mx="http://www.adobe.com/2006/mxml"
		xmlns:sharedComponent="tanakaLibrary.sharedComponent.*"
		width="270"
		maxChars="30"
		focusIn="onFocusIn(event)" focusOut="onFocusOut(event)" 
		doubleClickEnabled="true" doubleClick="onDoubleClick()"
		backgroundColor="0xFFFFFF"
		translationTarget="{_ownerData}"
		creationComplete="init()">
<mx:Script>
<![CDATA[
	import cls.com.ils.biz.component.TsAbstructPanel;
	import cls.com.ils.common.component.IlsDataGrid;
	import mx.controls.DataGrid;
	import mx.events.ValidationResultEvent;
	import cls.com.ils.common.model.MsgMgr;
	import commonLibrary.sharedValidators.NumberValidator;
	import mx.validators.ValidationResult;
	import commonLibrary.sharedValidators.StringValidator;
	import mx.validators.Validator;
	import mx.events.FlexEvent;
	import cls.com.ils.biz.model.enum.ActionMode;
	import mx.controls.dataGridClasses.DataGridListData;             

	 [Bindable("dataChange")]
	// DataGridのデータプロパイダ
    private var _ownerData:Object;

	public var label:String = "";
	public var rowIndex:int=0;
	
	private var _validator:Validator;
	private var _validType:String;

	 [Bindable]
	private var _imeMode:String;
	
	private function init():void
	{
		
		if (parentDocument.actionMode == ActionMode.DEL){
			// 削除の場合
			enabled=false;
		}
		else{
			//その他の場合
			enabled=true;
		}
		
		addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown)
		
	}

	// データプロパイダのゲッター
    override public function get data():Object
    {
		
       	// _ownerDataにデータプロパイダ設定前にdataを取得する場合がある。
       	// この場合dataの初期値を返すため、nullチェックを行う。
       	if(_ownerData != null){
			var col:DataGridListData = DataGridListData(listData);
			_ownerData[col.dataField] = this.text;			
       	}
        
        return _ownerData;
    }
    
	// データプロパイダのセッター
    override public function set data(pValue:Object):void
    {
        _ownerData = pValue;
		
        if(_ownerData){
            var col:DataGridListData = DataGridListData(listData);
            this.text = _ownerData[col.dataField];
        }
        
        dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
    }
    
	//IME制御を行う為に必要
	override public function setFocus():void
	{
		super.setFocus();
		dispatchEvent(new FocusEvent(FocusEvent.FOCUS_IN));                							
	}
    
	public function set validMaxLength(value:Number):void{
    	switch(validType){
    		case "String":
				StringValidator(_validator).maxLength = value;
    			break;
    		case "Number":
				NumberValidator(_validator).maxValue = value;
    			break;
    		default:
    			break;    		
    	}
	}
	
	public function set validMinLength(value:Number):void{
    	switch(validType){
    		case "String":
				StringValidator(_validator).minLength = value;		
    			break;
    		case "Number":
				NumberValidator(_validator).minValue = value;		
    			break;
    		default:
    			break;    		
    	}
	}

	public function set validRequired(value:Boolean):void{
		_validator.required = value;
	}

	public function set validType(value:String):void{
		if(value){
			_validType = value;
	    	switch(value){
	    		case "String":
	    			_validator = new StringValidator();
	    			break;
	    		case "Number":
	    			_validator = new NumberValidator();
	    			break;
	    		default:
	    			_validator = new StringValidator();
	    			break;    		
	    	}
	    	_validator.source = this;
			_validator.trigger = this;
	    	_validator.property = "text";
			_validator.triggerEvent="dataChange"
		}				
	}
	
	public function get validType():String{
		return _validType;
	}
	
	public function getValidator():Validator{
		return _validator;
	}

	private function onFocusIn(event:FocusEvent):void{

        var parent:Object = event.currentTarget.parentDocument;
        if (parent is TsAbstructPanel)
        {
			if(isZoom){
				//使用可
				parent.zoomEnabled = true;
			}else{
				//使用不可
				parent.zoomEnabled = false;
			}
            return;
        }
	}

	private function onFocusOut(event:FocusEvent):void{

		if(event.relatedObject is ZoomButton){
			//フォーカスの移動先がズームボタンの場合、何もしない
		}else{
	        var parent:Object = event.currentTarget.parentDocument;

            if (parent is TsAbstructPanel)
            {
				//使用不可
				parent.zoomEnabled = false;
                return;
            }
		}
	}
	
	private function onDoubleClick():void{
		if(isZoom){
	        var parent:Object = this.parentDocument;

            if (parent is TsAbstructPanel)
            {
            	parent.zoom(this);
                return;
            }
		}				
	}

	// keyDown event handler.
	private function onKeyDown(event:KeyboardEvent):void
	{
		// Ctrl keyを押下したか？
		if (event.ctrlKey){
			switch (event.keyCode) {
			// 下向き矢印キー
			case Keyboard.DOWN :
				if(isZoom){
			        var parent:Object = this.parentDocument;
		
		            if (parent is TsAbstructPanel)
		            {
		            	parent.zoom(this);
		                return;
		            }
				}									
				break;
			default :
				break;
			}
		}
	}

]]>
</mx:Script>

	
</TsAbstructTextInput>