Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/OldClient/src/org/litesoft/GWT/forms/client/nonpublic/AbstractFormAttributeAdapter.java

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