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
310
311
312
313
314
315
316
317
318
319
320
321
322
package com.temp.client.foundation.widget.input.fieldsupport;

import org.litesoft.core.util.externalization.*;

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.*;
import com.temp.client.foundation.widget.input.support.*;
import com.temp.shared.*;
import com.temp.shared.utils.*;
import com.temp.shared.validators.*;

/**
 * Common abstract helper for the generated Widget versions of the InputField.
 */
public abstract class AbstractGeneratedInputField<T, C extends AbstractGeneratedInputField<T, C>> extends AbstractNonProxyInputField<T, C> 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 String helpLink;

    // The above must be set/changed BEFORE the widget is attached!

    private final NamedHorizontalPanel container = new NamedHorizontalPanel();

    public AbstractGeneratedInputField() {
        container.add( new Label( "!?!" ) );
    }

    @Override
    protected Panel getContainer() {
        return container;
    }

    @Override
    public Widget asWidget() {
        return container;
    }

    // Configuration Methods

    public final String getLabel() {
        return labelPosition.name();
    }

    public final void setLabel( String labelPosition ) {
        assertBuildMode( "setLabel" );
        labelPosition = StringUtils.noEmpty( labelPosition );
        LabelPosition position = ObjectUtils.oneOfToStringIgnoreCase( labelPosition, LabelPosition.values() );
        if ( position == null ) {
            throw new IllegalArgumentException( "Unacceptable LabelPosition of: " + labelPosition );
        }
        setValidatedLabelPosition( position );
    }

    public final LabelPosition getLabelPosition() {
        return labelPosition;
    }

    public final void setLabelPosition( LabelPosition labelPosition ) {
        assertBuildMode( "setLabelPosition" );
        Validate.notNull( "LabelPosition", labelPosition );
        setValidatedLabelPosition( labelPosition );
    }

    public C labelPosition( LabelPosition labelPosition ) {
        assertBuildMode( "labelPosition" );
        Validate.notNull( "LabelPosition", labelPosition );
        setValidatedLabelPosition( labelPosition );
        return inheritanceLeaf();
    }

    protected void setValidatedLabelPosition( LabelPosition labelPosition ) {
        this.labelPosition = labelPosition;
    }

    public final boolean isRequired() {
        return required;
    }

    public final void setRequired( boolean required ) {
        assertBuildMode( "setRequired" );
        setValidatedRequired( required );
    }

    public C required() {
        assertBuildMode( "required" );
        setValidatedRequired( true );
        return inheritanceLeaf();
    }

    protected void setValidatedRequired( boolean required ) {
        this.required = required;
        if ( required ) {
            setValidatedErrorLabel( true );
        }
    }

    public final boolean isErrorLabel() {
        return errorLabel;
    }

    public final void setErrorLabel( boolean errorLabel ) {
        assertBuildMode( "setErrorLabel" );
        setValidatedErrorLabel( errorLabel );
    }

    public C errorLabel() {
        assertBuildMode( "errorLabel" );
        setValidatedErrorLabel( true );
        return inheritanceLeaf();
    }

    protected void setValidatedErrorLabel( boolean errorLabel ) {
        this.errorLabel = errorLabel;
    }

    public final boolean isExtendedLabel() {
        return extendedLabel;
    }

    public final void setExtendedLabel( boolean extendedLabel ) {
        assertBuildMode( "setExtendedLabel" );
        setValidatedExtendedLabel( extendedLabel );
    }

    public C extendedLabel() {
        assertBuildMode( "extendedLabel" );
        setValidatedExtendedLabel( true );
        return inheritanceLeaf();
    }

    protected void setValidatedExtendedLabel( boolean extendedLabel ) {
        this.extendedLabel = extendedLabel;
    }

    public final boolean isExample() {
        return example;
    }

    public final void setExample( boolean example ) {
        assertBuildMode( "setExample" );
        setValidatedExample( example );
    }

    public C example() {
        assertBuildMode( "example" );
        setValidatedExample( true );
        return inheritanceLeaf();
    }

    protected void setValidatedExample( boolean example ) {
        this.example = example;
    }

    public final String getHelpLink() {
        return helpLink;
    }

    public final void setHelpLink( String helpLink ) {
        assertBuildMode( "setHelpLink" );
        setValidatedHelpLink( StringUtils.noEmpty( helpLink ) );
    }

    public C helpLink( String helpLink ) {
        assertBuildMode( "helpLink" );
        setValidatedHelpLink( StringUtils.noEmpty( helpLink ) );
        return inheritanceLeaf();
    }

    protected void setValidatedHelpLink( String helpLink ) {
        this.helpLink = helpLink;
    }

    // Anytime Methods

    // Widget/Component Accessor Methods

    // Support Methods...

    @Override
    protected void validatorAdded( ValueValidator<T> validator ) {
        CompleteInputFieldAccessor<T> fieldAccessor = checkRunMode();
        if ( fieldAccessor != null ) {
            updateStyle( fieldAccessor );
        }
    }

    @Override
    protected void updateErrorLabel( Widget errorLabel, E13nData error ) {
        String errorText = revolve( "updateErrorLabel", error );
        ((TextLabel) errorLabel).setText( errorText );
        UtilsGwt.setHidden( errorLabel, errorText == null );
    }

    protected CompleteInputFieldAccessor<T> buildActualWidget( E13nResolver resolver ) {
        container.setName( getName() );
        namedWidgets.add( container );

        InputFieldAccessor<T> accessor = createBaseAccessor();
        InputWidgetValidator<T> validator = accessor.getValidator();

        TextLabel labelTextLabel = null;
        TextLabel extendedTextLabel = null;
        if ( !LabelPosition.None.equals( labelPosition ) ) {
            labelTextLabel = createWrappingLabel( "labelLabel", true, resolver, "field-label" );
            extendedTextLabel = createWrappingLabel( "extendedLabel", extendedLabel, resolver, "field-extendedLabel" );
        }
        TextLabel exampleTextLabel = createWrappingLabel( "exampleLabel", example, resolver, "field-example" );
        TextLabel errorTextLabel = null;
        if ( validator != null ) {
            errorTextLabel = createClippingLabel( "field-error", errorLabel );
            if ( required ) {
                addTo( validator, RequiredValueValidator.INSTANCE );
            }
            augmentValidator( validator );
            validator.addValidators( getValidators() );
        }
        HelpWidget helpWidget = (helpLink != null) ? createHelpWidget() : null;
        CompleteInputFieldAccessor<T> completeAccessor = new CompleteInputFieldAccessor<T>( resolver, //
                                                                                            labelTextLabel, //
                                                                                            extendedTextLabel, //
                                                                                            accessor, //
                                                                                            helpWidget, //
                                                                                            exampleTextLabel, //
                                                                                            errorTextLabel );
        populate( container, completeAccessor );
        return completeAccessor;
    }

    protected HelpWidget createHelpWidget() {
        return addNamedWidgetWithNameExtension( new HelpWidget().link( helpLink ), "helpWidget" );
    }

    @SuppressWarnings("UnusedParameters")
    protected void augmentValidator( InputWidgetValidator<T> validator ) {
    }

    @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 addNamedWidgetWithStyle( new WrappingLabel( text ), styleName );
            }
        }
        return null;
    }

    protected final TextLabel createClippingLabel( String styleName, boolean create ) {
        return create ? addNamedWidgetWithStyle( new ClippingLabel(), styleName ) : null;
    }

    private TextLabel createRequiredLabel() {
        return addNamedWidgetWithStyle( new NonWrappingLabel( required ? " * " : "   ", true ), "requiredSpacer" );
    }

    protected void populate( HorizontalPanel container, CompleteInputFieldAccessor<T> completeAccessor ) {
        container.clear(); // Remove "Stand In"
        container.addStyleName( ObjectUtils.getSimpleClassName( this ) ); // Add Style on Container for Cascade customization!

        container.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_LEFT );
        container.setVerticalAlignment( HasVerticalAlignment.ALIGN_TOP );

        VerticalPanel labelPanel = null;
        VerticalPanel centerPanel = UtilsGwt.vertical( "fieldCenter" );

        HelpWidget helpWidget = completeAccessor.getHelpWidget();

        switch ( labelPosition ) {
            default:
            case Left:
                container.add( labelPanel = UtilsGwt.vertical( "fieldLeft" ) );
                labelPanel.add( completeAccessor.getLabelLabel() );
                container.add( createRequiredLabel() );
                container.add( centerPanel );
                break;
            case Top:
                container.add( labelPanel = centerPanel );
                labelPanel.add( UtilsGwt.horizontal( completeAccessor.getLabelLabel(), createRequiredLabel() ) );
                break;
            case Right:
                container.add( centerPanel );
                container.add( labelPanel = UtilsGwt.vertical( "fieldRight" ) );
                labelPanel.add( UtilsGwt.horizontal( completeAccessor.getLabelLabel(), createRequiredLabel(), helpWidget ) );
                helpWidget = null;
                break;
            case None:
                break;
        }
        UtilsGwt.add( labelPanel, completeAccessor.getExtendedLabel() );

        // Add HelpWidget
        if ( helpWidget != null ) {
            container.add( UtilsGwt.add( UtilsGwt.vertical( "fieldRight" ), helpWidget ) );
        }

        // populate the Center
        centerPanel.add( completeAccessor.getInputWidget() );
        UtilsGwt.add( centerPanel, completeAccessor.getExampleLabel() );
        UtilsGwt.add( centerPanel, completeAccessor.getErrorLabel() );
    }

    protected <W extends Widget & HasName> InputFieldAccessor<T> createBaseAccessor( InputWidgetValueAdapter<T> valueAdapter, W inputWidget, String style,
                                                                                     Focusable... focusables ) {
        InputWidgetValidator<T> validator = new InputWidgetValidator<T>( valueAdapter );
        InputWidgetChangeFilter<T> input = new InputWidgetChangeFilter<T>( validator );
        return new InputFieldAccessor<T>( input, validator, valueAdapter, addNamedWidgetWithStyle( inputWidget, style ), focusables );
    }

    abstract protected InputFieldAccessor<T> createBaseAccessor();
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/widget/input/fieldsupport/AbstractGeneratedInputField.java

Diff revisions: vs.
Revision Author Commited Message
950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

724 Diff Diff GeorgeS picture GeorgeS Mon 11 Jun, 2012 00:47:26 +0000
633 Diff Diff GeorgeS picture GeorgeS Thu 19 Apr, 2012 02:30:46 +0000
630 Diff Diff GeorgeS picture GeorgeS Tue 17 Apr, 2012 20:22:17 +0000
629 GeorgeS picture GeorgeS Tue 17 Apr, 2012 05:47:55 +0000