|
@@ -1,212 +1,211 @@ |
1 |
|
- |
package org.litesoft.GWT.client.view; |
2 |
|
- |
|
3 |
|
- |
import org.litesoft.GWT.client.*; |
4 |
|
- |
import org.litesoft.GWT.client.context.*; |
5 |
|
- |
import org.litesoft.GWT.client.widgets.*; |
6 |
|
- |
import org.litesoft.GWT.forms.client.*; |
7 |
|
- |
import org.litesoft.GWT.forms.client.components.*; |
8 |
|
- |
import org.litesoft.bo.views.*; |
9 |
|
- |
import org.litesoft.commonfoundation.base.*; |
10 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
11 |
|
- |
import org.litesoft.core.*; |
12 |
|
- |
import org.litesoft.security.*; |
13 |
|
- |
import org.litesoft.uispecification.*; |
14 |
|
- |
|
15 |
|
- |
import com.google.gwt.user.client.ui.*; |
16 |
|
- |
|
17 |
|
- |
import static org.litesoft.uispecification.FormWidgetCtrl.*; |
18 |
|
- |
|
19 |
|
- |
public class ChangePassword<T extends SecurityUserView<T>> extends DialogView implements SecurityUserViewNames { |
20 |
|
- |
private FormEngine mFE; |
21 |
|
- |
|
22 |
|
- |
private SecurityUserViewDataProvider<T> mDataProvider; |
23 |
|
- |
private FormBinder<T> mFormBinder; |
24 |
|
- |
private ButtonBase mSubmitButton; |
25 |
|
- |
private boolean mAllowCancel; |
26 |
|
- |
|
27 |
|
- |
public ChangePassword( String pSection, ViewDef pViewDef ) { |
28 |
|
- |
this( title( pSection, pViewDef ), true ); |
29 |
|
- |
} |
30 |
|
- |
|
31 |
|
- |
public ChangePassword( String pTitle ) // e.g. Reset Password |
32 |
|
- |
{ |
33 |
|
- |
this( title( pTitle ), false ); |
34 |
|
- |
} |
35 |
|
- |
|
36 |
|
- |
private ChangePassword( CO pCO, boolean pAllowCancel ) { |
37 |
|
- |
super( pCO, Opaqueness.Semi ); |
38 |
|
- |
|
39 |
|
- |
mAllowCancel = pAllowCancel; |
40 |
|
- |
|
41 |
|
- |
ClientContext zContext = ClientContext.get(); |
42 |
|
- |
|
43 |
|
- |
mDataProvider = zContext.get( SecurityUserViewDataProvider.class ); |
44 |
|
- |
SecurityUserViewMetaData<T> zUserViewMetaData = zContext.get( SecurityUserViewMetaData.class ); |
45 |
|
- |
|
46 |
|
- |
final T zUser = ((AbstractCurrentUserViewAccessor<T>) zContext.get( AbstractCurrentUserViewAccessor.class )).getUser(); |
47 |
|
- |
|
48 |
|
- |
WidgetCtrlMap zWidgetCtrlMap = new WidgetCtrlMap( VISIBLE_AND_ACTIVE_ENABLED ); |
49 |
|
- |
|
50 |
|
- |
zWidgetCtrlMap.add( VISIBLE_BUT_DISABLED, aLogonEmail ); |
51 |
|
- |
zWidgetCtrlMap.add( EDIT_ONLY.required(), aCurrentPassword, aNewPassword, aConfirmPassword ); |
52 |
|
- |
|
53 |
|
- |
mFE = new FormEngine( zWidgetCtrlMap, FormEngine.Mode.EditRegular, new MyListenerFactory() ) { |
54 |
|
- |
@Override |
55 |
|
- |
protected void changeOccurredOn( String pName, IFormComponent pComponent, boolean pChanged ) { |
56 |
|
- |
super.changeOccurredOn( pName, pComponent, pChanged ); |
57 |
|
- |
setDialogErrorMessage( null ); |
58 |
|
- |
} |
59 |
|
- |
|
60 |
|
- |
@Override |
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() ) { |
65 |
|
- |
submitRequested(); |
66 |
|
- |
} else { |
67 |
|
- |
super.enterPressedOn( pName, pComponent, pModifiers ); |
68 |
|
- |
} |
69 |
|
- |
} |
70 |
|
- |
} |
71 |
|
- |
} |
72 |
|
- |
|
73 |
|
- |
private boolean focusFromTo( String pNameActual, String pFrom, String pTo ) { |
74 |
|
- |
if ( pFrom.equals( pNameActual ) ) { |
75 |
|
- |
getNamedComponent( pTo ).setFocus(); |
76 |
|
- |
return true; |
77 |
|
- |
} |
78 |
|
- |
return false; |
79 |
|
- |
} |
80 |
|
- |
}; |
81 |
|
- |
mFormBinder = new FormBinder<T>( mFE, zUserViewMetaData ); |
82 |
|
- |
|
83 |
|
- |
mContent.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_CENTER ); |
84 |
|
- |
add( new OurLabel( zUser.getFullName() ).style( "ChangePasswordUserName" ) ); |
85 |
|
- |
addLogonAndPasswords(); |
86 |
|
- |
add( new SizeableSpacer( 5 ).stretchable() ); |
87 |
|
- |
|
88 |
|
- |
mFormBinder.setExistingObject( mDataProvider.copyIntoNewTS( zUser ).clearPasswordFields(), FormEngine.Mode.EditRegular ); |
89 |
|
- |
} |
90 |
|
- |
|
91 |
|
- |
private void addLogonAndPasswords() { |
92 |
|
- |
SizeableHorizontalPanel zPanel = new SizeableHorizontalPanel().stretchableHorizontally(); |
93 |
|
- |
zPanel.add( mFormBinder.add( aLogonEmail, 0 ) ); |
94 |
|
- |
zPanel.add( mFormBinder.add( aCurrentPassword, PASSWORD_LENGTH ) ); |
95 |
|
- |
add( zPanel ); |
96 |
|
- |
add( new Spacer( 5 ) ); |
97 |
|
- |
zPanel = new SizeableHorizontalPanel().stretchableHorizontally(); |
98 |
|
- |
zPanel.setVerticalAlignment( HasVerticalAlignment.ALIGN_MIDDLE ); |
99 |
|
- |
zPanel.add( new SizeableSpacer( 5 ).stretchableHorizontally() ); |
100 |
|
- |
zPanel.add( new Label( "New Password: " ) ); |
101 |
|
- |
zPanel.add( mFormBinder.add( aNewPassword, PASSWORD_LENGTH, "" ) ); |
102 |
|
- |
add( zPanel ); |
103 |
|
- |
add( new Spacer( 5 ) ); |
104 |
|
- |
zPanel = new SizeableHorizontalPanel().stretchableHorizontally(); |
105 |
|
- |
zPanel.setVerticalAlignment( HasVerticalAlignment.ALIGN_MIDDLE ); |
106 |
|
- |
zPanel.add( new SizeableSpacer( 5 ).stretchableHorizontally() ); |
107 |
|
- |
zPanel.add( new Label( "Confirm New Password: " ) ); |
108 |
|
- |
zPanel.add( mFormBinder.add( aConfirmPassword, PASSWORD_LENGTH, "" ) ); |
109 |
|
- |
add( zPanel ); |
110 |
|
- |
} |
111 |
|
- |
|
112 |
|
- |
@Override |
113 |
|
- |
public Widget getBottomBar() { |
114 |
|
- |
LeftCenterRightHorizontalPanel zActionPanel = new LeftCenterRightHorizontalPanel(); |
115 |
|
- |
if ( mAllowCancel ) { |
116 |
|
- |
zActionPanel.addLeft( createCancelButton() ); |
117 |
|
- |
} |
118 |
|
- |
zActionPanel.addRight( mFE.addEditSubmitButton( mSubmitButton = createSubmitButton() ) ); |
119 |
|
- |
return zActionPanel; |
120 |
|
- |
} |
121 |
|
- |
|
122 |
|
- |
@Override |
123 |
|
- |
public void aboutToShow() { |
124 |
|
- |
super.aboutToShow(); |
125 |
|
- |
mFE.initialize(); |
126 |
|
- |
} |
127 |
|
- |
|
128 |
|
- |
@Override |
129 |
|
- |
protected void justLoaded() { |
130 |
|
- |
super.justLoaded(); |
131 |
|
- |
getStatusMessageSinc().clearMessage(); |
132 |
|
- |
mFE.setFocus(); |
133 |
|
- |
} |
134 |
|
- |
|
135 |
|
- |
@Override |
136 |
|
- |
public void cancel() { |
137 |
|
- |
getStatusMessageSinc().clearMessage(); |
138 |
|
- |
super.cancel(); |
139 |
|
- |
} |
140 |
|
- |
|
141 |
|
- |
@Override |
142 |
|
- |
protected void submitRequested() { |
143 |
|
- |
mFormBinder.commitForm(); |
144 |
|
- |
mDataProvider.changePassword( mFormBinder.getObject(), new SimpleDataProviderCallBack() { |
145 |
|
- |
@Override |
146 |
|
- |
public void error( String pError ) { |
147 |
|
- |
if ( Strings.isNotNullOrEmpty( pError ) ) { |
148 |
|
- |
setDialogErrorMessage( pError ); |
149 |
|
- |
} else { |
150 |
|
- |
submitSucceeded(); |
151 |
|
- |
} |
152 |
|
- |
} |
153 |
|
- |
} ); |
154 |
|
- |
} |
155 |
|
- |
|
156 |
|
- |
protected void submitSucceeded() { |
157 |
|
- |
getStatusMessageSinc().setWarningMessage( "Password Updated" ); |
158 |
|
- |
close(); |
159 |
|
- |
} |
160 |
|
- |
|
161 |
|
- |
private static class MyListenerFactory implements IFormComponent.Listener.Factory, |
162 |
|
- |
SecurityUserViewNames { |
163 |
|
- |
private MyListener mNewPasswordListener, mConfirmPasswordListener; |
164 |
|
- |
|
165 |
|
- |
@Override |
166 |
|
- |
public IFormComponent.Listener createListenerFor( String pName, IFormComponent pComponent ) { |
167 |
|
- |
if ( aNewPassword.equals( pName ) ) { |
168 |
|
- |
return mNewPasswordListener = new MyListener( pName, pComponent ); |
169 |
|
- |
} |
170 |
|
- |
if ( aConfirmPassword.equals( pName ) ) { |
171 |
|
- |
return mConfirmPasswordListener = new MyListener( pName, pComponent ); |
172 |
|
- |
} |
173 |
|
- |
return NoOpFormListener.INSTANCE; |
174 |
|
- |
} |
175 |
|
- |
|
176 |
|
- |
private MyListener getOtherListener( MyListener pUs ) { |
177 |
|
- |
return (mNewPasswordListener == pUs) ? mConfirmPasswordListener : mNewPasswordListener; |
178 |
|
- |
} |
179 |
|
- |
|
180 |
|
- |
private class MyListener extends NoOpFormListener { |
181 |
|
- |
private String mLabel; |
182 |
|
- |
private IFormComponent mComponent; |
183 |
|
- |
|
184 |
|
- |
private MyListener( String pName, IFormComponent pComponent ) { |
185 |
|
- |
mLabel = DeCamelizer.resolve( pName ); |
186 |
|
- |
mComponent = pComponent; |
187 |
|
- |
} |
188 |
|
- |
|
189 |
|
- |
private String getCurrentValue() { |
190 |
|
- |
Object zValue = mComponent.getCurrentValue(); |
191 |
|
- |
return (zValue != null) ? Strings.noEmpty( zValue.toString() ) : null; |
192 |
|
- |
} |
193 |
|
- |
|
194 |
|
- |
@Override |
195 |
|
- |
public void changeOccurred() { |
196 |
|
- |
super.changeOccurred(); |
197 |
|
- |
MyListener them = getOtherListener( this ); |
198 |
|
- |
String zThisValue = this.getCurrentValue(); |
199 |
|
- |
String zThemValue = them.getCurrentValue(); |
200 |
|
- |
if ( (zThisValue != null) && (zThemValue != null) ) { |
201 |
|
- |
boolean zMatches = zThisValue.equals( zThemValue ); |
202 |
|
- |
this.updateError( them, zMatches ); |
203 |
|
- |
them.updateError( this, zMatches ); |
204 |
|
- |
} |
205 |
|
- |
} |
206 |
|
- |
|
207 |
|
- |
private void updateError( MyListener pThem, boolean pMatches ) { |
208 |
|
- |
mComponent.setError( pMatches ? null : mLabel + " does not match " + pThem.mLabel ); |
209 |
|
- |
} |
210 |
|
- |
} |
211 |
|
- |
} |
212 |
|
- |
} |
|
1 |
+ |
package org.litesoft.GWT.client.view; |
|
2 |
+ |
|
|
3 |
+ |
import org.litesoft.GWT.client.*; |
|
4 |
+ |
import org.litesoft.GWT.client.context.*; |
|
5 |
+ |
import org.litesoft.GWT.client.widgets.*; |
|
6 |
+ |
import org.litesoft.GWT.forms.client.*; |
|
7 |
+ |
import org.litesoft.GWT.forms.client.components.*; |
|
8 |
+ |
import org.litesoft.bo.views.*; |
|
9 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
10 |
+ |
import org.litesoft.core.*; |
|
11 |
+ |
import org.litesoft.security.*; |
|
12 |
+ |
import org.litesoft.uispecification.*; |
|
13 |
+ |
|
|
14 |
+ |
import com.google.gwt.user.client.ui.*; |
|
15 |
+ |
|
|
16 |
+ |
import static org.litesoft.uispecification.FormWidgetCtrl.*; |
|
17 |
+ |
|
|
18 |
+ |
public class ChangePassword<T extends SecurityUserView<T>> extends DialogView implements SecurityUserViewNames { |
|
19 |
+ |
private FormEngine mFE; |
|
20 |
+ |
|
|
21 |
+ |
private SecurityUserViewDataProvider<T> mDataProvider; |
|
22 |
+ |
private FormBinder<T> mFormBinder; |
|
23 |
+ |
private ButtonBase mSubmitButton; |
|
24 |
+ |
private boolean mAllowCancel; |
|
25 |
+ |
|
|
26 |
+ |
public ChangePassword( String pSection, ViewDef pViewDef ) { |
|
27 |
+ |
this( title( pSection, pViewDef ), true ); |
|
28 |
+ |
} |
|
29 |
+ |
|
|
30 |
+ |
public ChangePassword( String pTitle ) // e.g. Reset Password |
|
31 |
+ |
{ |
|
32 |
+ |
this( title( pTitle ), false ); |
|
33 |
+ |
} |
|
34 |
+ |
|
|
35 |
+ |
private ChangePassword( CO pCO, boolean pAllowCancel ) { |
|
36 |
+ |
super( pCO, Opaqueness.Semi ); |
|
37 |
+ |
|
|
38 |
+ |
mAllowCancel = pAllowCancel; |
|
39 |
+ |
|
|
40 |
+ |
ClientContext zContext = ClientContext.get(); |
|
41 |
+ |
|
|
42 |
+ |
mDataProvider = zContext.get( SecurityUserViewDataProvider.class ); |
|
43 |
+ |
SecurityUserViewMetaData<T> zUserViewMetaData = zContext.get( SecurityUserViewMetaData.class ); |
|
44 |
+ |
|
|
45 |
+ |
final T zUser = ((AbstractCurrentUserViewAccessor<T>) zContext.get( AbstractCurrentUserViewAccessor.class )).getUser(); |
|
46 |
+ |
|
|
47 |
+ |
WidgetCtrlMap zWidgetCtrlMap = new WidgetCtrlMap( VISIBLE_AND_ACTIVE_ENABLED ); |
|
48 |
+ |
|
|
49 |
+ |
zWidgetCtrlMap.add( VISIBLE_BUT_DISABLED, aLogonEmail ); |
|
50 |
+ |
zWidgetCtrlMap.add( EDIT_ONLY.required(), aCurrentPassword, aNewPassword, aConfirmPassword ); |
|
51 |
+ |
|
|
52 |
+ |
mFE = new FormEngine( zWidgetCtrlMap, FormEngine.Mode.EditRegular, new MyListenerFactory() ) { |
|
53 |
+ |
@Override |
|
54 |
+ |
protected void changeOccurredOn( String pName, IFormComponent pComponent, boolean pChanged ) { |
|
55 |
+ |
super.changeOccurredOn( pName, pComponent, pChanged ); |
|
56 |
+ |
setDialogErrorMessage( null ); |
|
57 |
+ |
} |
|
58 |
+ |
|
|
59 |
+ |
@Override |
|
60 |
+ |
protected void enterPressedOn( String pName, IFormComponent pComponent, KeyboardKeyModifier pModifiers ) { |
|
61 |
+ |
if ( !focusFromTo( pName, aCurrentPassword, aNewPassword ) ) { |
|
62 |
+ |
if ( !focusFromTo( pName, aNewPassword, aConfirmPassword ) ) { |
|
63 |
+ |
if ( pName.equals( aConfirmPassword ) && (mSubmitButton != null) && mSubmitButton.isEnabled() ) { |
|
64 |
+ |
submitRequested(); |
|
65 |
+ |
} else { |
|
66 |
+ |
super.enterPressedOn( pName, pComponent, pModifiers ); |
|
67 |
+ |
} |
|
68 |
+ |
} |
|
69 |
+ |
} |
|
70 |
+ |
} |
|
71 |
+ |
|
|
72 |
+ |
private boolean focusFromTo( String pNameActual, String pFrom, String pTo ) { |
|
73 |
+ |
if ( pFrom.equals( pNameActual ) ) { |
|
74 |
+ |
getNamedComponent( pTo ).setFocus(); |
|
75 |
+ |
return true; |
|
76 |
+ |
} |
|
77 |
+ |
return false; |
|
78 |
+ |
} |
|
79 |
+ |
}; |
|
80 |
+ |
mFormBinder = new FormBinder<T>( mFE, zUserViewMetaData ); |
|
81 |
+ |
|
|
82 |
+ |
mContent.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_CENTER ); |
|
83 |
+ |
add( new OurLabel( zUser.getFullName() ).style( "ChangePasswordUserName" ) ); |
|
84 |
+ |
addLogonAndPasswords(); |
|
85 |
+ |
add( new SizeableSpacer( 5 ).stretchable() ); |
|
86 |
+ |
|
|
87 |
+ |
mFormBinder.setExistingObject( mDataProvider.copyIntoNewTS( zUser ).clearPasswordFields(), FormEngine.Mode.EditRegular ); |
|
88 |
+ |
} |
|
89 |
+ |
|
|
90 |
+ |
private void addLogonAndPasswords() { |
|
91 |
+ |
SizeableHorizontalPanel zPanel = new SizeableHorizontalPanel().stretchableHorizontally(); |
|
92 |
+ |
zPanel.add( mFormBinder.add( aLogonEmail, 0 ) ); |
|
93 |
+ |
zPanel.add( mFormBinder.add( aCurrentPassword, PASSWORD_LENGTH ) ); |
|
94 |
+ |
add( zPanel ); |
|
95 |
+ |
add( new Spacer( 5 ) ); |
|
96 |
+ |
zPanel = new SizeableHorizontalPanel().stretchableHorizontally(); |
|
97 |
+ |
zPanel.setVerticalAlignment( HasVerticalAlignment.ALIGN_MIDDLE ); |
|
98 |
+ |
zPanel.add( new SizeableSpacer( 5 ).stretchableHorizontally() ); |
|
99 |
+ |
zPanel.add( new Label( "New Password: " ) ); |
|
100 |
+ |
zPanel.add( mFormBinder.add( aNewPassword, PASSWORD_LENGTH, "" ) ); |
|
101 |
+ |
add( zPanel ); |
|
102 |
+ |
add( new Spacer( 5 ) ); |
|
103 |
+ |
zPanel = new SizeableHorizontalPanel().stretchableHorizontally(); |
|
104 |
+ |
zPanel.setVerticalAlignment( HasVerticalAlignment.ALIGN_MIDDLE ); |
|
105 |
+ |
zPanel.add( new SizeableSpacer( 5 ).stretchableHorizontally() ); |
|
106 |
+ |
zPanel.add( new Label( "Confirm New Password: " ) ); |
|
107 |
+ |
zPanel.add( mFormBinder.add( aConfirmPassword, PASSWORD_LENGTH, "" ) ); |
|
108 |
+ |
add( zPanel ); |
|
109 |
+ |
} |
|
110 |
+ |
|
|
111 |
+ |
@Override |
|
112 |
+ |
public Widget getBottomBar() { |
|
113 |
+ |
LeftCenterRightHorizontalPanel zActionPanel = new LeftCenterRightHorizontalPanel(); |
|
114 |
+ |
if ( mAllowCancel ) { |
|
115 |
+ |
zActionPanel.addLeft( createCancelButton() ); |
|
116 |
+ |
} |
|
117 |
+ |
zActionPanel.addRight( mFE.addEditSubmitButton( mSubmitButton = createSubmitButton() ) ); |
|
118 |
+ |
return zActionPanel; |
|
119 |
+ |
} |
|
120 |
+ |
|
|
121 |
+ |
@Override |
|
122 |
+ |
public void aboutToShow() { |
|
123 |
+ |
super.aboutToShow(); |
|
124 |
+ |
mFE.initialize(); |
|
125 |
+ |
} |
|
126 |
+ |
|
|
127 |
+ |
@Override |
|
128 |
+ |
protected void justLoaded() { |
|
129 |
+ |
super.justLoaded(); |
|
130 |
+ |
getStatusMessageSinc().clearMessage(); |
|
131 |
+ |
mFE.setFocus(); |
|
132 |
+ |
} |
|
133 |
+ |
|
|
134 |
+ |
@Override |
|
135 |
+ |
public void cancel() { |
|
136 |
+ |
getStatusMessageSinc().clearMessage(); |
|
137 |
+ |
super.cancel(); |
|
138 |
+ |
} |
|
139 |
+ |
|
|
140 |
+ |
@Override |
|
141 |
+ |
protected void submitRequested() { |
|
142 |
+ |
mFormBinder.commitForm(); |
|
143 |
+ |
mDataProvider.changePassword( mFormBinder.getObject(), new SimpleDataProviderCallBack() { |
|
144 |
+ |
@Override |
|
145 |
+ |
public void error( String pError ) { |
|
146 |
+ |
if ( Currently.isNotNullOrEmpty( pError ) ) { |
|
147 |
+ |
setDialogErrorMessage( pError ); |
|
148 |
+ |
} else { |
|
149 |
+ |
submitSucceeded(); |
|
150 |
+ |
} |
|
151 |
+ |
} |
|
152 |
+ |
} ); |
|
153 |
+ |
} |
|
154 |
+ |
|
|
155 |
+ |
protected void submitSucceeded() { |
|
156 |
+ |
getStatusMessageSinc().setWarningMessage( "Password Updated" ); |
|
157 |
+ |
close(); |
|
158 |
+ |
} |
|
159 |
+ |
|
|
160 |
+ |
private static class MyListenerFactory implements IFormComponent.Listener.Factory, |
|
161 |
+ |
SecurityUserViewNames { |
|
162 |
+ |
private MyListener mNewPasswordListener, mConfirmPasswordListener; |
|
163 |
+ |
|
|
164 |
+ |
@Override |
|
165 |
+ |
public IFormComponent.Listener createListenerFor( String pName, IFormComponent pComponent ) { |
|
166 |
+ |
if ( aNewPassword.equals( pName ) ) { |
|
167 |
+ |
return mNewPasswordListener = new MyListener( pName, pComponent ); |
|
168 |
+ |
} |
|
169 |
+ |
if ( aConfirmPassword.equals( pName ) ) { |
|
170 |
+ |
return mConfirmPasswordListener = new MyListener( pName, pComponent ); |
|
171 |
+ |
} |
|
172 |
+ |
return NoOpFormListener.INSTANCE; |
|
173 |
+ |
} |
|
174 |
+ |
|
|
175 |
+ |
private MyListener getOtherListener( MyListener pUs ) { |
|
176 |
+ |
return (mNewPasswordListener == pUs) ? mConfirmPasswordListener : mNewPasswordListener; |
|
177 |
+ |
} |
|
178 |
+ |
|
|
179 |
+ |
private class MyListener extends NoOpFormListener { |
|
180 |
+ |
private String mLabel; |
|
181 |
+ |
private IFormComponent mComponent; |
|
182 |
+ |
|
|
183 |
+ |
private MyListener( String pName, IFormComponent pComponent ) { |
|
184 |
+ |
mLabel = DeCamelizer.resolve( pName ); |
|
185 |
+ |
mComponent = pComponent; |
|
186 |
+ |
} |
|
187 |
+ |
|
|
188 |
+ |
private String getCurrentValue() { |
|
189 |
+ |
Object zValue = mComponent.getCurrentValue(); |
|
190 |
+ |
return (zValue != null) ? ConstrainTo.significantOrNull( zValue.toString() ) : null; |
|
191 |
+ |
} |
|
192 |
+ |
|
|
193 |
+ |
@Override |
|
194 |
+ |
public void changeOccurred() { |
|
195 |
+ |
super.changeOccurred(); |
|
196 |
+ |
MyListener them = getOtherListener( this ); |
|
197 |
+ |
String zThisValue = this.getCurrentValue(); |
|
198 |
+ |
String zThemValue = them.getCurrentValue(); |
|
199 |
+ |
if ( (zThisValue != null) && (zThemValue != null) ) { |
|
200 |
+ |
boolean zMatches = zThisValue.equals( zThemValue ); |
|
201 |
+ |
this.updateError( them, zMatches ); |
|
202 |
+ |
them.updateError( this, zMatches ); |
|
203 |
+ |
} |
|
204 |
+ |
} |
|
205 |
+ |
|
|
206 |
+ |
private void updateError( MyListener pThem, boolean pMatches ) { |
|
207 |
+ |
mComponent.setError( pMatches ? null : mLabel + " does not match " + pThem.mLabel ); |
|
208 |
+ |
} |
|
209 |
+ |
} |
|
210 |
+ |
} |
|
211 |
+ |
} |