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
|
package com.temp.client.foundation.widget.input;
import java.util.*;
import com.google.gwt.user.client.ui.*;
import com.temp.client.foundation.util.*;
import com.temp.client.foundation.widget.*;
import com.temp.client.foundation.widget.input.fieldsupport.*;
import com.temp.client.foundation.widget.input.support.*;
import com.temp.shared.*;
import com.temp.shared.externalization.*;
import com.temp.shared.utils.*;
import com.temp.shared.validators.*;
/**
* Common abstract helper for the generated Widget versions of the InputField.
*/
public class AbstractGeneratedInputField<T> extends AbstractInputField<T> implements IsWidget
{
// Optionally set/changed
private boolean required = false;
private boolean errorLabel = true;
private boolean extendedLabel = false;
private boolean example = false;
private LabelPosition labelPosition = LabelPosition.Left;
// Optionally set
private Integer maxLength;
private String helpLink;
// The above must be set/changed BEFORE the widget is attached!
private State visibility = State.Visible;
private HorizontalPanel container = new HorizontalPanel();
public AbstractGeneratedInputField()
{
container.add( new Label( "!?!" ) );
}
// Configuration Methods
public final String getLabel()
{
return labelPosition.name();
}
public final void setLabel( String labelPosition )
{
assertBuildMode();
labelPosition = StringUtils.noEmpty( labelPosition );
LabelPosition position = ObjectUtils.oneOfToStringIgnoreCase( labelPosition, LabelPosition.values() );
if ( position == null )
{
throw new IllegalArgumentException( "Unacceptable LabelPosition of: " + labelPosition );
}
setLabelPosition( position );
}
public final LabelPosition getLabelPosition()
{
return labelPosition;
}
public final void setLabelPosition( LabelPosition labelPosition )
{
assertBuildMode();
Validate.notNull( "LabelPosition", this.labelPosition = labelPosition );
}
public AbstractGeneratedInputField<T> labelPosition( LabelPosition labelPosition )
{
setLabelPosition( labelPosition );
return this;
}
public final boolean isRequired()
{
return required;
}
public final void setRequired( boolean required )
{
assertBuildMode();
this.required = required;
if ( required )
{
setErrorLabel( true );
}
}
public AbstractGeneratedInputField<T> required()
{
setRequired( true );
return this;
}
public final boolean isErrorLabel()
{
return errorLabel;
}
public final void setErrorLabel( boolean pErrorLabel )
{
assertBuildMode();
errorLabel = pErrorLabel;
}
public AbstractGeneratedInputField<T> errorLabel()
{
setErrorLabel( true );
return this;
}
public final boolean isExtendedLabel()
{
return extendedLabel;
}
public final void setExtendedLabel( boolean pExtendedLabel )
{
assertBuildMode();
extendedLabel = pExtendedLabel;
}
public AbstractGeneratedInputField<T> extendedLabel()
{
setExtendedLabel( true );
return this;
}
public final boolean isExample()
{
return example;
}
public final void setExample( boolean pExample )
{
assertBuildMode();
example = pExample;
}
public AbstractGeneratedInputField<T> example()
{
setExample( true );
return this;
}
public final Integer getMaxLength()
{
return maxLength;
}
public final void setMaxLength( Integer maxLength )
{
assertBuildMode();
this.maxLength = Validate.optionalLength( "MaxLength", maxLength );
}
public AbstractGeneratedInputField<T> maxLength( int maxLength )
{
setMaxLength( maxLength );
return this;
}
public final String getHelpLink()
{
return helpLink;
}
public final void setHelpLink( String helpLink )
{
assertBuildMode();
this.helpLink = StringUtils.noEmpty( helpLink );
}
public AbstractGeneratedInputField<T> helpLink( String helpLink )
{
setHelpLink( Validate.noEmpty( "HelpLink", helpLink ) );
return this;
}
// Anytime Methods
// Widget/Component Accessor Methods
public E13nResolver getE13nResolver()
{
return checkRunMode( "E13nResolver" ).getE13nResolver();
}
public T getCurrentValue()
{
return getInput().getValue();
}
public Widget getInputWidget()
{
return checkRunMode( "InputWidget" ).getInputWidget();
}
public InputWidgetChangeFilter<T> getInput()
{
return checkRunMode( "Input" ).getInput();
}
public InputWidgetValidator<T> getValidator()
{
return checkRunMode( "Validator" ).getValidator();
}
public TextLabel getLabelLabel()
{
return checkRunMode( "LabelLabel" ).getLabelLabel();
}
public TextLabel getExtendedLabel()
{
return checkRunMode( "ExtendedLabel" ).getExtendedLabel();
}
public TextLabel getExampleLabel()
{
return checkRunMode( "ExampleLabel" ).getExampleLabel();
}
public TextLabel getErrorLabel()
{
return checkRunMode( "ErrorLabel" ).getErrorLabel();
}
public HelpWidget getHelpWidget()
{
return checkRunMode( "HelpWidget" ).getHelpWidget();
}
// Support Methods...
protected final void assertBuildMode()
{
if ( completeInputFieldAccessor != null )
{
throw new IllegalStateException( "Unable to Mutate InputField Named '" + name + "', because no longer in Build Mode (init called)" );
}
}
protected final CompleteInputFieldAccessor<T> checkRunMode( String method )
{
if ( completeInputFieldAccessor == null )
{
throw new IllegalStateException( "Unable to access component '" + method + "' of InputField Named '" + name + "', because not in Run Mode (init NOT called)" );
}
return completeInputFieldAccessor;
}
protected CompleteInputFieldAccessor<T> buildActualWidget( E13nResolver resolver )
{
InputFieldAccessor<T> accessor = inputType.createAccessor();
InputWidgetValidator<T> validator = accessor.getValidator();
TextLabel labelTextLabel = null;
TextLabel extendedTextLabel = null;
if ( !LabelPosition.None.equals( labelPosition ) )
{
labelTextLabel = createWrappingLabel( "labelLabel", true, resolver, "fieldLabel" );
extendedTextLabel = createWrappingLabel( "extendedLabel", extendedLabel, resolver, "fieldExtendedLabel" );
}
TextLabel exampleTextLabel = createWrappingLabel( "exampleLabel", example, resolver, "fieldExample" );
TextLabel errorTextLabel = null;
if ( validator != null )
{
errorTextLabel = createClippingLabel( "errorLabel", errorLabel );
if ( required )
{
addTo( validator, RequiredValueValidator.INSTANCE );
}
if ( maxLength != null )
{
addTo( validator, new MaxLengthValueValidator( maxLength ) );
}
validator.addValidators( getValidators() );
}
HelpWidget helpWidget = (helpLink != null) ? new HelpWidget().link( helpLink ) : null;
CompleteInputFieldAccessor<T> completeAccessor = new CompleteInputFieldAccessor<T>( resolver, //
labelTextLabel, //
extendedTextLabel, //
accessor, //
helpWidget, //
exampleTextLabel, //
errorTextLabel );
populate( container, completeAccessor );
return completeAccessor;
}
@SuppressWarnings("unchecked")
protected void addTo( InputWidgetValidator<T> validator, ValueValidator valueValidator )
{
validator.addValidator( valueValidator );
}
protected final TextLabel createWrappingLabel( String styleName, boolean create, E13nResolver resolver, String resolveKey )
{
if ( create )
{
String text = resolver.resolve( resolveKey );
if ( text != null )
{
return new WrappingLabel( text ).style( styleName );
}
}
return null;
}
protected final TextLabel createClippingLabel( String styleName, boolean create )
{
return create ? new ClippingLabel().style( styleName ) : null;
}
protected void populate( HorizontalPanel container, CompleteInputFieldAccessor<T> completeAccessor )
{
// completeAccessor.
// boolean required = false;
// boolean errorLabel = true;
// boolean extendedLabel = false;
// boolean example = false;
// LabelPosition labelPosition = LabelPosition.Left;
//
// // Optionally set
// Integer maxLength;
// String helpLink;
//
// E13nResolverAccessor resolverAccessor;
// CompleteInputFieldAccessor<T> completeInputFieldAccessor;
}
}
|