bjoern@4956: package de.intevation.flys.client.client.ui.stationinfo; bjoern@4956: bjoern@4956: import com.google.gwt.core.client.GWT; bjoern@4956: import com.google.gwt.i18n.client.DateTimeFormat; bjoern@4956: import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; bjoern@4956: import com.google.gwt.user.client.ui.Grid; 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; bjoern@4957: import com.smartgwt.client.widgets.layout.VLayout; bjoern@4956: bjoern@4956: import de.intevation.flys.client.client.FLYS; bjoern@4956: import de.intevation.flys.client.shared.model.MeasurementStation; bjoern@4956: import de.intevation.flys.client.shared.model.RiverInfo; bjoern@4956: bjoern@4956: import java.util.ArrayList; bjoern@4956: import java.util.Date; bjoern@4956: import java.util.List; bjoern@4956: bjoern@4956: /** bjoern@4956: * @author Björn Ricks bjoern@4956: */ bjoern@4956: public class MeasurementStationListGrid extends InfoListGrid { 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); bjoern@4956: this.setFields(nfield, sfield, efield, stfield, lfield); 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@4957: class MeasurementStationDecoratorPanel extends VLayout { bjoern@4956: bjoern@4956: public MeasurementStationDecoratorPanel(MeasurementStation station) { bjoern@4956: setStyleName("infopanel"); bjoern@4957: setWidth100(); bjoern@4957: bjoern@4956: Grid grid = new Grid(5, 2); bjoern@4956: bjoern@4956: String type = station.getMeasurementType(); bjoern@4956: if (type != null) { bjoern@4956: grid.setText(0, 0, MSG.measurement_station_type()); bjoern@4956: grid.setText(0, 1, type); bjoern@4956: } bjoern@4956: bjoern@4956: String riverside = station.getRiverSide(); bjoern@4956: if (riverside != null) { bjoern@4956: grid.setText(1, 0, MSG.riverside()); bjoern@4956: grid.setText(1, 1, riverside); bjoern@4956: } bjoern@4956: bjoern@4956: String gaugename = station.getGaugeName(); bjoern@4956: if (gaugename != null) { bjoern@4956: grid.setText(2, 0, MSG.measurement_station_gauge_name()); bjoern@4956: grid.setText(2, 1, gaugename); bjoern@4956: } bjoern@4956: bjoern@4956: DateTimeFormat df = DateTimeFormat.getFormat( bjoern@4956: PredefinedFormat.DATE_MEDIUM); bjoern@4956: bjoern@4956: Date starttime = station.getStartTime(); bjoern@4956: if (starttime != null) { bjoern@4956: grid.setText(3, 0, MSG.measurement_station_start_time()); bjoern@4956: grid.setText(3, 1, df.format(starttime)); bjoern@4956: } bjoern@4956: bjoern@4956: String moperator = station.getOperator(); bjoern@4956: if (moperator != null) { bjoern@4956: grid.setText(4, 0, MSG.measurement_station_operator()); bjoern@4956: grid.setText(4, 1, moperator); bjoern@4956: } bjoern@4956: bjoern@4957: addMember(grid); bjoern@4956: } 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@4956: return new WidgetCanvas(new MeasurementStationDecoratorPanel(station)); bjoern@4956: } bjoern@4956: }