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
package org.litesoft.sampleapplication.sampleApplication.client;

import java.util.*;

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

import com.google.gwt.core.client.*;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.user.client.Timer;
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.shared.externalization.*;
import com.temp.shared.utils.*;
import com.temp.shared.validators.*;

public class SampleApplication implements EntryPoint
{
    String[] externalizedData = { //
                                  "Fred_field-label", "Name", //
                                  "Family_field-extendedLabel", "(Primary Key)", //
                                  "Family_field-example", "(e.g. XYZ_Outbound)", //
                                  "Family_Wilma_field-label", "Fav Color", //
                                  "Pebbles_field-label", "Active", //
                                  "Fred_Required", "Please provide a Name", //
                                  "Required", "* means Required", //
                                  "NotIdentifier", "Unacceptable entry: {why}", //
                                  "Fred_BadCharacter", "'{character}' not allowed", //
                                  "Public_field-label", "Public", //
                                  "Private_field-label", "Private", //
                                  "SetValue", "Set Value", //
    };

    private E13nResolver globalResolver = new TemplateSourceE13nResolver( new TemplateSource()
    {
        private Map<String, String> dictionary = CollectionsUtils.newMap( externalizedData );

        @Override
        public String get( String key )
        {
            System.out.println( "Template Get: " + key );
            return dictionary.get( key );
        }

        @Override
        public String get( String key, String defaultValue )
        {
            return StringUtils.deNull( get( key ), defaultValue );
        }
    } );

    enum Options
    {
        Red, Green, Blue
    }

    // Pretend "Injected" by the "ui.xml" file
    private TextInputField tif = new TextInputField().name( "Fred" ).helpLink( "XX#Fred" ).required().maxLength( 9 ).extendedLabel().example().errorLabel();
    private OptionBoxInputField<Options> obif = new OptionBoxInputField<Options>().name("Wilma").helpLink("XX#YY").required().labelPosition(LabelPosition.Top).errorLabel();
    private CheckBoxInputField cbif = new CheckBoxInputField().name("Pebbles").helpLink("XX#YY").labelPosition(LabelPosition.Right);
    private RadioButtonInputField rbif1 = new RadioButtonInputField().name("Public").group("Visibility").helpLink( "XX#YY" ).labelPosition( LabelPosition.Right );
    private RadioButtonInputField rbif2 = new RadioButtonInputField().name("Private").group("Visibility").helpLink("XX#YY").labelPosition(LabelPosition.Right);

    VerticalPanel radioButtonContainer = UtilsGwt.add( UtilsGwt.add( UtilsGwt.vertical("radioButtonContainer"), rbif1 ), rbif2 );

    private NamedTextButton buttonSetValue = new NamedTextButton( "SetValue", new ClickHandler()
    {
        public void onClick( ClickEvent event )
        {
            tif.setCurrentValue( tif.getCurrentValue() );
            System.out.println( "Set Value!" );
        }
    } );
    private Button buttonSetValueAsUser = new Button( "User Set Value", new ClickHandler()
    {
        public void onClick( ClickEvent event )
        {
            tif.getInput().setValueAsUser( tif.getCurrentValue() + "!" );
            System.out.println( "User Set Value!" );
        }
    } );
    private Button buttonValidate = new Button( "Validate" );

    private RadioButtonGroupInputField rbgif;

    private SimplePanel rootPanel;
    private VerticalPanel formPanel;

    // Fake "View"
    public void onModuleLoad()
    {
        // Initialize the "View" Resolver
        E13nResolver viewResolver = new OptionallyPrefixingE13nResolver( "BusinessUnitManager", globalResolver );

        // Create Composite(s)
        rbgif = new RadioButtonGroupInputField(radioButtonContainer, rbif1, rbif2);

        // Create FormEngine
        FormEngine fe = new FormEngine( "Family" );

        // Add the Input Fields to the FormEngine
        fe.add( tif.add( IdentifierValueValidator.INSTANCE ), //
                obif.addNullOptional().addOptions( Options.values() ), //
                cbif, //
                rbgif );
        // Add the Managed Buttons
        fe.addManaged( buttonSetValue, buttonSetValueAsUser );
        // Add the Submit Button and its Callback
        fe.setSubmit( buttonValidate, new FormEngine.Callback()
        {
            @Override
            public void submit( String name )
            {
                System.out.println( "Form '"+name+"' says OK to Submit!" );
            }
        } );
        // Initialize the FormEngine (which will in turn initialize all the Input Fields)
        fe.init( viewResolver );
        // Finally apply IDs to "everything" named
        fe.addNamedWidgetsTo( new NameToID() ).applyIDs();


        // Below here is what would normally be handled by the "ui.xml" file.

        formPanel = new VerticalPanel();
        formPanel.add( new HTML( "&nbsp;" ) );
        formPanel.add( horizontalWithSpacers( tif, new HTML( "&nbsp;" ), obif, new HTML( "&nbsp;" ), cbif ) );
        formPanel.add( new HTML( "&nbsp;" ) );
        formPanel.add( rbif1 );
        formPanel.add( rbif2 );
        formPanel.add( new HTML( "&nbsp;" ) );
        formPanel.add( horizontalWithSpacers( buttonSetValue, buttonSetValueAsUser, buttonValidate ) );
        formPanel.add( new HTML( "&nbsp;" ) );
        formPanel.add( new HTML( "&nbsp;" ) );
        formPanel.add( new HTML( "&nbsp;" ) );
        formPanel.add( new HTML( "&nbsp;" ) );

        VerticalPanel vp = new VerticalPanel();
        RootPanel.get( "centeredWidget" ).add( vp );
        vp.add( createFormInteractionButtons( fe ) );
        vp.add( rootPanel = new SimplePanel( formPanel ) );

        complete( tif );
        complete( obif );
        complete( cbif );
        complete( rbgif );

        fe.setFocused();
    }

    private void attachForm()
    {
        rootPanel.add( formPanel );
    }

    private void detachForm()
    {
        rootPanel.clear();
    }

    private HorizontalPanel createFormInteractionButtons( final FormEngine fe )
    {
        return horizontalWithSpacers( new Button( "ServerStart", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                fe.busyInteractingWithServer();
            }
        } ), new Button( "ServerStop", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                fe.doneInteractingWithServer();
            }
        } ), new Button( "Reset", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                fe.reset();
            }
        } ), new Button( "Revert", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                fe.revert();
            }
        } ), new Button( "IsChanged", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                System.out.println( "Form '" + fe.getName() + "' Changed: " + fe.isChanged() );
            }
        } ), new Button( "IsErrored", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                System.out.println( "Form '" + fe.getName() + "' Errored: " + fe.isErrored() );
            }
        } ), new Button( "Focus", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                new Timer() {
                    public void run() {
                        fe.setFocused();
                    }
                }.schedule( 100 );
            }
        } ), new Button( "Detach", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                detachForm();
            }
        } ), new Button( "Attach", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                attachForm();
            }
        } ), new Button( "Disable Form", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                fe.setEnabled( false );
            }
        } ), new Button( "Enable Form", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                fe.setEnabled( true );
            }
        } ), new Button( "Disable Fields", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                tif.setEnabled( false );
                obif.setEnabled( false );
                cbif.setEnabled( false );
                rbgif.setEnabled( false );
            }
        } ), new Button( "Enable Fields", new ClickHandler()
        {
            public void onClick( ClickEvent event )
            {
                tif.setEnabled( true );
                obif.setEnabled( true );
                cbif.setEnabled( true );
                rbgif.setEnabled( true );
            }
        } ) );
    }

    private <T> void complete( InputField<T> inputField )
    {
        inputField.add( new InputField.ChangeListener<T>()
        {
            @Override
            public void changed( InputField<T> field )
            {
                T value = field.getCurrentValue();
                System.out.println( "Change (" + field.getName() + "): " + field.isChanged() + " '" + value + "' | " + field.getErrorData() );
                if ( "OK".equals( value ) )
                {
                    field.setCurrentValue( value );
                }
            }
        } );
    }

    private HorizontalPanel horizontalWithSpacers( IsWidget... widgets )
    {
        HorizontalPanel zPanel = new HorizontalPanel();
        zPanel.add( widgets[0] );
        for ( int i = 1; i < widgets.length; i++ )
        {
            zPanel.add( new HTML( "&nbsp;&nbsp;" ) );
            zPanel.add( widgets[i] );
        }
        return zPanel;
    }
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/org/litesoft/sampleapplication/sampleApplication/client/SampleApplication.java

Diff revisions: vs.
Revision Author Commited Message
724 Diff Diff GeorgeS picture GeorgeS Mon 11 Jun, 2012 00:47:26 +0000
637 Diff Diff GeorgeS picture GeorgeS Sun 22 Apr, 2012 02:10:25 +0000
636 Diff Diff GeorgeS picture GeorgeS Thu 19 Apr, 2012 20:21:25 +0000
635 Diff Diff GeorgeS picture GeorgeS Thu 19 Apr, 2012 18:20:49 +0000
632 Diff Diff GeorgeS picture GeorgeS Wed 18 Apr, 2012 18:11:29 +0000
631 Diff Diff GeorgeS picture GeorgeS Tue 17 Apr, 2012 23:24:54 +0000
630 Diff Diff GeorgeS picture GeorgeS Tue 17 Apr, 2012 20:22:17 +0000
629 Diff Diff GeorgeS picture GeorgeS Tue 17 Apr, 2012 05:47:55 +0000
626 Diff Diff GeorgeS picture GeorgeS Wed 11 Apr, 2012 19:39:41 +0000
601 GeorgeS picture GeorgeS Wed 08 Feb, 2012 01:52:17 +0000