view flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java @ 94:eb54fb9f5f2c

Fixed some issues. flys-client/trunk@1607 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 29 Mar 2011 12:51:09 +0000
parents 4d7c6a63602b
children 33e24b33fc38
line wrap: on
line source
package de.intevation.flys.client.client.ui;

import com.google.gwt.core.client.GWT;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;

import de.intevation.flys.client.client.FLYS;
import de.intevation.flys.client.client.FLYSMessages;
import de.intevation.flys.client.shared.model.User;


/**
 * @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);

    /** An instance to FLYS.*/
    protected FLYS flys;

    /** The user that is currently logged in. */
    protected User currentUser;

    /** The label that displays the current logged in user. */
    protected Label userText;

    /** The button to log the current user out.*/
    protected Label logout;

    /** The button to add new projects.*/
    protected Label newProject;

    /** The button to open the project list.*/
    protected Label projectList;

    /** The button to switch between the english and german version.*/
    protected Label language;

    /** The button to open an info panel.*/
    protected Label info;

    /**
     * The default constructor for creating a new MainMenu.
     */
    public MainMenu(FLYS flys) {
        this.flys     = flys;

        userText    = new Label(messages.user(messages.guest()));
        newProject  = new Label(messages.new_project());
        projectList = new Label(messages.manage_projects());
        logout      = new Label(messages.logout());
        language    = new Label(messages.switch_language());
        info        = new Label(messages.info());

        newProject.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                GWT.log("Clicked 'New Project' button.");
                createNewProject();
            }
        });

        projectList.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                GWT.log("Clicked 'Open ProjectList' button.");
                ProjectList list = getFlys().getProjectList();
                if (list.isVisible())
                    list.hide();
                else
                    list.show();
            }
        });

        logout.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                GWT.log("Clicked 'logout' button.");
                GWT.log("IMPLEMENT the 'logout' function.");
            }
        });

        language.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                GWT.log("Clicked 'language' button.");
                GWT.log("IMPLEMENT the 'switch language' function.");
            }
        });

        info.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                GWT.log("Clicked 'info' button.");
                GWT.log("IMPLEMENT the 'open info panel' function.");
            }
        });

        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() {
        setStyleName("bgBlueDark");
        setHeight("25px");
        setLayoutMargin(5);

        newProject.setStyleName("fontLightSmall");
        projectList.setStyleName("fontLightSmall");
        userText.setStyleName("fontLightSmall");
        newProject.setStyleName("fontLightSmall");
        logout.setStyleName("fontLightSmall");
        language.setStyleName("fontLightSmall");
        info.setStyleName("fontLightSmall");

        projectList.setWidth("140px");

        HLayout leftPanel = new HLayout();
        leftPanel.setWidth("80%");
        leftPanel.setMembersMargin(5);
        leftPanel.addMember(newProject);
        leftPanel.addMember(projectList);

        userText.setAlign(Alignment.RIGHT);
        logout.setAlign(Alignment.RIGHT);
        info.setAlign(Alignment.RIGHT);
        language.setAlign(Alignment.RIGHT);

        userText.setWidth(200);
        logout.setWidth(70);
        info.setWidth(40);
        language.setWidth(70);

        HLayout rightPanel = new HLayout();
        rightPanel.setAlign(Alignment.RIGHT);
        rightPanel.setMembersMargin(3);
        rightPanel.setLayoutRightMargin(5);
        rightPanel.addMember(userText);
        rightPanel.addMember(logout);
        rightPanel.addMember(language);
        rightPanel.addMember(info);

        addMember(leftPanel);
        addMember(rightPanel);
    }


    /**
     * Returns the FLYS instance stored in this class.
     *
     * @return the flys instance.
     */
    protected FLYS getFlys() {
        return flys;
    }


    /**
     * 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.getName()
            : messages.guest();

        GWT.log("Update the current user: " + name);
        userText.setContents(messages.user(name));
    }


    /**
     * Create a new project by calling FLYS.newProject().
     */
    protected void createNewProject() {
        flys.newProject();
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org