# HG changeset patch # User Ingo Weinzierl # Date 1297328254 0 # Node ID bc5d4d2297b9cb80c1bf488b8eade5a0be0c3171 # Parent 0e22a19852e74f649e6fcd96e534dd636449e53a 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 diff -r 0e22a19852e7 -r bc5d4d2297b9 flys-client/ChangeLog --- /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 + + * 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. diff -r 0e22a19852e7 -r bc5d4d2297b9 flys-client/pom.xml --- 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 @@ 2.4 + de.intevation.artifacts.common + artifacts-common + 1.0-SNAPSHOT + + junit junit 4.4 diff -r 0e22a19852e7 -r bc5d4d2297b9 flys-client/src/main/java/de/intevation/flys/client/FLYS.gwt.xml --- 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 @@ + + diff -r 0e22a19852e7 -r bc5d4d2297b9 flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java --- 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() { + 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 : diff -r 0e22a19852e7 -r bc5d4d2297b9 flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages.java --- 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 : diff -r 0e22a19852e7 -r bc5d4d2297b9 flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties --- 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 diff -r 0e22a19852e7 -r bc5d4d2297b9 flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties --- 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 diff -r 0e22a19852e7 -r bc5d4d2297b9 flys-client/src/main/java/de/intevation/flys/client/client/services/UserService.java --- /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 Ingo Weinzierl + */ +@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 : diff -r 0e22a19852e7 -r bc5d4d2297b9 flys-client/src/main/java/de/intevation/flys/client/client/services/UserServiceAsync.java --- /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 Ingo Weinzierl + */ +public interface UserServiceAsync { + + void getCurrentUser(AsyncCallback callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 0e22a19852e7 -r bc5d4d2297b9 flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java --- 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 : diff -r 0e22a19852e7 -r bc5d4d2297b9 flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java --- /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 Ingo Weinzierl + */ +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 : diff -r 0e22a19852e7 -r bc5d4d2297b9 flys-client/src/main/webapp/WEB-INF/web.xml --- 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 @@ -