view flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemeNavigationPanel.java @ 5462:f2371f3aaf03

Show top level folder icons only if node has no factory If you have an empty folder the folder icon is still shown. This makes it possible to add functional "Top Level" entries in the Datacage
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 26 Mar 2013 18:29:13 +0100
parents e70ff0a600a3
children
line wrap: on
line source
package de.intevation.flys.client.client.ui;

import java.util.ArrayList;
import java.util.List;

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

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.ImgButton;
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.FLYSConstants;
import de.intevation.flys.client.client.event.OnMoveEvent;
import de.intevation.flys.client.client.event.OnMoveHandler;


/**
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class ThemeNavigationPanel extends Canvas {

    public static final int PANEL_MARGIN  = 5;
    public static final int BUTTON_HEIGHT = 20;
    public static final int BUTTON_MARGIN = 5;
    private static final int BOTTON_WIDTH = 20;

    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);

    protected List<OnMoveHandler> handlers;


    public ThemeNavigationPanel() {
        this.handlers = new ArrayList<OnMoveHandler>();

        setWidth100();
        setHeight(BUTTON_HEIGHT);
        setMargin(PANEL_MARGIN);

        HLayout layout = new HLayout();
        layout.setWidth100();
        layout.setHeight(BUTTON_HEIGHT);
        layout.setMembersMargin(BUTTON_MARGIN);
        layout.setDefaultLayoutAlign(VerticalAlignment.CENTER);
        layout.setDefaultLayoutAlign(Alignment.CENTER);

        Canvas cu = createButton(MSG.theme_top(), OnMoveEvent.TOP);
        Canvas u  = createButton(MSG.theme_up(), OnMoveEvent.UP);
        Canvas d  = createButton(MSG.theme_down(), OnMoveEvent.DOWN);
        Canvas cd = createButton(MSG.theme_bottom(), OnMoveEvent.BOTTOM);

        HLayout left = new HLayout();
        left.setMembersMargin(BUTTON_MARGIN);
        left.setLayoutAlign(Alignment.LEFT);
        left.setDefaultLayoutAlign(Alignment.LEFT);
        left.setAlign(Alignment.LEFT);
        left.addMember(cu);
        left.addMember(u);

        HLayout right = new HLayout();
        right.setMembersMargin(BUTTON_MARGIN);
        right.setLayoutAlign(Alignment.RIGHT);
        right.setDefaultLayoutAlign(Alignment.RIGHT);
        right.setAlign(Alignment.RIGHT);
        right.addMember(d);
        right.addMember(cd);

        layout.addMember(left);
        layout.addMember(right);

        addChild(layout);
    }


    protected Canvas createButton(final String title, final int moveType) {
        String url = GWT.getHostPageBaseURL() + title;

        ImgButton b = new ImgButton();
        b.setSrc(url);
        b.setWidth(BOTTON_WIDTH);
        b.setHeight(BUTTON_HEIGHT);
        b.setIconHeight(BUTTON_HEIGHT);
        b.setIconWidth(BOTTON_WIDTH);
        b.setShowDown(false);
        b.setShowRollOver(false);
        b.setShowDisabled(false);
        b.setShowDisabledIcon(true);
        b.setShowDownIcon(false);
        b.setShowFocusedIcon(false);
        b.setValign(VerticalAlignment.CENTER);

        b.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                fireOnMoveEvent(moveType);
            }
        });

        return b;
    }


    protected void addOnMoveHandler(OnMoveHandler handler) {
        if (handler != null) {
            handlers.add(handler);
        }
    }


    protected void fireOnMoveEvent(int type) {
        OnMoveEvent event = new OnMoveEvent(type);

        for (OnMoveHandler handler: handlers) {
            handler.onMove(event);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org