[sandbox.akabana]/trunk/yui/yui-framework/src/main/flex/org/seasar/akabana/yui/framework/customizer/HelperCustomizer.as
Parent Directory
|
Revision Log
Revision 1504 -
(hide annotations)
Sat Feb 19 16:23:33 2011 JST (2 years, 3 months ago) by e1arkw
File size: 7432 byte(s)
Sat Feb 19 16:23:33 2011 JST (2 years, 3 months ago) by e1arkw
File size: 7432 byte(s)
Copyrightを変更
| 1 | e1arkw | 1077 | /* |
| 2 | e1arkw | 1504 | * Copyright 2004-2011 the Seasar Foundation and the Others. |
| 3 | e1arkw | 1077 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | * you may not use this file except in compliance with the License. | ||
| 6 | * You may obtain a copy of the License at | ||
| 7 | * | ||
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | * | ||
| 10 | * Unless required by applicable law or agreed to in writing, software | ||
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
| 13 | * either express or implied. See the License for the specific language | ||
| 14 | * governing permissions and limitations under the License. | ||
| 15 | */ | ||
| 16 | package org.seasar.akabana.yui.framework.customizer | ||
| 17 | { | ||
| 18 | CONFIG::FP10 { | ||
| 19 | import __AS3__.vec.Vector; | ||
| 20 | } | ||
| 21 | import mx.core.UIComponent; | ||
| 22 | e1arkw | 1255 | |
| 23 | e1arkw | 1077 | import org.seasar.akabana.yui.core.reflection.ClassRef; |
| 24 | import org.seasar.akabana.yui.core.reflection.PropertyRef; | ||
| 25 | import org.seasar.akabana.yui.framework.YuiFrameworkGlobals; | ||
| 26 | e1arkw | 1255 | import org.seasar.akabana.yui.framework.core.ILifeCyclable; |
| 27 | e1arkw | 1467 | import org.seasar.akabana.yui.framework.ns.viewpart; |
| 28 | e1arkw | 1077 | import org.seasar.akabana.yui.framework.util.UIComponentUtil; |
| 29 | e1arkw | 1431 | import org.seasar.akabana.yui.framework.logging.debug; |
| 30 | e1arkw | 1077 | |
| 31 | [ExcludeClass] | ||
| 32 | public class HelperCustomizer extends AbstractComponentCustomizer { | ||
| 33 | e1arkw | 1264 | |
| 34 | e1arkw | 1255 | public override function customizeView(container:UIComponent):void { |
| 35 | e1arkw | 1472 | const viewProperties:Object = UIComponentUtil.getProperties(container); |
| 36 | e1arkw | 1255 | const viewClassName:String = getCanonicalName(container); |
| 37 | e1arkw | 1077 | const helperClassName:String = YuiFrameworkGlobals.namingConvention.getHelperClassName(viewClassName); |
| 38 | |||
| 39 | try { | ||
| 40 | CONFIG::DEBUG { | ||
| 41 | e1arkw | 1431 | debug(this,getMessage("Customizing",viewClassName,helperClassName)); |
| 42 | e1arkw | 1077 | } |
| 43 | e1arkw | 1472 | viewProperties[YuiFrameworkGlobals.namingConvention.getHelperPackageName()] = {}; |
| 44 | e1arkw | 1077 | // |
| 45 | e1arkw | 1472 | const action:Object = viewProperties[YuiFrameworkGlobals.namingConvention.getActionPackageName()]; |
| 46 | e1arkw | 1077 | if(action != null) { |
| 47 | e1arkw | 1341 | setHelperProperties(container,action); |
| 48 | e1arkw | 1077 | } |
| 49 | e1arkw | 1341 | |
| 50 | e1arkw | 1128 | // |
| 51 | e1arkw | 1472 | const behaviors:Array = viewProperties[YuiFrameworkGlobals.namingConvention.getBehaviorPackageName()]; |
| 52 | e1arkw | 1128 | if(behaviors != null) { |
| 53 | for each( var behavior:Object in behaviors){ | ||
| 54 | e1arkw | 1341 | setHelperProperties(container,behavior); |
| 55 | e1arkw | 1128 | } |
| 56 | } | ||
| 57 | e1arkw | 1077 | CONFIG::DEBUG { |
| 58 | e1arkw | 1431 | debug(this,getMessage("Customized",viewClassName,helperClassName)); |
| 59 | e1arkw | 1077 | } |
| 60 | } catch(e:Error) { | ||
| 61 | CONFIG::DEBUG { | ||
| 62 | e1arkw | 1431 | debug(this,getMessage("CustomizeError",container,e.getStackTrace())); |
| 63 | e1arkw | 1077 | } |
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | e1arkw | 1255 | public override function uncustomizeView(container:UIComponent):void { |
| 68 | e1arkw | 1472 | const viewProperties:Object = UIComponentUtil.getProperties(container); |
| 69 | e1arkw | 1255 | const viewClassName:String = getCanonicalName(container); |
| 70 | e1arkw | 1077 | const helperClassName:String = YuiFrameworkGlobals.namingConvention.getHelperClassName(viewClassName); |
| 71 | |||
| 72 | try { | ||
| 73 | CONFIG::DEBUG { | ||
| 74 | e1arkw | 1431 | debug(this,getMessage("Uncustomizing",viewClassName,helperClassName)); |
| 75 | e1arkw | 1077 | } |
| 76 | // | ||
| 77 | e1arkw | 1472 | const helperMap:Object = viewProperties[YuiFrameworkGlobals.namingConvention.getHelperPackageName()]; |
| 78 | e1arkw | 1346 | for each( var helper:Object in helperMap){ |
| 79 | if( helper is ILifeCyclable ){ | ||
| 80 | (helper as ILifeCyclable).stop(); | ||
| 81 | } | ||
| 82 | e1arkw | 1397 | // |
| 83 | setPropertiesValue(helper,viewClassName,null); | ||
| 84 | e1arkw | 1264 | } |
| 85 | e1arkw | 1472 | viewProperties[YuiFrameworkGlobals.namingConvention.getHelperPackageName()] = null; |
| 86 | delete viewProperties[YuiFrameworkGlobals.namingConvention.getHelperPackageName()]; | ||
| 87 | e1arkw | 1077 | // |
| 88 | CONFIG::DEBUG { | ||
| 89 | e1arkw | 1431 | debug(this,getMessage("Uncustomized",viewClassName,helperClassName)); |
| 90 | e1arkw | 1077 | } |
| 91 | } catch(e:Error) { | ||
| 92 | CONFIG::DEBUG { | ||
| 93 | e1arkw | 1431 | debug(this,getMessage("CustomizeError",container,e.getStackTrace())); |
| 94 | e1arkw | 1077 | } |
| 95 | } | ||
| 96 | } | ||
| 97 | e1arkw | 1341 | |
| 98 | |||
| 99 | protected function setHelperProperties(container:UIComponent,obj:Object):void{ | ||
| 100 | e1arkw | 1472 | const viewProperties:Object = UIComponentUtil.getProperties(container); |
| 101 | e1arkw | 1341 | const viewClassName:String = getCanonicalName(container); |
| 102 | e1arkw | 1472 | const targetClassRef:ClassRef = getClassRef(obj); |
| 103 | const helperMap:Object = viewProperties[YuiFrameworkGlobals.namingConvention.getHelperPackageName()]; | ||
| 104 | e1arkw | 1341 | CONFIG::FP9 { |
| 105 | e1arkw | 1386 | const props:Array = |
| 106 | e1arkw | 1472 | targetClassRef.properties.filter( |
| 107 | e1arkw | 1386 | function(item:*,index:int,array:Array):Boolean { |
| 108 | return ( YuiFrameworkGlobals.namingConvention.isHelperOfView( viewClassName, (item as PropertyRef).typeClassRef.name )); | ||
| 109 | } | ||
| 110 | ); | ||
| 111 | e1arkw | 1341 | } |
| 112 | CONFIG::FP10 { | ||
| 113 | e1arkw | 1386 | const props:Vector.<PropertyRef> = |
| 114 | e1arkw | 1472 | targetClassRef.properties.filter( |
| 115 | e1arkw | 1386 | function(item:*,index:int,array:Vector.<PropertyRef>):Boolean { |
| 116 | return ( YuiFrameworkGlobals.namingConvention.isHelperOfView( viewClassName, (item as PropertyRef).typeClassRef.name )); | ||
| 117 | } | ||
| 118 | ); | ||
| 119 | e1arkw | 1341 | } |
| 120 | |||
| 121 | var helper:Object; | ||
| 122 | var helperClassRef:ClassRef; | ||
| 123 | for each(var prop:PropertyRef in props) { | ||
| 124 | e1arkw | 1386 | helperClassRef = getClassRef(prop.typeClassRef.name); |
| 125 | if( helperClassRef.name in helperMap){ | ||
| 126 | helper = helperMap[helperClassRef.name]; | ||
| 127 | e1arkw | 1341 | } else { |
| 128 | e1arkw | 1393 | helper = newInstance(prop.typeClassRef); |
| 129 | e1arkw | 1386 | helperMap[helperClassRef.name] = helper; |
| 130 | e1arkw | 1341 | } |
| 131 | e1arkw | 1386 | |
| 132 | setPropertiesValue(helper,viewClassName,container); | ||
| 133 | setViewComponents(container,helperClassRef,helper); | ||
| 134 | |||
| 135 | prop.setValue(obj,helper); | ||
| 136 | // | ||
| 137 | if( helper is ILifeCyclable ){ | ||
| 138 | (helper as ILifeCyclable).start(); | ||
| 139 | } | ||
| 140 | e1arkw | 1341 | } |
| 141 | } | ||
| 142 | |||
| 143 | protected function setViewComponents(container:UIComponent,helperClassRef:ClassRef,helper:Object):void{ | ||
| 144 | CONFIG::FP9 { | ||
| 145 | e1arkw | 1444 | const viewProps:Array = getClassRef(container).properties; |
| 146 | e1arkw | 1341 | } |
| 147 | CONFIG::FP10 { | ||
| 148 | e1arkw | 1444 | const viewProps:Vector.<PropertyRef> = getClassRef(container).properties; |
| 149 | e1arkw | 1341 | } |
| 150 | var helperPropRef:PropertyRef; | ||
| 151 | for each(var viewProp:PropertyRef in viewProps) { | ||
| 152 | helperPropRef = helperClassRef.getPropertyRef(viewProp.name); | ||
| 153 | e1arkw | 1467 | if( helperPropRef != null && helperPropRef.uri == viewpart.toString()){ |
| 154 | e1arkw | 1341 | helperPropRef.setValue(helper,viewProp.getValue(container)); |
| 155 | } | ||
| 156 | } | ||
| 157 | } | ||
| 158 | e1arkw | 1077 | } |
| 159 | } |
| Repository Top ViewVC Help |
![]() |
| Powered by ViewVC |

