teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5993: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5993: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: 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.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]"); rrenkert@6272: ListGridField lfield = new ListGridField("infolink", "Link"); rrenkert@5503: ListGridField cfield = new ListGridField("curvelink", "SQ"); rrenkert@5503: cfield.addRecordClickHandler(this); rrenkert@6272: rrenkert@6272: this.setShowRecordComponents(true); rrenkert@6272: this.setShowRecordComponentsByCell(true); 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: rrenkert@6272: @Override rrenkert@6272: public String getCellCSSText(ListGridRecord record, int rowNum, rrenkert@6272: int colNum) { rrenkert@6272: if (colNum == 6) { rrenkert@6272: return "text-decoration: underline; color: #0000EE; cursor: pointer;"; rrenkert@6272: } rrenkert@6272: else { rrenkert@6272: return super.getCellCSSText(record, rowNum, colNum); rrenkert@6272: } rrenkert@6272: } rrenkert@6272: bjoern@4956: }