view gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/MeasurementStationListGrid.java @ 8285:2c20907f8dd0

Fixed style for sq relation link in measurement station info grid.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 17 Sep 2014 12:32:01 +0200
parents 0a994bbe645e
children e3a63d9c5bb1
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.widgets.Canvas;
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 mfield = new ListGridField("measurementtype", "Messstellenart");
        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("infolink", "Info");
        ListGridField cfield = new ListGridField("curvelink", "Feststofftransport-Abfluss-Beziehung");
        cfield.addRecordClickHandler(this);

        this.setShowRecordComponents(true);
        this.setShowRecordComponentsByCell(true);
        this.setFields(nfield, mfield, 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) {
        /* switch off sorting stations without range to the end
        if (station.getKmStart() != null && station.getKmEnd() != null) {
            addStation(station);
        }
        else {
            empty.add(station);
        }
        */
        addStation(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 MeasurementStationInfoPanel(station);
    }

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

    @Override
    public String getCellCSSText(ListGridRecord record, int rowNum,
            int colNum) {
        if (colNum == 7) {
            return "text-decoration: underline; color: #0000EE; cursor: pointer;";
        }
        else {
            return super.getCellCSSText(record, rowNum, colNum);
        }
    }

}

http://dive4elements.wald.intevation.org