Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/pavsupport/PlaceActivityManager.java

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