Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/widget/input/fieldsupport/AbstractGeneratedInputField.java

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