Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/MeasurementStationListGrid.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/MeasurementStationListGrid.java@821a02bbfb4e |
children | 172338b1407f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/MeasurementStationListGrid.java Thu Apr 25 15:23:37 2013 +0200 @@ -0,0 +1,105 @@ +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()); + } + +}