changeset 2:bc5d4d2297b9

Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar. flys-client/trunk@1309 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 10 Feb 2011 08:57:34 +0000
parents 0e22a19852e7
children 9cf5a40b62c7
files flys-client/ChangeLog 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/services/UserService.java flys-client/src/main/java/de/intevation/flys/client/client/services/UserServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java flys-client/src/main/webapp/WEB-INF/web.xml
diffstat 12 files changed, 192 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/ChangeLog	Thu Feb 10 08:57:34 2011 +0000
@@ -0,0 +1,28 @@
+2011-02-10  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/FLYS.gwt.xml: The artifact-common
+	  package is available in the GWT code now.
+
+	* pom.xml: Made the artifact-common package available.
+
+	* src/main/java/de/intevation/flys/client/server/UserServiceImpl.java,
+	  src/main/java/de/intevation/flys/client/client/services/UserService.java,
+	  src/main/java/de/intevation/flys/client/client/services/UserServiceAsync.java:
+	  A service definition that retrieves user information. Currently, this
+	  service defines a single method that returns the user that is currently
+	  logged in.
+
+	* src/main/webapp/WEB-INF/web.xml: Added a servlet definition that provides
+	  the UserService.
+
+	* src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSMessages.java: Added
+	  I18N string for a guest user.
+
+	* src/main/java/de/intevation/flys/client/client/ui/MainMenu.java: There are
+	  new methods to set the current user and to update the menu with its name.
+
+	* src/main/java/de/intevation/flys/client/client/FLYS.java: After creating
+	  the necessary components, the current user is queried by the UserService
+	  and displayed in the menu bar.
--- a/flys-client/pom.xml	Wed Feb 09 09:59:27 2011 +0000
+++ b/flys-client/pom.xml	Thu Feb 10 08:57:34 2011 +0000
@@ -43,6 +43,11 @@
       <version>2.4</version>
     </dependency>
     <dependency>
+      <groupId>de.intevation.artifacts.common</groupId>
+      <artifactId>artifacts-common</artifactId>
+      <version>1.0-SNAPSHOT</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	Wed Feb 09 09:59:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/FLYS.gwt.xml	Thu Feb 10 08:57:34 2011 +0000
@@ -9,6 +9,8 @@
   <!-- Inherit the SmartGwt library.                              -->
   <inherits name="com.smartgwt.SmartGwt"/>
 
+  <inherits name="de.intevation.artifacts.common.Common"/>
+
   <!-- Inherit the default GWT style sheet.  You can change       -->
   <!-- the theme of your GWT application by uncommenting          -->
   <!-- any one of the following lines.                            -->
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Wed Feb 09 09:59:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Thu Feb 10 08:57:34 2011 +0000
@@ -1,10 +1,16 @@
 package de.intevation.flys.client.client;
 
 import com.google.gwt.core.client.EntryPoint;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.user.client.ui.RootPanel;
 
 import com.smartgwt.client.widgets.layout.VLayout;
 
+import de.intevation.artifacts.common.model.User;
+
+import de.intevation.flys.client.client.services.UserService;
+import de.intevation.flys.client.client.services.UserServiceAsync;
 import de.intevation.flys.client.client.ui.FLYSView;
 import de.intevation.flys.client.client.ui.MainMenu;
 
@@ -16,24 +22,43 @@
  */
 public class FLYS implements EntryPoint {
 
+    /** The UserService used to retrieve information about the current user. */
+    protected UserServiceAsync userService = GWT.create(UserService.class);
+
+    protected MainMenu menu;
+    protected FLYSView view;
+
+
     /**
      * This is the entry point method.
      */
     public void onModuleLoad() {
 
         VLayout vertical = new VLayout();
-        vertical.setMembersMargin(5);
+        vertical.setMembersMargin(2);
         vertical.setLayoutMargin(1);
         vertical.setWidth100();
         vertical.setHeight100();
 
-        MainMenu menu = new MainMenu();
-        FLYSView view = new FLYSView();
+        menu = new MainMenu();
+        view = new FLYSView();
 
         vertical.addMember(menu);
         vertical.addMember(view);
 
         RootPanel.get("app").add(vertical);
+
+        userService.getCurrentUser(new AsyncCallback<User>() {
+            public void onFailure(Throwable caught) {
+                GWT.log("Could not find a logged in user.");
+                // TODO do something
+            }
+
+            public void onSuccess(User user) {
+                GWT.log("Found a user. Set '"+ user.getLastName()+"'");
+                menu.setCurrentUser(user);
+            }
+        });
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages.java	Wed Feb 09 09:59:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages.java	Thu Feb 10 08:57:34 2011 +0000
@@ -11,7 +11,10 @@
     @DefaultMessage("FLYS-3.0")
     String title();
 
-    @DefaultMessage("Hello '{0}'")
-    String greeting(String user);
+    @DefaultMessage("User: ''{0}''")
+    String user(String user);
+
+    @DefaultMessage("guest")
+    String guest();
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties	Wed Feb 09 09:59:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties	Thu Feb 10 08:57:34 2011 +0000
@@ -1,2 +1,3 @@
 title = FLYS-3.0
-greeting = Hallo ''{0}''
+user = Benutzer: ''{0}''
+guest = Gast
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties	Wed Feb 09 09:59:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties	Thu Feb 10 08:57:34 2011 +0000
@@ -1,2 +1,3 @@
 title = FLYS-3.0
-greeting = Hello ''{0}''
+user = User: ''{0}''
+guest = guest
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/UserService.java	Thu Feb 10 08:57:34 2011 +0000
@@ -0,0 +1,24 @@
+package de.intevation.flys.client.client.services;
+
+import com.google.gwt.user.client.rpc.RemoteService;
+import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
+
+import de.intevation.artifacts.common.model.User;
+
+
+/**
+ * This interface describes services for the user.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+@RemoteServiceRelativePath("user")
+public interface UserService extends RemoteService {
+
+    /**
+     * This method retrieves the user that is currently logged in.
+     *
+     * @return the current {@link User}.
+     */
+    User getCurrentUser();
+}
+// 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/services/UserServiceAsync.java	Thu Feb 10 08:57:34 2011 +0000
@@ -0,0 +1,17 @@
+package de.intevation.flys.client.client.services;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+import de.intevation.artifacts.common.model.User;
+
+
+/**
+ * This interface describes services for the user.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface UserServiceAsync {
+
+    void getCurrentUser(AsyncCallback<User> callback);
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java	Wed Feb 09 09:59:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java	Thu Feb 10 08:57:34 2011 +0000
@@ -5,6 +5,8 @@
 import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.layout.HLayout;
 
+import de.intevation.artifacts.common.model.User;
+
 import de.intevation.flys.client.client.FLYSMessages;
 
 
@@ -16,23 +18,68 @@
     /** The interface that provides i18n messages. */
     private FLYSMessages messages = GWT.create(FLYSMessages.class);
 
+    /** The user that is currently logged in. */
+    protected User currentUser;
+
+    /** The label that displays the current logged in user. */
+    protected Label userText;
+
+    /** The label that displays the title of the application. */
+    protected Label titleText;
+
     /**
      * The default constructor for creating a new MainMenu.
      */
     public MainMenu() {
+        userText  = new Label(messages.user(messages.guest()));
+        titleText = new Label(messages.title());
+
         init();
     }
 
 
+    /**
+     * This method is called by the constructor after creating the necessary
+     * components. It initializes layout specific stuff like width, height,
+     * colors and so on and appends the components.
+     */
     protected void init() {
         setWidth("100%");
         setHeight("50");
-
         setBorder("1px solid #808080");
         setBackgroundColor("#C3D9FF");
 
-        addMember(new Label(messages.title()));
-        addMember(new Label(messages.greeting("GAST")));
+        titleText.setWidth("60%");
+
+        addMember(titleText);
+        addMember(userText);
+    }
+
+
+    /**
+     * Set the current {@link User} and call {@link updateCurrentUser()}
+     * afterwards.
+     *
+     * @param user the new user.
+     */
+    public void setCurrentUser(User currentUser) {
+        this.currentUser = currentUser;
+
+        updateCurrentUser();
+    }
+
+
+    /**
+     * Update the text field that shows the current user. If no user is
+     * currently logged in, the text will display {@link FLYSMessages.guest()}.
+     */
+    public void updateCurrentUser() {
+        String name = currentUser != null
+            ? currentUser.getLastName() + ", " + currentUser.getFirstName()
+            : messages.guest();
+
+        GWT.log("Update the current user: " + name);
+        userText.setContents(messages.user(name));
     }
 }
 // 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/server/UserServiceImpl.java	Thu Feb 10 08:57:34 2011 +0000
@@ -0,0 +1,25 @@
+package de.intevation.flys.client.server;
+
+import com.google.gwt.user.server.rpc.RemoteServiceServlet;
+
+import com.google.gwt.core.client.GWT;
+
+import de.intevation.artifacts.common.model.DefaultUser;
+import de.intevation.artifacts.common.model.User;
+
+import de.intevation.flys.client.client.services.UserService;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class UserServiceImpl
+extends      RemoteServiceServlet
+implements   UserService
+{
+    public User getCurrentUser() {
+        GWT.log("Return the current user 'Max Mustermann'.");
+        return new DefaultUser("Max", "Mustermann");
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml	Wed Feb 09 09:59:27 2011 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/web.xml	Thu Feb 10 08:57:34 2011 +0000
@@ -6,17 +6,15 @@
 <web-app>
   
   <!-- Servlets -->
-  <!--
   <servlet>
-    <servlet-name>greetServlet</servlet-name>
-    <servlet-class>de.intevation.flys.client.server.GreetingServiceImpl</servlet-class>
+    <servlet-name>user</servlet-name>
+    <servlet-class>de.intevation.flys.client.server.UserServiceImpl</servlet-class>
   </servlet>
   
   <servlet-mapping>
-    <servlet-name>greetServlet</servlet-name>
-    <url-pattern>/flys/greet</url-pattern>
+    <servlet-name>user</servlet-name>
+    <url-pattern>/flys/user</url-pattern>
   </servlet-mapping>
-  -->
 
   <!-- Default page to serve -->
   <welcome-file-list>

http://dive4elements.wald.intevation.org