Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java @ 1:0e22a19852e7
Removed useless auto generated classes and added first ui elements with i18n support.
flys-client/trunk@1306 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 09 Feb 2011 09:59:27 +0000 |
parents | 4e8be5e7855f |
children | bc5d4d2297b9 |
comparison
equal
deleted
inserted
replaced
0:4e8be5e7855f | 1:0e22a19852e7 |
---|---|
1 package de.intevation.flys.client.client; | 1 package de.intevation.flys.client.client; |
2 | 2 |
3 import de.intevation.flys.client.shared.FieldVerifier; | |
4 import com.google.gwt.core.client.EntryPoint; | 3 import com.google.gwt.core.client.EntryPoint; |
5 import com.google.gwt.core.client.GWT; | |
6 import com.google.gwt.event.dom.client.ClickEvent; | |
7 import com.google.gwt.event.dom.client.ClickHandler; | |
8 import com.google.gwt.event.dom.client.KeyCodes; | |
9 import com.google.gwt.event.dom.client.KeyUpEvent; | |
10 import com.google.gwt.event.dom.client.KeyUpHandler; | |
11 import com.google.gwt.user.client.rpc.AsyncCallback; | |
12 import com.google.gwt.user.client.ui.Button; | |
13 import com.google.gwt.user.client.ui.DialogBox; | |
14 import com.google.gwt.user.client.ui.HTML; | |
15 import com.google.gwt.user.client.ui.Label; | |
16 import com.google.gwt.user.client.ui.RootPanel; | 4 import com.google.gwt.user.client.ui.RootPanel; |
17 import com.google.gwt.user.client.ui.TextBox; | 5 |
18 import com.google.gwt.user.client.ui.VerticalPanel; | 6 import com.smartgwt.client.widgets.layout.VLayout; |
7 | |
8 import de.intevation.flys.client.client.ui.FLYSView; | |
9 import de.intevation.flys.client.client.ui.MainMenu; | |
10 | |
19 | 11 |
20 /** | 12 /** |
21 * Entry point classes define <code>onModuleLoad()</code>. | 13 * Entry point classes define <code>onModuleLoad()</code>. |
14 * | |
15 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
22 */ | 16 */ |
23 public class FLYS implements EntryPoint { | 17 public class FLYS implements EntryPoint { |
24 /** | |
25 * The message displayed to the user when the server cannot be reached or | |
26 * returns an error. | |
27 */ | |
28 private static final String SERVER_ERROR = "An error occurred while " | |
29 + "attempting to contact the server. Please check your network " | |
30 + "connection and try again."; | |
31 | 18 |
32 /** | 19 /** |
33 * Create a remote service proxy to talk to the server-side Greeting service. | 20 * This is the entry point method. |
34 */ | 21 */ |
35 private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class); | 22 public void onModuleLoad() { |
36 | 23 |
37 /** | 24 VLayout vertical = new VLayout(); |
38 * This is the entry point method. | 25 vertical.setMembersMargin(5); |
39 */ | 26 vertical.setLayoutMargin(1); |
40 public void onModuleLoad() { | 27 vertical.setWidth100(); |
41 final Button sendButton = new Button("Send"); | 28 vertical.setHeight100(); |
42 final TextBox nameField = new TextBox(); | |
43 nameField.setText("GWT User"); | |
44 final Label errorLabel = new Label(); | |
45 | 29 |
46 // We can add style names to widgets | 30 MainMenu menu = new MainMenu(); |
47 sendButton.addStyleName("sendButton"); | 31 FLYSView view = new FLYSView(); |
48 | 32 |
49 // Add the nameField and sendButton to the RootPanel | 33 vertical.addMember(menu); |
50 // Use RootPanel.get() to get the entire body element | 34 vertical.addMember(view); |
51 RootPanel.get("nameFieldContainer").add(nameField); | |
52 RootPanel.get("sendButtonContainer").add(sendButton); | |
53 RootPanel.get("errorLabelContainer").add(errorLabel); | |
54 | 35 |
55 // Focus the cursor on the name field when the app loads | 36 RootPanel.get("app").add(vertical); |
56 nameField.setFocus(true); | |
57 nameField.selectAll(); | |
58 | |
59 // Create the popup dialog box | |
60 final DialogBox dialogBox = new DialogBox(); | |
61 dialogBox.setText("Remote Procedure Call"); | |
62 dialogBox.setAnimationEnabled(true); | |
63 final Button closeButton = new Button("Close"); | |
64 // We can set the id of a widget by accessing its Element | |
65 closeButton.getElement().setId("closeButton"); | |
66 final Label textToServerLabel = new Label(); | |
67 final HTML serverResponseLabel = new HTML(); | |
68 VerticalPanel dialogVPanel = new VerticalPanel(); | |
69 dialogVPanel.addStyleName("dialogVPanel"); | |
70 dialogVPanel.add(new HTML("<b>Sending name to the server:</b>")); | |
71 dialogVPanel.add(textToServerLabel); | |
72 dialogVPanel.add(new HTML("<br><b>Server replies:</b>")); | |
73 dialogVPanel.add(serverResponseLabel); | |
74 dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); | |
75 dialogVPanel.add(closeButton); | |
76 dialogBox.setWidget(dialogVPanel); | |
77 | |
78 // Add a handler to close the DialogBox | |
79 closeButton.addClickHandler(new ClickHandler() { | |
80 public void onClick(ClickEvent event) { | |
81 dialogBox.hide(); | |
82 sendButton.setEnabled(true); | |
83 sendButton.setFocus(true); | |
84 } | |
85 }); | |
86 | |
87 // Create a handler for the sendButton and nameField | |
88 class MyHandler implements ClickHandler, KeyUpHandler { | |
89 /** | |
90 * Fired when the user clicks on the sendButton. | |
91 */ | |
92 public void onClick(ClickEvent event) { | |
93 sendNameToServer(); | |
94 } | |
95 | |
96 /** | |
97 * Fired when the user types in the nameField. | |
98 */ | |
99 public void onKeyUp(KeyUpEvent event) { | |
100 if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { | |
101 sendNameToServer(); | |
102 } | |
103 } | |
104 | |
105 /** | |
106 * Send the name from the nameField to the server and wait for a response. | |
107 */ | |
108 private void sendNameToServer() { | |
109 // First, we validate the input. | |
110 errorLabel.setText(""); | |
111 String textToServer = nameField.getText(); | |
112 if (!FieldVerifier.isValidName(textToServer)) { | |
113 errorLabel.setText("Please enter at least four characters"); | |
114 return; | |
115 } | |
116 | |
117 // Then, we send the input to the server. | |
118 sendButton.setEnabled(false); | |
119 textToServerLabel.setText(textToServer); | |
120 serverResponseLabel.setText(""); | |
121 greetingService.greetServer(textToServer, new AsyncCallback<String>() { | |
122 public void onFailure(Throwable caught) { | |
123 // Show the RPC error message to the user | |
124 dialogBox.setText("Remote Procedure Call - Failure"); | |
125 serverResponseLabel.addStyleName("serverResponseLabelError"); | |
126 serverResponseLabel.setHTML(SERVER_ERROR); | |
127 dialogBox.center(); | |
128 closeButton.setFocus(true); | |
129 } | |
130 | |
131 public void onSuccess(String result) { | |
132 dialogBox.setText("Remote Procedure Call"); | |
133 serverResponseLabel.removeStyleName("serverResponseLabelError"); | |
134 serverResponseLabel.setHTML(result); | |
135 dialogBox.center(); | |
136 closeButton.setFocus(true); | |
137 } | |
138 }); | |
139 } | |
140 } | 37 } |
141 | |
142 // Add a handler to send the name to the server | |
143 MyHandler handler = new MyHandler(); | |
144 sendButton.addClickHandler(handler); | |
145 nameField.addKeyUpHandler(handler); | |
146 } | |
147 } | 38 } |
39 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |