Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -5,10 +5,11 @@
5 5 import com.google.gwt.user.client.ui.*;
6 6 import com.temp.foundation.widgets.*;
7 7 import com.temp.foundation.widgets.support.*;
8 + import com.temp.shared.validators.*;
8 9
9 10 public class SampleApplication implements EntryPoint {
10 11 public void onModuleLoad() {
11 - Button button = new Button("Click me");
12 +
12 13 Label fieldLabel = new Label("Name:");
13 14 Label errorLabel = new Label("Error");
14 15 HTML stateLabel = new HTML(" ");
  @@ -16,6 +17,7 @@
16 17
17 18 final InputWidgetValidator<String> validator = new InputWidgetValidator<String>(new TextBoxBaseValueAdapter(field));
18 19 final InputWidgetChangeFilter<String> input = new InputWidgetChangeFilter<String>(validator);
20 +
19 21 input.addChangeHandler(new ChangeHandler() {
20 22 @Override
21 23 public void onChange(ChangeEvent event) {
  @@ -27,31 +29,53 @@
27 29 }
28 30 });
29 31
30 - button.addClickHandler(new ClickHandler() {
31 - public void onClick(ClickEvent event) {
32 - input.setValue(input.getValue() + "!");
33 - System.out.println("Clicked!");
32 + validator.addChangeHandler(new ChangeHandler() {
33 + @Override
34 + public void onChange(ChangeEvent event) {
35 + String value = input.getValue();
36 + System.out.println("Valid: '" + value + "' | "+ validator.getErrorData() );
34 37 }
35 38 });
36 39
37 - VerticalPanel zVPanel = new VerticalPanel();
38 - zVPanel.add(field);
39 - zVPanel.add(errorLabel);
40 40
41 - HorizontalPanel zHPanel = new HorizontalPanel();
42 - zHPanel.add(fieldLabel);
43 - zHPanel.add(new HTML("&nbsp;&nbsp;"));
44 - zHPanel.add(zVPanel);
45 - zHPanel.add(new HTML("&nbsp;"));
46 - zHPanel.add(stateLabel);
47 41
48 - zVPanel = new VerticalPanel();
42 + validator.addValidators(RequiredValueValidator.INSTANCE, //
43 + AlphaNumericUnderScore7bitAsciiValueValidator.INSTANCE);
44 +
45 + Button buttonSetValue = new Button("Set Value", new ClickHandler() {
46 + public void onClick(ClickEvent event) {
47 + input.setValue(input.getValue());
48 + System.out.println("Set Value!");
49 + }
50 + });
51 + Button buttonSetValueAsUser = new Button("User Set Value", new ClickHandler() {
52 + public void onClick(ClickEvent event) {
53 + input.setValueAsUser(input.getValue() + "!");
54 + System.out.println("User Set Value!");
55 + }
56 + });
57 +
58 + VerticalPanel zFieldErrorPanel = new VerticalPanel();
59 + zFieldErrorPanel.add(field);
60 + zFieldErrorPanel.add(errorLabel);
61 +
62 + VerticalPanel zVPanel = new VerticalPanel();
49 63 zVPanel.add(new HTML("&nbsp;"));
50 - zVPanel.add(zHPanel);
64 + zVPanel.add(horizontalWithSpacers(fieldLabel, zFieldErrorPanel, stateLabel));
51 65 zVPanel.add(new HTML("&nbsp;"));
52 - zVPanel.add(button);
66 + zVPanel.add(horizontalWithSpacers(buttonSetValue, buttonSetValueAsUser));
53 67
54 68 RootPanel zRootPanel = RootPanel.get("centeredWidget");
55 69 zRootPanel.add(zVPanel);
56 70 }
71 +
72 + private HorizontalPanel horizontalWithSpacers(Widget... widgets) {
73 + HorizontalPanel zPanel = new HorizontalPanel();
74 + zPanel.add(widgets[0]);
75 + for (int i = 1; i < widgets.length; i++) {
76 + zPanel.add(new HTML("&nbsp;&nbsp;"));
77 + zPanel.add(widgets[i]);
78 + }
79 + return zPanel;
80 + }
57 81 }