|
@@ -16,8 +16,7 @@ |
16 |
16 |
|
|
17 |
17 |
|
import static org.litesoft.uispecification.FormWidgetCtrl.*; |
18 |
18 |
|
|
19 |
|
- |
public class ChangePassword<T extends SecurityUserView<T>> extends DialogView implements SecurityUserViewNames |
20 |
|
- |
{ |
|
19 |
+ |
public class ChangePassword<T extends SecurityUserView<T>> extends DialogView implements SecurityUserViewNames { |
21 |
20 |
|
private FormEngine mFE; |
22 |
21 |
|
|
23 |
22 |
|
private SecurityUserViewDataProvider<T> mDataProvider; |
|
@@ -25,8 +24,7 @@ |
25 |
24 |
|
private ButtonBase mSubmitButton; |
26 |
25 |
|
private boolean mAllowCancel; |
27 |
26 |
|
|
28 |
|
- |
public ChangePassword( String pSection, ViewDef pViewDef ) |
29 |
|
- |
{ |
|
27 |
+ |
public ChangePassword( String pSection, ViewDef pViewDef ) { |
30 |
28 |
|
this( title( pSection, pViewDef ), true ); |
31 |
29 |
|
} |
32 |
30 |
|
|
|
@@ -35,8 +33,7 @@ |
35 |
33 |
|
this( title( pTitle ), false ); |
36 |
34 |
|
} |
37 |
35 |
|
|
38 |
|
- |
private ChangePassword( CO pCO, boolean pAllowCancel ) |
39 |
|
- |
{ |
|
36 |
+ |
private ChangePassword( CO pCO, boolean pAllowCancel ) { |
40 |
37 |
|
super( pCO, Opaqueness.Semi ); |
41 |
38 |
|
|
42 |
39 |
|
mAllowCancel = pAllowCancel; |
|
@@ -53,38 +50,28 @@ |
53 |
50 |
|
zWidgetCtrlMap.add( VISIBLE_BUT_DISABLED, aLogonEmail ); |
54 |
51 |
|
zWidgetCtrlMap.add( EDIT_ONLY.required(), aCurrentPassword, aNewPassword, aConfirmPassword ); |
55 |
52 |
|
|
56 |
|
- |
mFE = new FormEngine( zWidgetCtrlMap, FormEngine.Mode.EditRegular, new MyListenerFactory() ) |
57 |
|
- |
{ |
|
53 |
+ |
mFE = new FormEngine( zWidgetCtrlMap, FormEngine.Mode.EditRegular, new MyListenerFactory() ) { |
58 |
54 |
|
@Override |
59 |
|
- |
protected void changeOccurredOn( String pName, IFormComponent pComponent, boolean pChanged ) |
60 |
|
- |
{ |
|
55 |
+ |
protected void changeOccurredOn( String pName, IFormComponent pComponent, boolean pChanged ) { |
61 |
56 |
|
super.changeOccurredOn( pName, pComponent, pChanged ); |
62 |
57 |
|
setDialogErrorMessage( null ); |
63 |
58 |
|
} |
64 |
59 |
|
|
65 |
60 |
|
@Override |
66 |
|
- |
protected void enterPressedOn( String pName, IFormComponent pComponent, KeyboardKeyModifier pModifiers ) |
67 |
|
- |
{ |
68 |
|
- |
if ( !focusFromTo( pName, aCurrentPassword, aNewPassword ) ) |
69 |
|
- |
{ |
70 |
|
- |
if ( !focusFromTo( pName, aNewPassword, aConfirmPassword ) ) |
71 |
|
- |
{ |
72 |
|
- |
if ( pName.equals( aConfirmPassword ) && (mSubmitButton != null) && mSubmitButton.isEnabled() ) |
73 |
|
- |
{ |
|
61 |
+ |
protected void enterPressedOn( String pName, IFormComponent pComponent, KeyboardKeyModifier pModifiers ) { |
|
62 |
+ |
if ( !focusFromTo( pName, aCurrentPassword, aNewPassword ) ) { |
|
63 |
+ |
if ( !focusFromTo( pName, aNewPassword, aConfirmPassword ) ) { |
|
64 |
+ |
if ( pName.equals( aConfirmPassword ) && (mSubmitButton != null) && mSubmitButton.isEnabled() ) { |
74 |
65 |
|
submitRequested(); |
75 |
|
- |
} |
76 |
|
- |
else |
77 |
|
- |
{ |
|
66 |
+ |
} else { |
78 |
67 |
|
super.enterPressedOn( pName, pComponent, pModifiers ); |
79 |
68 |
|
} |
80 |
69 |
|
} |
81 |
70 |
|
} |
82 |
71 |
|
} |
83 |
72 |
|
|
84 |
|
- |
private boolean focusFromTo( String pNameActual, String pFrom, String pTo ) |
85 |
|
- |
{ |
86 |
|
- |
if ( pFrom.equals( pNameActual ) ) |
87 |
|
- |
{ |
|
73 |
+ |
private boolean focusFromTo( String pNameActual, String pFrom, String pTo ) { |
|
74 |
+ |
if ( pFrom.equals( pNameActual ) ) { |
88 |
75 |
|
getNamedComponent( pTo ).setFocus(); |
89 |
76 |
|
return true; |
90 |
77 |
|
} |
|
@@ -101,8 +88,7 @@ |
101 |
88 |
|
mFormBinder.setExistingObject( mDataProvider.copyIntoNewTS( zUser ).clearPasswordFields(), FormEngine.Mode.EditRegular ); |
102 |
89 |
|
} |
103 |
90 |
|
|
104 |
|
- |
private void addLogonAndPasswords() |
105 |
|
- |
{ |
|
91 |
+ |
private void addLogonAndPasswords() { |
106 |
92 |
|
SizeableHorizontalPanel zPanel = new SizeableHorizontalPanel().stretchableHorizontally(); |
107 |
93 |
|
zPanel.add( mFormBinder.add( aLogonEmail, 0 ) ); |
108 |
94 |
|
zPanel.add( mFormBinder.add( aCurrentPassword, PASSWORD_LENGTH ) ); |
|
@@ -124,11 +110,9 @@ |
124 |
110 |
|
} |
125 |
111 |
|
|
126 |
112 |
|
@Override |
127 |
|
- |
public Widget getBottomBar() |
128 |
|
- |
{ |
|
113 |
+ |
public Widget getBottomBar() { |
129 |
114 |
|
LeftCenterRightHorizontalPanel zActionPanel = new LeftCenterRightHorizontalPanel(); |
130 |
|
- |
if ( mAllowCancel ) |
131 |
|
- |
{ |
|
115 |
+ |
if ( mAllowCancel ) { |
132 |
116 |
|
zActionPanel.addLeft( createCancelButton() ); |
133 |
117 |
|
} |
134 |
118 |
|
zActionPanel.addRight( mFE.addEditSubmitButton( mSubmitButton = createSubmitButton() ) ); |
|
@@ -136,112 +120,91 @@ |
136 |
120 |
|
} |
137 |
121 |
|
|
138 |
122 |
|
@Override |
139 |
|
- |
public void aboutToShow() |
140 |
|
- |
{ |
|
123 |
+ |
public void aboutToShow() { |
141 |
124 |
|
super.aboutToShow(); |
142 |
125 |
|
mFE.initialize(); |
143 |
126 |
|
} |
144 |
127 |
|
|
145 |
128 |
|
@Override |
146 |
|
- |
protected void justLoaded() |
147 |
|
- |
{ |
|
129 |
+ |
protected void justLoaded() { |
148 |
130 |
|
super.justLoaded(); |
149 |
131 |
|
getStatusMessageSinc().clearMessage(); |
150 |
132 |
|
mFE.setFocus(); |
151 |
133 |
|
} |
152 |
134 |
|
|
153 |
135 |
|
@Override |
154 |
|
- |
public void cancel() |
155 |
|
- |
{ |
|
136 |
+ |
public void cancel() { |
156 |
137 |
|
getStatusMessageSinc().clearMessage(); |
157 |
138 |
|
super.cancel(); |
158 |
139 |
|
} |
159 |
140 |
|
|
160 |
141 |
|
@Override |
161 |
|
- |
protected void submitRequested() |
162 |
|
- |
{ |
|
142 |
+ |
protected void submitRequested() { |
163 |
143 |
|
mFormBinder.commitForm(); |
164 |
|
- |
mDataProvider.changePassword( mFormBinder.getObject(), new SimpleDataProviderCallBack() |
165 |
|
- |
{ |
|
144 |
+ |
mDataProvider.changePassword( mFormBinder.getObject(), new SimpleDataProviderCallBack() { |
166 |
145 |
|
@Override |
167 |
|
- |
public void error( String pError ) |
168 |
|
- |
{ |
169 |
|
- |
if ( Strings.isNotNullOrEmpty( pError ) ) |
170 |
|
- |
{ |
|
146 |
+ |
public void error( String pError ) { |
|
147 |
+ |
if ( Strings.isNotNullOrEmpty( pError ) ) { |
171 |
148 |
|
setDialogErrorMessage( pError ); |
172 |
|
- |
} |
173 |
|
- |
else |
174 |
|
- |
{ |
|
149 |
+ |
} else { |
175 |
150 |
|
submitSucceeded(); |
176 |
151 |
|
} |
177 |
152 |
|
} |
178 |
153 |
|
} ); |
179 |
154 |
|
} |
180 |
155 |
|
|
181 |
|
- |
protected void submitSucceeded() |
182 |
|
- |
{ |
|
156 |
+ |
protected void submitSucceeded() { |
183 |
157 |
|
getStatusMessageSinc().setWarningMessage( "Password Updated" ); |
184 |
158 |
|
close(); |
185 |
159 |
|
} |
186 |
160 |
|
|
187 |
161 |
|
private static class MyListenerFactory implements IFormComponent.Listener.Factory, |
188 |
|
- |
SecurityUserViewNames |
189 |
|
- |
{ |
|
162 |
+ |
SecurityUserViewNames { |
190 |
163 |
|
private MyListener mNewPasswordListener, mConfirmPasswordListener; |
191 |
164 |
|
|
192 |
165 |
|
@Override |
193 |
|
- |
public IFormComponent.Listener createListenerFor( String pName, IFormComponent pComponent ) |
194 |
|
- |
{ |
195 |
|
- |
if ( aNewPassword.equals( pName ) ) |
196 |
|
- |
{ |
|
166 |
+ |
public IFormComponent.Listener createListenerFor( String pName, IFormComponent pComponent ) { |
|
167 |
+ |
if ( aNewPassword.equals( pName ) ) { |
197 |
168 |
|
return mNewPasswordListener = new MyListener( pName, pComponent ); |
198 |
169 |
|
} |
199 |
|
- |
if ( aConfirmPassword.equals( pName ) ) |
200 |
|
- |
{ |
|
170 |
+ |
if ( aConfirmPassword.equals( pName ) ) { |
201 |
171 |
|
return mConfirmPasswordListener = new MyListener( pName, pComponent ); |
202 |
172 |
|
} |
203 |
173 |
|
return NoOpFormListener.INSTANCE; |
204 |
174 |
|
} |
205 |
175 |
|
|
206 |
|
- |
private MyListener getOtherListener( MyListener pUs ) |
207 |
|
- |
{ |
|
176 |
+ |
private MyListener getOtherListener( MyListener pUs ) { |
208 |
177 |
|
return (mNewPasswordListener == pUs) ? mConfirmPasswordListener : mNewPasswordListener; |
209 |
178 |
|
} |
210 |
179 |
|
|
211 |
|
- |
private class MyListener extends NoOpFormListener |
212 |
|
- |
{ |
|
180 |
+ |
private class MyListener extends NoOpFormListener { |
213 |
181 |
|
private String mLabel; |
214 |
182 |
|
private IFormComponent mComponent; |
215 |
183 |
|
|
216 |
|
- |
private MyListener( String pName, IFormComponent pComponent ) |
217 |
|
- |
{ |
|
184 |
+ |
private MyListener( String pName, IFormComponent pComponent ) { |
218 |
185 |
|
mLabel = DeCamelizer.resolve( pName ); |
219 |
186 |
|
mComponent = pComponent; |
220 |
187 |
|
} |
221 |
188 |
|
|
222 |
|
- |
private String getCurrentValue() |
223 |
|
- |
{ |
|
189 |
+ |
private String getCurrentValue() { |
224 |
190 |
|
Object zValue = mComponent.getCurrentValue(); |
225 |
191 |
|
return (zValue != null) ? Strings.noEmpty( zValue.toString() ) : null; |
226 |
192 |
|
} |
227 |
193 |
|
|
228 |
194 |
|
@Override |
229 |
|
- |
public void changeOccurred() |
230 |
|
- |
{ |
|
195 |
+ |
public void changeOccurred() { |
231 |
196 |
|
super.changeOccurred(); |
232 |
197 |
|
MyListener them = getOtherListener( this ); |
233 |
198 |
|
String zThisValue = this.getCurrentValue(); |
234 |
199 |
|
String zThemValue = them.getCurrentValue(); |
235 |
|
- |
if ( (zThisValue != null) && (zThemValue != null) ) |
236 |
|
- |
{ |
|
200 |
+ |
if ( (zThisValue != null) && (zThemValue != null) ) { |
237 |
201 |
|
boolean zMatches = zThisValue.equals( zThemValue ); |
238 |
202 |
|
this.updateError( them, zMatches ); |
239 |
203 |
|
them.updateError( this, zMatches ); |
240 |
204 |
|
} |
241 |
205 |
|
} |
242 |
206 |
|
|
243 |
|
- |
private void updateError( MyListener pThem, boolean pMatches ) |
244 |
|
- |
{ |
|
207 |
+ |
private void updateError( MyListener pThem, boolean pMatches ) { |
245 |
208 |
|
mComponent.setError( pMatches ? null : mLabel + " does not match " + pThem.mLabel ); |
246 |
209 |
|
} |
247 |
210 |
|
} |