ingo@1: package de.intevation.flys.client.client.ui; ingo@1: ingo@1: import com.google.gwt.core.client.GWT; ingo@1: ingo@6: import com.smartgwt.client.widgets.Button; ingo@6: import com.smartgwt.client.widgets.Canvas; ingo@1: import com.smartgwt.client.widgets.Label; ingo@6: import com.smartgwt.client.widgets.events.ClickEvent; ingo@6: import com.smartgwt.client.widgets.events.ClickHandler; ingo@1: import com.smartgwt.client.widgets.layout.HLayout; ingo@1: ingo@2: import de.intevation.artifacts.common.model.User; ingo@2: ingo@6: import de.intevation.flys.client.client.FLYS; 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@6: /** An instance to FLYS.*/ ingo@6: protected FLYS flys; ingo@6: 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@6: /** The button to add new projects.*/ ingo@6: protected Button newCollection; ingo@6: ingo@1: /** ingo@1: * The default constructor for creating a new MainMenu. ingo@1: */ ingo@6: public MainMenu(FLYS flys) { ingo@6: this.flys = flys; ingo@6: ingo@6: userText = new Label(messages.user(messages.guest())); ingo@6: titleText = new Label(messages.title()); ingo@6: newCollection = new Button(messages.new_project()); ingo@6: ingo@6: newCollection.addClickHandler(new ClickHandler() { ingo@6: public void onClick(ClickEvent event) { ingo@6: GWT.log("Clicked 'New Project' button."); ingo@6: createNewProject(); ingo@6: } ingo@6: }); 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@6: setWidth100(); ingo@6: setHeight("40px"); ingo@1: setBorder("1px solid #808080"); ingo@1: setBackgroundColor("#C3D9FF"); ingo@6: setLayoutMargin(10); ingo@1: ingo@6: titleText.setWidth("7%"); ingo@6: ingo@6: Canvas buttonWrapper = new Canvas(); ingo@6: buttonWrapper.setWidth("*"); ingo@6: buttonWrapper.addChild(newCollection); ingo@6: ingo@6: userText.setWidth("20%"); ingo@2: ingo@2: addMember(titleText); ingo@6: addMember(buttonWrapper); 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@6: ingo@6: ingo@6: /** ingo@6: * Create a new project by calling FLYS.newProject(). ingo@6: */ ingo@6: protected void createNewProject() { ingo@6: flys.newProject(); ingo@6: } ingo@1: } ingo@1: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :