view flys-client/src/main/java/de/intevation/flys/client/client/ui/MeasurementStationTree.java @ 4269:0c766c475805

Add Panel and Tree UI classes for dispayling the measurement station info The new ui classes are using the new extracted base class InfoPanel and InfoTree which are in common with the gauge info.
author Björn Ricks <bjoern.ricks@intevation.de>
date Fri, 26 Oct 2012 12:22:06 +0200
parents
children 6aa8cd8da224
line wrap: on
line source
package de.intevation.flys.client.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeItem;

import com.smartgwt.client.widgets.layout.HLayout;

import de.intevation.flys.client.client.FLYS;
import de.intevation.flys.client.shared.model.Data;
import de.intevation.flys.client.shared.model.DataItem;
import de.intevation.flys.client.shared.model.DataList;
import de.intevation.flys.client.shared.model.MeasurementStation;
import de.intevation.flys.client.shared.model.RiverInfo;

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

/**
 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
 */
public class MeasurementStationTree extends InfoTree {

    public MeasurementStationTree(FLYS flys) {
        this.flys = flys;
        tree = new Tree();
        setWidget(tree);
    }

    /**
     * Resets the items of the tree.
     * If the list of gauges is empty or null the tree will be empty.
     */
    @Override
    public void setRiverInfo(RiverInfo riverinfo) {
        tree.clear();

        List<MeasurementStation> stations = riverinfo.getMeasurementStations();

        if (stations != null && !stations.isEmpty()) {

            ArrayList<MeasurementStation> emptystations =
                new ArrayList<MeasurementStation>();

            if (!riverinfo.isKmUp()) {
                for (MeasurementStation station : stations) {
                    addStation(station, emptystations);
                }
            }
            else {
                for (int i = stations.size()-1; i >= 0; i--) {
                    MeasurementStation station = stations.get(i);
                    addStation(station, emptystations);
                }
            }

            // put empty stations to the end
            for (MeasurementStation station : emptystations) {
                addStation(station);
            }
        }
    }

    private void addStation(MeasurementStation station,
            List<MeasurementStation> empty) {
        if (station.getKmStart() != null && station.getKmEnd() != null) {
            addStation(station);
        }
        else {
            empty.add(station);
        }
    }

    private void addStation(MeasurementStation station) {
        MeasurementStationItem sitem =
            new MeasurementStationItem(flys, station);
        tree.addItem(sitem);
    }

    class MeasurementStationItem extends TreeItem {

        private MeasurementStation station;

        public MeasurementStationItem(FLYS flys, MeasurementStation station) {
            MeasurementStationHead head =
                new MeasurementStationHead(flys, station);
            MeasurementStationDecoratorPanel
                panel = new MeasurementStationDecoratorPanel(station);
            setWidget(head);
            addItem(panel);
            this.station = station;
        }

        public Double getStart() {
            return station.getKmStart();
        }

        public Double getEnd() {
            return station.getKmEnd();
        }

        public Integer getID() {
            return station.getID();
        }
    }

    class MeasurementStationHead extends HLayout {

        public MeasurementStationHead(FLYS flys, MeasurementStation station) {
            setStyleName("infohead");
            setAutoHeight();
            setAutoWidth();

            NumberFormat nf = NumberFormat.getDecimalFormat();

            Label label = new Label(station.getName(), true);
            addMember(label);

            Double start;
            Double end;

            if (!station.isKmUp()) {
                start = station.getKmStart();
                end   = station.getKmEnd();
            }
            else {
                start = station.getKmEnd();
                end   = station.getKmStart();
            }

            String kmtext = "";
            if (start != null) {
                kmtext += nf.format(start);
                kmtext += " - ";
            }
            if (end != null) {
                kmtext += nf.format(end);
            }
            if (start != null || end != null) {
                kmtext += " km";
            }

            label = new Label(kmtext);

            addMember(label);

            Double dstation = station.getStation();
            if (dstation != null) {
                String stext = nf.format(dstation);
                stext += " km";
                label = new Label(stext);
                addMember(label);
            }

            /* Long number = gauge.getOfficialNumber(); */
            /* String url = number != null ? */
            /*     MSG.gauge_url() + number : */
            /*     MSG.gauge_url(); */
            /* Anchor anchor = new Anchor(MSG.gauge_info_link(), url, "_blank"); */
            /* addMember(anchor); */
        }
    }

    class MeasurementStationDecoratorPanel extends DecoratorPanel {

        public MeasurementStationDecoratorPanel(MeasurementStation station) {
            setStyleName("infopanel");
            Grid grid = new Grid(4, 2);

            NumberFormat nf = NumberFormat.getDecimalFormat();

            String riverside = station.getRiverSide();
            if (riverside != null) {
                grid.setText(0, 0, MSG.riverside());
                grid.setText(0, 1, riverside);
            }

            String type = station.getMeasurementType();
            if (type != null) {
                grid.setText(1, 0, MSG.measurement_station_type());
                grid.setText(1, 1, type);
            }

            String moperator = station.getOperator();
            if (moperator != null) {
                grid.setText(2, 0, MSG.measurement_station_operator());
                grid.setText(2, 1, moperator);
            }

            setWidget(grid);
        }
    }

    @Override
    public void open() {
    }
}

http://dive4elements.wald.intevation.org