view flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationListGrid.java @ 4956:f46a07c11324

Refactor Pegel- and Messtelleninfo in client ui Use SmartGWT ListGrid instead of GWT Tree to display the station entires.
author Björn Ricks <bjoern.ricks@intevation.de>
date Fri, 01 Feb 2013 16:32:48 +0100
parents
children 5652aa0ad9e5
line wrap: on
line source
package de.intevation.flys.client.client.ui.stationinfo;

import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.Grid;

import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.WidgetCanvas;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;

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

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

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

    public MeasurementStationListGrid(FLYS flys) {
        super(flys);
        ListGridField nfield = new ListGridField("name", "Messtelle");
        ListGridField sfield = new ListGridField("kmstart", "Start [km]", 60);
        ListGridField efield = new ListGridField("kmend", "Ende [km]", 60);
        ListGridField stfield = new ListGridField("station", "Station [km]");
        ListGridField lfield = new ListGridField("link", "Link");
        lfield.setType(ListGridFieldType.LINK);
        this.setFields(nfield, sfield, efield, stfield, lfield);
    }

    /**
     * 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) {
        List<MeasurementStation> stations = riverinfo.getMeasurementStations();
        GWT.log("MeasurmentStationListGrid - setRiverInfo " + stations);

        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) {
        ListGridRecord record = new MeasurementStationRecord(station);
        this.addData(record);
    }

    class MeasurementStationDecoratorPanel extends DecoratorPanel {

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

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

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

            String gaugename = station.getGaugeName();
            if (gaugename != null) {
               grid.setText(2, 0, MSG.measurement_station_gauge_name());
               grid.setText(2, 1, gaugename);
            }

            DateTimeFormat df = DateTimeFormat.getFormat(
                    PredefinedFormat.DATE_MEDIUM);

            Date starttime = station.getStartTime();
            if (starttime != null) {
               grid.setText(3, 0, MSG.measurement_station_start_time());
               grid.setText(3, 1, df.format(starttime));
            }

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

            setWidget(grid);
        }
    }

    @Override
    public void open() {
    }

    @Override
    protected Canvas getExpandPanel(ListGridRecord record) {
        MeasurementStationRecord station = (MeasurementStationRecord)record;
        return new WidgetCanvas(new MeasurementStationDecoratorPanel(station));
    }
}

http://dive4elements.wald.intevation.org