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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
package com.temp.client.foundation.widget.input;
import java.util.*;
import com.google.gwt.user.client.ui.*;
import com.temp.client.foundation.widget.input.fieldsupport.*;
import com.temp.shared.*;
import com.temp.shared.externalization.*;
import com.temp.shared.utils.*;
/**
* Common abstract helper for both the generated Widget and the Proxied versions of the InputField.
*/
public abstract class AbstractInputField<T> implements InputField<T>
{
// Required to be set
private String name;
// The above must be set/changed BEFORE the widget is attached!
// Optionally set
private List<ValueValidator<T>> validators = new ArrayList<ValueValidator<T>>();
private Set<ChangeListener<T>> changeListeners = new HashSet<ChangeListener<T>>();
private boolean enabled = true;
private CompleteInputFieldAccessor<T> completeInputFieldAccessor;
// Configuration Methods
@Override
public final String getName()
{
return name;
}
@Override
public final void setName( String name )
{
assertBuildMode( "setName" );
this.name = Validate.noEmptyIdentifier( "Name", name );
}
@Override
public final InputField<T> name( String name )
{
setName( name );
return this;
}
/**
* The 'Builder' to 'Run' state transition method fully constructs/populates the InputField's Widget / container.
*
* @return this for method chaining
*/
@Override
public final InputField<T> init( E13nResolver resolver )
{
Validate.notNull( "resolver", resolver );
if ( name == null )
{
throw new IllegalStateException( "Unable to init, Name not set" );
}
assertBuildMode( "init" );
resolver = new OptionallyPrefixingE13nResolver( name, resolver ); // add our name to keys!
(completeInputFieldAccessor = buildActualWidget( resolver )).setEnabled( enabled ); // propagate current enabled state
return this;
}
@Override
public final boolean isRunMode()
{
return (completeInputFieldAccessor != null);
}
@Override
public final InputField<T> add( ChangeListener<T> changeListener )
{
if ( changeListener != null )
{
changeListeners.add( changeListener );
}
return this;
}
@Override
public final boolean remove( ChangeListener<T> changeListener )
{
return (changeListener == null) ? false : changeListeners.remove( changeListener );
}
@Override
public final void removeAllChangeListeners()
{
changeListeners.clear();
}
@Override
public final ValueValidator<T>[] getValidators()
{
return ObjectUtils.cast( validators.isEmpty() ? ValueValidator.EMPTY_ARRAY : validators.toArray( new ValueValidator[validators.size()] ) );
}
@Override
public final InputField<T> add( ValueValidator<T> validator )
{
if ( validator != null )
{
validators.add( validator );
validatorAdded( validator );
}
return this;
}
@Override
public final InputField<T> add( ValueValidator<T>... additionalValidators )
{
if ( additionalValidators != null )
{
for ( ValueValidator<T> validator : additionalValidators )
{
add( validator ); // null OK will be filter later
}
}
return this;
}
abstract protected void validatorAdded( ValueValidator<T> validator );
private Enableable getEnableable()
{
return completeInputFieldAccessor;
}
// Anytime Methods
// For Enableable
@Override
public final boolean isEnabled()
{
Enableable enableable = getEnableable();
return (enableable != null) ? enableable.isEnabled() : enabled;
}
@Override
public final void setEnabled( boolean enable )
{
enabled = enable;
Enableable enableable = getEnableable();
if ( enableable != null )
{
enableable.setEnabled( enable );
}
}
@Override
public final InputField<T> enable()
{
setEnabled( true );
return this;
}
@Override
public final InputField<T> disable()
{
setEnabled( false );
return this;
}
// For Visible
@Override
public final boolean isVisible()
{
return State.Visible == getVisibility();
}
@Override
public final boolean isCloaked()
{
return State.Cloaked == getVisibility();
}
@Override
public final boolean isInvisible()
{
return State.Invisible == getVisibility();
}
@Override
public final InputField<T> visible()
{
setVisibility( State.Visible );
return this;
}
@Override
public final InputField<T> cloak()
{
setVisibility( State.Visible );
return this;
}
@Override
public final InputField<T> invisible()
{
setVisibility( State.Invisible );
return this;
}
// Only callable in Run Mode
@Override
public final void reset()
{
checkRunMode( "reset" ).setCurrentValue( null );
}
@Override
public final T setCurrentValue( T value )
{
return checkRunMode( "setCurrentValue" ).setCurrentValue( value );
}
@Override
public final T getCurrentValue()
{
return checkRunMode( "getCurrentValue" ).getCurrentValue();
}
@Override
public final T getBaseValue()
{
return checkRunMode( "getBaseValue" ).getBaseValue();
}
@Override
public final void revert()
{
checkRunMode( "revert" ).revert();
}
@Override
public final boolean isChanged()
{
return checkRunMode( "isChanged" ).isChanged();
}
@Override
public final boolean isErrored()
{
return checkRunMode( "isErrored" ).isErrored();
}
@Override
public final boolean validate()
{
return checkRunMode( "validate" ).validate();
}
@Override
public final E13nResolver getE13nResolver()
{
return checkRunMode( "E13nResolver" ).getE13nResolver();
}
@Override
public final Widget getInputWidget()
{
return checkRunMode( "InputWidget" ).getInputWidget();
}
@Override
public final InputWidgetChangeFilter<T> getInput()
{
return checkRunMode( "Input" ).getInput();
}
@Override
public final InputWidgetValidator<T> getValidator()
{
return checkRunMode( "Validator" ).getValidator();
}
@Override
public final Widget getLabelLabel()
{
return checkRunMode( "LabelLabel" ).getLabelLabel();
}
@Override
public final Widget getExtendedLabel()
{
return checkRunMode( "ExtendedLabel" ).getExtendedLabel();
}
@Override
public final Widget getExampleLabel()
{
return checkRunMode( "ExampleLabel" ).getExampleLabel();
}
@Override
public final Widget getErrorLabel()
{
return checkRunMode( "ErrorLabel" ).getErrorLabel();
}
@Override
public final Widget getHelpWidget()
{
return checkRunMode( "HelpWidget" ).getHelpWidget();
}
// Support Methods...
protected final void processDataChanged()
{
xxx
}
protected final void assertBuildMode( String method )
{
if ( completeInputFieldAccessor != null )
{
throw new IllegalStateException( "Unable to process method '" + method + "' of InputField Named '" + name + "', because no longer in Build Mode (init has already been called)" );
}
}
protected final CompleteInputFieldAccessor<T> checkRunMode( String method )
{
if ( completeInputFieldAccessor == null )
{
throw new IllegalStateException( "Unable to access component/method '" + method + "' of InputField Named '" + name + "', because not in Run Mode (init NOT called)" );
}
return completeInputFieldAccessor;
}
abstract protected CompleteInputFieldAccessor<T> buildActualWidget( E13nResolver resolver );
}
|
Revision |
Author |
Commited |
Message |
628
|
GeorgeS
|
Fri 13 Apr, 2012 03:53:33 +0000 |
|