Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -9,8 +9,7 @@
9 9 import com.google.gwt.user.client.*;
10 10 import com.google.gwt.user.client.ui.*;
11 11
12 - public class PlaceActivityManager<CommonActivityParam extends CommonActivityParameter> implements PlaceChangerWithCurrentUrlSupport
13 - {
12 + public class PlaceActivityManager<CommonActivityParam extends CommonActivityParameter> implements PlaceChangerWithCurrentUrlSupport {
14 13 private static final Logger LOGGER = LoggerFactory.getLogger( PlaceActivityManager.class );
15 14
16 15 private final PanelPlaceActivityHelper<CommonActivityParam> mActivityHelper;
  @@ -22,42 +21,35 @@
22 21 private final Historian mHistorian;
23 22 private Place mPendingCodePlace;
24 23
25 - public PlaceActivityManager( AcceptsOneWidget pPanel, PlaceHistoryMapper pMapper, WindowClose pWindowClose, Historian pHistorian, CommonActivityParam pCommonActivityParam )
26 - {
24 + public PlaceActivityManager( AcceptsOneWidget pPanel, PlaceHistoryMapper pMapper, WindowClose pWindowClose, Historian pHistorian,
25 + CommonActivityParam pCommonActivityParam ) {
27 26 mCommonActivityParam = (pCommonActivityParam != null) ? pCommonActivityParam : createDefaultCommonActivityParam();
28 27 mActivityHelper = new PanelPlaceActivityHelper<CommonActivityParam>( pPanel, mCommonActivityParam );
29 28 mMapper = (pMapper != null) ? pMapper : new PlaceRegistry( mCommonActivityParam );
30 29 mWindowClose = (pWindowClose != null) ? pWindowClose : new WindowCloseImpl();
31 - mWindowClose.addWindowClosingHandler( new Window.ClosingHandler()
32 - {
30 + mWindowClose.addWindowClosingHandler( new Window.ClosingHandler() {
33 31 @Override
34 - public void onWindowClosing( Window.ClosingEvent event )
35 - {
32 + public void onWindowClosing( Window.ClosingEvent event ) {
36 33 String zWarning = getLeavingCurrentPlaceWarningText();
37 - if ( zWarning != null )
38 - {
34 + if ( zWarning != null ) {
39 35 event.setMessage( zWarning );
40 36 }
41 37 }
42 38 } );
43 39 mHistorian = (pHistorian != null) ? pHistorian : new HistorianImpl();
44 - mHistorian.addValueChangeHandler( new ValueChangeHandler<String>()
45 - {
40 + mHistorian.addValueChangeHandler( new ValueChangeHandler<String>() {
46 41 @Override
47 - public void onValueChange( ValueChangeEvent<String> event )
48 - {
42 + public void onValueChange( ValueChangeEvent<String> event ) {
49 43 handleHistoryToken( event.getValue() );
50 44 }
51 45 } );
52 46 }
53 47
54 - public PlaceActivityManager( AcceptsOneWidget pPanel, CommonActivityParam pCommonActivityParam )
55 - {
48 + public PlaceActivityManager( AcceptsOneWidget pPanel, CommonActivityParam pCommonActivityParam ) {
56 49 this( pPanel, null, null, null, pCommonActivityParam );
57 50 }
58 51
59 - public PlaceActivityManager( AcceptsOneWidget pPanel )
60 - {
52 + public PlaceActivityManager( AcceptsOneWidget pPanel ) {
61 53 this( pPanel, null, null, null, null );
62 54 }
63 55
  @@ -67,8 +59,7 @@
67 59 * Typically called at application start, to ensure bookmark launches work.
68 60 */
69 61 @Override
70 - public void goToCurrentUrl()
71 - {
62 + public void goToCurrentUrl() {
72 63 handleHistoryToken( mHistorian.getToken() );
73 64 }
74 65
  @@ -78,8 +69,7 @@
78 69 * @return a {@link Place} instance
79 70 */
80 71 @Override
81 - public Place getWhere()
82 - {
72 + public Place getWhere() {
83 73 return mActivityHelper.getCurrentPlace();
84 74 }
85 75
  @@ -94,24 +84,20 @@
94 84 * @return null if going to pNewPlace, !null means NOT going and why
95 85 */
96 86 @Override
97 - public GoToPlace goTo( Place pNewPlace )
98 - {
87 + public GoToPlace goTo( Place pNewPlace ) {
99 88 Place zCurrentPlace = mActivityHelper.getCurrentPlace();
100 89 pNewPlace = UtilsCommon.deNull( pNewPlace, zCurrentPlace );
101 - if ( pNewPlace.equals( zCurrentPlace ) )
102 - {
90 + if ( pNewPlace.equals( zCurrentPlace ) ) {
103 91 return GoToPlace.AlreadyThere;
104 92 }
105 - if ( pNewPlace.equals( mPendingCodePlace ) || mActivityHelper.isPendingAsync( pNewPlace ) )
106 - {
93 + if ( pNewPlace.equals( mPendingCodePlace ) || mActivityHelper.isPendingAsync( pNewPlace ) ) {
107 94 return null;
108 95 }
109 96 if ( null == mActivityHelper.get( pNewPlace ) ) // Check for Factory
110 97 {
111 98 return GoToPlace.NoActivity;
112 99 }
113 - if ( userRejectedLeavingCurrentPlace( pNewPlace ) )
114 - {
100 + if ( userRejectedLeavingCurrentPlace( pNewPlace ) ) {
115 101 return GoToPlace.CurrentActivityRejectedLeaving; // From Code, maybe the code shouldn't have allowed it!
116 102 }
117 103 mActivityHelper.clearPendingAsync();
  @@ -120,99 +106,81 @@
120 106 return null;
121 107 }
122 108
123 - private void handleHistoryToken( String pToken )
124 - {
109 + private void handleHistoryToken( String pToken ) {
125 110 Place zWasGoingToCodePlace = mPendingCodePlace;
126 111 mPendingCodePlace = null;
127 112 mCommonActivityParam.getMessageUserSink().clearMessage();
128 113
129 114 Place zNewPlace = null;
130 115
131 - if ( null == (pToken = UtilsCommon.noEmpty( pToken )) )
132 - {
116 + if ( null == (pToken = UtilsCommon.noEmpty( pToken )) ) {
133 117 zNewPlace = PlaceRegistry.getDefaultPlace();
134 - }
135 - else
136 - {
137 - try
138 - {
139 - if ( null == (zNewPlace = mMapper.getPlace( pToken )) )
140 - {
118 + } else {
119 + try {
120 + if ( null == (zNewPlace = mMapper.getPlace( pToken )) ) {
141 121 LOGGER.info.log( "Unrecognized history token: ", pToken );
142 122 }
143 123 }
144 - catch ( RuntimeException e )
145 - {
124 + catch ( RuntimeException e ) {
146 125 LOGGER.warn.log( e, "Unable to parse history token: ", pToken );
147 126 }
148 127 }
149 128 Place zCurrentPlace = mActivityHelper.getCurrentPlace();
150 129 zNewPlace = UtilsCommon.deNull( zNewPlace, zCurrentPlace );
151 - if ( zNewPlace.equals( zCurrentPlace ) )
152 - {
130 + if ( zNewPlace.equals( zCurrentPlace ) ) {
153 131 mActivityHelper.clearPendingAsync();
154 132 return;
155 133 }
156 - if ( (zWasGoingToCodePlace != null) && !zNewPlace.equals( zWasGoingToCodePlace ) && userWantsToStopUrlChange( zNewPlace ) )
157 - {
134 + if ( (zWasGoingToCodePlace != null) && !zNewPlace.equals( zWasGoingToCodePlace ) && userWantsToStopUrlChange( zNewPlace ) ) {
158 135 mActivityHelper.clearPendingAsync();
159 136 resetURLbackTo( zCurrentPlace );
160 137 return;
161 138 }
162 - if ( !mActivityHelper.activate( zNewPlace ) )
163 - {
164 - mCommonActivityParam.getMessageUserSink().setErrorMessage( "No Activity Factory for '" + UtilsCommon.justSimpleName( zNewPlace ) + "' from: " + pToken );
139 + if ( !mActivityHelper.activate( zNewPlace ) ) {
140 + mCommonActivityParam.getMessageUserSink()
141 + .setErrorMessage( "No Activity Factory for '" + UtilsCommon.justSimpleName( zNewPlace ) + "' from: " + pToken );
165 142 resetURLbackTo( zCurrentPlace );
166 143 }
167 144 }
168 145
169 - protected boolean userWantsToStopUrlChange( Place pNewPlace )
170 - {
146 + protected boolean userWantsToStopUrlChange( Place pNewPlace ) {
171 147 return userRejectedLeavingCurrentPlace( pNewPlace );
172 148 }
173 149
174 - protected void resetURLbackTo( Place pCurrentPlace )
175 - {
150 + protected void resetURLbackTo( Place pCurrentPlace ) {
176 151 mHistorian.newItem( mMapper.getToken( pCurrentPlace ), false ); // reset the URL back to the Current Place
177 152 }
178 153
179 - protected boolean userRejectedLeavingCurrentPlace( Place newPlace )
180 - {
154 + protected boolean userRejectedLeavingCurrentPlace( Place newPlace ) {
181 155 String zWarning = getLeavingCurrentPlaceWarningText();
182 156 return (zWarning != null) && !mWindowClose.confirm( zWarning );
183 157 }
184 158
185 - protected String getLeavingCurrentPlaceWarningText()
186 - {
159 + protected String getLeavingCurrentPlaceWarningText() {
187 160 return mActivityHelper.getCurrentActivityMayStop();
188 161 }
189 162
190 163 @SuppressWarnings({"unchecked"})
191 - protected CommonActivityParam createDefaultCommonActivityParam()
192 - {
164 + protected CommonActivityParam createDefaultCommonActivityParam() {
193 165 return (CommonActivityParam) new DefaultCommonActivityParam();
194 166 }
195 167
196 168 /**
197 169 * Default implementation of CommonActivityParameter, based on {@link Window}.
198 170 */
199 - private class DefaultCommonActivityParam implements CommonActivityParameter
200 - {
171 + private class DefaultCommonActivityParam implements CommonActivityParameter {
201 172 @Override
202 - public MessageUserSink getMessageUserSink()
203 - {
173 + public MessageUserSink getMessageUserSink() {
204 174 return DialogMessageUserSink.INSTANCE;
205 175 }
206 176
207 177 @Override
208 - public Place getWhere()
209 - {
178 + public Place getWhere() {
210 179 return PlaceActivityManager.this.getWhere();
211 180 }
212 181
213 182 @Override
214 - public GoToPlace goTo( Place pNewPlace )
215 - {
183 + public GoToPlace goTo( Place pNewPlace ) {
216 184 return PlaceActivityManager.this.goTo( pNewPlace );
217 185 }
218 186 }