Subversion Repository Public Repository

litesoft

Diff Revisions 545 vs 546 for /trunk/GWT_Sandbox/MultiModule/common/src/org/litesoft/sandbox/infrastructure/client/PlaceActivityManager.java

Diff revisions: vs.
  @@ -3,7 +3,9 @@
3 3 import java.util.*;
4 4
5 5 import org.litesoft.logger.*;
6 + import org.litesoft.sandbox.anywhere.util.*;
6 7
8 + import com.google.gwt.event.logical.shared.*;
7 9 import com.google.gwt.event.shared.*;
8 10 import com.google.gwt.place.shared.*;
9 11 import com.google.gwt.user.client.*;
  @@ -24,18 +26,21 @@
24 26 private final AcceptsOneWidget display;
25 27 private final CommonActivityParam mCommonActivityParam;
26 28
27 - private final Delegate mDelegate;
29 + private final PlaceHistoryMapper mMapper;
30 + private final WindowClose mWindowClose;
31 + private final Historian mHistorian;
28 32 private Place mCurrentPlace = Place.NOWHERE;
29 33 private Place mPendingAsyncPlace;
30 34 private Activity currentActivity = NULL_ACTIVITY;
31 35 private boolean startingNext = false;
32 36
33 - public PlaceActivityManager( AcceptsOneWidget pPanel, Delegate pDelegate, CommonActivityParam pCommonActivityParam )
37 + public PlaceActivityManager( AcceptsOneWidget pPanel, PlaceHistoryMapper pMapper, WindowClose pWindowClose, Historian pHistorian, CommonActivityParam pCommonActivityParam )
34 38 {
35 39 display = pPanel;
36 40 mCommonActivityParam = (pCommonActivityParam != null) ? pCommonActivityParam : DefaultCommonActivityParam.<CommonActivityParam>createInstance();
37 - mDelegate = (pDelegate != null) ? pDelegate : new DefaultDelegate();
38 - mDelegate.addWindowClosingHandler( new Window.ClosingHandler()
41 + mMapper = (pMapper != null) ? pMapper : new PlaceRegistry( mCommonActivityParam );
42 + mWindowClose = (pWindowClose != null) ? pWindowClose : new WindowCloseImpl();
43 + mWindowClose.addWindowClosingHandler( new Window.ClosingHandler()
39 44 {
40 45 @Override
41 46 public void onWindowClosing( Window.ClosingEvent event )
  @@ -47,16 +52,34 @@
47 52 }
48 53 }
49 54 } );
55 + mHistorian = (pHistorian != null) ? pHistorian : new HistorianImpl();
56 + mHistorian.addValueChangeHandler( new ValueChangeHandler<String>()
57 + {
58 + @Override
59 + public void onValueChange( ValueChangeEvent<String> event )
60 + {
61 + System.out.println( "PlaceActivityManager.onValueChange: " + event.getValue() ); // todo...
62 + }
63 + } );
50 64 }
51 65
52 66 public PlaceActivityManager( AcceptsOneWidget pPanel, CommonActivityParam pCommonActivityParam )
53 67 {
54 - this( pPanel, null, pCommonActivityParam );
68 + this( pPanel, null, null, null, pCommonActivityParam );
55 69 }
56 70
57 71 public PlaceActivityManager( AcceptsOneWidget pPanel )
58 72 {
59 - this( pPanel, null, null );
73 + this( pPanel, null, null, null, null );
74 + }
75 +
76 + /**
77 + * Handle the current history token. Typically called at application start, to
78 + * ensure bookmark launches work.
79 + */
80 + public void handleCurrentHistory()
81 + {
82 + handleHistoryToken( mHistorian.getToken() );
60 83 }
61 84
62 85 @Override
  @@ -68,6 +91,11 @@
68 91 @Override
69 92 public GoToPlace goTo( Place pNewPlace )
70 93 {
94 + return goTo( pNewPlace, false );
95 + }
96 +
97 + private GoToPlace goTo( Place pNewPlace, boolean pFromHistory )
98 + {
71 99 if ( (pNewPlace == null) || pNewPlace.equals( mCurrentPlace ) )
72 100 {
73 101 return GoToPlace.AlreadyThere;
  @@ -84,18 +112,24 @@
84 112 }
85 113
86 114 String zWarning = maybeGoTo( pNewPlace );
87 - if ( zWarning != null && !mDelegate.confirm( zWarning ) )
115 + if ( zWarning != null && !mWindowClose.confirm( zWarning ) )
88 116 {
89 - return GoToPlace.CurrentActivityRejectedLeaving;
117 + return GoToPlace.CurrentActivityRejectedLeaving; // todo: if from Code, then why didn't the code not allow it, if from History, then the URL no longer matches the View!!!
90 118 }
91 119 if ( zFactory instanceof ActivityFactory.Asynchronous ) // Un-Happy Case!
92 120 {
93 121 return LoadSyncFactory( (ActivityFactory.Asynchronous) zFactory, mPendingAsyncPlace = pNewPlace );
94 122 }
95 123 mPendingAsyncPlace = null;
124 + // todo: Historian?
96 125 return justGo( pNewPlace, (ActivityFactory.Synchronous) zFactory );
97 126 }
98 127
128 + private String maybeGoTo( Place newPlace )
129 + {
130 + return currentActivity.mayStop();
131 + }
132 +
99 133 private void switchAsyncToSync( Place pPlace, ActivityFactory.Asynchronous pAsyncFactory, ActivityFactory.Synchronous pSyncFactory )
100 134 {
101 135 boolean zStillGoing = pPlace.equals( mPendingAsyncPlace );
  @@ -109,8 +143,7 @@
109 143 private GoToPlace justGo( Place pPlace, ActivityFactory.Synchronous pSyncFactory )
110 144 {
111 145 mCurrentPlace = pPlace;
112 - IsWidget zView = pSyncFactory.getView();
113 - Activity zActivity = pSyncFactory.createActivity( mCommonActivityParam, zView, pPlace );
146 + Activity zActivity = createActivity( pSyncFactory, pPlace );
114 147 onPlaceChange( pPlace, zActivity );
115 148 return null;
116 149 }
  @@ -293,9 +326,29 @@
293 326 return null;
294 327 }
295 328
296 - private String maybeGoTo( Place newPlace )
329 + private void handleHistoryToken( String token )
297 330 {
298 - return currentActivity.mayStop();
331 + Place newPlace = null;
332 +
333 + if ( null != (token = UtilsCommon.noEmpty( token )) )
334 + {
335 + try
336 + {
337 + if ( null == (newPlace = mMapper.getPlace( token )) )
338 + {
339 + LOGGER.info.log( "Unrecognized history token: ", token );
340 + }
341 + }
342 + catch ( RuntimeException e )
343 + {
344 + LOGGER.warn.log( e, "Unable to parse history token: ", token );
345 + }
346 + }
347 + if ( newPlace == null )
348 + {
349 + newPlace = PlaceRegistry.getDefaultPlace();
350 + }
351 + goTo( newPlace, true );
299 352 }
300 353
301 354 /**
  @@ -316,24 +369,6 @@
316 369 }
317 370 }
318 371
319 - /**
320 - * Default implementation of {@link Delegate}, based on {@link Window}.
321 - */
322 - private static class DefaultDelegate implements Delegate
323 - {
324 - @Override
325 - public HandlerRegistration addWindowClosingHandler( Window.ClosingHandler handler )
326 - {
327 - return Window.addWindowClosingHandler( handler );
328 - }
329 -
330 - @Override
331 - public boolean confirm( String message )
332 - {
333 - return Window.confirm( message );
334 - }
335 - }
336 -
337 372 /**
338 373 * Wraps our real display to prevent an Activity from taking it over if it is
339 374 * not the currentActivity.