00001 import mx.utils.Delegate;
00002
00003 import gugga.application.ApplicatiotionNavigationalStateMemento;
00004 import gugga.application.NavigationManager;
00005 import gugga.application.SectionsController;
00006 import gugga.application.SectionsTransition;
00007 import gugga.commands.INavigationCommandReceiver;
00008 import gugga.common.EventDescriptor;
00009 import gugga.utils.DoLaterUtil;
00010 import gugga.utils.Listener;
00011
00015 class gugga.application.ApplicationController
00016 extends SectionsController
00017 implements INavigationCommandReceiver
00018 {
00019 private var mPendingSectionPath : String;
00020 private var mTargetSectionPath : String;
00021 private var mFullTransition : SectionsTransition;
00022
00023 public function get TargetSectionPath() : String
00024 {
00025 return mTargetSectionPath;
00026 }
00027
00028 function ApplicationController()
00029 {
00030 super();
00031 _global.ApplicationController = this;
00032 }
00033
00034 private function initUI() : Void
00035 {
00036 super.initUI();
00037 show();
00038 }
00039
00040
00041
00042
00043
00044
00045 public function createNavigationState() : ApplicatiotionNavigationalStateMemento
00046 {
00047 var state = new ApplicatiotionNavigationalStateMemento();
00048 state.NavigationPath = mCurrentSectionPath;
00049
00050 return state;
00051 }
00052
00053
00054
00055
00056 public function setNavigationState(aMemento : ApplicatiotionNavigationalStateMemento) : Void
00057 {
00058 navigateTo(aMemento.NavigationPath);
00059 }
00060
00061
00062
00063
00064
00065
00066 public function navigateTo(aSectionPath:String) : Boolean
00067 {
00068 var result : Boolean = false;
00069
00070 if(aSectionPath == mCurrentSectionPath)
00071 {
00072 result = false;
00073 }
00074 else
00075 {
00076 if(mFullTransition && mFullTransition.isRunning())
00077 {
00078 if(aSectionPath == mTargetSectionPath || aSectionPath == mPendingSectionPath)
00079 {
00080 result = false;
00081 }
00082 else
00083 {
00084 result = true;
00085 }
00086
00087 var hasPendingSectionPath : Boolean = false;
00088 if(mPendingSectionPath)
00089 {
00090 hasPendingSectionPath = true;
00091 }
00092
00093 mPendingSectionPath = aSectionPath;
00094
00095
00096
00097
00098 if(!hasPendingSectionPath)
00099 {
00100 if(canInterruptCurrentTransition())
00101 {
00102 interruptCurrentTransition();
00103 }
00104 }
00105 }
00106 else if(!mFullTransition)
00107 {
00108 var transition : SectionsTransition = openSection(aSectionPath);
00109 mFullTransition = transition;
00110
00111 if(mFullTransition)
00112 {
00113
00114 mTargetSectionPath = aSectionPath;
00115
00116 Listener.createSingleTimeListener(
00117 new EventDescriptor(mFullTransition, "disposed"),
00118 Delegate.create(this, onTransitionDisposed2)
00119 );
00120
00121 NavigationManager.Instance.markNavigations(aSectionPath);
00122 result = true;
00123 }
00124 else
00125 {
00126 result = false;
00127 }
00128 }
00129 }
00130
00131 return result;
00132 }
00133
00134 private function canInterruptCurrentTransition() : Boolean
00135 {
00136 return mFullTransition.canInterrupt() && !isSectionClosing(mPendingSectionPath);
00137 }
00138
00139 private function interruptCurrentTransition() : Void
00140 {
00141 Listener.createSingleTimeListener(
00142 new EventDescriptor(mFullTransition, "interrupted"),
00143 Delegate.create(this, onFullTransitionInterrupted)
00144 );
00145
00146 mFullTransition.interrupt();
00147 }
00148
00149 private function onFullTransitionInterrupted(ev) : Void
00150 {
00151 NavigationManager.Instance.markNavigations(mCurrentSectionPath);
00152 }
00153
00154 private function onTransitionDisposed2(ev) : Void
00155 {
00156
00157 DoLaterUtil.doLater(this, onTransitionDisposed2Actual, [ev], 1);
00158 }
00159
00160 private function onTransitionDisposed2Actual(ev) : Void
00161 {
00162 delete mFullTransition;
00163
00164 if(mPendingSectionPath)
00165 {
00166 var pendingSectionPath : String = mPendingSectionPath;
00167 mPendingSectionPath = null;
00168
00169 navigateTo(pendingSectionPath);
00170 }
00171 }
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 }