view gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/MeasurementStationListGrid.java @ 5861:172338b1407f

GWT client: Added copyright header.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 28 Apr 2013 14:30:15 +0200
parents 5aa05a7a34b7
children ea9eef426962
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU AGPL (>=v3) 
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details. 
 */

package org.dive4elements.river.client.client.ui.stationinfo;

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

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 com.smartgwt.client.widgets.grid.events.RecordClickEvent;
import com.smartgwt.client.widgets.grid.events.RecordClickHandler;

import org.dive4elements.river.client.client.FLYS;
import org.dive4elements.river.client.shared.model.MeasurementStation;
import org.dive4elements.river.client.shared.model.RiverInfo;

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

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

    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);
        ListGridField cfield = new ListGridField("curvelink", "SQ");
        cfield.addRecordClickHandler(this);
        this.setFields(nfield, sfield, efield, stfield, lfield, cfield);
    }

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

    @Override
    public void open() {
    }

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

    @Override
    public void onRecordClick(RecordClickEvent event) {
        MeasurementStationRecord station =
            (MeasurementStationRecord)event.getRecord();
        flys.newSQRelation(station.getRiverName(), station.getID());
    }

}

http://dive4elements.wald.intevation.org