view flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java @ 3715:8d3e48f189d2

Add first draft for the gauge overview info ui flys-client/trunk@5472 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 14 Sep 2012 14:07:48 +0000
parents
children 4e33aa341e51
line wrap: on
line source
package de.intevation.flys.client.client.ui;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeItem;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.ScrollPanel;

import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.LayoutPolicy;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.Layout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.Label;

import de.intevation.flys.client.client.FLYSConstants;
import de.intevation.flys.client.client.services.GaugeOverviewInfoService;
import de.intevation.flys.client.client.services.GaugeOverviewInfoServiceAsync;
import de.intevation.flys.client.shared.model.GaugeInfo;
import de.intevation.flys.client.shared.model.RiverInfo;

/**
 * The GaugePanel is intendet to be used within a SectionStackSection
 * It extends the VLayout by two methods to show and hide the
 * section stack section.
 */
public class GaugePanel extends VLayout {

    /** SectionStackSection where this GaugePanel belongs in*/
    private SectionStackSection sectionStack;

    /** Name of the river */
    private String river;

    /** The message class that provides i18n strings.*/
    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);

    protected GaugeOverviewInfoServiceAsync gaugeOverviewInfoService =
        GWT.create(GaugeOverviewInfoService.class);

    /**
     * Creates a new VLayout with a SectionStackSection
     * The GaugePanel's SectionStackSection is hidden by default.
     * @param sectionStack The section stack section to place the VLayout in.
     */
    public GaugePanel(SectionStackSection sectionStack) {
        super();
        sectionStack.setItems(this);
        sectionStack.setHidden(true);
        this.sectionStack = sectionStack;
        setStyleName("gaugeoverview");
    }

    public void setRiver(String river) {
        this.river = river;
        this.refresh();
    }

    /**
     * Loads the river info and renders it afterwards
     */
    public void refresh() {
        gaugeOverviewInfoService.getRiverInfo(this.river, new AsyncCallback<RiverInfo>() {
            public void onFailure(Throwable e) {
                GWT.log("Could not load the river info." + e);
            }

            public void onSuccess(RiverInfo riverinfo) {
                GWT.log("Loaded river info");
                renderGaugeOverviewInfo(riverinfo);
            }
        });
    }

    public void renderGaugeOverviewInfo(RiverInfo riverinfo) {
        setStyleName("gaugepanel");
        sectionStack.setResizeable(true);

        RiverInfoPanel riverinfopanel = new RiverInfoPanel(riverinfo);

        addMember(riverinfopanel);

        VLayout treewrapper = new VLayout();
        Tree gaugetree = new Tree();
        gaugetree.setHeight("100%");

        treewrapper.addMember(gaugetree);
        treewrapper.setHeight100();
        treewrapper.setOverflow(Overflow.AUTO);

        addMember(treewrapper);

        List<GaugeInfo> gauges = riverinfo.getGauges();
        if (!gauges.isEmpty()) {

            for (GaugeInfo gauge : gauges) {
                TreeItem gaugeitem = new GaugeInfoItem(gauge);
                gaugetree.addItem(gaugeitem);
            }
        }
    }

    /**
     * Hide the section stack section.
     */
    public void hide() {
        GWT.log("GaugePanel - hide");
        this.sectionStack.setHidden(true);
    }

    /**
     * Show the section stack section.
     */
    public void show() {
        GWT.log("GaugePanel - show");
        this.sectionStack.setHidden(false);
    }

    class RiverInfoPanel extends HLayout {

        public RiverInfoPanel(RiverInfo riverinfo) {
            setStyleName("riverinfo");
            setShowEdges(true);
            setEdgeSize(3);
            setBackgroundColor("white");
            setEdgeImage("");
            setEdgeBackgroundColor("#CFE1F1");
            setPadding(8);
            setOverflow(Overflow.VISIBLE);
            setAutoHeight();
            setWidth100();
            setMembersMargin(10);
            setMinHeight(30);

            Label label = new Label(riverinfo.getName());
            label.setWidth("*");
            addMember(label);

            String kmtext = "";
            Double start = riverinfo.getKmStart();
            Double end = riverinfo.getKmEnd();

            if (!riverinfo.isKmUp()) {
                Double tmp = end;
                end = start;
                start = tmp;
            }
            if (end != null) {
                kmtext += end.toString();
                kmtext += " - ";
            }
            if (start != null) {
                kmtext += start.toString();
            }
            kmtext += " km";

            label = new Label(kmtext);
            label.setWidth("*");
            label.setAlign(Alignment.CENTER);
            addMember(label);

            String qtext = "";
            Double qmin = riverinfo.getMinQ();
            Double qmax = riverinfo.getMaxQ();
            if (qmin != null) {
                qtext += qmin.toString();
                qtext += " qm/s";
                qtext += " - ";
            }
            if (qmax != null) {
                qtext += qmax.toString();
                qtext += " qm/s";
            }

            label = new Label(qtext);
            label.setWidth("*");
            label.setAlign(Alignment.CENTER);
            addMember(label);
        }
    }

    class GaugeInfoItem extends TreeItem {
        public GaugeInfoItem(GaugeInfo gauge) {
            GaugeInfoHead gaugeinfohead = new GaugeInfoHead(gauge);
            GaugeInfoPanel gaugeinfopanel = new GaugeInfoPanel(gauge);
            setWidget(gaugeinfohead);
            addItem(gaugeinfopanel);
        }
    }

    class GaugeInfoHead extends HLayout {

        public GaugeInfoHead(GaugeInfo gauge) {
            setStyleName("gaugeinfohead");
            setOverflow(Overflow.VISIBLE);
            setAutoHeight();
            setAutoWidth();

            Label label = new Label(gauge.getName());
            addMember(label);

            Double start = gauge.getKmStart();
            Double end   = gauge.getKmEnd();
            String kmtext = "";
            if (start != null) {
                kmtext += start.toString();
                kmtext += " - ";
            }
            if (end != null) {
                kmtext += end.toString();
            }
            kmtext +=" km";

            label = new Label(kmtext);

            addMember(label);
        }
    }

    class GaugeInfoPanel extends DecoratorPanel {
        public GaugeInfoPanel(GaugeInfo gauge) {
            setStyleName("gaugeinfopanel");
            Grid grid = new Grid(4, 2);

            grid.setText(0, 0, "W-Bereich [cm]");
            grid.setText(0, 1, "" + gauge.getMinW() + " - " + gauge.getMaxW());
            grid.setText(1, 0, "Q-Bereich [m²/s]");
            grid.setText(1, 1, "" + gauge.getMinQ() + " - " + gauge.getMaxQ());
            grid.setText(2, 0, "AEO [km²]");
            grid.setText(2, 1, "" + gauge.getAeo());
            grid.setText(3, 0, "Pegelnullpunk [NN+m]");
            grid.setText(3, 1, "" + gauge.getDatum());

            setWidget(grid);
        }
    }
}

http://dive4elements.wald.intevation.org