changeset 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
files flys-client/pom.xml flys-client/src/main/java/de/intevation/flys/client/FLYS.gwt.xml flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/FLYSView.java flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java flys-client/src/main/java/de/intevation/flys/client/server/GreetingServiceImpl.java flys-client/src/main/webapp/FLYS.html flys-client/src/main/webapp/WEB-INF/web.xml flys-client/src/test/java/de/intevation/flys/client/client/FLYSTest.java
diffstat 12 files changed, 146 insertions(+), 281 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/pom.xml	Tue Feb 08 10:29:49 2011 +0000
+++ b/flys-client/pom.xml	Wed Feb 09 09:59:27 2011 +0000
@@ -38,6 +38,11 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>com.smartgwt</groupId>
+      <artifactId>smartgwt</artifactId>
+      <version>2.4</version>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.4</version>
--- a/flys-client/src/main/java/de/intevation/flys/client/FLYS.gwt.xml	Tue Feb 08 10:29:49 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/FLYS.gwt.xml	Wed Feb 09 09:59:27 2011 +0000
@@ -3,6 +3,12 @@
   <!-- Inherit the core Web Toolkit stuff.                        -->
   <inherits name='com.google.gwt.user.User'/>
 
+  <!-- Inherit the i18n google stuff.                             -->
+  <inherits name="com.google.gwt.i18n.I18N"/>
+
+  <!-- Inherit the SmartGwt library.                              -->
+  <inherits name="com.smartgwt.SmartGwt"/>
+
   <!-- Inherit the default GWT style sheet.  You can change       -->
   <!-- the theme of your GWT application by uncommenting          -->
   <!-- any one of the following lines.                            -->
@@ -19,4 +25,5 @@
   <source path='client'/>
   <source path='shared'/>
 
+  <extend-property name="locale" values="de,en"/>
 </module>
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Tue Feb 08 10:29:49 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Wed Feb 09 09:59:27 2011 +0000
@@ -1,147 +1,39 @@
 package de.intevation.flys.client.client;
 
-import de.intevation.flys.client.shared.FieldVerifier;
 import com.google.gwt.core.client.EntryPoint;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.event.dom.client.KeyCodes;
-import com.google.gwt.event.dom.client.KeyUpEvent;
-import com.google.gwt.event.dom.client.KeyUpHandler;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.ui.Button;
-import com.google.gwt.user.client.ui.DialogBox;
-import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.Label;
 import com.google.gwt.user.client.ui.RootPanel;
-import com.google.gwt.user.client.ui.TextBox;
-import com.google.gwt.user.client.ui.VerticalPanel;
+
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import de.intevation.flys.client.client.ui.FLYSView;
+import de.intevation.flys.client.client.ui.MainMenu;
+
 
 /**
  * Entry point classes define <code>onModuleLoad()</code>.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public class FLYS implements EntryPoint {
-  /**
-   * The message displayed to the user when the server cannot be reached or
-   * returns an error.
-   */
-  private static final String SERVER_ERROR = "An error occurred while "
-      + "attempting to contact the server. Please check your network "
-      + "connection and try again.";
-
-  /**
-   * Create a remote service proxy to talk to the server-side Greeting service.
-   */
-  private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
-
-  /**
-   * This is the entry point method.
-   */
-  public void onModuleLoad() {
-    final Button sendButton = new Button("Send");
-    final TextBox nameField = new TextBox();
-    nameField.setText("GWT User");
-    final Label errorLabel = new Label();
-
-    // We can add style names to widgets
-    sendButton.addStyleName("sendButton");
-
-    // Add the nameField and sendButton to the RootPanel
-    // Use RootPanel.get() to get the entire body element
-    RootPanel.get("nameFieldContainer").add(nameField);
-    RootPanel.get("sendButtonContainer").add(sendButton);
-    RootPanel.get("errorLabelContainer").add(errorLabel);
-
-    // Focus the cursor on the name field when the app loads
-    nameField.setFocus(true);
-    nameField.selectAll();
-
-    // Create the popup dialog box
-    final DialogBox dialogBox = new DialogBox();
-    dialogBox.setText("Remote Procedure Call");
-    dialogBox.setAnimationEnabled(true);
-    final Button closeButton = new Button("Close");
-    // We can set the id of a widget by accessing its Element
-    closeButton.getElement().setId("closeButton");
-    final Label textToServerLabel = new Label();
-    final HTML serverResponseLabel = new HTML();
-    VerticalPanel dialogVPanel = new VerticalPanel();
-    dialogVPanel.addStyleName("dialogVPanel");
-    dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
-    dialogVPanel.add(textToServerLabel);
-    dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
-    dialogVPanel.add(serverResponseLabel);
-    dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
-    dialogVPanel.add(closeButton);
-    dialogBox.setWidget(dialogVPanel);
 
-    // Add a handler to close the DialogBox
-    closeButton.addClickHandler(new ClickHandler() {
-      public void onClick(ClickEvent event) {
-        dialogBox.hide();
-        sendButton.setEnabled(true);
-        sendButton.setFocus(true);
-      }
-    });
-
-    // Create a handler for the sendButton and nameField
-    class MyHandler implements ClickHandler, KeyUpHandler {
-      /**
-       * Fired when the user clicks on the sendButton.
-       */
-      public void onClick(ClickEvent event) {
-        sendNameToServer();
-      }
-
-      /**
-       * Fired when the user types in the nameField.
-       */
-      public void onKeyUp(KeyUpEvent event) {
-        if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
-          sendNameToServer();
-        }
-      }
+    /**
+     * This is the entry point method.
+     */
+    public void onModuleLoad() {
 
-      /**
-       * Send the name from the nameField to the server and wait for a response.
-       */
-      private void sendNameToServer() {
-        // First, we validate the input.
-        errorLabel.setText("");
-        String textToServer = nameField.getText();
-        if (!FieldVerifier.isValidName(textToServer)) {
-          errorLabel.setText("Please enter at least four characters");
-          return;
-        }
-        
-        // Then, we send the input to the server.
-        sendButton.setEnabled(false);
-        textToServerLabel.setText(textToServer);
-        serverResponseLabel.setText("");
-        greetingService.greetServer(textToServer, new AsyncCallback<String>() {
-          public void onFailure(Throwable caught) {
-            // Show the RPC error message to the user
-            dialogBox.setText("Remote Procedure Call - Failure");
-            serverResponseLabel.addStyleName("serverResponseLabelError");
-            serverResponseLabel.setHTML(SERVER_ERROR);
-            dialogBox.center();
-            closeButton.setFocus(true);
-          }
+        VLayout vertical = new VLayout();
+        vertical.setMembersMargin(5);
+        vertical.setLayoutMargin(1);
+        vertical.setWidth100();
+        vertical.setHeight100();
 
-          public void onSuccess(String result) {
-            dialogBox.setText("Remote Procedure Call");
-            serverResponseLabel.removeStyleName("serverResponseLabelError");
-            serverResponseLabel.setHTML(result);
-            dialogBox.center();
-            closeButton.setFocus(true);
-          }
-        });
-      }
+        MainMenu menu = new MainMenu();
+        FLYSView view = new FLYSView();
+
+        vertical.addMember(menu);
+        vertical.addMember(view);
+
+        RootPanel.get("app").add(vertical);
     }
-
-    // Add a handler to send the name to the server
-    MyHandler handler = new MyHandler();
-    sendButton.addClickHandler(handler);
-    nameField.addKeyUpHandler(handler);
-  }
 }
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages.java	Wed Feb 09 09:59:27 2011 +0000
@@ -0,0 +1,17 @@
+package de.intevation.flys.client.client;
+
+import com.google.gwt.i18n.client.Messages;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface FLYSMessages extends Messages {
+
+    @DefaultMessage("FLYS-3.0")
+    String title();
+
+    @DefaultMessage("Hello '{0}'")
+    String greeting(String user);
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties	Wed Feb 09 09:59:27 2011 +0000
@@ -0,0 +1,2 @@
+title = FLYS-3.0
+greeting = Hallo ''{0}''
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties	Wed Feb 09 09:59:27 2011 +0000
@@ -0,0 +1,2 @@
+title = FLYS-3.0
+greeting = Hello ''{0}''
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/FLYSView.java	Wed Feb 09 09:59:27 2011 +0000
@@ -0,0 +1,27 @@
+package de.intevation.flys.client.client.ui;
+
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class FLYSView extends Canvas {
+
+    public FLYSView() {
+        init();
+    }
+
+
+    protected void init() {
+        setWidth("100%");
+        setHeight("*");
+
+        setBorder("1px solid #808080");
+        setBackgroundColor("#C3D9FF");
+
+        addChild(new Label("Hello Content!"));
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java	Wed Feb 09 09:59:27 2011 +0000
@@ -0,0 +1,38 @@
+package de.intevation.flys.client.client.ui;
+
+import com.google.gwt.core.client.GWT;
+
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.layout.HLayout;
+
+import de.intevation.flys.client.client.FLYSMessages;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class MainMenu extends HLayout {
+
+    /** The interface that provides i18n messages. */
+    private FLYSMessages messages = GWT.create(FLYSMessages.class);
+
+    /**
+     * The default constructor for creating a new MainMenu.
+     */
+    public MainMenu() {
+        init();
+    }
+
+
+    protected void init() {
+        setWidth("100%");
+        setHeight("50");
+
+        setBorder("1px solid #808080");
+        setBackgroundColor("#C3D9FF");
+
+        addMember(new Label(messages.title()));
+        addMember(new Label(messages.greeting("GAST")));
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/GreetingServiceImpl.java	Tue Feb 08 10:29:49 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-package de.intevation.flys.client.server;
-
-import de.intevation.flys.client.client.GreetingService;
-import de.intevation.flys.client.shared.FieldVerifier;
-import com.google.gwt.user.server.rpc.RemoteServiceServlet;
-
-/**
- * The server side implementation of the RPC service.
- */
-@SuppressWarnings("serial")
-public class GreetingServiceImpl extends RemoteServiceServlet implements
-    GreetingService {
-
-  public String greetServer(String input) throws IllegalArgumentException {
-    // Verify that the input is valid. 
-    if (!FieldVerifier.isValidName(input)) {
-      // If the input is not valid, throw an IllegalArgumentException back to
-      // the client.
-      throw new IllegalArgumentException(
-          "Name must be at least 4 characters long");
-    }
-
-    String serverInfo = getServletContext().getServerInfo();
-    String userAgent = getThreadLocalRequest().getHeader("User-Agent");
-
-    // Escape data from the client to avoid cross-site script vulnerabilities.
-    input = escapeHtml(input);
-    userAgent = escapeHtml(userAgent);
-
-    return "Hello, " + input + "!<br><br>I am running " + serverInfo
-        + ".<br><br>It looks like you are using:<br>" + userAgent;
-  }
-
-  /**
-   * Escape an html string. Escaping data received from the client helps to
-   * prevent cross-site script vulnerabilities.
-   * 
-   * @param html the html string to escape
-   * @return the escaped string
-   */
-  private String escapeHtml(String html) {
-    if (html == null) {
-      return null;
-    }
-    return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(
-        ">", "&gt;");
-  }
-}
--- a/flys-client/src/main/webapp/FLYS.html	Tue Feb 08 10:29:49 2011 +0000
+++ b/flys-client/src/main/webapp/FLYS.html	Wed Feb 09 09:59:27 2011 +0000
@@ -9,6 +9,8 @@
   <head>
     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
 
+    <meta name="gwt:property" content="locale=de">
+
     <!--                                                               -->
     <!-- Consider inlining CSS to reduce the number of requested files -->
     <!--                                                               -->
@@ -27,37 +29,24 @@
     <script type="text/javascript" language="javascript" src="flys/flys.nocache.js"></script>
   </head>
 
-  <!--                                           -->
-  <!-- The body can have arbitrary html, or      -->
-  <!-- you can leave the body empty if you want  -->
-  <!-- to create a completely dynamic UI.        -->
-  <!--                                           -->
-  <body>
+    <!--                                           -->
+    <!-- The body can have arbitrary html, or      -->
+    <!-- you can leave the body empty if you want  -->
+    <!-- to create a completely dynamic UI.        -->
+    <!--                                           -->
+    <body>
 
-    <!-- OPTIONAL: include this if you want history support -->
-    <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
-    
-    <!-- RECOMMENDED if your web app will not function without JavaScript enabled -->
-    <noscript>
-      <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
-        Your web browser must have JavaScript enabled
-        in order for this application to display correctly.
-      </div>
-    </noscript>
-
-    <h1>Web Application Starter Project</h1>
+        <!-- OPTIONAL: include this if you want history support -->
+        <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
 
-    <table align="center">
-      <tr>
-        <td colspan="2" style="font-weight:bold;">Please enter your name:</td>        
-      </tr>
-      <tr>
-        <td id="nameFieldContainer"></td>
-        <td id="sendButtonContainer"></td>
-      </tr>
-      <tr>
-        <td colspan="2" style="color:red;" id="errorLabelContainer"></td>
-      </tr>
-    </table>
-  </body>
+        <!-- RECOMMENDED if your web app will not function without JavaScript enabled -->
+        <noscript>
+            <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
+                Your web browser must have JavaScript enabled
+                in order for this application to display correctly.
+            </div>
+        </noscript>
+
+        <div id="app"></div>
+    </body>
 </html>
--- a/flys-client/src/main/webapp/WEB-INF/web.xml	Tue Feb 08 10:29:49 2011 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/web.xml	Wed Feb 09 09:59:27 2011 +0000
@@ -6,6 +6,7 @@
 <web-app>
   
   <!-- Servlets -->
+  <!--
   <servlet>
     <servlet-name>greetServlet</servlet-name>
     <servlet-class>de.intevation.flys.client.server.GreetingServiceImpl</servlet-class>
@@ -15,7 +16,8 @@
     <servlet-name>greetServlet</servlet-name>
     <url-pattern>/flys/greet</url-pattern>
   </servlet-mapping>
-  
+  -->
+
   <!-- Default page to serve -->
   <welcome-file-list>
     <welcome-file>FLYS.html</welcome-file>
--- a/flys-client/src/test/java/de/intevation/flys/client/client/FLYSTest.java	Tue Feb 08 10:29:49 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-package de.intevation.flys.client.client;
-
-import de.intevation.flys.client.shared.FieldVerifier;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.junit.client.GWTTestCase;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.rpc.ServiceDefTarget;
-
-/**
- * GWT JUnit tests must extend GWTTestCase.
- */
-public class FLYSTest extends GWTTestCase {
-
-  /**
-   * Must refer to a valid module that sources this class.
-   */
-  public String getModuleName() {
-    return "de.intevation.flys.client.FLYSJUnit";
-  }
-
-  /**
-   * Tests the FieldVerifier.
-   */
-  public void testFieldVerifier() {
-    assertFalse(FieldVerifier.isValidName(null));
-    assertFalse(FieldVerifier.isValidName(""));
-    assertFalse(FieldVerifier.isValidName("a"));
-    assertFalse(FieldVerifier.isValidName("ab"));
-    assertFalse(FieldVerifier.isValidName("abc"));
-    assertTrue(FieldVerifier.isValidName("abcd"));
-  }
-
-  /**
-   * This test will send a request to the server using the greetServer method in
-   * GreetingService and verify the response.
-   */
-  public void testGreetingService() {
-    // Create the service that we will test.
-    GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
-    ServiceDefTarget target = (ServiceDefTarget) greetingService;
-    target.setServiceEntryPoint(GWT.getModuleBaseURL() + "flys/greet");
-
-    // Since RPC calls are asynchronous, we will need to wait for a response
-    // after this test method returns. This line tells the test runner to wait
-    // up to 10 seconds before timing out.
-    delayTestFinish(10000);
-
-    // Send a request to the server.
-    greetingService.greetServer("GWT User", new AsyncCallback<String>() {
-      public void onFailure(Throwable caught) {
-        // The request resulted in an unexpected error.
-        fail("Request failure: " + caught.getMessage());
-      }
-
-      public void onSuccess(String result) {
-        // Verify that the response is correct.
-        assertTrue(result.startsWith("Hello, GWT User!"));
-
-        // Now that we have received a response, we need to tell the test runner
-        // that the test is complete. You must call finishTest() after an
-        // asynchronous test finishes successfully, or the test will time out.
-        finishTest();
-      }
-    });
-  }
-
-
-}

http://dive4elements.wald.intevation.org