|
@@ -1,322 +1,322 @@ |
1 |
|
- |
package com.temp.client.foundation.widget.input.fieldsupport; |
2 |
|
- |
|
3 |
|
- |
import org.litesoft.core.util.externalization.*; |
4 |
|
- |
|
5 |
|
- |
import com.google.gwt.user.client.ui.*; |
6 |
|
- |
import com.temp.client.foundation.util.*; |
7 |
|
- |
import com.temp.client.foundation.widget.*; |
8 |
|
- |
import com.temp.client.foundation.widget.input.*; |
9 |
|
- |
import com.temp.client.foundation.widget.input.support.*; |
10 |
|
- |
import com.temp.shared.*; |
11 |
|
- |
import com.temp.shared.utils.*; |
12 |
|
- |
import com.temp.shared.validators.*; |
13 |
|
- |
|
14 |
|
- |
/** |
15 |
|
- |
* Common abstract helper for the generated Widget versions of the InputField. |
16 |
|
- |
*/ |
17 |
|
- |
public abstract class AbstractGeneratedInputField<T, C extends AbstractGeneratedInputField<T, C>> extends AbstractNonProxyInputField<T, C> implements IsWidget { |
18 |
|
- |
// Optionally set/changed |
19 |
|
- |
private boolean required = false; |
20 |
|
- |
private boolean errorLabel = true; |
21 |
|
- |
private boolean extendedLabel = false; |
22 |
|
- |
private boolean example = false; |
23 |
|
- |
private LabelPosition labelPosition = LabelPosition.Left; |
24 |
|
- |
|
25 |
|
- |
// Optionally set |
26 |
|
- |
private String helpLink; |
27 |
|
- |
|
28 |
|
- |
// The above must be set/changed BEFORE the widget is attached! |
29 |
|
- |
|
30 |
|
- |
private final NamedHorizontalPanel container = new NamedHorizontalPanel(); |
31 |
|
- |
|
32 |
|
- |
public AbstractGeneratedInputField() { |
33 |
|
- |
container.add( new Label( "!?!" ) ); |
34 |
|
- |
} |
35 |
|
- |
|
36 |
|
- |
@Override |
37 |
|
- |
protected Panel getContainer() { |
38 |
|
- |
return container; |
39 |
|
- |
} |
40 |
|
- |
|
41 |
|
- |
@Override |
42 |
|
- |
public Widget asWidget() { |
43 |
|
- |
return container; |
44 |
|
- |
} |
45 |
|
- |
|
46 |
|
- |
// Configuration Methods |
47 |
|
- |
|
48 |
|
- |
public final String getLabel() { |
49 |
|
- |
return labelPosition.name(); |
50 |
|
- |
} |
51 |
|
- |
|
52 |
|
- |
public final void setLabel( String labelPosition ) { |
53 |
|
- |
assertBuildMode( "setLabel" ); |
54 |
|
- |
labelPosition = StringUtils.noEmpty( labelPosition ); |
55 |
|
- |
LabelPosition position = ObjectUtils.oneOfToStringIgnoreCase( labelPosition, LabelPosition.values() ); |
56 |
|
- |
if ( position == null ) { |
57 |
|
- |
throw new IllegalArgumentException( "Unacceptable LabelPosition of: " + labelPosition ); |
58 |
|
- |
} |
59 |
|
- |
setValidatedLabelPosition( position ); |
60 |
|
- |
} |
61 |
|
- |
|
62 |
|
- |
public final LabelPosition getLabelPosition() { |
63 |
|
- |
return labelPosition; |
64 |
|
- |
} |
65 |
|
- |
|
66 |
|
- |
public final void setLabelPosition( LabelPosition labelPosition ) { |
67 |
|
- |
assertBuildMode( "setLabelPosition" ); |
68 |
|
- |
Validate.notNull( "LabelPosition", labelPosition ); |
69 |
|
- |
setValidatedLabelPosition( labelPosition ); |
70 |
|
- |
} |
71 |
|
- |
|
72 |
|
- |
public C labelPosition( LabelPosition labelPosition ) { |
73 |
|
- |
assertBuildMode( "labelPosition" ); |
74 |
|
- |
Validate.notNull( "LabelPosition", labelPosition ); |
75 |
|
- |
setValidatedLabelPosition( labelPosition ); |
76 |
|
- |
return inheritanceLeaf(); |
77 |
|
- |
} |
78 |
|
- |
|
79 |
|
- |
protected void setValidatedLabelPosition( LabelPosition labelPosition ) { |
80 |
|
- |
this.labelPosition = labelPosition; |
81 |
|
- |
} |
82 |
|
- |
|
83 |
|
- |
public final boolean isRequired() { |
84 |
|
- |
return required; |
85 |
|
- |
} |
86 |
|
- |
|
87 |
|
- |
public final void setRequired( boolean required ) { |
88 |
|
- |
assertBuildMode( "setRequired" ); |
89 |
|
- |
setValidatedRequired( required ); |
90 |
|
- |
} |
91 |
|
- |
|
92 |
|
- |
public C required() { |
93 |
|
- |
assertBuildMode( "required" ); |
94 |
|
- |
setValidatedRequired( true ); |
95 |
|
- |
return inheritanceLeaf(); |
96 |
|
- |
} |
97 |
|
- |
|
98 |
|
- |
protected void setValidatedRequired( boolean required ) { |
99 |
|
- |
this.required = required; |
100 |
|
- |
if ( required ) { |
101 |
|
- |
setValidatedErrorLabel( true ); |
102 |
|
- |
} |
103 |
|
- |
} |
104 |
|
- |
|
105 |
|
- |
public final boolean isErrorLabel() { |
106 |
|
- |
return errorLabel; |
107 |
|
- |
} |
108 |
|
- |
|
109 |
|
- |
public final void setErrorLabel( boolean errorLabel ) { |
110 |
|
- |
assertBuildMode( "setErrorLabel" ); |
111 |
|
- |
setValidatedErrorLabel( errorLabel ); |
112 |
|
- |
} |
113 |
|
- |
|
114 |
|
- |
public C errorLabel() { |
115 |
|
- |
assertBuildMode( "errorLabel" ); |
116 |
|
- |
setValidatedErrorLabel( true ); |
117 |
|
- |
return inheritanceLeaf(); |
118 |
|
- |
} |
119 |
|
- |
|
120 |
|
- |
protected void setValidatedErrorLabel( boolean errorLabel ) { |
121 |
|
- |
this.errorLabel = errorLabel; |
122 |
|
- |
} |
123 |
|
- |
|
124 |
|
- |
public final boolean isExtendedLabel() { |
125 |
|
- |
return extendedLabel; |
126 |
|
- |
} |
127 |
|
- |
|
128 |
|
- |
public final void setExtendedLabel( boolean extendedLabel ) { |
129 |
|
- |
assertBuildMode( "setExtendedLabel" ); |
130 |
|
- |
setValidatedExtendedLabel( extendedLabel ); |
131 |
|
- |
} |
132 |
|
- |
|
133 |
|
- |
public C extendedLabel() { |
134 |
|
- |
assertBuildMode( "extendedLabel" ); |
135 |
|
- |
setValidatedExtendedLabel( true ); |
136 |
|
- |
return inheritanceLeaf(); |
137 |
|
- |
} |
138 |
|
- |
|
139 |
|
- |
protected void setValidatedExtendedLabel( boolean extendedLabel ) { |
140 |
|
- |
this.extendedLabel = extendedLabel; |
141 |
|
- |
} |
142 |
|
- |
|
143 |
|
- |
public final boolean isExample() { |
144 |
|
- |
return example; |
145 |
|
- |
} |
146 |
|
- |
|
147 |
|
- |
public final void setExample( boolean example ) { |
148 |
|
- |
assertBuildMode( "setExample" ); |
149 |
|
- |
setValidatedExample( example ); |
150 |
|
- |
} |
151 |
|
- |
|
152 |
|
- |
public C example() { |
153 |
|
- |
assertBuildMode( "example" ); |
154 |
|
- |
setValidatedExample( true ); |
155 |
|
- |
return inheritanceLeaf(); |
156 |
|
- |
} |
157 |
|
- |
|
158 |
|
- |
protected void setValidatedExample( boolean example ) { |
159 |
|
- |
this.example = example; |
160 |
|
- |
} |
161 |
|
- |
|
162 |
|
- |
public final String getHelpLink() { |
163 |
|
- |
return helpLink; |
164 |
|
- |
} |
165 |
|
- |
|
166 |
|
- |
public final void setHelpLink( String helpLink ) { |
167 |
|
- |
assertBuildMode( "setHelpLink" ); |
168 |
|
- |
setValidatedHelpLink( StringUtils.noEmpty( helpLink ) ); |
169 |
|
- |
} |
170 |
|
- |
|
171 |
|
- |
public C helpLink( String helpLink ) { |
172 |
|
- |
assertBuildMode( "helpLink" ); |
173 |
|
- |
setValidatedHelpLink( StringUtils.noEmpty( helpLink ) ); |
174 |
|
- |
return inheritanceLeaf(); |
175 |
|
- |
} |
176 |
|
- |
|
177 |
|
- |
protected void setValidatedHelpLink( String helpLink ) { |
178 |
|
- |
this.helpLink = helpLink; |
179 |
|
- |
} |
180 |
|
- |
|
181 |
|
- |
// Anytime Methods |
182 |
|
- |
|
183 |
|
- |
// Widget/Component Accessor Methods |
184 |
|
- |
|
185 |
|
- |
// Support Methods... |
186 |
|
- |
|
187 |
|
- |
@Override |
188 |
|
- |
protected void validatorAdded( ValueValidator<T> validator ) { |
189 |
|
- |
CompleteInputFieldAccessor<T> fieldAccessor = checkRunMode(); |
190 |
|
- |
if ( fieldAccessor != null ) { |
191 |
|
- |
updateStyle( fieldAccessor ); |
192 |
|
- |
} |
193 |
|
- |
} |
194 |
|
- |
|
195 |
|
- |
@Override |
196 |
|
- |
protected void updateErrorLabel( Widget errorLabel, E13nData error ) { |
197 |
|
- |
String errorText = revolve( "updateErrorLabel", error ); |
198 |
|
- |
((TextLabel) errorLabel).setText( errorText ); |
199 |
|
- |
UtilsGwt.setHidden( errorLabel, errorText == null ); |
200 |
|
- |
} |
201 |
|
- |
|
202 |
|
- |
protected CompleteInputFieldAccessor<T> buildActualWidget( E13nResolver resolver ) { |
203 |
|
- |
container.setName( getName() ); |
204 |
|
- |
namedWidgets.add( container ); |
205 |
|
- |
|
206 |
|
- |
InputFieldAccessor<T> accessor = createBaseAccessor(); |
207 |
|
- |
InputWidgetValidator<T> validator = accessor.getValidator(); |
208 |
|
- |
|
209 |
|
- |
TextLabel labelTextLabel = null; |
210 |
|
- |
TextLabel extendedTextLabel = null; |
211 |
|
- |
if ( !LabelPosition.None.equals( labelPosition ) ) { |
212 |
|
- |
labelTextLabel = createWrappingLabel( "labelLabel", true, resolver, "field-label" ); |
213 |
|
- |
extendedTextLabel = createWrappingLabel( "extendedLabel", extendedLabel, resolver, "field-extendedLabel" ); |
214 |
|
- |
} |
215 |
|
- |
TextLabel exampleTextLabel = createWrappingLabel( "exampleLabel", example, resolver, "field-example" ); |
216 |
|
- |
TextLabel errorTextLabel = null; |
217 |
|
- |
if ( validator != null ) { |
218 |
|
- |
errorTextLabel = createClippingLabel( "field-error", errorLabel ); |
219 |
|
- |
if ( required ) { |
220 |
|
- |
addTo( validator, RequiredValueValidator.INSTANCE ); |
221 |
|
- |
} |
222 |
|
- |
augmentValidator( validator ); |
223 |
|
- |
validator.addValidators( getValidators() ); |
224 |
|
- |
} |
225 |
|
- |
HelpWidget helpWidget = (helpLink != null) ? createHelpWidget() : null; |
226 |
|
- |
CompleteInputFieldAccessor<T> completeAccessor = new CompleteInputFieldAccessor<T>( resolver, // |
227 |
|
- |
labelTextLabel, // |
228 |
|
- |
extendedTextLabel, // |
229 |
|
- |
accessor, // |
230 |
|
- |
helpWidget, // |
231 |
|
- |
exampleTextLabel, // |
232 |
|
- |
errorTextLabel ); |
233 |
|
- |
populate( container, completeAccessor ); |
234 |
|
- |
return completeAccessor; |
235 |
|
- |
} |
236 |
|
- |
|
237 |
|
- |
protected HelpWidget createHelpWidget() { |
238 |
|
- |
return addNamedWidgetWithNameExtension( new HelpWidget().link( helpLink ), "helpWidget" ); |
239 |
|
- |
} |
240 |
|
- |
|
241 |
|
- |
@SuppressWarnings("UnusedParameters") |
242 |
|
- |
protected void augmentValidator( InputWidgetValidator<T> validator ) { |
243 |
|
- |
} |
244 |
|
- |
|
245 |
|
- |
@SuppressWarnings("unchecked") |
246 |
|
- |
protected void addTo( InputWidgetValidator<T> validator, ValueValidator valueValidator ) { |
247 |
|
- |
validator.addValidator( valueValidator ); |
248 |
|
- |
} |
249 |
|
- |
|
250 |
|
- |
protected final TextLabel createWrappingLabel( String styleName, boolean create, E13nResolver resolver, String resolveKey ) { |
251 |
|
- |
if ( create ) { |
252 |
|
- |
String text = resolver.resolve( resolveKey ); |
253 |
|
- |
if ( text != null ) { |
254 |
|
- |
return addNamedWidgetWithStyle( new WrappingLabel( text ), styleName ); |
255 |
|
- |
} |
256 |
|
- |
} |
257 |
|
- |
return null; |
258 |
|
- |
} |
259 |
|
- |
|
260 |
|
- |
protected final TextLabel createClippingLabel( String styleName, boolean create ) { |
261 |
|
- |
return create ? addNamedWidgetWithStyle( new ClippingLabel(), styleName ) : null; |
262 |
|
- |
} |
263 |
|
- |
|
264 |
|
- |
private TextLabel createRequiredLabel() { |
265 |
|
- |
return addNamedWidgetWithStyle( new NonWrappingLabel( required ? " * " : " ", true ), "requiredSpacer" ); |
266 |
|
- |
} |
267 |
|
- |
|
268 |
|
- |
protected void populate( HorizontalPanel container, CompleteInputFieldAccessor<T> completeAccessor ) { |
269 |
|
- |
container.clear(); // Remove "Stand In" |
270 |
|
- |
container.addStyleName( ObjectUtils.getSimpleClassName( this ) ); // Add Style on Container for Cascade customization! |
271 |
|
- |
|
272 |
|
- |
container.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_LEFT ); |
273 |
|
- |
container.setVerticalAlignment( HasVerticalAlignment.ALIGN_TOP ); |
274 |
|
- |
|
275 |
|
- |
VerticalPanel labelPanel = null; |
276 |
|
- |
VerticalPanel centerPanel = UtilsGwt.vertical( "fieldCenter" ); |
277 |
|
- |
|
278 |
|
- |
HelpWidget helpWidget = completeAccessor.getHelpWidget(); |
279 |
|
- |
|
280 |
|
- |
switch ( labelPosition ) { |
281 |
|
- |
default: |
282 |
|
- |
case Left: |
283 |
|
- |
container.add( labelPanel = UtilsGwt.vertical( "fieldLeft" ) ); |
284 |
|
- |
labelPanel.add( completeAccessor.getLabelLabel() ); |
285 |
|
- |
container.add( createRequiredLabel() ); |
286 |
|
- |
container.add( centerPanel ); |
287 |
|
- |
break; |
288 |
|
- |
case Top: |
289 |
|
- |
container.add( labelPanel = centerPanel ); |
290 |
|
- |
labelPanel.add( UtilsGwt.horizontal( completeAccessor.getLabelLabel(), createRequiredLabel() ) ); |
291 |
|
- |
break; |
292 |
|
- |
case Right: |
293 |
|
- |
container.add( centerPanel ); |
294 |
|
- |
container.add( labelPanel = UtilsGwt.vertical( "fieldRight" ) ); |
295 |
|
- |
labelPanel.add( UtilsGwt.horizontal( completeAccessor.getLabelLabel(), createRequiredLabel(), helpWidget ) ); |
296 |
|
- |
helpWidget = null; |
297 |
|
- |
break; |
298 |
|
- |
case None: |
299 |
|
- |
break; |
300 |
|
- |
} |
301 |
|
- |
UtilsGwt.add( labelPanel, completeAccessor.getExtendedLabel() ); |
302 |
|
- |
|
303 |
|
- |
// Add HelpWidget |
304 |
|
- |
if ( helpWidget != null ) { |
305 |
|
- |
container.add( UtilsGwt.add( UtilsGwt.vertical( "fieldRight" ), helpWidget ) ); |
306 |
|
- |
} |
307 |
|
- |
|
308 |
|
- |
// populate the Center |
309 |
|
- |
centerPanel.add( completeAccessor.getInputWidget() ); |
310 |
|
- |
UtilsGwt.add( centerPanel, completeAccessor.getExampleLabel() ); |
311 |
|
- |
UtilsGwt.add( centerPanel, completeAccessor.getErrorLabel() ); |
312 |
|
- |
} |
313 |
|
- |
|
314 |
|
- |
protected <W extends Widget & HasName> InputFieldAccessor<T> createBaseAccessor( InputWidgetValueAdapter<T> valueAdapter, W inputWidget, String style, |
315 |
|
- |
Focusable... focusables ) { |
316 |
|
- |
InputWidgetValidator<T> validator = new InputWidgetValidator<T>( valueAdapter ); |
317 |
|
- |
InputWidgetChangeFilter<T> input = new InputWidgetChangeFilter<T>( validator ); |
318 |
|
- |
return new InputFieldAccessor<T>( input, validator, valueAdapter, addNamedWidgetWithStyle( inputWidget, style ), focusables ); |
319 |
|
- |
} |
320 |
|
- |
|
321 |
|
- |
abstract protected InputFieldAccessor<T> createBaseAccessor(); |
322 |
|
- |
} |
|
1 |
+ |
package com.temp.client.foundation.widget.input.fieldsupport; |
|
2 |
+ |
|
|
3 |
+ |
import org.litesoft.core.util.externalization.*; |
|
4 |
+ |
|
|
5 |
+ |
import com.google.gwt.user.client.ui.*; |
|
6 |
+ |
import com.temp.client.foundation.util.*; |
|
7 |
+ |
import com.temp.client.foundation.widget.*; |
|
8 |
+ |
import com.temp.client.foundation.widget.input.*; |
|
9 |
+ |
import com.temp.client.foundation.widget.input.support.*; |
|
10 |
+ |
import com.temp.shared.*; |
|
11 |
+ |
import com.temp.shared.utils.*; |
|
12 |
+ |
import com.temp.shared.validators.*; |
|
13 |
+ |
|
|
14 |
+ |
/** |
|
15 |
+ |
* Common abstract helper for the generated Widget versions of the InputField. |
|
16 |
+ |
*/ |
|
17 |
+ |
public abstract class AbstractGeneratedInputField<T, C extends AbstractGeneratedInputField<T, C>> extends AbstractNonProxyInputField<T, C> implements IsWidget { |
|
18 |
+ |
// Optionally set/changed |
|
19 |
+ |
private boolean required = false; |
|
20 |
+ |
private boolean errorLabel = true; |
|
21 |
+ |
private boolean extendedLabel = false; |
|
22 |
+ |
private boolean example = false; |
|
23 |
+ |
private LabelPosition labelPosition = LabelPosition.Left; |
|
24 |
+ |
|
|
25 |
+ |
// Optionally set |
|
26 |
+ |
private String helpLink; |
|
27 |
+ |
|
|
28 |
+ |
// The above must be set/changed BEFORE the widget is attached! |
|
29 |
+ |
|
|
30 |
+ |
private final NamedHorizontalPanel container = new NamedHorizontalPanel(); |
|
31 |
+ |
|
|
32 |
+ |
public AbstractGeneratedInputField() { |
|
33 |
+ |
container.add( new Label( "!?!" ) ); |
|
34 |
+ |
} |
|
35 |
+ |
|
|
36 |
+ |
@Override |
|
37 |
+ |
protected Panel getContainer() { |
|
38 |
+ |
return container; |
|
39 |
+ |
} |
|
40 |
+ |
|
|
41 |
+ |
@Override |
|
42 |
+ |
public Widget asWidget() { |
|
43 |
+ |
return container; |
|
44 |
+ |
} |
|
45 |
+ |
|
|
46 |
+ |
// Configuration Methods |
|
47 |
+ |
|
|
48 |
+ |
public final String getLabel() { |
|
49 |
+ |
return labelPosition.name(); |
|
50 |
+ |
} |
|
51 |
+ |
|
|
52 |
+ |
public final void setLabel( String labelPosition ) { |
|
53 |
+ |
assertBuildMode( "setLabel" ); |
|
54 |
+ |
labelPosition = StringUtils.noEmpty( labelPosition ); |
|
55 |
+ |
LabelPosition position = ObjectUtils.oneOfToStringIgnoreCase( labelPosition, LabelPosition.values() ); |
|
56 |
+ |
if ( position == null ) { |
|
57 |
+ |
throw new IllegalArgumentException( "Unacceptable LabelPosition of: " + labelPosition ); |
|
58 |
+ |
} |
|
59 |
+ |
setValidatedLabelPosition( position ); |
|
60 |
+ |
} |
|
61 |
+ |
|
|
62 |
+ |
public final LabelPosition getLabelPosition() { |
|
63 |
+ |
return labelPosition; |
|
64 |
+ |
} |
|
65 |
+ |
|
|
66 |
+ |
public final void setLabelPosition( LabelPosition labelPosition ) { |
|
67 |
+ |
assertBuildMode( "setLabelPosition" ); |
|
68 |
+ |
Validate.notNull( "LabelPosition", labelPosition ); |
|
69 |
+ |
setValidatedLabelPosition( labelPosition ); |
|
70 |
+ |
} |
|
71 |
+ |
|
|
72 |
+ |
public C labelPosition( LabelPosition labelPosition ) { |
|
73 |
+ |
assertBuildMode( "labelPosition" ); |
|
74 |
+ |
Validate.notNull( "LabelPosition", labelPosition ); |
|
75 |
+ |
setValidatedLabelPosition( labelPosition ); |
|
76 |
+ |
return inheritanceLeaf(); |
|
77 |
+ |
} |
|
78 |
+ |
|
|
79 |
+ |
protected void setValidatedLabelPosition( LabelPosition labelPosition ) { |
|
80 |
+ |
this.labelPosition = labelPosition; |
|
81 |
+ |
} |
|
82 |
+ |
|
|
83 |
+ |
public final boolean isRequired() { |
|
84 |
+ |
return required; |
|
85 |
+ |
} |
|
86 |
+ |
|
|
87 |
+ |
public final void setRequired( boolean required ) { |
|
88 |
+ |
assertBuildMode( "setRequired" ); |
|
89 |
+ |
setValidatedRequired( required ); |
|
90 |
+ |
} |
|
91 |
+ |
|
|
92 |
+ |
public C required() { |
|
93 |
+ |
assertBuildMode( "required" ); |
|
94 |
+ |
setValidatedRequired( true ); |
|
95 |
+ |
return inheritanceLeaf(); |
|
96 |
+ |
} |
|
97 |
+ |
|
|
98 |
+ |
protected void setValidatedRequired( boolean required ) { |
|
99 |
+ |
this.required = required; |
|
100 |
+ |
if ( required ) { |
|
101 |
+ |
setValidatedErrorLabel( true ); |
|
102 |
+ |
} |
|
103 |
+ |
} |
|
104 |
+ |
|
|
105 |
+ |
public final boolean isErrorLabel() { |
|
106 |
+ |
return errorLabel; |
|
107 |
+ |
} |
|
108 |
+ |
|
|
109 |
+ |
public final void setErrorLabel( boolean errorLabel ) { |
|
110 |
+ |
assertBuildMode( "setErrorLabel" ); |
|
111 |
+ |
setValidatedErrorLabel( errorLabel ); |
|
112 |
+ |
} |
|
113 |
+ |
|
|
114 |
+ |
public C errorLabel() { |
|
115 |
+ |
assertBuildMode( "errorLabel" ); |
|
116 |
+ |
setValidatedErrorLabel( true ); |
|
117 |
+ |
return inheritanceLeaf(); |
|
118 |
+ |
} |
|
119 |
+ |
|
|
120 |
+ |
protected void setValidatedErrorLabel( boolean errorLabel ) { |
|
121 |
+ |
this.errorLabel = errorLabel; |
|
122 |
+ |
} |
|
123 |
+ |
|
|
124 |
+ |
public final boolean isExtendedLabel() { |
|
125 |
+ |
return extendedLabel; |
|
126 |
+ |
} |
|
127 |
+ |
|
|
128 |
+ |
public final void setExtendedLabel( boolean extendedLabel ) { |
|
129 |
+ |
assertBuildMode( "setExtendedLabel" ); |
|
130 |
+ |
setValidatedExtendedLabel( extendedLabel ); |
|
131 |
+ |
} |
|
132 |
+ |
|
|
133 |
+ |
public C extendedLabel() { |
|
134 |
+ |
assertBuildMode( "extendedLabel" ); |
|
135 |
+ |
setValidatedExtendedLabel( true ); |
|
136 |
+ |
return inheritanceLeaf(); |
|
137 |
+ |
} |
|
138 |
+ |
|
|
139 |
+ |
protected void setValidatedExtendedLabel( boolean extendedLabel ) { |
|
140 |
+ |
this.extendedLabel = extendedLabel; |
|
141 |
+ |
} |
|
142 |
+ |
|
|
143 |
+ |
public final boolean isExample() { |
|
144 |
+ |
return example; |
|
145 |
+ |
} |
|
146 |
+ |
|
|
147 |
+ |
public final void setExample( boolean example ) { |
|
148 |
+ |
assertBuildMode( "setExample" ); |
|
149 |
+ |
setValidatedExample( example ); |
|
150 |
+ |
} |
|
151 |
+ |
|
|
152 |
+ |
public C example() { |
|
153 |
+ |
assertBuildMode( "example" ); |
|
154 |
+ |
setValidatedExample( true ); |
|
155 |
+ |
return inheritanceLeaf(); |
|
156 |
+ |
} |
|
157 |
+ |
|
|
158 |
+ |
protected void setValidatedExample( boolean example ) { |
|
159 |
+ |
this.example = example; |
|
160 |
+ |
} |
|
161 |
+ |
|
|
162 |
+ |
public final String getHelpLink() { |
|
163 |
+ |
return helpLink; |
|
164 |
+ |
} |
|
165 |
+ |
|
|
166 |
+ |
public final void setHelpLink( String helpLink ) { |
|
167 |
+ |
assertBuildMode( "setHelpLink" ); |
|
168 |
+ |
setValidatedHelpLink( StringUtils.noEmpty( helpLink ) ); |
|
169 |
+ |
} |
|
170 |
+ |
|
|
171 |
+ |
public C helpLink( String helpLink ) { |
|
172 |
+ |
assertBuildMode( "helpLink" ); |
|
173 |
+ |
setValidatedHelpLink( StringUtils.noEmpty( helpLink ) ); |
|
174 |
+ |
return inheritanceLeaf(); |
|
175 |
+ |
} |
|
176 |
+ |
|
|
177 |
+ |
protected void setValidatedHelpLink( String helpLink ) { |
|
178 |
+ |
this.helpLink = helpLink; |
|
179 |
+ |
} |
|
180 |
+ |
|
|
181 |
+ |
// Anytime Methods |
|
182 |
+ |
|
|
183 |
+ |
// Widget/Component Accessor Methods |
|
184 |
+ |
|
|
185 |
+ |
// Support Methods... |
|
186 |
+ |
|
|
187 |
+ |
@Override |
|
188 |
+ |
protected void validatorAdded( ValueValidator<T> validator ) { |
|
189 |
+ |
CompleteInputFieldAccessor<T> fieldAccessor = checkRunMode(); |
|
190 |
+ |
if ( fieldAccessor != null ) { |
|
191 |
+ |
updateStyle( fieldAccessor ); |
|
192 |
+ |
} |
|
193 |
+ |
} |
|
194 |
+ |
|
|
195 |
+ |
@Override |
|
196 |
+ |
protected void updateErrorLabel( Widget errorLabel, E13nData error ) { |
|
197 |
+ |
String errorText = revolve( "updateErrorLabel", error ); |
|
198 |
+ |
((TextLabel) errorLabel).setText( errorText ); |
|
199 |
+ |
UtilsGwt.setHidden( errorLabel, errorText == null ); |
|
200 |
+ |
} |
|
201 |
+ |
|
|
202 |
+ |
protected CompleteInputFieldAccessor<T> buildActualWidget( E13nResolver resolver ) { |
|
203 |
+ |
container.setName( getName() ); |
|
204 |
+ |
namedWidgets.add( container ); |
|
205 |
+ |
|
|
206 |
+ |
InputFieldAccessor<T> accessor = createBaseAccessor(); |
|
207 |
+ |
InputWidgetValidator<T> validator = accessor.getValidator(); |
|
208 |
+ |
|
|
209 |
+ |
TextLabel labelTextLabel = null; |
|
210 |
+ |
TextLabel extendedTextLabel = null; |
|
211 |
+ |
if ( !LabelPosition.None.equals( labelPosition ) ) { |
|
212 |
+ |
labelTextLabel = createWrappingLabel( "labelLabel", true, resolver, "field-label" ); |
|
213 |
+ |
extendedTextLabel = createWrappingLabel( "extendedLabel", extendedLabel, resolver, "field-extendedLabel" ); |
|
214 |
+ |
} |
|
215 |
+ |
TextLabel exampleTextLabel = createWrappingLabel( "exampleLabel", example, resolver, "field-example" ); |
|
216 |
+ |
TextLabel errorTextLabel = null; |
|
217 |
+ |
if ( validator != null ) { |
|
218 |
+ |
errorTextLabel = createClippingLabel( "field-error", errorLabel ); |
|
219 |
+ |
if ( required ) { |
|
220 |
+ |
addTo( validator, RequiredValueValidator.INSTANCE ); |
|
221 |
+ |
} |
|
222 |
+ |
augmentValidator( validator ); |
|
223 |
+ |
validator.addValidators( getValidators() ); |
|
224 |
+ |
} |
|
225 |
+ |
HelpWidget helpWidget = (helpLink != null) ? createHelpWidget() : null; |
|
226 |
+ |
CompleteInputFieldAccessor<T> completeAccessor = new CompleteInputFieldAccessor<T>( resolver, // |
|
227 |
+ |
labelTextLabel, // |
|
228 |
+ |
extendedTextLabel, // |
|
229 |
+ |
accessor, // |
|
230 |
+ |
helpWidget, // |
|
231 |
+ |
exampleTextLabel, // |
|
232 |
+ |
errorTextLabel ); |
|
233 |
+ |
populate( container, completeAccessor ); |
|
234 |
+ |
return completeAccessor; |
|
235 |
+ |
} |
|
236 |
+ |
|
|
237 |
+ |
protected HelpWidget createHelpWidget() { |
|
238 |
+ |
return addNamedWidgetWithNameExtension( new HelpWidget().link( helpLink ), "helpWidget" ); |
|
239 |
+ |
} |
|
240 |
+ |
|
|
241 |
+ |
@SuppressWarnings("UnusedParameters") |
|
242 |
+ |
protected void augmentValidator( InputWidgetValidator<T> validator ) { |
|
243 |
+ |
} |
|
244 |
+ |
|
|
245 |
+ |
@SuppressWarnings("unchecked") |
|
246 |
+ |
protected void addTo( InputWidgetValidator<T> validator, ValueValidator valueValidator ) { |
|
247 |
+ |
validator.addValidator( valueValidator ); |
|
248 |
+ |
} |
|
249 |
+ |
|
|
250 |
+ |
protected final TextLabel createWrappingLabel( String styleName, boolean create, E13nResolver resolver, String resolveKey ) { |
|
251 |
+ |
if ( create ) { |
|
252 |
+ |
String text = resolver.resolve( resolveKey ); |
|
253 |
+ |
if ( text != null ) { |
|
254 |
+ |
return addNamedWidgetWithStyle( new WrappingLabel( text ), styleName ); |
|
255 |
+ |
} |
|
256 |
+ |
} |
|
257 |
+ |
return null; |
|
258 |
+ |
} |
|
259 |
+ |
|
|
260 |
+ |
protected final TextLabel createClippingLabel( String styleName, boolean create ) { |
|
261 |
+ |
return create ? addNamedWidgetWithStyle( new ClippingLabel(), styleName ) : null; |
|
262 |
+ |
} |
|
263 |
+ |
|
|
264 |
+ |
private TextLabel createRequiredLabel() { |
|
265 |
+ |
return addNamedWidgetWithStyle( new NonWrappingLabel( required ? " * " : " ", true ), "requiredSpacer" ); |
|
266 |
+ |
} |
|
267 |
+ |
|
|
268 |
+ |
protected void populate( HorizontalPanel container, CompleteInputFieldAccessor<T> completeAccessor ) { |
|
269 |
+ |
container.clear(); // Remove "Stand In" |
|
270 |
+ |
container.addStyleName( ObjectUtils.getSimpleClassName( this ) ); // Add Style on Container for Cascade customization! |
|
271 |
+ |
|
|
272 |
+ |
container.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_LEFT ); |
|
273 |
+ |
container.setVerticalAlignment( HasVerticalAlignment.ALIGN_TOP ); |
|
274 |
+ |
|
|
275 |
+ |
VerticalPanel labelPanel = null; |
|
276 |
+ |
VerticalPanel centerPanel = UtilsGwt.vertical( "fieldCenter" ); |
|
277 |
+ |
|
|
278 |
+ |
HelpWidget helpWidget = completeAccessor.getHelpWidget(); |
|
279 |
+ |
|
|
280 |
+ |
switch ( labelPosition ) { |
|
281 |
+ |
default: |
|
282 |
+ |
case Left: |
|
283 |
+ |
container.add( labelPanel = UtilsGwt.vertical( "fieldLeft" ) ); |
|
284 |
+ |
labelPanel.add( completeAccessor.getLabelLabel() ); |
|
285 |
+ |
container.add( createRequiredLabel() ); |
|
286 |
+ |
container.add( centerPanel ); |
|
287 |
+ |
break; |
|
288 |
+ |
case Top: |
|
289 |
+ |
container.add( labelPanel = centerPanel ); |
|
290 |
+ |
labelPanel.add( UtilsGwt.horizontal( completeAccessor.getLabelLabel(), createRequiredLabel() ) ); |
|
291 |
+ |
break; |
|
292 |
+ |
case Right: |
|
293 |
+ |
container.add( centerPanel ); |
|
294 |
+ |
container.add( labelPanel = UtilsGwt.vertical( "fieldRight" ) ); |
|
295 |
+ |
labelPanel.add( UtilsGwt.horizontal( completeAccessor.getLabelLabel(), createRequiredLabel(), helpWidget ) ); |
|
296 |
+ |
helpWidget = null; |
|
297 |
+ |
break; |
|
298 |
+ |
case None: |
|
299 |
+ |
break; |
|
300 |
+ |
} |
|
301 |
+ |
UtilsGwt.add( labelPanel, completeAccessor.getExtendedLabel() ); |
|
302 |
+ |
|
|
303 |
+ |
// Add HelpWidget |
|
304 |
+ |
if ( helpWidget != null ) { |
|
305 |
+ |
container.add( UtilsGwt.add( UtilsGwt.vertical( "fieldRight" ), helpWidget ) ); |
|
306 |
+ |
} |
|
307 |
+ |
|
|
308 |
+ |
// populate the Center |
|
309 |
+ |
centerPanel.add( completeAccessor.getInputWidget() ); |
|
310 |
+ |
UtilsGwt.add( centerPanel, completeAccessor.getExampleLabel() ); |
|
311 |
+ |
UtilsGwt.add( centerPanel, completeAccessor.getErrorLabel() ); |
|
312 |
+ |
} |
|
313 |
+ |
|
|
314 |
+ |
protected <W extends Widget & HasName> InputFieldAccessor<T> createBaseAccessor( InputWidgetValueAdapter<T> valueAdapter, W inputWidget, String style, |
|
315 |
+ |
Focusable... focusables ) { |
|
316 |
+ |
InputWidgetValidator<T> validator = new InputWidgetValidator<T>( valueAdapter ); |
|
317 |
+ |
InputWidgetChangeFilter<T> input = new InputWidgetChangeFilter<T>( validator ); |
|
318 |
+ |
return new InputFieldAccessor<T>( input, validator, valueAdapter, addNamedWidgetWithStyle( inputWidget, style ), focusables ); |
|
319 |
+ |
} |
|
320 |
+ |
|
|
321 |
+ |
abstract protected InputFieldAccessor<T> createBaseAccessor(); |
|
322 |
+ |
} |