ingo@1: package de.intevation.flys.client.client.ui; ingo@1: ingo@1: import com.google.gwt.core.client.GWT; ingo@1: ingo@28: import com.smartgwt.client.types.Alignment; 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@6: import de.intevation.flys.client.client.FLYS; ingo@1: import de.intevation.flys.client.client.FLYSMessages; ingo@25: import de.intevation.flys.client.shared.model.User; 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@28: /** The button to log the current user out.*/ ingo@28: protected Label logout; ingo@2: ingo@6: /** The button to add new projects.*/ ingo@28: protected Label newProject; ingo@28: ingo@28: /** The button to open the project list.*/ ingo@28: protected Label projectList; ingo@28: ingo@28: /** The button to switch between the english and german version.*/ ingo@28: protected Label language; ingo@28: ingo@28: /** The button to open an info panel.*/ ingo@28: protected Label info; 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@28: userText = new Label(messages.user(messages.guest())); ingo@28: newProject = new Label(messages.new_project()); ingo@28: projectList = new Label(messages.manage_projects()); ingo@28: logout = new Label(messages.logout()); ingo@28: language = new Label(messages.switch_language()); ingo@28: info = new Label(messages.info()); ingo@6: ingo@28: newProject.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@28: projectList.addClickHandler(new ClickHandler() { ingo@28: public void onClick(ClickEvent event) { ingo@28: GWT.log("Clicked 'Open ProjectList' button."); raimund@88: ProjectList list = getFlys().getProjectList(); raimund@82: if (getFlys().getProjectList().isVisible()) raimund@88: list.hide(); raimund@82: else raimund@88: list.show(); ingo@28: } ingo@28: }); ingo@28: ingo@28: logout.addClickHandler(new ClickHandler() { ingo@28: public void onClick(ClickEvent event) { ingo@28: GWT.log("Clicked 'logout' button."); ingo@28: GWT.log("IMPLEMENT the 'logout' function."); ingo@28: } ingo@28: }); ingo@28: ingo@28: language.addClickHandler(new ClickHandler() { ingo@28: public void onClick(ClickEvent event) { ingo@28: GWT.log("Clicked 'language' button."); ingo@28: GWT.log("IMPLEMENT the 'switch language' function."); ingo@28: } ingo@28: }); ingo@28: ingo@28: info.addClickHandler(new ClickHandler() { ingo@28: public void onClick(ClickEvent event) { ingo@28: GWT.log("Clicked 'info' button."); ingo@28: GWT.log("IMPLEMENT the 'open info panel' function."); ingo@28: } ingo@28: }); ingo@28: 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() { raimund@66: setStyleName("bgBlueDark"); raimund@66: setHeight("25px"); ingo@28: setLayoutMargin(5); ingo@6: raimund@66: newProject.setStyleName("fontLightSmall"); raimund@66: projectList.setStyleName("fontLightSmall"); raimund@66: userText.setStyleName("fontLightSmall"); raimund@66: newProject.setStyleName("fontLightSmall"); raimund@66: logout.setStyleName("fontLightSmall"); raimund@66: language.setStyleName("fontLightSmall"); raimund@66: info.setStyleName("fontLightSmall"); raimund@66: raimund@66: projectList.setWidth("140px"); raimund@66: ingo@28: HLayout leftPanel = new HLayout(); ingo@28: leftPanel.setWidth("80%"); ingo@28: leftPanel.setMembersMargin(5); ingo@28: leftPanel.addMember(newProject); ingo@28: leftPanel.addMember(projectList); ingo@6: ingo@28: userText.setAlign(Alignment.RIGHT); ingo@28: logout.setAlign(Alignment.RIGHT); ingo@28: info.setAlign(Alignment.RIGHT); ingo@28: language.setAlign(Alignment.RIGHT); ingo@2: ingo@28: userText.setWidth(200); ingo@28: logout.setWidth(70); ingo@28: info.setWidth(40); ingo@28: language.setWidth(70); ingo@28: ingo@28: HLayout rightPanel = new HLayout(); ingo@28: rightPanel.setAlign(Alignment.RIGHT); ingo@28: rightPanel.setMembersMargin(3); ingo@28: rightPanel.setLayoutRightMargin(5); ingo@28: rightPanel.addMember(userText); ingo@28: rightPanel.addMember(logout); ingo@28: rightPanel.addMember(language); ingo@28: rightPanel.addMember(info); ingo@28: ingo@28: addMember(leftPanel); ingo@28: addMember(rightPanel); ingo@28: } ingo@28: ingo@28: ingo@28: /** ingo@28: * Returns the FLYS instance stored in this class. ingo@28: * ingo@28: * @return the flys instance. ingo@28: */ ingo@28: protected FLYS getFlys() { ingo@28: return flys; 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@25: ? currentUser.getName() 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 :