利用者向け情報

開発者向け情報

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

Properties

Name Value
svn:keywords Author Revision

Repository Top
ViewVC Help  
ViewVC logotype
Powered by ViewVC