ingo@1: package de.intevation.flys.client.client.ui; ingo@1: ingo@1: import com.google.gwt.core.client.GWT; ingo@1: ingo@1: import com.smartgwt.client.widgets.Label; ingo@1: import com.smartgwt.client.widgets.layout.HLayout; ingo@1: ingo@2: import de.intevation.artifacts.common.model.User; ingo@2: ingo@1: import de.intevation.flys.client.client.FLYSMessages; ingo@1: ingo@1: ingo@1: /** ingo@1: * @author Ingo Weinzierl ingo@1: */ ingo@1: public class MainMenu extends HLayout { ingo@1: ingo@1: /** The interface that provides i18n messages. */ ingo@1: private FLYSMessages messages = GWT.create(FLYSMessages.class); ingo@1: ingo@2: /** The user that is currently logged in. */ ingo@2: protected User currentUser; ingo@2: ingo@2: /** The label that displays the current logged in user. */ ingo@2: protected Label userText; ingo@2: ingo@2: /** The label that displays the title of the application. */ ingo@2: protected Label titleText; ingo@2: ingo@1: /** ingo@1: * The default constructor for creating a new MainMenu. ingo@1: */ ingo@1: public MainMenu() { ingo@2: userText = new Label(messages.user(messages.guest())); ingo@2: titleText = new Label(messages.title()); ingo@2: ingo@1: init(); ingo@1: } ingo@1: ingo@1: ingo@2: /** ingo@2: * This method is called by the constructor after creating the necessary ingo@2: * components. It initializes layout specific stuff like width, height, ingo@2: * colors and so on and appends the components. ingo@2: */ ingo@1: protected void init() { ingo@1: setWidth("100%"); ingo@1: setHeight("50"); ingo@1: setBorder("1px solid #808080"); ingo@1: setBackgroundColor("#C3D9FF"); ingo@1: ingo@2: titleText.setWidth("60%"); ingo@2: ingo@2: addMember(titleText); ingo@2: addMember(userText); ingo@2: } ingo@2: ingo@2: ingo@2: /** ingo@2: * Set the current {@link User} and call {@link updateCurrentUser()} ingo@2: * afterwards. ingo@2: * ingo@2: * @param user the new user. ingo@2: */ ingo@2: public void setCurrentUser(User currentUser) { ingo@2: this.currentUser = currentUser; ingo@2: ingo@2: updateCurrentUser(); ingo@2: } ingo@2: ingo@2: ingo@2: /** ingo@2: * Update the text field that shows the current user. If no user is ingo@2: * currently logged in, the text will display {@link FLYSMessages.guest()}. ingo@2: */ ingo@2: public void updateCurrentUser() { ingo@2: String name = currentUser != null ingo@2: ? currentUser.getLastName() + ", " + currentUser.getFirstName() ingo@2: : messages.guest(); ingo@2: ingo@2: GWT.log("Update the current user: " + name); ingo@2: userText.setContents(messages.user(name)); ingo@1: } ingo@1: } ingo@1: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :