利用者向け情報

開発者向け情報

[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 1565 - (hide annotations)
Mon Jun 6 13:08:38 2011 JST (23 months, 2 weeks ago) by e1arkw
Original Path: trunk/yui/yui-framework/src/main/flex/org/seasar/akabana/yui/framework/core/YuiFrameworkController.as
File size: 19600 byte(s)
ログの修正
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     {
69     CursorManager;
70     PopUpManager;
71     DragManager;
72 e1arkw 1303 }
73    
74 e1arkw 1520 private static var _this:IYuiFrameworkController;
75 e1arkw 1316
76 e1arkw 1520 public static function getInstance():IYuiFrameworkController{
77     return _this;
78 e1arkw 683 }
79 e1arkw 1316
80 e1arkw 1523 protected function set currentSystemManger(value:ISystemManager):void{
81 e1arkw 1565 CONFIG::DEBUG{
82     if( _currentRoot != value ){
83     _debug("CurrentRoot",value);
84     }
85     }
86 e1arkw 1523 _currentRoot = value as DisplayObject;
87     }
88    
89 e1arkw 1482 public function YuiFrameworkController(){
90 e1arkw 834 super();
91 e1arkw 1520 if( _this == null ){
92     _this = this;
93 e1arkw 834 } else {
94 e1arkw 1482 throw new YuiFrameworkError("container is already created.");
95 e1arkw 1316 }
96 e1arkw 404 }
97 e1arkw 1316
98     public override function customizeView( container:DisplayObjectContainer ):void{
99     var view:UIComponent = container as UIComponent;
100 e1arkw 1336 if( !view.initialized ){
101 e1arkw 1565 CONFIG::DEBUG{
102     _debug("ViewCustomizeInitializeError",view);
103 e1arkw 1336 }
104 e1arkw 1316 return;
105     }
106 e1arkw 1264 CONFIG::DEBUG{
107 e1arkw 1565 _debug("ViewCustomizing", view, view.owner);
108 e1arkw 1264 }
109 e1arkw 1523 currentSystemManger = view.systemManager;
110 e1arkw 1264 var viewcustomizer_:IViewCustomizer;
111 e1arkw 1206 for each( var customizer_:IElementCustomizer in _customizers ){
112 e1arkw 1264 viewcustomizer_ = customizer_ as IViewCustomizer;
113     if( viewcustomizer_ != null ){
114 e1arkw 1316 viewcustomizer_.customizeView( view );
115 e1arkw 1264 }
116 e1arkw 903 }
117 e1arkw 1487 if( view.hasEventListener(YuiFrameworkEvent.VIEW_INITIALIZED)){
118     view.dispatchEvent( new YuiFrameworkEvent(YuiFrameworkEvent.VIEW_INITIALIZED));
119     }
120 e1arkw 1565 CONFIG::DEBUG{
121     _debug("ViewCustomized",view,view.owner);
122     }
123 e1arkw 903 }
124 e1arkw 1316
125     public override function uncustomizeView( container:DisplayObjectContainer ):void{
126     var view:UIComponent = container as UIComponent;
127     if( !view.initialized ){
128 e1arkw 1336 CONFIG::DEBUG {
129 e1arkw 1565 _debug("ViewUncustomizeInitializeError",view);
130 e1arkw 1336 }
131 e1arkw 1316 return;
132     }
133     CONFIG::DEBUG{
134 e1arkw 1565 _debug("ViewUncustomizing",view,view.owner);
135 e1arkw 1316 }
136 e1arkw 1523 currentSystemManger = view.systemManager;
137 e1arkw 903 var numCustomizers:int = customizers.length;
138 e1arkw 1264 var viewcustomizer_:IViewCustomizer;
139 e1arkw 903 for( var i:int = numCustomizers-1; i >= 0; i-- ){
140 e1arkw 1213 viewcustomizer_ = customizers[i] as IViewCustomizer;
141 e1arkw 1264 if( viewcustomizer_ != null ){
142 e1arkw 1316 viewcustomizer_.uncustomizeView( view );
143 e1arkw 1264 }
144 e1arkw 903 }
145 e1arkw 1565 CONFIG::DEBUG{
146     _debug("ViewUncustomized",view,view.owner);
147     }
148 e1arkw 903 }
149 e1arkw 1264
150 e1arkw 1316 public override function customizeComponent( container:DisplayObjectContainer, child:DisplayObject ):void{
151     var view:UIComponent = container as UIComponent;
152     var component:UIComponent = child as UIComponent;
153     if( !view.initialized || !component.initialized){
154 e1arkw 1336 CONFIG::DEBUG{
155 e1arkw 1565 _debug("ComponentCustomizeViewInitializeError",view,view.owner);
156 e1arkw 1336 }
157 e1arkw 1316 return;
158     }
159     CONFIG::DEBUG{
160 e1arkw 1565 _debug("ComponentCustomizing",child,container);
161 e1arkw 1316 }
162 e1arkw 1523 currentSystemManger = view.systemManager;
163 e1arkw 1264 var componentcustomizer_:IComponentCustomizer;
164     for each( var customizer_:IElementCustomizer in _customizers ){
165     componentcustomizer_ = customizer_ as IComponentCustomizer;
166     if( componentcustomizer_ != null ){
167 e1arkw 1316 componentcustomizer_.customizeComponent( view, component );
168 e1arkw 1264 }
169     }
170 e1arkw 1346 CONFIG::DEBUG{
171 e1arkw 1565 _debug("ComponentCustomized",child,container);
172 e1arkw 1346 }
173 e1arkw 1264 }
174    
175 e1arkw 1316 public override function uncustomizeComponent( container:DisplayObjectContainer, child:DisplayObject ):void{
176     var view:UIComponent = container as UIComponent;
177     var component:UIComponent = child as UIComponent;
178 e1arkw 1336 if( !view.initialized ){
179     CONFIG::DEBUG{
180 e1arkw 1565 _debug("ComponentUncustomizeViewInitializeError",view);
181 e1arkw 1336 }
182 e1arkw 1316 return;
183     }
184     CONFIG::DEBUG{
185 e1arkw 1565 _debug("ComponentUncustomizing",child, container);
186 e1arkw 1316 }
187 e1arkw 1523 currentSystemManger = view.systemManager;
188 e1arkw 1264 var numCustomizers:int = customizers.length;
189     var componentcustomizer_:IComponentCustomizer;
190     for( var i:int = numCustomizers-1; i >= 0; i-- ){
191     componentcustomizer_ = customizers[i] as IComponentCustomizer;
192     if( componentcustomizer_ != null ){
193 e1arkw 1316 componentcustomizer_.uncustomizeComponent( view, component );
194 e1arkw 1264 }
195     }
196 e1arkw 1346 CONFIG::DEBUG{
197 e1arkw 1565 _debug("ComponentUncustomized",child, container);
198 e1arkw 1346 }
199 e1arkw 1316 }
200    
201 e1arkw 1125 private function applicationInitCompleteHandler( event:Event ):void{
202 e1arkw 1475 Logging.initialize();
203 e1arkw 1316 CONFIG::DEBUG_EVENT{
204 e1arkw 1475 dump(this,event);
205 e1arkw 1316 }
206 e1arkw 1125 }
207 e1arkw 1316
208 e1arkw 1125 private function applicationPreloaderDoneHandler( event:Event ):void{
209 e1arkw 1316 CONFIG::DEBUG_EVENT{
210 e1arkw 1475 dump(this,event);
211 e1arkw 903 }
212 e1arkw 1477 if( event.currentTarget is ISystemManager ){
213     var sm:ISystemManager = event.currentTarget as ISystemManager;
214     super.yui_internal::systemManagerMonitoringStart(sm as DisplayObject);
215     } else {
216     throw new IllegalOperationError("Illegal SystemManager"+event.currentTarget);
217     }
218 e1arkw 1316 YuiFrameworkGlobals.initNamingConvention();
219     CONFIG::DEBUG{
220 e1arkw 1565 _debug("ApplicationConventions",YuiFrameworkGlobals.public::namingConvention.conventions.toString());
221 e1arkw 1316 }
222 e1arkw 903 }
223 e1arkw 1316
224     private function applicationCompleteHandler( event:FlexEvent ):void{
225     CONFIG::DEBUG_EVENT{
226 e1arkw 1475 dump(this,event);
227 e1arkw 1264 }
228 e1arkw 1316 applicationMonitoringStop(event.currentTarget as DisplayObject);
229 e1arkw 903 }
230 e1arkw 1303
231 e1arkw 1316 private function creationCompleteHandler(event:FlexEvent):void{
232     CONFIG::DEBUG_EVENT{
233 e1arkw 1475 dump(this,event);
234 e1arkw 1316 }
235     doAssembleComponent(event.target as DisplayObject);
236 e1arkw 1303 }
237    
238 e1arkw 1316 protected override function doRegisterComponent( target:DisplayObject ):void{
239     var component:UIComponent = target as UIComponent;
240     super.doRegisterComponent(component);
241 e1arkw 1303 }
242    
243 e1arkw 1316 protected override function doUnregisterComponent(target:DisplayObject):void{
244     var component:UIComponent = target as UIComponent;
245 e1arkw 1519 if( component == null || !component.initialized ){
246     return;
247     }
248 e1arkw 1316 if( isView(component)){
249     super.doUnregisterComponent(component);
250     } else if(isComponent(component)){
251     var document:UIComponent = component.document as UIComponent;
252     if( document != null && document.initialized && isView(document)){
253 e1arkw 1487 processViewChildDisassemble(document,component);
254 e1arkw 472 }
255 e1arkw 404 }
256 e1arkw 424 }
257 e1arkw 1264
258 e1arkw 1316 protected override function doAssembleComponent( target:DisplayObject ):void{
259     var component:UIComponent = target as UIComponent;
260     if( component == null || !component.initialized ){
261     return;
262     }
263 e1arkw 1206 if( isView(component)){
264 e1arkw 1487 processViewAssemble(component);
265 e1arkw 1240 } else if(isComponent(component)){
266 e1arkw 1264 var document:UIComponent = component.document as UIComponent;
267     if( document != null && document.initialized && isView(document)){
268 e1arkw 1487 processViewChildAssemble(document,component);
269 e1arkw 1264 }
270     }
271 e1arkw 842 }
272 e1arkw 1316
273 e1arkw 1506 protected override function processApplicationRegister(component:DisplayObjectContainer):void{
274     super.processApplicationRegister(component);
275    
276     const root:DisplayObject = YuiFrameworkGlobals.public::frameworkBridge.systemManager;
277     systemManagerMonitoringStop(root);
278     applicationMonitoringStart(root);
279     CONFIG::UNCAUGHT_ERROR_GLOBAL{
280     root.loaderInfo.uncaughtErrorEvents
281     .addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, loaderInfoUncaughtErrorHandler,false,int.MAX_VALUE);
282     }
283     if( root is SystemManager ){
284     var sm:SystemManager = root as SystemManager;
285     var preloadedRSLs:Dictionary = sm.preloadedRSLs;
286    
287     for( var item:Object in preloadedRSLs ){
288     var loaderInfo:LoaderInfo = item as LoaderInfo;
289     CONFIG::DEBUG{
290     debug(this,"preloadedRSLs:"+loaderInfo.url);
291     }
292     CONFIG::UNCAUGHT_ERROR_GLOBAL{
293     loaderInfo.loader.uncaughtErrorEvents
294     .addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, loaderInfoUncaughtErrorHandler,false,int.MAX_VALUE);
295     }
296     }
297     }
298     }
299    
300 e1arkw 1316 protected override function processApplicationStart():void{
301 e1arkw 1507 const frameworkBridge:FrameworkBridge = YuiFrameworkGlobals.public::frameworkBridge as FrameworkBridge;
302     const app:UIComponent = frameworkBridge.application as UIComponent;
303     const rootView:DisplayObjectContainer = frameworkBridge.rootView as DisplayObjectContainer;
304 e1arkw 1316 app.setVisible(true,true);
305 e1arkw 1373 super.processApplicationStart();
306 e1arkw 1477
307     var allView:Dictionary = ViewComponentRepository.allView;
308 e1arkw 1485 var fevent:YuiFrameworkEvent;
309 e1arkw 1477 for each (var view:UIComponent in allView)
310     {
311     if( view === rootView ){
312     continue;
313     }
314 e1arkw 1485 if( view.hasEventListener(YuiFrameworkEvent.APPLICATION_START)){
315     fevent = new YuiFrameworkEvent(YuiFrameworkEvent.APPLICATION_START);
316 e1arkw 1477 view.dispatchEvent( fevent );
317     }
318     }
319 e1arkw 1303 }
320    
321 e1arkw 1316 protected override function getDefaultCustomizerClasses():Array{
322     const styleManager:IStyleManager2 = StyleManagerUtil.getStyleManager();
323     const customizersDef:CSSStyleDeclaration = styleManager.getStyleDeclaration(".customizers");
324     const defaultFactory:Function = customizersDef.defaultFactory;
325    
326     const result:Array = [];
327     const keys:Array = [];
328    
329     var customizers:Object = {};
330     if (defaultFactory != null)
331     {
332     defaultFactory.prototype = {};
333     customizers = new defaultFactory();
334 e1arkw 1264 }
335 e1arkw 1316
336     var customizer:Class;
337     for( var key:String in customizers ){
338     keys.push(key);
339 e1arkw 424 }
340 e1arkw 1316 keys.sort();
341     for( var i:int = 0; i < keys.length; i++ ){
342     customizer = customizers[keys[i]] as Class;
343     result.push(customizer);
344     }
345     CONFIG::DEBUG{
346 e1arkw 1565 _debug("CustomizerLoaded",result);
347 e1arkw 1316 }
348     return result;
349 e1arkw 404 }
350 e1arkw 1409
351 e1arkw 1317 yui_internal override function applicationInitialize():void{
352 e1arkw 1506
353 e1arkw 1316 if( _customizers == null ){
354     _customizers = getDefaultCustomizers();
355     }
356     CONFIG::DEBUG{
357 e1arkw 1565 _debug("ViewAssembleStart");
358 e1arkw 1316 }
359    
360 e1arkw 1445 var allView:Dictionary = ViewComponentRepository.allView;
361 e1arkw 1316 var view:UIComponent;
362 e1arkw 1445 for ( var viewName:String in allView ){
363 e1arkw 1316 CONFIG::DEBUG{
364 e1arkw 1565 _debug("ViewAssembleing",viewName);
365 e1arkw 404 }
366 e1arkw 1316 view = ViewComponentRepository.getComponent(viewName) as UIComponent;
367     if( view != null && view.initialized ){
368 e1arkw 1487 processViewAssemble(view);
369 e1arkw 1316 }
370     CONFIG::DEBUG{
371 e1arkw 1565 _debug("ViewAssembled",viewName);
372 e1arkw 1316 }
373 e1arkw 404 }
374 e1arkw 1316
375     CONFIG::DEBUG{
376 e1arkw 1565 _debug("ViewAssembleEnd");
377 e1arkw 468 }
378 e1arkw 1316 _isApplicationStarted = true;
379     callLater( processApplicationStart );
380 e1arkw 432 }
381 e1arkw 1264
382 e1arkw 1316 yui_internal override function isView(component:DisplayObject):Boolean{
383     if( component == null || !(component is UIComponent)){
384     return false;
385 e1arkw 1264 }
386 e1arkw 1507 const frameworkBridge:FrameworkBridge = YuiFrameworkGlobals.public::frameworkBridge as FrameworkBridge;
387     if( frameworkBridge.isContainer(component)){
388     const namingConvention:NamingConvention = YuiFrameworkGlobals.public::namingConvention as NamingConvention;
389     return namingConvention.isViewClassName( getCanonicalName(component) );
390 e1arkw 1316 } else {
391     return false;
392 e1arkw 404 }
393 e1arkw 468 }
394 e1arkw 1264
395 e1arkw 1316 yui_internal override function isComponent( target:DisplayObject ):Boolean{
396     var component:UIComponent = target as UIComponent;
397     if( component == null || component.id == null || !(component is UIComponent)){
398     return false;
399 e1arkw 1264 }
400 e1arkw 1507 const frameworkBridge:FrameworkBridge = YuiFrameworkGlobals.public::frameworkBridge as FrameworkBridge;
401     return frameworkBridge.isComponent(component);
402 e1arkw 1264 }
403 e1arkw 1316
404 e1arkw 1317 yui_internal override function applicationMonitoringStart(root:DisplayObject):void{
405     root.addEventListener(
406     FlexEvent.CREATION_COMPLETE,
407     creationCompleteHandler,
408     true,
409     int.MAX_VALUE
410     );
411 e1arkw 1507 super.applicationMonitoringStart(root);
412 e1arkw 1317 }
413    
414 e1arkw 1316 yui_internal override function applicationMonitoringStop(root:DisplayObject):void{
415     root.removeEventListener(
416     FlexEvent.APPLICATION_COMPLETE,
417     applicationCompleteHandler,
418     false
419     );
420    
421     root.removeEventListener(
422     FlexEvent.INIT_COMPLETE,
423     applicationInitCompleteHandler,
424     true
425     );
426    
427     root.removeEventListener(
428     FlexEvent.PRELOADER_DONE,
429     applicationPreloaderDoneHandler,
430     true
431     );
432     super.applicationMonitoringStop(root);
433 e1arkw 842 }
434 e1arkw 1316
435     yui_internal override function systemManagerMonitoringStart( root:DisplayObject ):void{
436     root.addEventListener(
437     FlexEvent.INIT_COMPLETE,
438     applicationInitCompleteHandler,
439     true,
440     int.MAX_VALUE
441     );
442    
443     root.addEventListener(
444     FlexEvent.PRELOADER_DONE,
445     applicationPreloaderDoneHandler,
446     true,
447     int.MAX_VALUE
448     );
449    
450     root.addEventListener(
451     FlexEvent.APPLICATION_COMPLETE,
452     applicationCompleteHandler,
453     false,
454     int.MAX_VALUE
455     );
456     }
457    
458     yui_internal override function systemManagerMonitoringStop(root:DisplayObject):void{
459 e1arkw 1507 const frameworkBridge:FrameworkBridge = YuiFrameworkGlobals.public::frameworkBridge as FrameworkBridge;
460     const application_:DisplayObjectContainer = frameworkBridge.application;
461 e1arkw 1316 if( application_ != null ){
462     root.removeEventListener(
463     FlexEvent.CREATION_COMPLETE,
464     creationCompleteHandler,
465     true
466     );
467 e1arkw 1071 }
468 e1arkw 1507 super.systemManagerMonitoringStop(root);
469 e1arkw 1071 }
470 e1arkw 404 }
471     }

Properties

Name Value
svn:keywords Author Revision

Repository Top
ViewVC Help  
ViewVC logotype
Powered by ViewVC