Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/pavment/internal/PanelPlaceActivityHelper.java

Diff revisions: vs.
  @@ -9,13 +9,10 @@
9 9 import java.util.*;
10 10
11 11 @SuppressWarnings("rawtypes")
12 - public class PanelPlaceActivityHelper<CommonActivityParam extends CommonActivityParameter> extends ActivityFactoryRegistry
13 - {
14 - private static final Activity NULL_ACTIVITY = new Activity()
15 - {
12 + public class PanelPlaceActivityHelper<CommonActivityParam extends CommonActivityParameter> extends ActivityFactoryRegistry {
13 + private static final Activity NULL_ACTIVITY = new Activity() {
16 14 @Override
17 - public void start( AcceptsOneWidget panel )
18 - {
15 + public void start( AcceptsOneWidget panel ) {
19 16 panel.setWidget( new Label( "!" ) );
20 17 }
21 18
  @@ -46,63 +43,50 @@
46 43
47 44 private Set<ActivityStartingListener> mActivityStartingListener = new HashSet<ActivityStartingListener>();
48 45
49 - public PanelPlaceActivityHelper( AcceptsOneWidget pPanel, CommonActivityParam pCommonActivityParam )
50 - {
46 + public PanelPlaceActivityHelper( AcceptsOneWidget pPanel, CommonActivityParam pCommonActivityParam ) {
51 47 mPanel = pPanel;
52 48 mCommonActivityParam = pCommonActivityParam;
53 49 }
54 50
55 - public boolean add( ActivityStartingListener pListener )
56 - {
57 - return mActivityStartingListener.add(pListener);
51 + public boolean add( ActivityStartingListener pListener ) {
52 + return mActivityStartingListener.add( pListener );
58 53 }
59 54
60 - public boolean remove( ActivityStartingListener pListener )
61 - {
62 - return mActivityStartingListener.remove(pListener);
55 + public boolean remove( ActivityStartingListener pListener ) {
56 + return mActivityStartingListener.remove( pListener );
63 57 }
64 58
65 - public Place getCurrentPlace()
66 - {
59 + public Place getCurrentPlace() {
67 60 return mCurrentPlace;
68 61 }
69 62
70 - public boolean isPendingAsync( Place pPlace )
71 - {
63 + public boolean isPendingAsync( Place pPlace ) {
72 64 return pPlace.equals( mPendingAsyncPlace );
73 65 }
74 66
75 - public void clearPendingAsync()
76 - {
67 + public void clearPendingAsync() {
77 68 mPendingAsyncPlace = null;
78 69 }
79 70
80 - public ActivityFactory get( Place pPlace )
81 - {
71 + public ActivityFactory get( Place pPlace ) {
82 72 return get( PlaceIdExtractor.getPlaceId( pPlace ) );
83 73 }
84 74
85 - public String getCurrentActivityMayStop()
86 - {
75 + public String getCurrentActivityMayStop() {
87 76 return mCurrentActivity.mayStop();
88 77 }
89 78
90 - public boolean activate( Place pNewPlace )
91 - {
92 - if ( !isPendingAsync( pNewPlace ) )
93 - {
79 + public boolean activate( Place pNewPlace ) {
80 + if ( !isPendingAsync( pNewPlace ) ) {
94 81 mPendingAsyncPlace = null;
95 82 ActivityFactory zFactory = get( pNewPlace );
96 - if ( zFactory == null )
97 - {
83 + if ( zFactory == null ) {
98 84 return false;
99 85 }
100 86 if ( zFactory instanceof ActivityFactory.Asynchronous ) // Un-Happy Case!
101 87 {
102 88 loadSyncFactory( (ActivityFactory.Asynchronous) zFactory, mPendingAsyncPlace = pNewPlace );
103 - }
104 - else
105 - {
89 + } else {
106 90 activate( pNewPlace, (ActivityFactory.Synchronous) zFactory );
107 91 }
108 92 }
  @@ -112,8 +96,7 @@
112 96 /**
113 97 * Activate the New Place and it's associated Activity (deactivating the current activity.
114 98 */
115 - public void activate( Place pNewPlace, ActivityFactory.Synchronous pSyncFactory )
116 - {
99 + public void activate( Place pNewPlace, ActivityFactory.Synchronous pSyncFactory ) {
117 100 Set<Throwable> zIssues = new LinkedHashSet<Throwable>();
118 101
119 102 mCurrentPlace = pNewPlace;
  @@ -132,87 +115,69 @@
132 115
133 116 notifyActivityStartingListener( pNewPlace, mPendingActivity );
134 117
135 - if ( !canStart( zIssues, mPendingActivity, zPanel ) )
136 - {
118 + if ( !canStart( zIssues, mPendingActivity, zPanel ) ) {
137 119 mPendingActivity = NULL_ACTIVITY;
138 120 notifyActivityStartingListener( null, mPendingActivity );
139 121 mPendingActivity.start( new ProtectedDisplay( zIssues, mPendingActivity ) ); // Can NOT fail!
140 122 }
141 123 }
142 124
143 -
144 - private void notifyActivityStartingListener(Place pNewPlace, Activity pPendingActivity)
145 - {
146 - for (ActivityStartingListener zListener : mActivityStartingListener) {
147 - zListener.startingActivity(pPendingActivity, pNewPlace);
125 + private void notifyActivityStartingListener( Place pNewPlace, Activity pPendingActivity ) {
126 + for ( ActivityStartingListener zListener : mActivityStartingListener ) {
127 + zListener.startingActivity( pPendingActivity, pNewPlace );
148 128 }
149 129 }
150 130
151 131 public void refreshCurrentActivity() {
152 - if ( (mPendingAsyncPlace == null) && (mPendingActivity == null) )
153 - {
132 + if ( (mPendingAsyncPlace == null) && (mPendingActivity == null) ) {
154 133 mCurrentActivity.refresh();
155 134 }
156 135 }
157 136
158 137 @SuppressWarnings({"unchecked"})
159 - protected Activity createActivity( Collection<Throwable> pIssues, ActivityFactory.Synchronous pFactory, Place pPlace )
160 - {
161 - try
162 - {
138 + protected Activity createActivity( Collection<Throwable> pIssues, ActivityFactory.Synchronous pFactory, Place pPlace ) {
139 + try {
163 140 return pFactory.createActivity( mCommonActivityParam, pFactory.getView(), pPlace );
164 141 }
165 - catch ( Exception e )
166 - {
142 + catch ( Exception e ) {
167 143 pIssues.add( e );
168 144 }
169 145 return null;
170 146 }
171 147
172 - private boolean canStart( Set<Throwable> pIssues, Activity pActivity, AcceptsOneWidget pPanel )
173 - {
174 - try
175 - {
148 + private boolean canStart( Set<Throwable> pIssues, Activity pActivity, AcceptsOneWidget pPanel ) {
149 + try {
176 150 pActivity.start( pPanel );
177 151 return true;
178 152 }
179 - catch ( Exception e )
180 - {
153 + catch ( Exception e ) {
181 154 pIssues.add( e );
182 155 }
183 156 return false;
184 157 }
185 158
186 - private void tryCancel( Collection<Throwable> pIssues, Activity pActivity )
187 - {
188 - try
189 - {
159 + private void tryCancel( Collection<Throwable> pIssues, Activity pActivity ) {
160 + try {
190 161 pActivity.onCancel();
191 162 }
192 - catch ( Exception e )
193 - {
163 + catch ( Exception e ) {
194 164 pIssues.add( e );
195 165 }
196 166 }
197 167
198 - private void tryStop( Collection<Throwable> pIssues, Activity pActivity )
199 - {
200 - try
201 - {
168 + private void tryStop( Collection<Throwable> pIssues, Activity pActivity ) {
169 + try {
202 170 pActivity.onStop();
203 171 }
204 - catch ( Exception e )
205 - {
172 + catch ( Exception e ) {
206 173 pIssues.add( e );
207 174 }
208 175 }
209 176
210 - private void possiblyUpdateActivityAndShowWidget( Set<Throwable> pIssues, Activity pActivity, IsWidget pWidget )
211 - {
177 + private void possiblyUpdateActivityAndShowWidget( Set<Throwable> pIssues, Activity pActivity, IsWidget pWidget ) {
212 178 if ( mPendingActivity == null ) // Normal? Happy case when No Pending Activity and request is from Current Activity
213 179 {
214 - if ( pActivity == mCurrentActivity )
215 - {
180 + if ( pActivity == mCurrentActivity ) {
216 181 showWidget( pWidget );
217 182 }
218 183 return;
  @@ -225,40 +190,32 @@
225 190 mCurrentActivity = mPendingActivity;
226 191 mPendingActivity = null;
227 192 showWidget( pWidget );
228 - if ( !pIssues.isEmpty() )
229 - {
193 + if ( !pIssues.isEmpty() ) {
230 194 throw new UmbrellaException( pIssues );
231 195 }
232 196 }
233 197
234 - private void showWidget( IsWidget pWidget )
235 - {
236 - if ( mPanel != null )
237 - {
198 + private void showWidget( IsWidget pWidget ) {
199 + if ( mPanel != null ) {
238 200 mPanel.setWidget( pWidget );
239 201 }
240 202 }
241 203
242 204 @SuppressWarnings({"unchecked"})
243 - private void loadSyncFactory( final ActivityFactory.Asynchronous pAsyncFactory, final Place pPlace )
244 - {
245 - pAsyncFactory.load( mCommonActivityParam, new ActivityFactory.Asynchronous.Callback<CommonActivityParam, View, Place>()
246 - {
205 + private void loadSyncFactory( final ActivityFactory.Asynchronous pAsyncFactory, final Place pPlace ) {
206 + pAsyncFactory.load( mCommonActivityParam, new ActivityFactory.Asynchronous.Callback<CommonActivityParam, View, Place>() {
247 207 @Override
248 - public void loaded( ActivityFactory.Synchronous<CommonActivityParam, View, Place> pSynchronousFactory )
249 - {
208 + public void loaded( ActivityFactory.Synchronous<CommonActivityParam, View, Place> pSynchronousFactory ) {
250 209 switchAsyncToSync( pPlace, pAsyncFactory, pSynchronousFactory );
251 210 }
252 211 } );
253 212 }
254 213
255 - private void switchAsyncToSync( Place pPlace, ActivityFactory.Asynchronous pAsyncFactory, ActivityFactory.Synchronous pSyncFactory )
256 - {
214 + private void switchAsyncToSync( Place pPlace, ActivityFactory.Asynchronous pAsyncFactory, ActivityFactory.Synchronous pSyncFactory ) {
257 215 System.out.println( "Switched " + ObjectUtils.getSimpleClassName( pPlace ) + " from Async to Sync" );
258 216 boolean zStillGoing = pPlace.equals( mPendingAsyncPlace );
259 217 mPendingAsyncPlace = null;
260 - if ( replace( pAsyncFactory, pSyncFactory ) && zStillGoing )
261 - {
218 + if ( replace( pAsyncFactory, pSyncFactory ) && zStillGoing ) {
262 219 activate( pPlace, pSyncFactory );
263 220 }
264 221 }
  @@ -267,20 +224,17 @@
267 224 * Wraps our real display to prevent an Activity from taking it over if it is
268 225 * not the currentActivity.
269 226 */
270 - private class ProtectedDisplay implements AcceptsOneWidget
271 - {
227 + private class ProtectedDisplay implements AcceptsOneWidget {
272 228 private final Set<Throwable> mIssues;
273 229 private final Activity mExpectedActivity;
274 230
275 - ProtectedDisplay( Set<Throwable> pIssues, Activity pExpectedActivity )
276 - {
231 + ProtectedDisplay( Set<Throwable> pIssues, Activity pExpectedActivity ) {
277 232 mIssues = pIssues;
278 233 mExpectedActivity = pExpectedActivity;
279 234 }
280 235
281 236 @Override
282 - public void setWidget( IsWidget pWidget )
283 - {
237 + public void setWidget( IsWidget pWidget ) {
284 238 possiblyUpdateActivityAndShowWidget( mIssues, mExpectedActivity, pWidget );
285 239 }
286 240 }