Subversion Repository Public Repository

litesoft

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
package org.litesoft.GWT.client.view;

import org.litesoft.GWT.client.*;
import org.litesoft.GWT.client.nonpublic.*;
import org.litesoft.GWT.client.widgets.*;
import org.litesoft.core.delayed.*;
import org.litesoft.core.util.*;

import com.google.gwt.event.dom.client.*;
import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;

public class LogoutSuspendDialog extends AbstractDialogAutoInitialized implements TimedRunnable
{
    private static final String LABEL_STYLE = "LogoutDialogText";

    private static final String SEC = "second.";
    private static final String SECS = "seconds.";

    private LogoutCallBack mLogoutCallBack;
    private SuspendCallBack mSuspendCallBack;
    private boolean mCountingDown = false;
    private long mNext;
    private int mSeconds = 30;
    private Label mLabelPrefix = new OurLabel( "Logout will proceed automatically in", false ).style( LABEL_STYLE );
    private Label mLabelSecsLefts = new OurLabel( "" + mSeconds ).style( LABEL_STYLE );
    private Label mLabelSeconds = new OurLabel( SECS ).style( LABEL_STYLE );

    public LogoutSuspendDialog( LogoutCallBack pLogoutCallBack, SuspendCallBack pSuspendCallBack )
    {
        super( "Logout", Opaqueness.Semi );

        UtilsCommon.assertNotNull( "LogoutCallBack", mLogoutCallBack = pLogoutCallBack );
        UtilsCommon.assertNotNull( "SuspendCallBack", mSuspendCallBack = pSuspendCallBack );
    }

    protected Widget createBodyPanel()
    {
        SizeableVerticalPanel zPanel = new SizeableVerticalPanel().stretchable();
        zPanel.add( new Spacer( 5 ) );
        zPanel.add( secondsLine1() );
        zPanel.add( secondsLine2() );
        zPanel.add( new SizeableSpacer( 20 ).stretchable() );
        zPanel.add( actions() );
        return zPanel;
    }

    private Widget secondsLine1()
    {
        LeftCenterRightHorizontalPanel zPanel = new LeftCenterRightHorizontalPanel();
        zPanel.addLeft( new Spacer().width( 20 ) );
        zPanel.addCenter( mLabelPrefix );
        zPanel.addCenter( new HTML( " " ) );
        zPanel.addCenter( mLabelSecsLefts );
        zPanel.addRight( new Spacer().width( 20 ) );
        return zPanel;
    }

    private Widget secondsLine2()
    {
        CenterHorizontalPanel zPanel = new CenterHorizontalPanel();
        zPanel.add( mLabelSeconds );
        return zPanel;
    }

    private Widget actions()
    {
        LeftCenterRightHorizontalPanel zActionPanel = new LeftCenterRightHorizontalPanel();
        zActionPanel.addLeft( createCancelButton() );
        zActionPanel.addCenter( createSuspendButton() );
        zActionPanel.addRight( createLogoutButton() );
        return zActionPanel;
    }

    private void startTimer()
    {
        mCountingDown = true;
        TimedRunnableManager.INSTANCE.runOnOrAfter( this, mNext = UtilsCommon.now().getTime() + 1000 );
    }

    public Again runOnce()
    {
        if ( mCountingDown )
        {
            switch ( --mSeconds )
            {
                case 1:
                    mLabelSeconds.setText( SEC );
                    // fall thru
                default:
                    mLabelSecsLefts.setText( "" + mSeconds );
                    return new RunAgainOnOrAfter( mNext += 1000 );
                case 0:
                    logoutConfirmed();
                    break;
            }
        }
        return null;
    }

    private void logoutConfirmed()
    {
        hide();
        DeferredCommand.addCommand( new Command()
        {
            public void execute()
            {
                mLogoutCallBack.logoutConfirmed();
            }
        } );
    }

    private void suspendRequested()
    {
        hide();
        DeferredCommand.addCommand( new Command()
        {
            public void execute()
            {
                mSuspendCallBack.suspendRequested();
            }
        } );
    }

    private void stopTimer()
    {
        mCountingDown = false;
        TimedRunnableManager.INSTANCE.cancel( this );
    }

    @Override protected void onAttach()
    {
        super.onAttach();
        startTimer();
    }

    @Override public void hide()
    {
        stopTimer();
        super.hide();
    }

    protected final ButtonBase createCancelButton()
    {
        return new CancelButton();
    }

    protected final ButtonBase createSuspendButton()
    {
        return new GreenButton( "Suspend", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                suspendRequested();
            }
        } );
    }

    protected final ButtonBase createLogoutButton()
    {
        return new GreenButton( "Logout", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                logoutConfirmed();
            }
        } );
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/view/LogoutSuspendDialog.java

Diff revisions: vs.
Revision Author Commited Message
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000