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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
package org.litesoft.GWT.forms.client.nonpublic;

import org.litesoft.GWT.forms.client.components.*;
import org.litesoft.core.util.*;
import org.litesoft.rpcpassable.*;
import org.litesoft.ui.def.nonpublic.support.*;

import com.google.gwt.user.client.ui.*;

public abstract class AbstractFormAttributeAdapter extends AbstractFormComponentAdapter
        implements FormAttributeAdapter,
                   IFormComponent.Listener
{
    private Integer mUniqueID;
    private String mAttributeReference;
    private IFormComponent mComponent;
    private String mErrorText = null;
    private Object mPublishedComponentValue = null;
    private Object mErrorComponentValue = null;
    private Object mBaseComponentValue = null;

    public AbstractFormAttributeAdapter( FormInstanceComponentHandler pComponentHandler,
                                         AttributeMetaData pMD, IFormComponent pComponent )
    {
        super( pComponentHandler );
        mUniqueID = pMD.getUniqueID();
        mAttributeReference = pMD.getAttributeReference();
        mComponent = pComponent;
        if ( pMD.isDisabled() )
        {
            mComponent.setEnabled( false );
        }
    }

    public final Widget init()
    {
        mComponent.addFormComponentListener( this );
        mComponentFormHandler.addAttributeAdapter( this );
        Widget widget = initWidget();
        Object zComponentCurrentValue = getComponentCurrentValue();
        RPCpassable zSendableCurrentValue = convertComponentValueToSendable( zComponentCurrentValue );
        LLsetErrorText( null, zSendableCurrentValue, zComponentCurrentValue );
        return widget;
    }

    public void add( IFormComponent pComponent )
    {
        // As we already have the Component, we can ignore this call...
    }

    public void remove( IFormComponent pComponent )
    {
        // Our Components life cycle is managed differently, we can ignore this call...
    }

    protected Widget initWidget()
    {
        return (Widget) mComponent;
    }

    // FormAttributeAdapter

    public Integer getUniqueID()
    {
        return mUniqueID;
    }

    public String getAttributeReference()
    {
        return mAttributeReference;
    }

    public boolean isErrorState()
    {
        return mErrorText != null;
    }

    public String getErrorText()
    {
        return mErrorText;
    }

    public void setErrorText( String pErrorText )
    {
        Object zComponentCurrentValue = getComponentCurrentValue();
        RPCpassable zSendableCurrentValue = convertComponentValueToSendable( zComponentCurrentValue );
        setErrorTextAndPublish( pErrorText, zSendableCurrentValue, zComponentCurrentValue );
    }

    public boolean isChangedState()
    {
        return !areEqual( mBaseComponentValue, getComponentCurrentValue() );
    }

    public RPCpassable getBaseValue()
    {
        return convertComponentValueToSendable( mBaseComponentValue );
    }

    public void setBaseValue( RPCpassable pBaseValue )
    {
        mBaseComponentValue = convertSendableToComponentValue( pBaseValue );
        setComponentCurrentValue( mPublishedComponentValue = mBaseComponentValue );
        chkChangeOccurred( pBaseValue, mBaseComponentValue );
    }

    public RPCpassable getCurrentValue()
    {
        return convertComponentValueToSendable( getComponentCurrentValue() );
    }

    public void setCurrentValue( RPCpassable pCurrentValue )
    {
        Object zComponentCurrentValue = convertSendableToComponentValue( pCurrentValue );
        setComponentCurrentValue( zComponentCurrentValue );
        chkChangeOccurred( pCurrentValue, zComponentCurrentValue );
    }

    public String getUserValue()
    {
        return convertComponentValueToString( getComponentCurrentValue() );
    }

    public void setUserValue( String pValue )
    {
        setComponentUserValue( convertStringToComponentValue( pValue ) );

        // handle change
        Object zComponentCurrentValue = getComponentCurrentValue();
        RPCpassable zSendableCurrentValue = convertComponentValueToSendable( zComponentCurrentValue );
        chkChangeOccurred( zSendableCurrentValue, zComponentCurrentValue );

        // handle update
        if ( !areEqual( mPublishedComponentValue, zComponentCurrentValue ) )
        {
            mPublishedComponentValue = zComponentCurrentValue;
            publishUpdatedValue( zSendableCurrentValue );
        }
    }

    protected void setComponentUserValue( Object pComponentValue )
    {
        setComponentCurrentValue( pComponentValue );
    }

    public void publishAnyPendingChanges()
    {
        mComponent.publishAnyPendingChanges();
    }

    public void updateValidOptions( RPCpassable[] pValidOptions )
    {
        // Do nothing as most components do NOT support valid Options
    }

    // FormComponentAdapter

    public boolean isVisible()
    {
        return mComponent.isVisible();
    }

    public boolean setFocus()
    {
        return mComponent.setFocus();
    }

    protected void setWidgetEnabled( boolean pEnabled )
    {
        mComponent.setEnabled( pEnabled );
    }

    public boolean isEnabled()
    {
        return mComponent.isEnabled();
    }

    // IFormComponent.Listener

    public void changeOccurred()
    {
        Object zComponentCurrentValue = getComponentCurrentValue();
//        System.out.println( "changeOccurred: " + this + " | " + zComponentCurrentValue );
        RPCpassable zSendableCurrentValue = convertComponentValueToSendable( zComponentCurrentValue );
        chkChangeOccurred( zSendableCurrentValue, zComponentCurrentValue );
    }

    public void blurOccurred()
    {
//        System.out.println( "blurOccurred: " + this );
        mComponent.setFocused( false );
        optionallyPublishUpdatedValue();
    }

    public void focusOccured()
    {
//        System.out.println( "focusOccured: " + this );
        mComponent.setFocused( true );
    }

    // Support...

    protected Object getComponentCurrentValue()
    {
        return mComponent.getCurrentValue();
    }

    protected void setComponentCurrentValue( Object pNewComponentCurrentValue )
    {
        mComponent.setCurrentValue( pNewComponentCurrentValue );
    }

    protected void setErrorTextAndPublish( String pErrorText, RPCpassable pSendableCurrentValue,
                                           Object pComponentCurrentValue )
    {
        LLsetErrorText( pErrorText, pSendableCurrentValue, pComponentCurrentValue );
        mErrorComponentValue = pComponentCurrentValue;
        publishErrorState( isErrorState() );
    }

    protected void LLsetErrorText( String pErrorText, RPCpassable pSendableCurrentValue,
                                   Object pComponentCurrentValue )
    {
        mComponent.setError( mErrorText = transformErrorText( pErrorText, //
                                                              pSendableCurrentValue, //
                                                              pComponentCurrentValue ) );
    }

    protected String transformErrorText( String pErrorText, RPCpassable pSendableCurrentValue,
                                         Object pComponentCurrentValue )
    {
        pErrorText = UtilsCommon.noEmpty( pErrorText );
        if ( (pErrorText == null) && (pComponentCurrentValue instanceof FormTextInputErrorValue) )
        {
            return ((FormTextInputErrorValue)pComponentCurrentValue).getErrorMessage();
        }
        return pErrorText;
    }

    protected void chkChangeOccurred( RPCpassable pSendableCurrentValue, Object pComponentCurrentValue )
    {
        boolean changedFromBaseCV = !areEqual( mBaseComponentValue, pComponentCurrentValue );
        boolean changedFromErrorCV = !areEqual( mErrorComponentValue, pComponentCurrentValue );
        if ( changedFromErrorCV )
        {
            resetErrorOnChangeOccurred( pSendableCurrentValue, pComponentCurrentValue );
        }
        mComponent.setValueChanged( changedFromBaseCV );
        publishChangedState( changedFromBaseCV );
    }

    protected void optionallyPublishUpdatedValue()
    {
        Object zComponentCurrentValue = getComponentCurrentValue();
        RPCpassable zSendableCurrentValue = convertComponentValueToSendable( zComponentCurrentValue );
        if ( !areEqual( mPublishedComponentValue, zComponentCurrentValue ) )
        {
            mPublishedComponentValue = zComponentCurrentValue;
            publishUpdatedValue( zSendableCurrentValue );
        }
    }

    protected void publishErrorState( boolean pErrorState )
    {
        mComponentFormHandler.componentErrorState( pErrorState );
    }

    protected void publishChangedState( boolean pChangedState )
    {
        mComponentFormHandler.componentChangedState( pChangedState );
    }

    protected void publishUpdatedValue( RPCpassable pCurrentValue )
    {
        mComponentFormHandler.componentUpdatedValue( this, pCurrentValue );
    }

    protected void resetErrorOnChangeOccurred( RPCpassable pSendableCurrentValue,
                                               Object pComponentCurrentValue )
    {
        setErrorTextAndPublish( null, pSendableCurrentValue,
                                pComponentCurrentValue ); // Turn off error - assume no error
    }

    protected RPCpassable convertComponentValueToSendable( Object pValue )
    {
        if ( (pValue == null) || (pValue instanceof FormTextInputErrorValue) )
        {
            return null;
        }
        return LLconvertNonNullComponentValueToSendable( pValue );
    }

    protected RPCpassable LLconvertNonNullComponentValueToSendable( Object pValue )
    {
        return (RPCpassable) pValue;
    }

    abstract protected Object convertSendableToComponentValue( RPCpassable pValue );

    abstract protected String convertComponentValueToString( Object pValue );

    abstract protected Object convertStringToComponentValue( String pValue );

    public String toString()
    {
        return "FormAttributeAdapter(" + getAttributeReference() + ")";
    }
}

Commits for litesoft/trunk/Java/GWT/OldClient/src/org/litesoft/GWT/forms/client/nonpublic/AbstractFormAttributeAdapter.java

Diff revisions: vs.
Revision Author Commited Message
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000