Subversion Repository Public Repository

litesoft

Diff Revisions 631 vs 632 for /trunk/GWT_Sandbox/FormEngine/src/org/litesoft/sampleapplication/sampleApplication/client/SampleApplication.java

Diff revisions: vs.
  @@ -1,9 +1,11 @@
1 1 package org.litesoft.sampleapplication.sampleApplication.client;
2 2
3 + import java.util.*;
4 +
3 5 import com.google.gwt.core.client.*;
4 6 import com.google.gwt.event.dom.client.*;
5 7 import com.google.gwt.user.client.ui.*;
6 - import com.temp.client.foundation.widget.NameToID;
8 + import com.temp.client.foundation.widget.*;
7 9 import com.temp.client.foundation.widget.input.*;
8 10 import com.temp.shared.externalization.*;
9 11 import com.temp.shared.utils.*;
  @@ -11,84 +13,178 @@
11 13
12 14 public class SampleApplication implements EntryPoint
13 15 {
14 - private TemplateSourceE13nResolver resolver = new TemplateSourceE13nResolver(new TemplateSource() {
16 + String[] externalizedData = { //
17 + "Fred_field-label", "Name", //
18 + "Family_field-extendedLabel", "(Primary Key)", //
19 + "Family_field-example", "(e.g. XYZ_Outbound)", //
20 + "Family_Wilma_field-label", "Fav Color", //
21 + "Pebbles_field-label", "Active", //
22 + "Fred_Required", "Please provide a Name", //
23 + "Required", "* means Required", //
24 + "NotIdentifier", "Unacceptable entry: {why}", //
25 + "Fred_BadCharacter", "'{character}' not allowed", //
26 + "SetValue", "Set Value", //
27 + };
28 +
29 + private E13nResolver globalResolver = new TemplateSourceE13nResolver( new TemplateSource()
30 + {
31 + private Map<String, String> dictionary = CollectionsUtils.newMap( externalizedData );
32 +
15 33 @Override
16 - public String get(String key) {
17 - System.out.println("Template Get: " + key);
18 - return null;
34 + public String get( String key )
35 + {
36 + System.out.println( "Template Get: " + key );
37 + return dictionary.get( key );
19 38 }
20 39
21 40 @Override
22 - public String get(String key, String defaultValue) {
23 - return StringUtils.deNull(get(key), defaultValue);
41 + public String get( String key, String defaultValue )
42 + {
43 + return StringUtils.deNull( get( key ), defaultValue );
24 44 }
25 - });
45 + } );
26 46
27 - enum Options {Red, Green, Blue}
47 + enum Options
48 + {
49 + Red, Green, Blue
50 + }
28 51
29 - public void onModuleLoad()
52 + // Pretend "Injected"
53 + private TextInputField tif = new TextInputField().name( "Fred" ).helpLink( "XX#Fred" ).required().maxLength( 9 ).extendedLabel().example().errorLabel();
54 + private OptionBoxInputField<Options> obif = new OptionBoxInputField<Options>().name( "Wilma" ).helpLink( "XX#YY" ).required().labelPosition( LabelPosition.Top ).errorLabel();
55 + private CheckBoxInputField cbif = new CheckBoxInputField().name( "Pebbles" ).helpLink( "XX#YY" ).labelPosition( LabelPosition.Right );
56 + private NamedTextButton buttonSetValue = new NamedTextButton( "SetValue", new ClickHandler()
30 57 {
31 - final TextInputField tif = new TextInputField().maxLength( 9 ).required().extendedLabel().example().errorLabel().helpLink( "XX#YY" ).name( "Fred" );
32 - tif.add( IdentifierValueValidator.INSTANCE );
33 - complete(tif);
58 + public void onClick( ClickEvent event )
59 + {
60 + tif.setCurrentValue( tif.getCurrentValue() );
61 + System.out.println( "Set Value!" );
62 + }
63 + } );
64 + private Button buttonSetValueAsUser = new Button( "User Set Value", new ClickHandler()
65 + {
66 + public void onClick( ClickEvent event )
67 + {
68 + tif.getInput().setValueAsUser( tif.getCurrentValue() + "!" );
69 + System.out.println( "User Set Value!" );
70 + }
71 + } );
72 + private Button buttonValidate = new Button( "Validate" );
34 73
35 - final OptionBoxInputField<Options> obif = new OptionBoxInputField<Options>().required().labelPosition(LabelPosition.Top).errorLabel().helpLink( "XX#YY" ).name( "Wilma" ).addNullOptional();
36 - complete(obif.addOptions(Options.values()));
74 + public void onModuleLoad()
75 + {
76 + E13nResolver viewResolver = new OptionallyPrefixingE13nResolver( "BusinessUnitManager", globalResolver );
37 77
38 - final CheckBoxInputField cbif = new CheckBoxInputField().helpLink( "XX#YY" ).labelPosition(LabelPosition.Right).name( "Pebbles" );
39 - complete(cbif);
78 + FormEngine fe = new FormEngine( "Family" );
40 79
41 - Button buttonSetValue = new Button( "Set Value", new ClickHandler()
42 - {
43 - public void onClick( ClickEvent event )
44 - {
45 - tif.setCurrentValue( tif.getCurrentValue() );
46 - System.out.println( "Set Value!" );
47 - }
48 - } );
49 - Button buttonSetValueAsUser = new Button( "User Set Value", new ClickHandler()
50 - {
51 - public void onClick( ClickEvent event )
52 - {
53 - tif.getInput().setValueAsUser( tif.getCurrentValue() + "!" );
54 - System.out.println( "User Set Value!" );
55 - }
56 - } );
57 - Button buttonValidate = new Button( "Validate", new ClickHandler()
80 + fe.add( tif.add( IdentifierValueValidator.INSTANCE ), //
81 + obif.addNullOptional().addOptions( Options.values() ), //
82 + cbif );
83 + fe.addManaged( buttonSetValue, buttonSetValueAsUser );
84 + fe.setSubmit( buttonValidate, new FormEngine.Callback()
58 85 {
59 - public void onClick( ClickEvent event )
86 + @Override
87 + public void submit( String name )
60 88 {
61 - tif.validate();
62 - obif.validate();
63 - cbif.validate();
89 + System.out.println( "Form '"+name+"' says OK to Submit!" );
64 90 }
65 91 } );
92 + fe.init( viewResolver );
93 + fe.addNamedWidgetsTo( new NameToID() ).applyIDs();
66 94
67 95 VerticalPanel zVPanel = new VerticalPanel();
68 96 zVPanel.add( new HTML( "&nbsp;" ) );
69 - zVPanel.add( horizontalWithSpacers( tif, new HTML( "&nbsp;" ), obif , new HTML( "&nbsp;" ), cbif ) );
97 + zVPanel.add( horizontalWithSpacers( tif, new HTML( "&nbsp;" ), obif, new HTML( "&nbsp;" ), cbif ) );
70 98 zVPanel.add( new HTML( "&nbsp;" ) );
71 99 zVPanel.add( horizontalWithSpacers( buttonSetValue, buttonSetValueAsUser, buttonValidate ) );
100 + zVPanel.add( new HTML( "&nbsp;" ) );
101 + zVPanel.add( new HTML( "&nbsp;" ) );
102 + zVPanel.add( new HTML( "&nbsp;" ) );
103 + zVPanel.add( new HTML( "&nbsp;" ) );
104 + zVPanel.add( createFormInteractionButtons( fe ) );
72 105
73 106 RootPanel zRootPanel = RootPanel.get( "centeredWidget" );
74 107 zRootPanel.add( zVPanel );
75 - }
76 108
77 - private <T> void complete(InputField<T> inputField) {
78 - inputField.init(resolver);
109 + complete( tif );
110 + complete( obif );
111 + complete( cbif );
112 + }
79 113
80 - inputField.addNamedWidgetsTo(new NameToID()).applyIDs();
114 + private HorizontalPanel createFormInteractionButtons( final FormEngine fe )
115 + {
116 + return horizontalWithSpacers( new Button( "ServerStart", new ClickHandler()
117 + {
118 + public void onClick( ClickEvent event )
119 + {
120 + fe.busyInteractingWithServer();
121 + }
122 + } ), new Button( "ServerStop", new ClickHandler()
123 + {
124 + public void onClick( ClickEvent event )
125 + {
126 + fe.doneInteractingWithServer();
127 + }
128 + } ), new Button( "Reset", new ClickHandler()
129 + {
130 + public void onClick( ClickEvent event )
131 + {
132 + fe.reset();
133 + }
134 + } ), new Button( "Revert", new ClickHandler()
135 + {
136 + public void onClick( ClickEvent event )
137 + {
138 + fe.revert();
139 + }
140 + } ), new Button( "IsChanged", new ClickHandler()
141 + {
142 + public void onClick( ClickEvent event )
143 + {
144 + System.out.println("Form '"+fe.getName()+"' Changed: " + fe.isChanged());
145 + }
146 + } ), new Button( "IsErrored", new ClickHandler()
147 + {
148 + public void onClick( ClickEvent event )
149 + {
150 + System.out.println("Form '"+fe.getName()+"' Errored: " + fe.isErrored());
151 + }
152 + } ), new Button( "Focus", new ClickHandler()
153 + {
154 + public void onClick( ClickEvent event )
155 + {
156 + fe.setFocused();
157 + }
158 + } ), new Button( "Disable", new ClickHandler()
159 + {
160 + public void onClick( ClickEvent event )
161 + {
162 + fe.setEnabled( false );
163 + }
164 + } ), new Button( "Enable", new ClickHandler()
165 + {
166 + public void onClick( ClickEvent event )
167 + {
168 + fe.setEnabled( true );
169 + }
170 + } ) );
171 + }
81 172
82 - inputField.add(new InputField.ChangeListener<T>() {
173 + private <T> void complete( InputField<T> inputField )
174 + {
175 + inputField.add( new InputField.ChangeListener<T>()
176 + {
83 177 @Override
84 - public void changed(InputField<T> field) {
178 + public void changed( InputField<T> field )
179 + {
85 180 T value = field.getCurrentValue();
86 - System.out.println("Change ("+field.getName()+"): " + field.isChanged() + " '" + value + "' | " + field.getValidator().getErrorData());
87 - if ("OK".equals(value)) {
88 - field.setCurrentValue(value);
181 + System.out.println( "Change (" + field.getName() + "): " + field.isChanged() + " '" + value + "' | " + field.getValidator().getErrorData() );
182 + if ( "OK".equals( value ) )
183 + {
184 + field.setCurrentValue( value );
89 185 }
90 186 }
91 - });
187 + } );
92 188 }
93 189
94 190 private HorizontalPanel horizontalWithSpacers( IsWidget... widgets )