|
@@ -1,19 +1,18 @@ |
1 |
1 |
|
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
2 |
|
package org.litesoft.GWT.forms.client.nonpublic; |
3 |
3 |
|
|
4 |
|
- |
import java.io.*; |
5 |
|
- |
|
6 |
|
- |
import org.litesoft.GWT.forms.client.components.*; |
7 |
4 |
|
import org.litesoft.GWT.client.*; |
|
5 |
+ |
import org.litesoft.GWT.forms.client.components.*; |
8 |
6 |
|
import org.litesoft.commonfoundation.typeutils.*; |
9 |
7 |
|
import org.litesoft.ui.def.nonpublic.support.*; |
10 |
8 |
|
|
11 |
9 |
|
import com.google.gwt.user.client.ui.*; |
12 |
10 |
|
|
|
11 |
+ |
import java.io.*; |
|
12 |
+ |
|
13 |
13 |
|
public abstract class AbstractFormAttributeAdapter extends AbstractFormComponentAdapter |
14 |
14 |
|
implements FormAttributeAdapter, |
15 |
|
- |
IFormComponent.Listener |
16 |
|
- |
{ |
|
15 |
+ |
IFormComponent.Listener { |
17 |
16 |
|
private Integer mUniqueID; |
18 |
17 |
|
private String mAttributeReference; |
19 |
18 |
|
private IFormComponent mComponent; |
|
@@ -23,20 +22,17 @@ |
23 |
22 |
|
private Object mBaseComponentValue = null; |
24 |
23 |
|
|
25 |
24 |
|
public AbstractFormAttributeAdapter( FormInstanceComponentHandler pComponentHandler, |
26 |
|
- |
AttributeMetaData pMD, IFormComponent pComponent ) |
27 |
|
- |
{ |
|
25 |
+ |
AttributeMetaData pMD, IFormComponent pComponent ) { |
28 |
26 |
|
super( pComponentHandler ); |
29 |
27 |
|
mUniqueID = pMD.getUniqueID(); |
30 |
28 |
|
mAttributeReference = pMD.getAttributeReference(); |
31 |
29 |
|
mComponent = pComponent; |
32 |
|
- |
if ( pMD.isDisabled() ) |
33 |
|
- |
{ |
|
30 |
+ |
if ( pMD.isDisabled() ) { |
34 |
31 |
|
mComponent.setEnabled( false ); |
35 |
32 |
|
} |
36 |
33 |
|
} |
37 |
34 |
|
|
38 |
|
- |
public final Widget init() |
39 |
|
- |
{ |
|
35 |
+ |
public final Widget init() { |
40 |
36 |
|
mComponent.addFormComponentListener( this ); |
41 |
37 |
|
mComponentFormHandler.addAttributeAdapter( this ); |
42 |
38 |
|
Widget widget = initWidget(); |
|
@@ -46,86 +42,71 @@ |
46 |
42 |
|
return widget; |
47 |
43 |
|
} |
48 |
44 |
|
|
49 |
|
- |
public void add( IFormComponent pComponent ) |
50 |
|
- |
{ |
|
45 |
+ |
public void add( IFormComponent pComponent ) { |
51 |
46 |
|
// As we already have the Component, we can ignore this call... |
52 |
47 |
|
} |
53 |
48 |
|
|
54 |
|
- |
public void remove( IFormComponent pComponent ) |
55 |
|
- |
{ |
|
49 |
+ |
public void remove( IFormComponent pComponent ) { |
56 |
50 |
|
// Our Components life cycle is managed differently, we can ignore this call... |
57 |
51 |
|
} |
58 |
52 |
|
|
59 |
|
- |
protected Widget initWidget() |
60 |
|
- |
{ |
|
53 |
+ |
protected Widget initWidget() { |
61 |
54 |
|
return (Widget) mComponent; |
62 |
55 |
|
} |
63 |
56 |
|
|
64 |
57 |
|
// FormAttributeAdapter |
65 |
58 |
|
|
66 |
|
- |
public Integer getUniqueID() |
67 |
|
- |
{ |
|
59 |
+ |
public Integer getUniqueID() { |
68 |
60 |
|
return mUniqueID; |
69 |
61 |
|
} |
70 |
62 |
|
|
71 |
|
- |
public String getAttributeReference() |
72 |
|
- |
{ |
|
63 |
+ |
public String getAttributeReference() { |
73 |
64 |
|
return mAttributeReference; |
74 |
65 |
|
} |
75 |
66 |
|
|
76 |
|
- |
public boolean isErrorState() |
77 |
|
- |
{ |
|
67 |
+ |
public boolean isErrorState() { |
78 |
68 |
|
return mErrorText != null; |
79 |
69 |
|
} |
80 |
70 |
|
|
81 |
|
- |
public String getErrorText() |
82 |
|
- |
{ |
|
71 |
+ |
public String getErrorText() { |
83 |
72 |
|
return mErrorText; |
84 |
73 |
|
} |
85 |
74 |
|
|
86 |
|
- |
public void setErrorText( String pErrorText ) |
87 |
|
- |
{ |
|
75 |
+ |
public void setErrorText( String pErrorText ) { |
88 |
76 |
|
Object zComponentCurrentValue = getComponentCurrentValue(); |
89 |
77 |
|
Serializable zSendableCurrentValue = convertComponentValueToSendable( zComponentCurrentValue ); |
90 |
78 |
|
setErrorTextAndPublish( pErrorText, zSendableCurrentValue, zComponentCurrentValue ); |
91 |
79 |
|
} |
92 |
80 |
|
|
93 |
|
- |
public boolean isChangedState() |
94 |
|
- |
{ |
|
81 |
+ |
public boolean isChangedState() { |
95 |
82 |
|
return !areEqual( mBaseComponentValue, getComponentCurrentValue() ); |
96 |
83 |
|
} |
97 |
84 |
|
|
98 |
|
- |
public Serializable getBaseValue() |
99 |
|
- |
{ |
|
85 |
+ |
public Serializable getBaseValue() { |
100 |
86 |
|
return convertComponentValueToSendable( mBaseComponentValue ); |
101 |
87 |
|
} |
102 |
88 |
|
|
103 |
|
- |
public void setBaseValue( Serializable pBaseValue ) |
104 |
|
- |
{ |
|
89 |
+ |
public void setBaseValue( Serializable pBaseValue ) { |
105 |
90 |
|
mBaseComponentValue = convertSendableToComponentValue( pBaseValue ); |
106 |
91 |
|
setComponentCurrentValue( mPublishedComponentValue = mBaseComponentValue ); |
107 |
92 |
|
chkChangeOccurred( pBaseValue, mBaseComponentValue ); |
108 |
93 |
|
} |
109 |
94 |
|
|
110 |
|
- |
public Serializable getCurrentValue() |
111 |
|
- |
{ |
|
95 |
+ |
public Serializable getCurrentValue() { |
112 |
96 |
|
return convertComponentValueToSendable( getComponentCurrentValue() ); |
113 |
97 |
|
} |
114 |
98 |
|
|
115 |
|
- |
public void setCurrentValue( Serializable pCurrentValue ) |
116 |
|
- |
{ |
|
99 |
+ |
public void setCurrentValue( Serializable pCurrentValue ) { |
117 |
100 |
|
Object zComponentCurrentValue = convertSendableToComponentValue( pCurrentValue ); |
118 |
101 |
|
setComponentCurrentValue( zComponentCurrentValue ); |
119 |
102 |
|
chkChangeOccurred( pCurrentValue, zComponentCurrentValue ); |
120 |
103 |
|
} |
121 |
104 |
|
|
122 |
|
- |
public String getUserValue() |
123 |
|
- |
{ |
|
105 |
+ |
public String getUserValue() { |
124 |
106 |
|
return convertComponentValueToString( getComponentCurrentValue() ); |
125 |
107 |
|
} |
126 |
108 |
|
|
127 |
|
- |
public void setUserValue( String pValue ) |
128 |
|
- |
{ |
|
109 |
+ |
public void setUserValue( String pValue ) { |
129 |
110 |
|
setComponentUserValue( convertStringToComponentValue( pValue ) ); |
130 |
111 |
|
|
131 |
112 |
|
// handle change |
|
@@ -134,168 +115,140 @@ |
134 |
115 |
|
chkChangeOccurred( zSendableCurrentValue, zComponentCurrentValue ); |
135 |
116 |
|
|
136 |
117 |
|
// handle update |
137 |
|
- |
if ( !areEqual( mPublishedComponentValue, zComponentCurrentValue ) ) |
138 |
|
- |
{ |
|
118 |
+ |
if ( !areEqual( mPublishedComponentValue, zComponentCurrentValue ) ) { |
139 |
119 |
|
mPublishedComponentValue = zComponentCurrentValue; |
140 |
120 |
|
publishUpdatedValue( zSendableCurrentValue ); |
141 |
121 |
|
} |
142 |
122 |
|
} |
143 |
123 |
|
|
144 |
|
- |
protected void setComponentUserValue( Object pComponentValue ) |
145 |
|
- |
{ |
|
124 |
+ |
protected void setComponentUserValue( Object pComponentValue ) { |
146 |
125 |
|
setComponentCurrentValue( pComponentValue ); |
147 |
126 |
|
} |
148 |
127 |
|
|
149 |
|
- |
public void publishAnyPendingChanges() |
150 |
|
- |
{ |
|
128 |
+ |
public void publishAnyPendingChanges() { |
151 |
129 |
|
mComponent.publishAnyPendingChanges(); |
152 |
130 |
|
} |
153 |
131 |
|
|
154 |
|
- |
public void updateValidOptions( Serializable[] pValidOptions ) |
155 |
|
- |
{ |
|
132 |
+ |
public void updateValidOptions( Serializable[] pValidOptions ) { |
156 |
133 |
|
// Do nothing as most components do NOT support valid Options |
157 |
134 |
|
} |
158 |
135 |
|
|
159 |
136 |
|
// FormComponentAdapter |
160 |
137 |
|
|
161 |
|
- |
public boolean isVisible() |
162 |
|
- |
{ |
|
138 |
+ |
public boolean isVisible() { |
163 |
139 |
|
return mComponent.isVisible(); |
164 |
140 |
|
} |
165 |
141 |
|
|
166 |
|
- |
public boolean setFocus() |
167 |
|
- |
{ |
|
142 |
+ |
public boolean setFocus() { |
168 |
143 |
|
return mComponent.setFocus(); |
169 |
144 |
|
} |
170 |
145 |
|
|
171 |
|
- |
protected void setWidgetEnabled( boolean pEnabled ) |
172 |
|
- |
{ |
|
146 |
+ |
protected void setWidgetEnabled( boolean pEnabled ) { |
173 |
147 |
|
mComponent.setEnabled( pEnabled ); |
174 |
148 |
|
} |
175 |
149 |
|
|
176 |
|
- |
public boolean isEnabled() |
177 |
|
- |
{ |
|
150 |
+ |
public boolean isEnabled() { |
178 |
151 |
|
return mComponent.isEnabled(); |
179 |
152 |
|
} |
180 |
153 |
|
|
181 |
154 |
|
// IFormComponent.Listener |
182 |
155 |
|
|
183 |
|
- |
public void changeOccurred() |
184 |
|
- |
{ |
|
156 |
+ |
public void changeOccurred() { |
185 |
157 |
|
Object zComponentCurrentValue = getComponentCurrentValue(); |
186 |
158 |
|
// System.out.println( "changeOccurred: " + this + " | " + zComponentCurrentValue ); |
187 |
159 |
|
Serializable zSendableCurrentValue = convertComponentValueToSendable( zComponentCurrentValue ); |
188 |
160 |
|
chkChangeOccurred( zSendableCurrentValue, zComponentCurrentValue ); |
189 |
161 |
|
} |
190 |
162 |
|
|
191 |
|
- |
public void blurOccurred() |
192 |
|
- |
{ |
|
163 |
+ |
public void blurOccurred() { |
193 |
164 |
|
// System.out.println( "blurOccurred: " + this ); |
194 |
165 |
|
mComponent.setFocused( false ); |
195 |
166 |
|
optionallyPublishUpdatedValue(); |
196 |
167 |
|
} |
197 |
168 |
|
|
198 |
|
- |
public void focusOccured() |
199 |
|
- |
{ |
|
169 |
+ |
public void focusOccured() { |
200 |
170 |
|
// System.out.println( "focusOccured: " + this ); |
201 |
171 |
|
mComponent.setFocused( true ); |
202 |
172 |
|
} |
203 |
173 |
|
|
204 |
174 |
|
// Support... |
205 |
175 |
|
|
206 |
|
- |
protected Object getComponentCurrentValue() |
207 |
|
- |
{ |
|
176 |
+ |
protected Object getComponentCurrentValue() { |
208 |
177 |
|
return mComponent.getCurrentValue(); |
209 |
178 |
|
} |
210 |
179 |
|
|
211 |
|
- |
protected void setComponentCurrentValue( Object pNewComponentCurrentValue ) |
212 |
|
- |
{ |
|
180 |
+ |
protected void setComponentCurrentValue( Object pNewComponentCurrentValue ) { |
213 |
181 |
|
mComponent.setCurrentValue( pNewComponentCurrentValue ); |
214 |
182 |
|
} |
215 |
183 |
|
|
216 |
184 |
|
protected void setErrorTextAndPublish( String pErrorText, Serializable pSendableCurrentValue, |
217 |
|
- |
Object pComponentCurrentValue ) |
218 |
|
- |
{ |
|
185 |
+ |
Object pComponentCurrentValue ) { |
219 |
186 |
|
LLsetErrorText( pErrorText, pSendableCurrentValue, pComponentCurrentValue ); |
220 |
187 |
|
mErrorComponentValue = pComponentCurrentValue; |
221 |
188 |
|
publishErrorState( isErrorState() ); |
222 |
189 |
|
} |
223 |
190 |
|
|
224 |
191 |
|
protected void LLsetErrorText( String pErrorText, Serializable pSendableCurrentValue, |
225 |
|
- |
Object pComponentCurrentValue ) |
226 |
|
- |
{ |
|
192 |
+ |
Object pComponentCurrentValue ) { |
227 |
193 |
|
mComponent.setError( mErrorText = transformErrorText( pErrorText, // |
228 |
194 |
|
pSendableCurrentValue, // |
229 |
195 |
|
pComponentCurrentValue ) ); |
230 |
196 |
|
} |
231 |
197 |
|
|
232 |
198 |
|
protected String transformErrorText( String pErrorText, Serializable pSendableCurrentValue, |
233 |
|
- |
Object pComponentCurrentValue ) |
234 |
|
- |
{ |
|
199 |
+ |
Object pComponentCurrentValue ) { |
235 |
200 |
|
pErrorText = Strings.noEmpty( pErrorText ); |
236 |
|
- |
if ( (pErrorText == null) && (pComponentCurrentValue instanceof FormTextInputErrorValue) ) |
237 |
|
- |
{ |
238 |
|
- |
return ((FormTextInputErrorValue)pComponentCurrentValue).getErrorMessage(); |
|
201 |
+ |
if ( (pErrorText == null) && (pComponentCurrentValue instanceof FormTextInputErrorValue) ) { |
|
202 |
+ |
return ((FormTextInputErrorValue) pComponentCurrentValue).getErrorMessage(); |
239 |
203 |
|
} |
240 |
204 |
|
return pErrorText; |
241 |
205 |
|
} |
242 |
206 |
|
|
243 |
|
- |
protected void chkChangeOccurred( Serializable pSendableCurrentValue, Object pComponentCurrentValue ) |
244 |
|
- |
{ |
|
207 |
+ |
protected void chkChangeOccurred( Serializable pSendableCurrentValue, Object pComponentCurrentValue ) { |
245 |
208 |
|
boolean changedFromBaseCV = !areEqual( mBaseComponentValue, pComponentCurrentValue ); |
246 |
209 |
|
boolean changedFromErrorCV = !areEqual( mErrorComponentValue, pComponentCurrentValue ); |
247 |
|
- |
if ( changedFromErrorCV ) |
248 |
|
- |
{ |
|
210 |
+ |
if ( changedFromErrorCV ) { |
249 |
211 |
|
resetErrorOnChangeOccurred( pSendableCurrentValue, pComponentCurrentValue ); |
250 |
212 |
|
} |
251 |
213 |
|
mComponent.setValueChanged( changedFromBaseCV ); |
252 |
214 |
|
publishChangedState( changedFromBaseCV ); |
253 |
215 |
|
} |
254 |
216 |
|
|
255 |
|
- |
protected void optionallyPublishUpdatedValue() |
256 |
|
- |
{ |
|
217 |
+ |
protected void optionallyPublishUpdatedValue() { |
257 |
218 |
|
Object zComponentCurrentValue = getComponentCurrentValue(); |
258 |
219 |
|
Serializable zSendableCurrentValue = convertComponentValueToSendable( zComponentCurrentValue ); |
259 |
|
- |
if ( !areEqual( mPublishedComponentValue, zComponentCurrentValue ) ) |
260 |
|
- |
{ |
|
220 |
+ |
if ( !areEqual( mPublishedComponentValue, zComponentCurrentValue ) ) { |
261 |
221 |
|
mPublishedComponentValue = zComponentCurrentValue; |
262 |
222 |
|
publishUpdatedValue( zSendableCurrentValue ); |
263 |
223 |
|
} |
264 |
224 |
|
} |
265 |
225 |
|
|
266 |
|
- |
protected void publishErrorState( boolean pErrorState ) |
267 |
|
- |
{ |
|
226 |
+ |
protected void publishErrorState( boolean pErrorState ) { |
268 |
227 |
|
mComponentFormHandler.componentErrorState( pErrorState ); |
269 |
228 |
|
} |
270 |
229 |
|
|
271 |
|
- |
protected void publishChangedState( boolean pChangedState ) |
272 |
|
- |
{ |
|
230 |
+ |
protected void publishChangedState( boolean pChangedState ) { |
273 |
231 |
|
mComponentFormHandler.componentChangedState( pChangedState ); |
274 |
232 |
|
} |
275 |
233 |
|
|
276 |
|
- |
protected void publishUpdatedValue( Serializable pCurrentValue ) |
277 |
|
- |
{ |
|
234 |
+ |
protected void publishUpdatedValue( Serializable pCurrentValue ) { |
278 |
235 |
|
mComponentFormHandler.componentUpdatedValue( this, pCurrentValue ); |
279 |
236 |
|
} |
280 |
237 |
|
|
281 |
238 |
|
protected void resetErrorOnChangeOccurred( Serializable pSendableCurrentValue, |
282 |
|
- |
Object pComponentCurrentValue ) |
283 |
|
- |
{ |
|
239 |
+ |
Object pComponentCurrentValue ) { |
284 |
240 |
|
setErrorTextAndPublish( null, pSendableCurrentValue, |
285 |
241 |
|
pComponentCurrentValue ); // Turn off error - assume no error |
286 |
242 |
|
} |
287 |
243 |
|
|
288 |
|
- |
protected Serializable convertComponentValueToSendable( Object pValue ) |
289 |
|
- |
{ |
290 |
|
- |
if ( (pValue == null) || (pValue instanceof FormTextInputErrorValue) ) |
291 |
|
- |
{ |
|
244 |
+ |
protected Serializable convertComponentValueToSendable( Object pValue ) { |
|
245 |
+ |
if ( (pValue == null) || (pValue instanceof FormTextInputErrorValue) ) { |
292 |
246 |
|
return null; |
293 |
247 |
|
} |
294 |
248 |
|
return LLconvertNonNullComponentValueToSendable( pValue ); |
295 |
249 |
|
} |
296 |
250 |
|
|
297 |
|
- |
protected Serializable LLconvertNonNullComponentValueToSendable( Object pValue ) |
298 |
|
- |
{ |
|
251 |
+ |
protected Serializable LLconvertNonNullComponentValueToSendable( Object pValue ) { |
299 |
252 |
|
return (Serializable) pValue; |
300 |
253 |
|
} |
301 |
254 |
|
|
|
@@ -305,13 +258,12 @@ |
305 |
258 |
|
|
306 |
259 |
|
abstract protected Object convertStringToComponentValue( String pValue ); |
307 |
260 |
|
|
308 |
|
- |
public String toString() |
309 |
|
- |
{ |
|
261 |
+ |
public String toString() { |
310 |
262 |
|
return "FormAttributeAdapter(" + getAttributeReference() + ")"; |
311 |
263 |
|
} |
312 |
264 |
|
|
313 |
|
- |
@Override public void enterPressed( KeyboardKeyModifier pModifiers ) |
314 |
|
- |
{ |
|
265 |
+ |
@Override |
|
266 |
+ |
public void enterPressed( KeyboardKeyModifier pModifiers ) { |
315 |
267 |
|
// todo: Implement! |
316 |
268 |
|
} |
317 |
269 |
|
} |