Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/view/LogoutSuspendDialog.java

Diff revisions: vs.
  @@ -1,147 +1,147 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.client.view;
3 -
4 - import org.litesoft.GWT.client.*;
5 - import org.litesoft.GWT.client.nonpublic.*;
6 - import org.litesoft.GWT.client.widgets.Button;
7 - import org.litesoft.GWT.client.widgets.*;
8 - import org.litesoft.commonfoundation.html.*;
9 - import org.litesoft.commonfoundation.typeutils.*;
10 - import org.litesoft.core.delayed.*;
11 -
12 - import com.google.gwt.core.client.*;
13 - import com.google.gwt.event.dom.client.*;
14 - import com.google.gwt.user.client.*;
15 - import com.google.gwt.user.client.ui.*;
16 -
17 - public class LogoutSuspendDialog extends AbstractDialogAutoInitialized implements TimedRunnable {
18 - private static final String LABEL_STYLE = "LogoutDialogText";
19 -
20 - private static final String SEC = "second.";
21 - private static final String SECS = "seconds.";
22 -
23 - private LogoutCallBack mLogoutCallBack;
24 - private SuspendCallBack mSuspendCallBack;
25 - private boolean mCountingDown = false;
26 - private long mNext;
27 - private int mSeconds = 30;
28 - private Label mLabelPrefix = new OurLabel( "Logout will proceed automatically in", false ).style( LABEL_STYLE );
29 - private Label mLabelSecsLefts = new OurLabel( "" + mSeconds ).style( LABEL_STYLE );
30 - private Label mLabelSeconds = new OurLabel( SECS ).style( LABEL_STYLE );
31 -
32 - public LogoutSuspendDialog( LogoutCallBack pLogoutCallBack, SuspendCallBack pSuspendCallBack ) {
33 - super( "Logout", Opaqueness.Semi );
34 -
35 - Objects.assertNotNull( "LogoutCallBack", mLogoutCallBack = pLogoutCallBack );
36 - Objects.assertNotNull( "SuspendCallBack", mSuspendCallBack = pSuspendCallBack );
37 - }
38 -
39 - @Override
40 - protected Widget createBodyPanel() {
41 - SizeableVerticalPanel zPanel = new SizeableVerticalPanel().stretchable();
42 - zPanel.add( new Spacer( 5 ) );
43 - zPanel.add( secondsLine1() );
44 - zPanel.add( secondsLine2() );
45 - zPanel.add( new SizeableSpacer( 20 ).stretchable() );
46 - zPanel.add( actions() );
47 - return zPanel;
48 - }
49 -
50 - private Widget secondsLine1() {
51 - LeftCenterRightHorizontalPanel zPanel = new LeftCenterRightHorizontalPanel();
52 - zPanel.addLeft( new Spacer().width( 20 ) );
53 - zPanel.addCenter( mLabelPrefix );
54 - zPanel.addCenter( new HTML( HTMLConstants.NBSP ) );
55 - zPanel.addCenter( mLabelSecsLefts );
56 - zPanel.addRight( new Spacer().width( 20 ) );
57 - return zPanel;
58 - }
59 -
60 - private Widget secondsLine2() {
61 - CenterHorizontalPanel zPanel = new CenterHorizontalPanel();
62 - zPanel.add( mLabelSeconds );
63 - return zPanel;
64 - }
65 -
66 - private Widget actions() {
67 - LeftCenterRightHorizontalPanel zActionPanel = new LeftCenterRightHorizontalPanel();
68 - zActionPanel.addLeft( createCancelButton() );
69 - zActionPanel.addCenter( Button.named( "Suspend" ).green().text().add( new ClickHandler() {
70 - @Override
71 - public void onClick( ClickEvent event ) {
72 - suspendRequested();
73 - }
74 - } ).create() );
75 - zActionPanel.addRight( LogoutGreenButton.factory().add( new ClickHandler() {
76 - @Override
77 - public void onClick( ClickEvent event ) {
78 - logoutConfirmed();
79 - }
80 - } ).create() );
81 - return zActionPanel;
82 - }
83 -
84 - private void startTimer() {
85 - mCountingDown = true;
86 - TimedRunnableManager.INSTANCE.runOnOrAfter( this, mNext = System.currentTimeMillis() + 1000 );
87 - }
88 -
89 - @Override
90 - public Again runOnce() {
91 - if ( mCountingDown ) {
92 - switch ( --mSeconds ) {
93 - case 1:
94 - mLabelSeconds.setText( SEC );
95 - // fall thru
96 - default:
97 - mLabelSecsLefts.setText( "" + mSeconds );
98 - return new RunAgainOnOrAfter( mNext += 1000 );
99 - case 0:
100 - logoutConfirmed();
101 - break;
102 - }
103 - }
104 - return null;
105 - }
106 -
107 - private void logoutConfirmed() {
108 - hide();
109 - Scheduler.get().scheduleDeferred( new Command() {
110 - @Override
111 - public void execute() {
112 - mLogoutCallBack.logoutConfirmed();
113 - }
114 - } );
115 - }
116 -
117 - private void suspendRequested() {
118 - hide();
119 - Scheduler.get().scheduleDeferred( new Command() {
120 - @Override
121 - public void execute() {
122 - mSuspendCallBack.suspendRequested();
123 - }
124 - } );
125 - }
126 -
127 - private void stopTimer() {
128 - mCountingDown = false;
129 - TimedRunnableManager.INSTANCE.cancel( this );
130 - }
131 -
132 - @Override
133 - protected void onAttach() {
134 - super.onAttach();
135 - startTimer();
136 - }
137 -
138 - @Override
139 - public void hide() {
140 - stopTimer();
141 - super.hide();
142 - }
143 -
144 - protected final ButtonBase createCancelButton() {
145 - return CancelButton.factory().add( new HideCommand() ).create();
146 - }
147 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.client.view;
3 +
4 + import org.litesoft.GWT.client.*;
5 + import org.litesoft.GWT.client.nonpublic.*;
6 + import org.litesoft.GWT.client.widgets.Button;
7 + import org.litesoft.GWT.client.widgets.*;
8 + import org.litesoft.commonfoundation.base.*;
9 + import org.litesoft.commonfoundation.html.*;
10 + import org.litesoft.core.delayed.*;
11 +
12 + import com.google.gwt.core.client.*;
13 + import com.google.gwt.event.dom.client.*;
14 + import com.google.gwt.user.client.*;
15 + import com.google.gwt.user.client.ui.*;
16 +
17 + public class LogoutSuspendDialog extends AbstractDialogAutoInitialized implements TimedRunnable {
18 + private static final String LABEL_STYLE = "LogoutDialogText";
19 +
20 + private static final String SEC = "second.";
21 + private static final String SECS = "seconds.";
22 +
23 + private LogoutCallBack mLogoutCallBack;
24 + private SuspendCallBack mSuspendCallBack;
25 + private boolean mCountingDown = false;
26 + private long mNext;
27 + private int mSeconds = 30;
28 + private Label mLabelPrefix = new OurLabel( "Logout will proceed automatically in", false ).style( LABEL_STYLE );
29 + private Label mLabelSecsLefts = new OurLabel( "" + mSeconds ).style( LABEL_STYLE );
30 + private Label mLabelSeconds = new OurLabel( SECS ).style( LABEL_STYLE );
31 +
32 + public LogoutSuspendDialog( LogoutCallBack pLogoutCallBack, SuspendCallBack pSuspendCallBack ) {
33 + super( "Logout", Opaqueness.Semi );
34 +
35 + Confirm.isNotNull( "LogoutCallBack", mLogoutCallBack = pLogoutCallBack );
36 + Confirm.isNotNull( "SuspendCallBack", mSuspendCallBack = pSuspendCallBack );
37 + }
38 +
39 + @Override
40 + protected Widget createBodyPanel() {
41 + SizeableVerticalPanel zPanel = new SizeableVerticalPanel().stretchable();
42 + zPanel.add( new Spacer( 5 ) );
43 + zPanel.add( secondsLine1() );
44 + zPanel.add( secondsLine2() );
45 + zPanel.add( new SizeableSpacer( 20 ).stretchable() );
46 + zPanel.add( actions() );
47 + return zPanel;
48 + }
49 +
50 + private Widget secondsLine1() {
51 + LeftCenterRightHorizontalPanel zPanel = new LeftCenterRightHorizontalPanel();
52 + zPanel.addLeft( new Spacer().width( 20 ) );
53 + zPanel.addCenter( mLabelPrefix );
54 + zPanel.addCenter( new HTML( HtmlEntity.NBSP ) );
55 + zPanel.addCenter( mLabelSecsLefts );
56 + zPanel.addRight( new Spacer().width( 20 ) );
57 + return zPanel;
58 + }
59 +
60 + private Widget secondsLine2() {
61 + CenterHorizontalPanel zPanel = new CenterHorizontalPanel();
62 + zPanel.add( mLabelSeconds );
63 + return zPanel;
64 + }
65 +
66 + private Widget actions() {
67 + LeftCenterRightHorizontalPanel zActionPanel = new LeftCenterRightHorizontalPanel();
68 + zActionPanel.addLeft( createCancelButton() );
69 + zActionPanel.addCenter( Button.named( "Suspend" ).green().text().add( new ClickHandler() {
70 + @Override
71 + public void onClick( ClickEvent event ) {
72 + suspendRequested();
73 + }
74 + } ).create() );
75 + zActionPanel.addRight( LogoutGreenButton.factory().add( new ClickHandler() {
76 + @Override
77 + public void onClick( ClickEvent event ) {
78 + logoutConfirmed();
79 + }
80 + } ).create() );
81 + return zActionPanel;
82 + }
83 +
84 + private void startTimer() {
85 + mCountingDown = true;
86 + TimedRunnableManager.INSTANCE.runOnOrAfter( this, mNext = System.currentTimeMillis() + 1000 );
87 + }
88 +
89 + @Override
90 + public Again runOnce() {
91 + if ( mCountingDown ) {
92 + switch ( --mSeconds ) {
93 + case 1:
94 + mLabelSeconds.setText( SEC );
95 + // fall thru
96 + default:
97 + mLabelSecsLefts.setText( "" + mSeconds );
98 + return new RunAgainOnOrAfter( mNext += 1000 );
99 + case 0:
100 + logoutConfirmed();
101 + break;
102 + }
103 + }
104 + return null;
105 + }
106 +
107 + private void logoutConfirmed() {
108 + hide();
109 + Scheduler.get().scheduleDeferred( new Command() {
110 + @Override
111 + public void execute() {
112 + mLogoutCallBack.logoutConfirmed();
113 + }
114 + } );
115 + }
116 +
117 + private void suspendRequested() {
118 + hide();
119 + Scheduler.get().scheduleDeferred( new Command() {
120 + @Override
121 + public void execute() {
122 + mSuspendCallBack.suspendRequested();
123 + }
124 + } );
125 + }
126 +
127 + private void stopTimer() {
128 + mCountingDown = false;
129 + TimedRunnableManager.INSTANCE.cancel( this );
130 + }
131 +
132 + @Override
133 + protected void onAttach() {
134 + super.onAttach();
135 + startTimer();
136 + }
137 +
138 + @Override
139 + public void hide() {
140 + stopTimer();
141 + super.hide();
142 + }
143 +
144 + protected final ButtonBase createCancelButton() {
145 + return CancelButton.factory().add( new HideCommand() ).create();
146 + }
147 + }