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

import org.litesoft.GWT.client.widgets.*;
import org.litesoft.GWT.forms.client.components.*;
import org.litesoft.bo.views.*;
import org.litesoft.commonfoundation.base.*;
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 AbstractSecurityDialogView<T> implements SecurityUserViewNames {
    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 pCancelable ) {
        super( pCO, Opaqueness.Semi, pCancelable );

        centerContent();

        initializeFormInfrastructure( new MyListenerFactory() )
                .add( VISIBLE_BUT_DISABLED, aLogonEmail )
                .add( EDIT_ONLY.required(), aCurrentPassword, aNewPassword, aConfirmPassword );

        T zUser = getUserView();

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

        setEditUser( mDataProvider.copyIntoNewTS( zUser ).clearPasswordFields() );
    }

    @Override
    protected boolean processEnterPressedOn( String pName ) {
        if ( !focusFromTo( pName, aCurrentPassword, aNewPassword ) ) {
            if ( !focusFromTo( pName, aNewPassword, aConfirmPassword ) ) {
                if ( pName.equals( aConfirmPassword ) && (mSubmitButton != null) && mSubmitButton.isEnabled() ) {
                    submitRequested();
                } else {
                    return true;
                }
            }
        }
        return false;
    }

    private boolean focusFromTo( String pNameActual, String pFrom, String pTo ) {
        if ( pFrom.equals( pNameActual ) ) {
            mFE.getNamedComponent( pTo ).setFocus();
            return true;
        }
        return false;
    }

    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
    protected void justLoaded() {
        getStatusMessageSinc().clearMessage();
        super.justLoaded();
    }

    @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 ( Currently.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) ? ConstrainTo.significantOrNull( 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
957 Diff Diff GeorgeS picture GeorgeS Tue 24 Jun, 2014 12:30:01 +0000

Dialog Code Shareing

955 Diff Diff GeorgeS picture GeorgeS Sun 22 Jun, 2014 18:11:25 +0000

Add Instance...

950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

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 GeorgeS picture GeorgeS Tue 06 Sep, 2011 03:00:59 +0000