Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java @ 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 | e2b3966b40ca |
line wrap: on
line source
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.artifacts.common.model.User; 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 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"); 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 :