bjoern@4269: package de.intevation.flys.client.client.ui;
bjoern@4269:
bjoern@4290: import java.util.Date;
bjoern@4290:
bjoern@4290: import com.google.gwt.i18n.client.DateTimeFormat;
bjoern@4269: import com.google.gwt.i18n.client.NumberFormat;
bjoern@4269: import com.google.gwt.user.client.ui.Anchor;
bjoern@4269: import com.google.gwt.user.client.ui.DecoratorPanel;
bjoern@4269: import com.google.gwt.user.client.ui.Grid;
bjoern@4269: import com.google.gwt.user.client.ui.Label;
bjoern@4269: import com.google.gwt.user.client.ui.Tree;
bjoern@4269: import com.google.gwt.user.client.ui.TreeItem;
bjoern@4269:
bjoern@4269: import com.smartgwt.client.widgets.layout.HLayout;
bjoern@4269:
bjoern@4269: import de.intevation.flys.client.client.FLYS;
bjoern@4269: import de.intevation.flys.client.shared.model.MeasurementStation;
bjoern@4269: import de.intevation.flys.client.shared.model.RiverInfo;
bjoern@4269:
bjoern@4269: import java.util.ArrayList;
bjoern@4269: import java.util.List;
bjoern@4269:
bjoern@4269: /**
bjoern@4269: * @author Björn Ricks
bjoern@4269: */
bjoern@4269: public class MeasurementStationTree extends InfoTree {
bjoern@4269:
bjoern@4269: public MeasurementStationTree(FLYS flys) {
bjoern@4269: this.flys = flys;
bjoern@4269: tree = new Tree();
bjoern@4269: setWidget(tree);
bjoern@4269: }
bjoern@4269:
bjoern@4269: /**
bjoern@4269: * Resets the items of the tree.
bjoern@4269: * If the list of gauges is empty or null the tree will be empty.
bjoern@4269: */
bjoern@4269: @Override
bjoern@4269: public void setRiverInfo(RiverInfo riverinfo) {
bjoern@4269: tree.clear();
bjoern@4269:
bjoern@4269: List stations = riverinfo.getMeasurementStations();
bjoern@4269:
bjoern@4269: if (stations != null && !stations.isEmpty()) {
bjoern@4269:
bjoern@4269: ArrayList emptystations =
bjoern@4269: new ArrayList();
bjoern@4269:
bjoern@4269: if (!riverinfo.isKmUp()) {
bjoern@4269: for (MeasurementStation station : stations) {
bjoern@4269: addStation(station, emptystations);
bjoern@4269: }
bjoern@4269: }
bjoern@4269: else {
bjoern@4269: for (int i = stations.size()-1; i >= 0; i--) {
bjoern@4269: MeasurementStation station = stations.get(i);
bjoern@4269: addStation(station, emptystations);
bjoern@4269: }
bjoern@4269: }
bjoern@4269:
bjoern@4269: // put empty stations to the end
bjoern@4269: for (MeasurementStation station : emptystations) {
bjoern@4269: addStation(station);
bjoern@4269: }
bjoern@4269: }
bjoern@4269: }
bjoern@4269:
bjoern@4269: private void addStation(MeasurementStation station,
bjoern@4269: List empty) {
bjoern@4269: if (station.getKmStart() != null && station.getKmEnd() != null) {
bjoern@4269: addStation(station);
bjoern@4269: }
bjoern@4269: else {
bjoern@4269: empty.add(station);
bjoern@4269: }
bjoern@4269: }
bjoern@4269:
bjoern@4269: private void addStation(MeasurementStation station) {
bjoern@4269: MeasurementStationItem sitem =
bjoern@4269: new MeasurementStationItem(flys, station);
bjoern@4269: tree.addItem(sitem);
bjoern@4269: }
bjoern@4269:
bjoern@4269: class MeasurementStationItem extends TreeItem {
bjoern@4269:
bjoern@4269: private MeasurementStation station;
bjoern@4269:
bjoern@4269: public MeasurementStationItem(FLYS flys, MeasurementStation station) {
bjoern@4269: MeasurementStationHead head =
bjoern@4269: new MeasurementStationHead(flys, station);
bjoern@4269: MeasurementStationDecoratorPanel
bjoern@4269: panel = new MeasurementStationDecoratorPanel(station);
bjoern@4269: setWidget(head);
bjoern@4269: addItem(panel);
bjoern@4269: this.station = station;
bjoern@4269: }
bjoern@4269:
bjoern@4269: public Double getStart() {
bjoern@4269: return station.getKmStart();
bjoern@4269: }
bjoern@4269:
bjoern@4269: public Double getEnd() {
bjoern@4269: return station.getKmEnd();
bjoern@4269: }
bjoern@4269:
bjoern@4269: public Integer getID() {
bjoern@4269: return station.getID();
bjoern@4269: }
bjoern@4269: }
bjoern@4269:
bjoern@4269: class MeasurementStationHead extends HLayout {
bjoern@4269:
bjoern@4269: public MeasurementStationHead(FLYS flys, MeasurementStation station) {
bjoern@4269: setStyleName("infohead");
bjoern@4269: setAutoHeight();
bjoern@4269: setAutoWidth();
bjoern@4269:
bjoern@4269: NumberFormat nf = NumberFormat.getDecimalFormat();
bjoern@4269:
bjoern@4269: Label label = new Label(station.getName(), true);
bjoern@4269: addMember(label);
bjoern@4269:
bjoern@4269: Double start;
bjoern@4269: Double end;
bjoern@4269:
bjoern@4269: if (!station.isKmUp()) {
bjoern@4269: start = station.getKmStart();
bjoern@4269: end = station.getKmEnd();
bjoern@4269: }
bjoern@4269: else {
bjoern@4269: start = station.getKmEnd();
bjoern@4269: end = station.getKmStart();
bjoern@4269: }
bjoern@4269:
bjoern@4269: String kmtext = "";
bjoern@4269: if (start != null) {
bjoern@4269: kmtext += nf.format(start);
bjoern@4269: kmtext += " - ";
bjoern@4269: }
bjoern@4269: if (end != null) {
bjoern@4269: kmtext += nf.format(end);
bjoern@4269: }
bjoern@4269: if (start != null || end != null) {
bjoern@4269: kmtext += " km";
bjoern@4269: }
bjoern@4269:
bjoern@4269: label = new Label(kmtext);
bjoern@4269:
bjoern@4269: addMember(label);
bjoern@4269:
bjoern@4269: Double dstation = station.getStation();
bjoern@4269: if (dstation != null) {
bjoern@4269: String stext = nf.format(dstation);
bjoern@4269: stext += " km";
bjoern@4269: label = new Label(stext);
bjoern@4269: addMember(label);
bjoern@4269: }
bjoern@4269:
bjoern@4291: Integer number = station.getID();
bjoern@4291: String url = number != null ?
bjoern@4291: MSG.measurement_station_url() + number :
bjoern@4291: MSG.measurement_station_url();
bjoern@4291: Anchor anchor = new Anchor(MSG.measurement_station_info_link(),
bjoern@4291: url, "_blank");
bjoern@4291: addMember(anchor);
bjoern@4269: }
bjoern@4269: }
bjoern@4269:
bjoern@4269: class MeasurementStationDecoratorPanel extends DecoratorPanel {
bjoern@4269:
bjoern@4269: public MeasurementStationDecoratorPanel(MeasurementStation station) {
bjoern@4269: setStyleName("infopanel");
bjoern@4327: Grid grid = new Grid(5, 2);
bjoern@4269:
bjoern@4327: String type = station.getMeasurementType();
bjoern@4327: if (type != null) {
bjoern@4327: grid.setText(0, 0, MSG.measurement_station_type());
bjoern@4327: grid.setText(0, 1, type);
bjoern@4327: }
bjoern@4327:
bjoern@4269: String riverside = station.getRiverSide();
bjoern@4269: if (riverside != null) {
bjoern@4327: grid.setText(1, 0, MSG.riverside());
bjoern@4327: grid.setText(1, 1, riverside);
bjoern@4269: }
bjoern@4269:
bjoern@4327: String gaugename = station.getGaugeName();
bjoern@4327: if (gaugename != null) {
bjoern@4327: grid.setText(2, 0, MSG.measurement_station_gauge_name());
bjoern@4327: grid.setText(2, 1, gaugename);
bjoern@4269: }
bjoern@4269:
bjoern@4290: DateTimeFormat df = DateTimeFormat.getMediumDateFormat();
bjoern@4290:
bjoern@4290: Date starttime = station.getStartTime();
bjoern@4290: if (starttime != null) {
bjoern@4290: grid.setText(3, 0, MSG.measurement_station_start_time());
bjoern@4290: grid.setText(3, 1, df.format(starttime));
bjoern@4290: }
bjoern@4290:
bjoern@4327: String moperator = station.getOperator();
bjoern@4327: if (moperator != null) {
bjoern@4327: grid.setText(4, 0, MSG.measurement_station_operator());
bjoern@4327: grid.setText(4, 1, moperator);
bjoern@4327: }
bjoern@4327:
bjoern@4269: setWidget(grid);
bjoern@4269: }
bjoern@4269: }
bjoern@4269:
bjoern@4269: @Override
bjoern@4269: public void open() {
bjoern@4269: }
bjoern@4269: }