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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package org.litesoft.GWT.client.view;

import org.litesoft.GWT.client.*;
import org.litesoft.GWT.client.context.*;
import org.litesoft.GWT.client.widgets.*;
import org.litesoft.GWT.forms.client.*;
import org.litesoft.GWT.forms.client.components.*;
import org.litesoft.bo.views.*;
import org.litesoft.commonfoundation.base.*;
import org.litesoft.commonfoundation.typeutils.*;
import org.litesoft.core.*;
import org.litesoft.security.*;
import org.litesoft.uispecification.*;

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

import static org.litesoft.uispecification.FormWidgetCtrl.*;

public class ChangePassword<T extends SecurityUserView<T>> extends DialogView implements SecurityUserViewNames
{
    private FormEngine mFE;

    private SecurityUserViewDataProvider<T> mDataProvider;
    private FormBinder<T> mFormBinder;
    private ButtonBase mSubmitButton;
    private boolean mAllowCancel;

    public ChangePassword( String pSection, ViewDef pViewDef )
    {
        this( title( pSection, pViewDef ), true );
    }

    public ChangePassword( String pTitle ) // e.g. Reset Password
    {
        this( title( pTitle ), false );
    }

    private ChangePassword( CO pCO, boolean pAllowCancel )
    {
        super( pCO, Opaqueness.Semi );

        mAllowCancel = pAllowCancel;

        ClientContext zContext = ClientContext.get();

        mDataProvider = zContext.get( SecurityUserViewDataProvider.class );
        SecurityUserViewMetaData<T> zUserViewMetaData = zContext.get( SecurityUserViewMetaData.class );

        final T zUser = ((AbstractCurrentUserViewAccessor<T>) zContext.get( AbstractCurrentUserViewAccessor.class )).getUser();

        WidgetCtrlMap zWidgetCtrlMap = new WidgetCtrlMap( VISIBLE_AND_ACTIVE_ENABLED );

        zWidgetCtrlMap.add( VISIBLE_BUT_DISABLED, aLogonEmail );
        zWidgetCtrlMap.add( EDIT_ONLY.required(), aCurrentPassword, aNewPassword, aConfirmPassword );

        mFE = new FormEngine( zWidgetCtrlMap, FormEngine.Mode.EditRegular, new MyListenerFactory() )
        {
            @Override
            protected void changeOccurredOn( String pName, IFormComponent pComponent, boolean pChanged )
            {
                super.changeOccurredOn( pName, pComponent, pChanged );
                setDialogErrorMessage( null );
            }

            @Override
            protected void enterPressedOn( String pName, IFormComponent pComponent, KeyboardKeyModifier pModifiers )
            {
                if ( !focusFromTo( pName, aCurrentPassword, aNewPassword ) )
                {
                    if ( !focusFromTo( pName, aNewPassword, aConfirmPassword ) )
                    {
                        if ( pName.equals( aConfirmPassword ) && (mSubmitButton != null) && mSubmitButton.isEnabled() )
                        {
                            submitRequested();
                        }
                        else
                        {
                            super.enterPressedOn( pName, pComponent, pModifiers );
                        }
                    }
                }
            }

            private boolean focusFromTo( String pNameActual, String pFrom, String pTo )
            {
                if ( pFrom.equals( pNameActual ) )
                {
                    getNamedComponent( pTo ).setFocus();
                    return true;
                }
                return false;
            }
        };
        mFormBinder = new FormBinder<T>( mFE, zUserViewMetaData );

        mContent.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_CENTER );
        add( new OurLabel( zUser.getFullName() ).style( "ChangePasswordUserName" ) );
        addLogonAndPasswords();
        add( new SizeableSpacer( 5 ).stretchable() );

        mFormBinder.setExistingObject( mDataProvider.copyIntoNewTS( zUser ).clearPasswordFields(), FormEngine.Mode.EditRegular );
    }

    private void addLogonAndPasswords()
    {
        SizeableHorizontalPanel zPanel = new SizeableHorizontalPanel().stretchableHorizontally();
        zPanel.add( mFormBinder.add( aLogonEmail, 0 ) );
        zPanel.add( mFormBinder.add( aCurrentPassword, PASSWORD_LENGTH ) );
        add( zPanel );
        add( new Spacer( 5 ) );
        zPanel = new SizeableHorizontalPanel().stretchableHorizontally();
        zPanel.setVerticalAlignment( HasVerticalAlignment.ALIGN_MIDDLE );
        zPanel.add( new SizeableSpacer( 5 ).stretchableHorizontally() );
        zPanel.add( new Label( "New Password: " ) );
        zPanel.add( mFormBinder.add( aNewPassword, PASSWORD_LENGTH, "" ) );
        add( zPanel );
        add( new Spacer( 5 ) );
        zPanel = new SizeableHorizontalPanel().stretchableHorizontally();
        zPanel.setVerticalAlignment( HasVerticalAlignment.ALIGN_MIDDLE );
        zPanel.add( new SizeableSpacer( 5 ).stretchableHorizontally() );
        zPanel.add( new Label( "Confirm New Password: " ) );
        zPanel.add( mFormBinder.add( aConfirmPassword, PASSWORD_LENGTH, "" ) );
        add( zPanel );
    }

    @Override
    public Widget getBottomBar()
    {
        LeftCenterRightHorizontalPanel zActionPanel = new LeftCenterRightHorizontalPanel();
        if ( mAllowCancel )
        {
            zActionPanel.addLeft( createCancelButton() );
        }
        zActionPanel.addRight( mFE.addEditSubmitButton( mSubmitButton = createSubmitButton() ) );
        return zActionPanel;
    }

    @Override
    public void aboutToShow()
    {
        super.aboutToShow();
        mFE.initialize();
    }

    @Override
    protected void justLoaded()
    {
        super.justLoaded();
        getStatusMessageSinc().clearMessage();
        mFE.setFocus();
    }

    @Override
    public void cancel()
    {
        getStatusMessageSinc().clearMessage();
        super.cancel();
    }

    @Override
    protected void submitRequested()
    {
        mFormBinder.commitForm();
        mDataProvider.changePassword( mFormBinder.getObject(), new SimpleDataProviderCallBack()
        {
            @Override
            public void error( String pError )
            {
                if ( Strings.isNotNullOrEmpty( pError ) )
                {
                    setDialogErrorMessage( pError );
                }
                else
                {
                    submitSucceeded();
                }
            }
        } );
    }

    protected void submitSucceeded()
    {
        getStatusMessageSinc().setWarningMessage( "Password Updated" );
        close();
    }

    private static class MyListenerFactory implements IFormComponent.Listener.Factory,
                                                      SecurityUserViewNames
    {
        private MyListener mNewPasswordListener, mConfirmPasswordListener;

        @Override
        public IFormComponent.Listener createListenerFor( String pName, IFormComponent pComponent )
        {
            if ( aNewPassword.equals( pName ) )
            {
                return mNewPasswordListener = new MyListener( pName, pComponent );
            }
            if ( aConfirmPassword.equals( pName ) )
            {
                return mConfirmPasswordListener = new MyListener( pName, pComponent );
            }
            return NoOpFormListener.INSTANCE;
        }

        private MyListener getOtherListener( MyListener pUs )
        {
            return (mNewPasswordListener == pUs) ? mConfirmPasswordListener : mNewPasswordListener;
        }

        private class MyListener extends NoOpFormListener
        {
            private String mLabel;
            private IFormComponent mComponent;

            private MyListener( String pName, IFormComponent pComponent )
            {
                mLabel = DeCamelizer.resolve( pName );
                mComponent = pComponent;
            }

            private String getCurrentValue()
            {
                Object zValue = mComponent.getCurrentValue();
                return (zValue != null) ? Strings.noEmpty( zValue.toString() ) : null;
            }

            @Override
            public void changeOccurred()
            {
                super.changeOccurred();
                MyListener them = getOtherListener( this );
                String zThisValue = this.getCurrentValue();
                String zThemValue = them.getCurrentValue();
                if ( (zThisValue != null) && (zThemValue != null) )
                {
                    boolean zMatches = zThisValue.equals( zThemValue );
                    this.updateError( them, zMatches );
                    them.updateError( this, zMatches );
                }
            }

            private void updateError( MyListener pThem, boolean pMatches )
            {
                mComponent.setError( pMatches ? null : mLabel + " does not match " + pThem.mLabel );
            }
        }
    }
}

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

Diff revisions: vs.
Revision Author Commited Message
942 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 23:41:46 +0000

Extracting commonfoundation

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

802 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 04:04:47 +0000
801 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 03:59:02 +0000
487 Diff Diff GeorgeS picture GeorgeS Thu 08 Sep, 2011 12:06:30 +0000

More elimination of uniqueness

486 Diff Diff GeorgeS picture GeorgeS Tue 06 Sep, 2011 03:00:59 +0000
480 Diff Diff GeorgeS picture GeorgeS Sun 04 Sep, 2011 02:38:20 +0000

Progress on common User Support...

398 GeorgeS picture GeorgeS Mon 15 Aug, 2011 19:57:47 +0000