litesoft
@ 948
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
package org.litesoft.GWT.client.pavsupport; import org.litesoft.GWT.client.historian.*; import org.litesoft.GWT.client.pavsupport.internal.*; import org.litesoft.GWT.client.util.*; import org.litesoft.commonfoundation.typeutils.*; import org.litesoft.logger.*; import com.google.gwt.event.logical.shared.*; import com.google.gwt.place.shared.*; import com.google.gwt.user.client.*; import com.google.gwt.user.client.ui.*; public class PlaceActivityManager<CommonActivityParam extends CommonActivityParameter> implements PlaceChangerWithCurrentUrlSupport { private static final Logger LOGGER = LoggerFactory.getLogger( PlaceActivityManager.class ); private final PanelPlaceActivityHelper<CommonActivityParam> mActivityHelper; private final CommonActivityParam mCommonActivityParam; private final PlaceHistoryMapper mMapper; private final WindowClose mWindowClose; private final Historian mHistorian; private Place mPendingCodePlace; public PlaceActivityManager( AcceptsOneWidget pPanel, PlaceHistoryMapper pMapper, WindowClose pWindowClose, Historian pHistorian, CommonActivityParam pCommonActivityParam ) { mCommonActivityParam = (pCommonActivityParam != null) ? pCommonActivityParam : createDefaultCommonActivityParam(); mActivityHelper = new PanelPlaceActivityHelper<CommonActivityParam>( pPanel, mCommonActivityParam ); mMapper = (pMapper != null) ? pMapper : new PlaceRegistry( mCommonActivityParam ); mWindowClose = (pWindowClose != null) ? pWindowClose : new WindowCloseImpl(); mWindowClose.addWindowClosingHandler( new Window.ClosingHandler() { @Override public void onWindowClosing( Window.ClosingEvent event ) { String zWarning = getLeavingCurrentPlaceWarningText(); if ( zWarning != null ) { event.setMessage( zWarning ); } } } ); mHistorian = (pHistorian != null) ? pHistorian : new HistorianImpl(); mHistorian.addValueChangeHandler( new ValueChangeHandler<String>() { @Override public void onValueChange( ValueChangeEvent<String> event ) { handleHistoryToken( event.getValue() ); } } ); } public PlaceActivityManager( AcceptsOneWidget pPanel, CommonActivityParam pCommonActivityParam ) { this( pPanel, null, null, null, pCommonActivityParam ); } public PlaceActivityManager( AcceptsOneWidget pPanel ) { this( pPanel, null, null, null, null ); } public void add( PlaceChangeListener pPlaceChangeListener ) { mActivityHelper.add( pPlaceChangeListener ); } /** * Go to the Current URL (current history token). * <p/> * Typically called at application start, to ensure bookmark launches work. */ @Override public void goToCurrentUrl() { handleHistoryToken( mHistorian.getToken() ); } /** * Returns the current place. * * @return a {@link Place} instance */ @Override public Place getWhere() { return mActivityHelper.getCurrentPlace(); } /** * Request a change to the previous place on the browser's history stack. * If there is a previous place on the browser's history stack, the location * changes and a {@link PlaceChangeEvent} is posted announcing the previous place. */ @Override public void goBack() { mActivityHelper.placeChangeRequested( null, PlaceChangeListener.Source.Back ); mHistorian.back(); } /** * Request a change to a new place. It is not a given that we'll actually get * there. If there is an ActivityFactory for the Place, and the user does not * reject leaving the current Place, then the URL is adjusted to have the user * taken to the new place. * * @param pNewPlace a {@link Place} instance * * @return null if going to pNewPlace, !null means NOT going and why */ @Override public GoToPlace goForwardTo( Place pNewPlace ) { Place zCurrentPlace = mActivityHelper.getCurrentPlace(); pNewPlace = Objects.deNull( pNewPlace, zCurrentPlace ); if ( pNewPlace.equals( zCurrentPlace ) ) { return GoToPlace.AlreadyThere; } if ( pNewPlace.equals( mPendingCodePlace ) || mActivityHelper.isPendingAsync( pNewPlace ) ) { return null; } if ( null == mActivityHelper.get( pNewPlace ) ) // Check for Factory { return GoToPlace.NoActivity; } if ( userRejectedLeavingCurrentPlace( pNewPlace ) ) { return GoToPlace.CurrentActivityRejectedLeaving; // From Code, maybe the code shouldn't have allowed it! } mActivityHelper.placeChangeRequested( pNewPlace, PlaceChangeListener.Source.Forward ); mActivityHelper.clearPendingAsync(); mPendingCodePlace = pNewPlace; mHistorian.newItem( mMapper.getToken( pNewPlace ), true ); return null; } private void handleHistoryToken( String pToken ) { Place zWasGoingToCodePlace = mPendingCodePlace; mPendingCodePlace = null; mCommonActivityParam.getMessageUserSink().clearMessage(); Place zNewPlace = null; if ( null == (pToken = Strings.noEmpty( pToken )) ) { zNewPlace = PlaceRegistry.getDefaultPlace(); } else { try { if ( null == (zNewPlace = mMapper.getPlace( pToken )) ) { LOGGER.info.log( "Unrecognized history token: ", pToken ); } } catch ( RuntimeException e ) { LOGGER.warn.log( e, "Unable to parse history token: ", pToken ); } } Place zCurrentPlace = mActivityHelper.getCurrentPlace(); zNewPlace = Objects.deNull( zNewPlace, zCurrentPlace ); if ( zNewPlace.equals( zCurrentPlace ) ) { mActivityHelper.clearPendingAsync(); return; } if ( (zWasGoingToCodePlace != null) && !zNewPlace.equals( zWasGoingToCodePlace ) && userWantsToStopUrlChange( zNewPlace ) ) { mActivityHelper.clearPendingAsync(); resetURLbackTo( zCurrentPlace ); return; } if ( !mActivityHelper.activate( zNewPlace ) ) { mCommonActivityParam.getMessageUserSink().setErrorMessage( "No Activity Factory for '" + Objects.justSimpleName( zNewPlace ) + "' from: " + pToken ); resetURLbackTo( zCurrentPlace ); } } protected boolean userWantsToStopUrlChange( Place pNewPlace ) { return userRejectedLeavingCurrentPlace( pNewPlace ); } protected void resetURLbackTo( Place pCurrentPlace ) { mHistorian.newItem( mMapper.getToken( pCurrentPlace ), false ); // reset the URL back to the Current Place } @SuppressWarnings("UnusedParameters") protected boolean userRejectedLeavingCurrentPlace( Place newPlace ) { String zWarning = getLeavingCurrentPlaceWarningText(); return (zWarning != null) && !mWindowClose.confirm( zWarning ); } protected String getLeavingCurrentPlaceWarningText() { return mActivityHelper.getCurrentActivityMayStop(); } @SuppressWarnings({"unchecked"}) protected CommonActivityParam createDefaultCommonActivityParam() { return (CommonActivityParam) new DefaultCommonActivityParam(); } /** * Default implementation of CommonActivityParameter, based on {@link Window}. */ private class DefaultCommonActivityParam implements CommonActivityParameter { @Override public MessageUserSink getMessageUserSink() { return DialogMessageUserSink.INSTANCE; } @Override public Place getWhere() { return PlaceActivityManager.this.getWhere(); } @Override public void goBack() { PlaceActivityManager.this.goBack(); } @Override public GoToPlace goForwardTo( Place pNewPlace ) { return PlaceActivityManager.this.goForwardTo( pNewPlace ); } } } |
Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/pavsupport/PlaceActivityManager.java
Revision | Author | Commited | Message |
---|---|---|---|
948 Diff | GeorgeS | Sat 07 Jun, 2014 23:42:39 +0000 | Jusefuls Formatter Updated to New Code Format |
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
811 Diff | GeorgeS | Sat 18 Aug, 2012 13:45:18 +0000 | |
804 Diff | GeorgeS | Wed 15 Aug, 2012 12:48:51 +0000 | |
801 Diff | GeorgeS | Wed 15 Aug, 2012 03:59:02 +0000 | |
735 Diff | GeorgeS | Sat 23 Jun, 2012 15:05:41 +0000 | ! |
728 Diff | GeorgeS | Sat 16 Jun, 2012 23:39:49 +0000 | |
727 Diff | GeorgeS | Sat 16 Jun, 2012 17:41:06 +0000 | |
722 Diff | GeorgeS | Sun 10 Jun, 2012 22:45:30 +0000 | |
720 | GeorgeS | Sun 10 Jun, 2012 16:20:42 +0000 |