利用者向け情報

開発者向け情報

[sandbox.akabana]/trunk/yui-frameworks/yui-framework/src/main/flex/jp/akb7/yui/core/YuiFrameworkController.as

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1586 - (hide annotations)
Fri Jun 10 01:43:04 2011 JST (2 years ago) by e1arkw
Original Path: trunk/yui/yui-framework/src/main/flex/org/seasar/akabana/yui/framework/core/YuiFrameworkController.as
File size: 19332 byte(s)
コンポーネントのドキュメントを取得する方法をブリッジに出した。
Flex4では、コンポーネントがスキンパーツ場合に、ドキュメントをスキンのhostComponentにするため
1 e1arkw 404 /*
2 e1arkw 1504 * Copyright 2004-2011 the Seasar Foundation and the Others.
3 e1arkw 1316 *
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 e1arkw 404 package org.seasar.akabana.yui.framework.core
17     {
18 e1arkw 1316 CONFIG::FP10{
19     import __AS3__.vec.Vector;
20     }
21    
22     CONFIG::UNCAUGHT_ERROR_GLOBAL{
23     import flash.events.UncaughtErrorEvent;
24     }
25    
26 e1arkw 404 import flash.events.Event;
27 e1arkw 1475 import flash.errors.IllegalOperationError;
28 e1arkw 863 import flash.system.Capabilities;
29 e1arkw 1316 import flash.display.DisplayObjectContainer;
30     import flash.display.DisplayObject;
31 e1arkw 1477 import flash.utils.Dictionary;
32 e1arkw 1525 import flash.display.LoaderInfo;
33 e1arkw 1316
34 e1arkw 404 import mx.core.UIComponent;
35     import mx.events.FlexEvent;
36 e1arkw 716 import mx.managers.ISystemManager;
37 e1arkw 1316 import mx.managers.SystemManager;
38 e1arkw 1475 import mx.managers.CursorManager;
39     import mx.managers.PopUpManager;
40     import mx.managers.DragManager;
41     import mx.styles.IStyleManager2;
42     import mx.styles.CSSStyleDeclaration;
43 e1arkw 1316
44 e1arkw 760 import org.seasar.akabana.yui.core.Environment;
45 e1arkw 1480 import org.seasar.akabana.yui.core.ns.yui_internal;
46 e1arkw 1316
47 e1arkw 955 import org.seasar.akabana.yui.framework.YuiFrameworkGlobals;
48 e1arkw 1485 import org.seasar.akabana.yui.framework.event.YuiFrameworkEvent;
49 e1arkw 1507 import org.seasar.akabana.yui.framework.bridge.FrameworkBridge;
50 e1arkw 404 import org.seasar.akabana.yui.framework.customizer.IComponentCustomizer;
51 e1arkw 1264 import org.seasar.akabana.yui.framework.customizer.IViewCustomizer;
52     import org.seasar.akabana.yui.framework.customizer.IElementCustomizer;
53 e1arkw 1482 import org.seasar.akabana.yui.framework.error.YuiFrameworkError;
54 e1arkw 1264 import org.seasar.akabana.yui.framework.util.UIComponentUtil;
55 e1arkw 1316 import org.seasar.akabana.yui.framework.util.StyleManagerUtil;
56 e1arkw 1482 import org.seasar.akabana.yui.framework.event.RuntimeErrorEvent;
57 e1arkw 1431 import org.seasar.akabana.yui.framework.logging.debug;
58 e1arkw 1475 import org.seasar.akabana.yui.framework.logging.dump;
59 e1arkw 1431 import org.seasar.akabana.yui.framework.logging.Logging;
60 e1arkw 1480 import org.seasar.akabana.yui.core.ns.yui_internal;
61 e1arkw 1507 import org.seasar.akabana.yui.framework.convention.NamingConvention;
62 e1arkw 1316
63     use namespace yui_internal;
64    
65 e1arkw 1034 [ExcludeClass]
66 e1arkw 1482 public final class YuiFrameworkController extends YuiFrameworkControllerBase
67 e1arkw 1316 {
68 e1arkw 1586
69     private static function getDocumentOf(target:DisplayObject):UIComponent{
70     if( target == null ){
71     return null;
72     }
73     const frameworkBridge:FrameworkBridge = YuiFrameworkGlobals.public::frameworkBridge as FrameworkBridge;
74     return frameworkBridge.getDocumentOf(target) as UIComponent;
75     }
76    
77 e1arkw 1316 {
78     CursorManager;
79     PopUpManager;
80     DragManager;
81 e1arkw 1303 }
82    
83 e1arkw 1520 private static var _this:IYuiFrameworkController;
84 e1arkw 1316
85 e1arkw 1520 public static function getInstance():IYuiFrameworkController{
86     return _this;
87 e1arkw 683 }
88 e1arkw 1316
89 e1arkw 1523 protected function set currentSystemManger(value:ISystemManager):void{
90 e1arkw 1565 CONFIG::DEBUG{
91     if( _currentRoot != value ){
92     _debug("CurrentRoot",value);
93     }
94     }
95 e1arkw 1523 _currentRoot = value as DisplayObject;
96     }
97    
98 e1arkw 1482 public function YuiFrameworkController(){
99 e1arkw 834 super();
100 e1arkw 1520 if( _this == null ){
101     _this = this;
102 e1arkw 834 } else {
103 e1arkw 1482 throw new YuiFrameworkError("container is already created.");
104 e1arkw 1316 }
105 e1arkw 404 }
106 e1arkw 1316
107     public override function customizeView( container:DisplayObjectContainer ):void{
108     var view:UIComponent = container as UIComponent;
109 e1arkw 1581 if( view == null || !view.initialized ){
110 e1arkw 1565 CONFIG::DEBUG{
111     _debug("ViewCustomizeInitializeError",view);
112 e1arkw 1336 }
113 e1arkw 1316 return;
114     }
115 e1arkw 1264 CONFIG::DEBUG{
116 e1arkw 1565 _debug("ViewCustomizing", view, view.owner);
117 e1arkw 1264 }
118 e1arkw 1523 currentSystemManger = view.systemManager;
119 e1arkw 1264 var viewcustomizer_:IViewCustomizer;
120 e1arkw 1206 for each( var customizer_:IElementCustomizer in _customizers ){
121 e1arkw 1264 viewcustomizer_ = customizer_ as IViewCustomizer;
122     if( viewcustomizer_ != null ){
123 e1arkw 1316 viewcustomizer_.customizeView( view );
124 e1arkw 1264 }
125 e1arkw 903 }
126 e1arkw 1487 if( view.hasEventListener(YuiFrameworkEvent.VIEW_INITIALIZED)){
127     view.dispatchEvent( new YuiFrameworkEvent(YuiFrameworkEvent.VIEW_INITIALIZED));
128     }
129 e1arkw 1565 CONFIG::DEBUG{
130     _debug("ViewCustomized",view,view.owner);
131     }
132 e1arkw 903 }
133 e1arkw 1316
134     public override function uncustomizeView( container:DisplayObjectContainer ):void{
135     var view:UIComponent = container as UIComponent;
136     if( !view.initialized ){
137 e1arkw 1336 CONFIG::DEBUG {
138 e1arkw 1565 _debug("ViewUncustomizeInitializeError",view);
139 e1arkw 1336 }
140 e1arkw 1316 return;
141     }
142     CONFIG::DEBUG{
143 e1arkw 1565 _debug("ViewUncustomizing",view,view.owner);
144 e1arkw 1316 }
145 e1arkw 1523 currentSystemManger = view.systemManager;
146 e1arkw 903 var numCustomizers:int = customizers.length;
147 e1arkw 1264 var viewcustomizer_:IViewCustomizer;
148 e1arkw 903 for( var i:int = numCustomizers-1; i >= 0; i-- ){
149 e1arkw 1213 viewcustomizer_ = customizers[i] as IViewCustomizer;
150 e1arkw 1264 if( viewcustomizer_ != null ){
151 e1arkw 1316 viewcustomizer_.uncustomizeView( view );
152 e1arkw 1264 }
153 e1arkw 903 }
154 e1arkw 1565 CONFIG::DEBUG{
155     _debug("ViewUncustomized",view,view.owner);
156     }
157 e1arkw 903 }
158 e1arkw 1264
159 e1arkw 1316 public override function customizeComponent( container:DisplayObjectContainer, child:DisplayObject ):void{
160     var view:UIComponent = container as UIComponent;
161     var component:UIComponent = child as UIComponent;
162     if( !view.initialized || !component.initialized){
163 e1arkw 1336 CONFIG::DEBUG{
164 e1arkw 1565 _debug("ComponentCustomizeViewInitializeError",view,view.owner);
165 e1arkw 1336 }
166 e1arkw 1316 return;
167     }
168     CONFIG::DEBUG{
169 e1arkw 1565 _debug("ComponentCustomizing",child,container);
170 e1arkw 1316 }
171 e1arkw 1523 currentSystemManger = view.systemManager;
172 e1arkw 1264 var componentcustomizer_:IComponentCustomizer;
173     for each( var customizer_:IElementCustomizer in _customizers ){
174     componentcustomizer_ = customizer_ as IComponentCustomizer;
175     if( componentcustomizer_ != null ){
176 e1arkw 1316 componentcustomizer_.customizeComponent( view, component );
177 e1arkw 1264 }
178     }
179 e1arkw 1346 CONFIG::DEBUG{
180 e1arkw 1565 _debug("ComponentCustomized",child,container);
181 e1arkw 1346 }
182 e1arkw 1264 }
183    
184 e1arkw 1316 public override function uncustomizeComponent( container:DisplayObjectContainer, child:DisplayObject ):void{
185     var view:UIComponent = container as UIComponent;
186     var component:UIComponent = child as UIComponent;
187 e1arkw 1336 if( !view.initialized ){
188     CONFIG::DEBUG{
189 e1arkw 1565 _debug("ComponentUncustomizeViewInitializeError",view);
190 e1arkw 1336 }
191 e1arkw 1316 return;
192     }
193     CONFIG::DEBUG{
194 e1arkw 1565 _debug("ComponentUncustomizing",child, container);
195 e1arkw 1316 }
196 e1arkw 1523 currentSystemManger = view.systemManager;
197 e1arkw 1264 var numCustomizers:int = customizers.length;
198     var componentcustomizer_:IComponentCustomizer;
199     for( var i:int = numCustomizers-1; i >= 0; i-- ){
200     componentcustomizer_ = customizers[i] as IComponentCustomizer;
201     if( componentcustomizer_ != null ){
202 e1arkw 1316 componentcustomizer_.uncustomizeComponent( view, component );
203 e1arkw 1264 }
204     }
205 e1arkw 1346 CONFIG::DEBUG{
206 e1arkw 1565 _debug("ComponentUncustomized",child, container);
207 e1arkw 1346 }
208 e1arkw 1316 }
209    
210 e1arkw 1581 private function application_initCompleteHandler( event:Event ):void{
211 e1arkw 1475 Logging.initialize();
212 e1arkw 1316 CONFIG::DEBUG_EVENT{
213 e1arkw 1475 dump(this,event);
214 e1arkw 1316 }
215 e1arkw 1125 }
216 e1arkw 1316
217 e1arkw 1581 private function application_preloaderDoneHandler( event:Event ):void{
218 e1arkw 1316 CONFIG::DEBUG_EVENT{
219 e1arkw 1475 dump(this,event);
220 e1arkw 903 }
221 e1arkw 1477 if( event.currentTarget is ISystemManager ){
222     var sm:ISystemManager = event.currentTarget as ISystemManager;
223     super.yui_internal::systemManagerMonitoringStart(sm as DisplayObject);
224     } else {
225     throw new IllegalOperationError("Illegal SystemManager"+event.currentTarget);
226     }
227 e1arkw 1316 YuiFrameworkGlobals.initNamingConvention();
228     CONFIG::DEBUG{
229 e1arkw 1565 _debug("ApplicationConventions",YuiFrameworkGlobals.public::namingConvention.conventions.toString());
230 e1arkw 1316 }
231 e1arkw 903 }
232 e1arkw 1316
233 e1arkw 1581 private function application_applicationCompleteHandler( event:FlexEvent ):void{
234 e1arkw 1316 CONFIG::DEBUG_EVENT{
235 e1arkw 1475 dump(this,event);
236 e1arkw 1264 }
237 e1arkw 1316 applicationMonitoringStop(event.currentTarget as DisplayObject);
238 e1arkw 903 }
239 e1arkw 1303
240 e1arkw 1581 private function systemManager_creationCompleteHandler(event:FlexEvent):void{
241 e1arkw 1316 CONFIG::DEBUG_EVENT{
242 e1arkw 1475 dump(this,event);
243 e1arkw 1316 }
244     doAssembleComponent(event.target as DisplayObject);
245 e1arkw 1303 }
246    
247 e1arkw 1316 protected override function doRegisterComponent( target:DisplayObject ):void{
248     var component:UIComponent = target as UIComponent;
249 e1arkw 1581 if( component == null || !component.initialized ){
250     return;
251     }
252 e1arkw 1583 const frameworkBridge:FrameworkBridge = YuiFrameworkGlobals.public::frameworkBridge as FrameworkBridge;
253     if( frameworkBridge.isApplication(component) ){
254     processApplicationRegister(component as DisplayObjectContainer);
255     } else {
256     processViewRegister(component as DisplayObjectContainer);
257     if( _isApplicationStarted ){
258     doAssembleComponent(component);
259     }
260     }
261 e1arkw 1303 }
262    
263 e1arkw 1316 protected override function doUnregisterComponent(target:DisplayObject):void{
264     var component:UIComponent = target as UIComponent;
265 e1arkw 1519 if( component == null || !component.initialized ){
266     return;
267     }
268 e1arkw 1316 if( isView(component)){
269 e1arkw 1586 uncustomizeView( component as DisplayObjectContainer);
270 e1arkw 1583 processViewUnregister( component as DisplayObjectContainer);
271 e1arkw 1316 } else if(isComponent(component)){
272 e1arkw 1586 var document:UIComponent = getDocumentOf(component);
273     if( document != null && isView(document)){
274     uncustomizeComponent(document,component);
275 e1arkw 472 }
276 e1arkw 404 }
277 e1arkw 424 }
278 e1arkw 1264
279 e1arkw 1316 protected override function doAssembleComponent( target:DisplayObject ):void{
280     var component:UIComponent = target as UIComponent;
281     if( component == null || !component.initialized ){
282     return;
283     }
284 e1arkw 1206 if( isView(component)){
285 e1arkw 1586 customizeView(component);
286 e1arkw 1240 } else if(isComponent(component)){
287 e1arkw 1586 var document:UIComponent = getDocumentOf(component);
288     if( document != null && isView(document)){
289     customizeComponent(document,component);
290 e1arkw 1264 }
291     }
292 e1arkw 842 }
293 e1arkw 1316
294 e1arkw 1506 protected override function processApplicationRegister(component:DisplayObjectContainer):void{
295     super.processApplicationRegister(component);
296 e1arkw 1581
297     const frameworkBridge:FrameworkBridge = YuiFrameworkGlobals.public::frameworkBridge as FrameworkBridge;
298     const root:DisplayObject = frameworkBridge.systemManager;
299 e1arkw 1506 systemManagerMonitoringStop(root);
300     applicationMonitoringStart(root);
301     CONFIG::UNCAUGHT_ERROR_GLOBAL{
302     root.loaderInfo.uncaughtErrorEvents
303     .addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, loaderInfoUncaughtErrorHandler,false,int.MAX_VALUE);
304     }
305     if( root is SystemManager ){
306     var sm:SystemManager = root as SystemManager;
307     var preloadedRSLs:Dictionary = sm.preloadedRSLs;
308    
309     for( var item:Object in preloadedRSLs ){
310     var loaderInfo:LoaderInfo = item as LoaderInfo;
311     CONFIG::DEBUG{
312     debug(this,"preloadedRSLs:"+loaderInfo.url);
313     }
314     CONFIG::UNCAUGHT_ERROR_GLOBAL{
315     loaderInfo.loader.uncaughtErrorEvents
316     .addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, loaderInfoUncaughtErrorHandler,false,int.MAX_VALUE);
317     }
318     }
319     }
320     }
321    
322 e1arkw 1316 protected override function processApplicationStart():void{
323 e1arkw 1507 const frameworkBridge:FrameworkBridge = YuiFrameworkGlobals.public::frameworkBridge as FrameworkBridge;
324     const app:UIComponent = frameworkBridge.application as UIComponent;
325     const rootView:DisplayObjectContainer = frameworkBridge.rootView as DisplayObjectContainer;
326 e1arkw 1316 app.setVisible(true,true);
327 e1arkw 1373 super.processApplicationStart();
328 e1arkw 1477
329     var allView:Dictionary = ViewComponentRepository.allView;
330 e1arkw 1485 var fevent:YuiFrameworkEvent;
331 e1arkw 1477 for each (var view:UIComponent in allView)
332     {
333     if( view === rootView ){
334     continue;
335     }
336 e1arkw 1485 if( view.hasEventListener(YuiFrameworkEvent.APPLICATION_START)){
337     fevent = new YuiFrameworkEvent(YuiFrameworkEvent.APPLICATION_START);
338 e1arkw 1477 view.dispatchEvent( fevent );
339     }
340     }
341 e1arkw 1581 _isApplicationStarted = true;
342 e1arkw 1303 }
343    
344 e1arkw 1316 protected override function getDefaultCustomizerClasses():Array{
345     const styleManager:IStyleManager2 = StyleManagerUtil.getStyleManager();
346     const customizersDef:CSSStyleDeclaration = styleManager.getStyleDeclaration(".customizers");
347     const defaultFactory:Function = customizersDef.defaultFactory;
348    
349     const result:Array = [];
350     const keys:Array = [];
351    
352     var customizers:Object = {};
353     if (defaultFactory != null)
354     {
355     defaultFactory.prototype = {};
356     customizers = new defaultFactory();
357 e1arkw 1264 }
358 e1arkw 1316
359     var customizer:Class;
360     for( var key:String in customizers ){
361     keys.push(key);
362 e1arkw 424 }
363 e1arkw 1316 keys.sort();
364     for( var i:int = 0; i < keys.length; i++ ){
365     customizer = customizers[keys[i]] as Class;
366     result.push(customizer);
367     }
368     CONFIG::DEBUG{
369 e1arkw 1565 _debug("CustomizerLoaded",result);
370 e1arkw 1316 }
371     return result;
372 e1arkw 404 }
373 e1arkw 1409
374 e1arkw 1317 yui_internal override function applicationInitialize():void{
375 e1arkw 1506
376 e1arkw 1316 if( _customizers == null ){
377     _customizers = getDefaultCustomizers();
378     }
379     CONFIG::DEBUG{
380 e1arkw 1565 _debug("ViewAssembleStart");
381 e1arkw 1316 }
382    
383 e1arkw 1445 var allView:Dictionary = ViewComponentRepository.allView;
384     for ( var viewName:String in allView ){
385 e1arkw 1316 CONFIG::DEBUG{
386 e1arkw 1565 _debug("ViewAssembleing",viewName);
387 e1arkw 404 }
388 e1arkw 1581 customizeView(ViewComponentRepository.getComponent(viewName));
389 e1arkw 1316 CONFIG::DEBUG{
390 e1arkw 1565 _debug("ViewAssembled",viewName);
391 e1arkw 1316 }
392 e1arkw 404 }
393 e1arkw 1316
394     CONFIG::DEBUG{
395 e1arkw 1565 _debug("ViewAssembleEnd");
396 e1arkw 468 }
397 e1arkw 1316 callLater( processApplicationStart );
398 e1arkw 432 }
399 e1arkw 1264
400 e1arkw 1317 yui_internal override function applicationMonitoringStart(root:DisplayObject):void{
401 e1arkw 1507 super.applicationMonitoringStart(root);
402 e1arkw 1317 }
403    
404 e1arkw 1316 yui_internal override function applicationMonitoringStop(root:DisplayObject):void{
405     root.removeEventListener(
406     FlexEvent.APPLICATION_COMPLETE,
407 e1arkw 1581 application_applicationCompleteHandler,
408 e1arkw 1316 false
409     );
410    
411     root.removeEventListener(
412     FlexEvent.INIT_COMPLETE,
413 e1arkw 1581 application_initCompleteHandler,
414 e1arkw 1316 true
415     );
416    
417     root.removeEventListener(
418     FlexEvent.PRELOADER_DONE,
419 e1arkw 1581 application_preloaderDoneHandler,
420 e1arkw 1316 true
421     );
422 e1arkw 1581
423     root.addEventListener(
424     FlexEvent.CREATION_COMPLETE,
425     systemManager_creationCompleteHandler,
426     true,
427     int.MAX_VALUE
428     );
429 e1arkw 1316 super.applicationMonitoringStop(root);
430 e1arkw 842 }
431 e1arkw 1316
432     yui_internal override function systemManagerMonitoringStart( root:DisplayObject ):void{
433     root.addEventListener(
434     FlexEvent.INIT_COMPLETE,
435 e1arkw 1581 application_initCompleteHandler,
436 e1arkw 1316 true,
437     int.MAX_VALUE
438     );
439    
440     root.addEventListener(
441     FlexEvent.PRELOADER_DONE,
442 e1arkw 1581 application_preloaderDoneHandler,
443 e1arkw 1316 true,
444     int.MAX_VALUE
445     );
446    
447     root.addEventListener(
448     FlexEvent.APPLICATION_COMPLETE,
449 e1arkw 1581 application_applicationCompleteHandler,
450 e1arkw 1316 false,
451     int.MAX_VALUE
452     );
453     }
454    
455     yui_internal override function systemManagerMonitoringStop(root:DisplayObject):void{
456 e1arkw 1507 const frameworkBridge:FrameworkBridge = YuiFrameworkGlobals.public::frameworkBridge as FrameworkBridge;
457     const application_:DisplayObjectContainer = frameworkBridge.application;
458 e1arkw 1581 if( application_ != null && application_.hasEventListener(FlexEvent.CREATION_COMPLETE)){
459 e1arkw 1316 root.removeEventListener(
460     FlexEvent.CREATION_COMPLETE,
461 e1arkw 1581 systemManager_creationCompleteHandler,
462 e1arkw 1316 true
463     );
464 e1arkw 1071 }
465 e1arkw 1507 super.systemManagerMonitoringStop(root);
466 e1arkw 1071 }
467 e1arkw 404 }
468     }

Properties

Name Value
svn:keywords Author Revision

Repository Top
ViewVC Help  
ViewVC logotype
Powered by ViewVC