Subversion Repository Public Repository

litesoft

Diff Revisions 512 vs 513 for /trunk/GWT_Sandbox/MultiModule/common/src/org/litesoft/sandbox/multimodule/common/client/infrastructure/ActivityFactoryRegistry.java

Diff revisions: vs.
  @@ -9,77 +9,21 @@
9 9 import com.google.gwt.place.shared.*;
10 10 import com.google.gwt.user.client.ui.*;
11 11
12 - public class ActivityFactoryRegistry implements ActivityMapper
12 + public class ActivityFactoryRegistry
13 13 {
14 - private static Logger LOGGER = LoggerFactory.getLogger( ActivityFactoryRegistry.class );
15 -
16 - public static <AClientFactory extends ClientFactory, View extends IsWidget, APlace extends Place> void register( ActivityFactory.Synchronous<AClientFactory, View, APlace> pFactory )
14 + public static <CommonActivityParam extends MessageUserSinkAccessor, View extends IsWidget, APlace extends Place> void register( ActivityFactory.Synchronous<CommonActivityParam, View, APlace> pFactory )
17 15 {
18 16 add( pFactory );
19 17 }
20 18
21 - public static <AClientFactory extends ClientFactory, View extends IsWidget, APlace extends Place> void register( ActivityFactory.Asynchronous<AClientFactory, View, APlace> pFactory )
19 + public static <CommonActivityParam extends MessageUserSinkAccessor, View extends IsWidget, APlace extends Place> void register( ActivityFactory.Asynchronous<CommonActivityParam, View, APlace> pFactory )
22 20 {
23 21 add( pFactory );
24 22 }
25 23
26 - private ProxyActivity mCurrentProxyActivity;
27 - private ClientFactory mClientFactory;
28 -
29 - public ActivityFactoryRegistry( ClientFactory pClientFactory )
30 - {
31 - mClientFactory = pClientFactory;
32 - }
33 -
34 - @Override
35 - public Activity getActivity( Place pPlace )
36 - {
37 - String zPlaceId = PlaceIdExtractor.getPlaceId( pPlace );
38 - if ( zPlaceId != null )
39 - {
40 - ActivityFactory zFactory = get( zPlaceId );
41 - if ( zFactory instanceof ActivityFactory.Synchronous )
42 - {
43 - try
44 - {
45 - return createActivity( (ActivityFactory.Synchronous) zFactory, pPlace );
46 - }
47 - catch ( RuntimeException e )
48 - {
49 - String zMessage = createMessage( zPlaceId );
50 - LOGGER.error.log( zMessage, ": ", pPlace.getClass().getName() );
51 - mClientFactory.getMessageUserSink().setErrorMessage( zMessage );
52 - return null;
53 - }
54 - }
55 - if ( zFactory instanceof ActivityFactory.Asynchronous )
56 - {
57 - ProxyActivity zCurrentProxyActivity = mCurrentProxyActivity; // Snag reference in case it gets cleared!
58 - if ( (zCurrentProxyActivity != null) && zCurrentProxyActivity.getPlaceId().equals( zFactory.getPlaceId() ) )
59 - {
60 - return zCurrentProxyActivity;
61 - }
62 - return new ProxyActivity( (ActivityFactory.Asynchronous) zFactory, pPlace );
63 - }
64 - mClientFactory.getMessageUserSink().setErrorMessage( createMessage( zPlaceId ) );
65 - }
66 - return null;
67 - }
68 -
69 - protected String createMessage( String pPlaceId )
70 - {
71 - return "Unable to locate 'View' for '" + pPlaceId + "'";
72 - }
73 -
74 - @SuppressWarnings({"unchecked"})
75 - protected Activity createActivity( ActivityFactory.Synchronous pFactory, Place pPlace )
76 - {
77 - return pFactory.createActivity( mClientFactory, pFactory.getView(), pPlace );
78 - }
79 -
80 24 private static final Map<String, ActivityFactory> PLACEID2ACTIVITYFACTORIES = new HashMap<String, ActivityFactory>();
81 25
82 - private static synchronized ActivityFactory get( String pPlaceId )
26 + protected static synchronized ActivityFactory get( String pPlaceId )
83 27 {
84 28 return PLACEID2ACTIVITYFACTORIES.get( pPlaceId );
85 29 }
  @@ -91,87 +35,4 @@
91 35 PLACEID2ACTIVITYFACTORIES.put( pFactory.getPlaceId(), pFactory );
92 36 }
93 37 }
94 -
95 - private class ProxyActivity implements Activity, HasPlaceId
96 - {
97 - private ActivityFactory.Asynchronous mFactory;
98 - private Place mPlace;
99 - private Activity mProxyFor = new ActivityStandIn();
100 -
101 - public ProxyActivity( ActivityFactory.Asynchronous pFactory, Place pPlace )
102 - {
103 - mFactory = pFactory;
104 - mPlace = pPlace;
105 - // todo: Trigger Factory
106 - }
107 -
108 - @Override
109 - public String getPlaceId()
110 - {
111 - return mFactory.getPlaceId();
112 - }
113 -
114 - @Override
115 - public String mayStop()
116 - {
117 - return mProxyFor.mayStop();
118 - }
119 -
120 - @Override
121 - public void onCancel()
122 - {
123 - mProxyFor.onCancel();
124 - }
125 -
126 - @Override
127 - public void onStop()
128 - {
129 - mProxyFor.onStop();
130 - }
131 -
132 - @Override
133 - public void start( AcceptsOneWidget pPanel, EventBus pEventBus )
134 - {
135 - mProxyFor.start( pPanel, pEventBus );
136 - }
137 - }
138 -
139 - private static class ActivityStandIn implements Activity
140 - {
141 - private boolean mCancelled, mStopped, mStarted;
142 - private AcceptsOneWidget mPanel;
143 - private EventBus mEventBus;
144 -
145 - @Override
146 - public String mayStop()
147 - {
148 - return null;
149 - }
150 -
151 - @Override
152 - public void onCancel()
153 - {
154 - mCancelled = resetFlags();
155 - }
156 -
157 - @Override
158 - public void onStop()
159 - {
160 - mStopped = resetFlags();
161 - }
162 -
163 - @Override
164 - public void start( AcceptsOneWidget pPanel, EventBus pEventBus )
165 - {
166 - mStarted = resetFlags();
167 - mEventBus = pEventBus;
168 - (mPanel = pPanel).setWidget( new Label( "Loading..." ) );
169 - }
170 -
171 - private boolean resetFlags()
172 - {
173 - mCancelled = mStopped = mStarted = false;
174 - return true;
175 - }
176 - }
177 38 }