Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -3,6 +3,7 @@
3 3 import com.google.gwt.core.client.*;
4 4 import com.google.gwt.event.dom.client.*;
5 5 import com.google.gwt.user.client.ui.*;
6 + import com.temp.client.foundation.widget.NameToID;
6 7 import com.temp.client.foundation.widget.input.*;
7 8 import com.temp.shared.externalization.*;
8 9 import com.temp.shared.utils.*;
  @@ -10,38 +11,32 @@
10 11
11 12 public class SampleApplication implements EntryPoint
12 13 {
14 + private TemplateSourceE13nResolver resolver = new TemplateSourceE13nResolver(new TemplateSource() {
15 + @Override
16 + public String get(String key) {
17 + System.out.println("Template Get: " + key);
18 + return null;
19 + }
20 +
21 + @Override
22 + public String get(String key, String defaultValue) {
23 + return StringUtils.deNull(get(key), defaultValue);
24 + }
25 + });
26 +
27 + enum Options {Red, Green, Blue}
28 +
13 29 public void onModuleLoad()
14 30 {
15 - final TextInputField tif = (TextInputField) new TextInputField().maxLength( 9 ).required().extendedLabel().example().errorLabel().helpLink( "XX:YY" ).name( "Fred" );
16 -
31 + final TextInputField tif = new TextInputField().maxLength( 9 ).required().extendedLabel().example().errorLabel().helpLink( "XX:YY" ).name( "Fred" );
17 32 tif.add( IdentifierValueValidator.INSTANCE );
33 + complete(tif);
18 34
19 - tif.init( new TemplateSourceE13nResolver( new TemplateSource()
20 - {
21 - @Override public String get( String key )
22 - {
23 - System.out.println( "Template Get: " + key );
24 - return null;
25 - }
26 -
27 - @Override public String get( String key, String defaultValue )
28 - {
29 - return StringUtils.deNull( get( key ), defaultValue );
30 - }
31 - } ) );
35 + OptionBoxInputField<Options> obif = new OptionBoxInputField<Options>().required().errorLabel().helpLink( "XX:YY" ).name( "Wilma" ).addNullOptional();
36 + complete(obif.addOptions(Options.values()));
32 37
33 - tif.add( new InputField.ChangeListener<String>()
34 - {
35 - @Override public void changed( InputField<String> field )
36 - {
37 - String value = field.getCurrentValue();
38 - System.out.println( "Change: " + field.isChanged() + " '" + value + "' | " + tif.getValidator().getErrorData());
39 - if ( "OK".equals( value ) )
40 - {
41 - field.setCurrentValue( value );
42 - }
43 - }
44 - } );
38 + CheckBoxInputField cbif = new CheckBoxInputField().helpLink( "XX:YY" ).name( "Pebbles" );
39 + complete(cbif);
45 40
46 41 Button buttonSetValue = new Button( "Set Value", new ClickHandler()
47 42 {
  @@ -62,7 +57,7 @@
62 57
63 58 VerticalPanel zVPanel = new VerticalPanel();
64 59 zVPanel.add( new HTML( "&nbsp;" ) );
65 - zVPanel.add( tif );
60 + zVPanel.add( horizontalWithSpacers( tif, new HTML( "&nbsp;" ), obif , new HTML( "&nbsp;" ), cbif ) );
66 61 zVPanel.add( new HTML( "&nbsp;" ) );
67 62 zVPanel.add( horizontalWithSpacers( buttonSetValue, buttonSetValueAsUser ) );
68 63
  @@ -70,7 +65,24 @@
70 65 zRootPanel.add( zVPanel );
71 66 }
72 67
73 - private HorizontalPanel horizontalWithSpacers( Widget... widgets )
68 + private <T> void complete(InputField<T> inputField) {
69 + inputField.init(resolver);
70 +
71 + inputField.addNamedWidgetsTo(new NameToID()).applyIDs();
72 +
73 + inputField.add(new InputField.ChangeListener<T>() {
74 + @Override
75 + public void changed(InputField<T> field) {
76 + T value = field.getCurrentValue();
77 + System.out.println("Change ("+field.getName()+"): " + field.isChanged() + " '" + value + "' | " + field.getValidator().getErrorData());
78 + if ("OK".equals(value)) {
79 + field.setCurrentValue(value);
80 + }
81 + }
82 + });
83 + }
84 +
85 + private HorizontalPanel horizontalWithSpacers( IsWidget... widgets )
74 86 {
75 87 HorizontalPanel zPanel = new HorizontalPanel();
76 88 zPanel.add( widgets[0] );