teichmann@5835: package org.dive4elements.river.client.client.ui.stationinfo; bjoern@4956: bjoern@4956: import com.google.gwt.core.client.GWT; bjoern@4956: bjoern@4956: import com.smartgwt.client.types.ListGridFieldType; bjoern@4956: import com.smartgwt.client.widgets.Canvas; bjoern@4956: import com.smartgwt.client.widgets.WidgetCanvas; bjoern@4956: import com.smartgwt.client.widgets.grid.ListGridField; bjoern@4956: import com.smartgwt.client.widgets.grid.ListGridRecord; rrenkert@5503: import com.smartgwt.client.widgets.grid.events.RecordClickEvent; rrenkert@5503: import com.smartgwt.client.widgets.grid.events.RecordClickHandler; bjoern@4956: teichmann@5835: import org.dive4elements.river.client.client.FLYS; teichmann@5835: import org.dive4elements.river.client.shared.model.MeasurementStation; teichmann@5835: import org.dive4elements.river.client.shared.model.RiverInfo; bjoern@4956: bjoern@4956: import java.util.ArrayList; bjoern@4956: import java.util.List; bjoern@4956: bjoern@4956: /** bjoern@4956: * @author Björn Ricks bjoern@4956: */ rrenkert@5503: public class MeasurementStationListGrid rrenkert@5503: extends InfoListGrid rrenkert@5503: implements RecordClickHandler { bjoern@4956: bjoern@4956: public MeasurementStationListGrid(FLYS flys) { bjoern@4956: super(flys); bjoern@4956: ListGridField nfield = new ListGridField("name", "Messtelle"); bjoern@4956: ListGridField sfield = new ListGridField("kmstart", "Start [km]", 60); bjoern@4956: ListGridField efield = new ListGridField("kmend", "Ende [km]", 60); bjoern@4956: ListGridField stfield = new ListGridField("station", "Station [km]"); bjoern@4956: ListGridField lfield = new ListGridField("link", "Link"); bjoern@4956: lfield.setType(ListGridFieldType.LINK); rrenkert@5503: ListGridField cfield = new ListGridField("curvelink", "SQ"); rrenkert@5503: cfield.addRecordClickHandler(this); rrenkert@5503: this.setFields(nfield, sfield, efield, stfield, lfield, cfield); bjoern@4956: } bjoern@4956: bjoern@4956: /** bjoern@4956: * Resets the items of the tree. bjoern@4956: * If the list of gauges is empty or null the tree will be empty. bjoern@4956: */ bjoern@4956: @Override bjoern@4956: public void setRiverInfo(RiverInfo riverinfo) { bjoern@4956: List stations = riverinfo.getMeasurementStations(); bjoern@4956: GWT.log("MeasurmentStationListGrid - setRiverInfo " + stations); bjoern@4956: bjoern@4956: if (stations != null && !stations.isEmpty()) { bjoern@4956: bjoern@4956: ArrayList emptystations = bjoern@4956: new ArrayList(); bjoern@4956: bjoern@4956: if (!riverinfo.isKmUp()) { bjoern@4956: for (MeasurementStation station : stations) { bjoern@4956: addStation(station, emptystations); bjoern@4956: } bjoern@4956: } bjoern@4956: else { bjoern@4956: for (int i = stations.size()-1; i >= 0; i--) { bjoern@4956: MeasurementStation station = stations.get(i); bjoern@4956: addStation(station, emptystations); bjoern@4956: } bjoern@4956: } bjoern@4956: bjoern@4956: // put empty stations to the end bjoern@4956: for (MeasurementStation station : emptystations) { bjoern@4956: addStation(station); bjoern@4956: } bjoern@4956: } bjoern@4956: } bjoern@4956: bjoern@4956: private void addStation(MeasurementStation station, bjoern@4956: List empty) { bjoern@4956: if (station.getKmStart() != null && station.getKmEnd() != null) { bjoern@4956: addStation(station); bjoern@4956: } bjoern@4956: else { bjoern@4956: empty.add(station); bjoern@4956: } bjoern@4956: } bjoern@4956: bjoern@4956: private void addStation(MeasurementStation station) { bjoern@4956: ListGridRecord record = new MeasurementStationRecord(station); bjoern@4956: this.addData(record); bjoern@4956: } bjoern@4956: bjoern@4956: @Override bjoern@4956: public void open() { bjoern@4956: } bjoern@4956: bjoern@4956: @Override bjoern@4956: protected Canvas getExpandPanel(ListGridRecord record) { bjoern@4956: MeasurementStationRecord station = (MeasurementStationRecord)record; bjoern@4962: return new WidgetCanvas(new MeasurementStationInfoPanel(station)); bjoern@4956: } rrenkert@5503: rrenkert@5503: @Override rrenkert@5503: public void onRecordClick(RecordClickEvent event) { rrenkert@5503: MeasurementStationRecord station = rrenkert@5503: (MeasurementStationRecord)event.getRecord(); rrenkert@5503: flys.newSQRelation(station.getRiverName(), station.getID()); rrenkert@5503: } rrenkert@5503: bjoern@4956: }