Subversion Repository Public Repository

litesoft

Diff Revisions 486 vs 487 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/view/ScreenView.java

Diff revisions: vs.
  @@ -3,23 +3,53 @@
3 3
4 4 import java.util.*;
5 5
6 + import org.litesoft.GWT.client.*;
6 7 import org.litesoft.GWT.client.command.*;
8 + import org.litesoft.GWT.client.context.*;
9 + import org.litesoft.GWT.client.dev.*;
7 10 import org.litesoft.GWT.client.widgets.*;
8 11 import org.litesoft.core.*;
9 12 import org.litesoft.core.util.*;
10 13 import org.litesoft.uispecification.*;
11 14
12 15 import com.google.gwt.event.dom.client.*;
16 + import com.google.gwt.user.client.*;
13 17 import com.google.gwt.user.client.ui.*;
14 18
15 - public abstract class ScreenView extends UiView implements PageRefreshable
19 + public abstract class ScreenView extends UiView implements PageRefreshable,
20 + SuspendLogoutCallBacks
16 21 {
22 + public interface TitleCustomizer
23 + {
24 + void addTitleCustomizations( ScreenView pView );
25 + }
26 +
27 + private static TitleCustomizer sTitleCustomizer;
28 +
29 + public static void setTitleCustomizer( TitleCustomizer pTitleCustomizer )
30 + {
31 + sTitleCustomizer = pTitleCustomizer;
32 + }
33 +
34 + private static boolean sOpenApp = false; // True would mean NO User Login / Management
35 +
36 + public static boolean isOpenApp()
37 + {
38 + return sOpenApp;
39 + }
40 +
41 + public static void setOpenApp( boolean pOpenApp )
42 + {
43 + sOpenApp = pOpenApp;
44 + }
45 +
17 46 private LeftCenterRightHorizontalPanel mTopBar = new LeftCenterRightHorizontalPanel().style( "TopBar" );
18 47
19 48 private SimpleLabel mTitleLabel = null;
20 49
21 - private void initialSetUp()
50 + protected ScreenView( CO pCO )
22 51 {
52 + super( pCO );
23 53 mTopBar.addRight( new Spacer( 5 ).style( "CACHE_BUG" ) );
24 54
25 55 if ( hasViewTitle() )
  @@ -34,30 +64,30 @@
34 64 }
35 65 }
36 66
67 + // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv Drop vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
68 +
37 69 protected ScreenView()
38 70 {
39 - super();
40 - initialSetUp();
71 + this( (CO) null );
41 72 }
42 73
43 74 protected ScreenView( ViewDef pViewDef )
44 75 {
45 - super( pViewDef );
46 - initialSetUp();
76 + this( title( pViewDef ) );
47 77 }
48 78
49 79 protected ScreenView( String pSection, ViewDef pViewDef )
50 80 {
51 - super( pSection, pViewDef );
52 - initialSetUp();
81 + this( title( pSection, pViewDef ) );
53 82 }
54 83
55 84 protected ScreenView( String pSection, String pViewSubTitle )
56 85 {
57 - super( pSection, pViewSubTitle );
58 - initialSetUp();
86 + this( title( pSection, pViewSubTitle ) );
59 87 }
60 88
89 + // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Drop ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
90 +
61 91 @Override
62 92 public Widget getContent()
63 93 {
  @@ -129,11 +159,21 @@
129 159 mTopBar.addRight( pWidget );
130 160 }
131 161
132 - protected void addStandardTitleBar( ClickHandler pLogoutClickHandler )
162 + protected void addStandardTitleBar()
133 163 {
134 164 styleTitleBar();
135 - addHome();
136 - addLogout( pLogoutClickHandler );
165 + if ( !isHomeScreen() )
166 + {
167 + addHome();
168 + }
169 + if ( sTitleCustomizer != null )
170 + {
171 + sTitleCustomizer.addTitleCustomizations( this );
172 + }
173 + if ( !sOpenApp )
174 + {
175 + addLogout();
176 + }
137 177 }
138 178
139 179 protected void styleTitleBar()
  @@ -151,6 +191,11 @@
151 191 addLeft( HomeButton.factory().add( ViewDef.HOME ).create() );
152 192 }
153 193
194 + protected boolean isHomeScreen()
195 + {
196 + return "Home".equals( UtilsGwt.justSimpleName( this ) );
197 + }
198 +
154 199 protected void addTitle( String pTitle )
155 200 {
156 201 setViewTitle( pTitle );
  @@ -174,6 +219,89 @@
174 219 addRight( LogoutBlueIconButton.factory().add( pClickHandler ).create() );
175 220 }
176 221
222 + protected void addLogout()
223 + {
224 + addLogout( new ClickHandler()
225 + {
226 + @Override
227 + public void onClick( ClickEvent event )
228 + {
229 + logoutButtonClicked();
230 + }
231 + } );
232 + }
233 +
234 + protected void logoutButtonClicked()
235 + {
236 + if ( UtilsGwt.wasCtrlKeyDownOnCurrentEvent() && Dev.isDevMode() && isHomeScreen() )
237 + {
238 + NextDemoUserRequestHandler zHandler = ClientContext.get().get( NextDemoUserRequestHandler.class );
239 + if ( zHandler != null )
240 + {
241 + zHandler.nextDemoUser();
242 + return;
243 + }
244 + }
245 + if ( UtilsGwt.wasAltKeyDownOnCurrentEvent() )
246 + {
247 + switchUserRequested();
248 + }
249 + else
250 + {
251 + logoutRequested();
252 + }
253 + }
254 +
255 + protected void switchUserRequested()
256 + {
257 + new DialogViewDialog( ClientContext.get().get( LoginDialogViewFactory.class ).createDialog( true, createLoginOnSuccessCommand() ) ).show();
258 + }
259 +
260 + protected void logoutRequested()
261 + {
262 + new LogoutSuspendDialog( this, this ).show();
263 + }
264 +
265 + @Override
266 + public void logoutConfirmed()
267 + {
268 + ClientContext.get().get( SecurityUserViewDataProvider.class ).logoutUser();
269 + new ShowScreenCommand( ViewDef.HOME ).execute();
270 + }
271 +
272 + @Override
273 + public void suspendRequested()
274 + {
275 + new DialogViewDialog( ClientContext.get().get( SuspendDialogViewFactory.class ).createDialog( this ) ).show();
276 + }
277 +
278 + private Command createLoginOnSuccessCommand()
279 + {
280 + return new Command()
281 + {
282 + @Override
283 + public void execute()
284 + {
285 + refreshPage();
286 + }
287 + };
288 + }
289 +
290 + @Override
291 + public void refreshPage()
292 + {
293 + if ( mViewDef == null )
294 + {
295 + new ShowScreenCommand( ViewDef.HOME ).execute();
296 + }
297 + else
298 + {
299 + new ShowScreenCommand( mViewDef, createRefreshParams() ).execute();
300 + }
301 + }
302 +
303 + abstract protected UriFragmentIdParams createRefreshParams();
304 +
177 305 protected Widget addVerticallyDistributed( Widget... pWidgets )
178 306 {
179 307 return addVerticallyDistributed( Arrays.asList( pWidgets ) );