comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationListGrid.java @ 4956:f46a07c11324

Refactor Pegel- and Messtelleninfo in client ui Use SmartGWT ListGrid instead of GWT Tree to display the station entires.
author Björn Ricks <bjoern.ricks@intevation.de>
date Fri, 01 Feb 2013 16:32:48 +0100
parents
children 5652aa0ad9e5
comparison
equal deleted inserted replaced
4950:4c7acc3a4ae1 4956:f46a07c11324
1 package de.intevation.flys.client.client.ui.stationinfo;
2
3 import com.google.gwt.core.client.GWT;
4 import com.google.gwt.i18n.client.DateTimeFormat;
5 import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
6 import com.google.gwt.user.client.ui.DecoratorPanel;
7 import com.google.gwt.user.client.ui.Grid;
8
9 import com.smartgwt.client.types.ListGridFieldType;
10 import com.smartgwt.client.widgets.Canvas;
11 import com.smartgwt.client.widgets.WidgetCanvas;
12 import com.smartgwt.client.widgets.grid.ListGridField;
13 import com.smartgwt.client.widgets.grid.ListGridRecord;
14
15 import de.intevation.flys.client.client.FLYS;
16 import de.intevation.flys.client.shared.model.MeasurementStation;
17 import de.intevation.flys.client.shared.model.RiverInfo;
18
19 import java.util.ArrayList;
20 import java.util.Date;
21 import java.util.List;
22
23 /**
24 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
25 */
26 public class MeasurementStationListGrid extends InfoListGrid {
27
28 public MeasurementStationListGrid(FLYS flys) {
29 super(flys);
30 ListGridField nfield = new ListGridField("name", "Messtelle");
31 ListGridField sfield = new ListGridField("kmstart", "Start [km]", 60);
32 ListGridField efield = new ListGridField("kmend", "Ende [km]", 60);
33 ListGridField stfield = new ListGridField("station", "Station [km]");
34 ListGridField lfield = new ListGridField("link", "Link");
35 lfield.setType(ListGridFieldType.LINK);
36 this.setFields(nfield, sfield, efield, stfield, lfield);
37 }
38
39 /**
40 * Resets the items of the tree.
41 * If the list of gauges is empty or null the tree will be empty.
42 */
43 @Override
44 public void setRiverInfo(RiverInfo riverinfo) {
45 List<MeasurementStation> stations = riverinfo.getMeasurementStations();
46 GWT.log("MeasurmentStationListGrid - setRiverInfo " + stations);
47
48 if (stations != null && !stations.isEmpty()) {
49
50 ArrayList<MeasurementStation> emptystations =
51 new ArrayList<MeasurementStation>();
52
53 if (!riverinfo.isKmUp()) {
54 for (MeasurementStation station : stations) {
55 addStation(station, emptystations);
56 }
57 }
58 else {
59 for (int i = stations.size()-1; i >= 0; i--) {
60 MeasurementStation station = stations.get(i);
61 addStation(station, emptystations);
62 }
63 }
64
65 // put empty stations to the end
66 for (MeasurementStation station : emptystations) {
67 addStation(station);
68 }
69 }
70 }
71
72 private void addStation(MeasurementStation station,
73 List<MeasurementStation> empty) {
74 if (station.getKmStart() != null && station.getKmEnd() != null) {
75 addStation(station);
76 }
77 else {
78 empty.add(station);
79 }
80 }
81
82 private void addStation(MeasurementStation station) {
83 ListGridRecord record = new MeasurementStationRecord(station);
84 this.addData(record);
85 }
86
87 class MeasurementStationDecoratorPanel extends DecoratorPanel {
88
89 public MeasurementStationDecoratorPanel(MeasurementStation station) {
90 setStyleName("infopanel");
91 Grid grid = new Grid(5, 2);
92
93 String type = station.getMeasurementType();
94 if (type != null) {
95 grid.setText(0, 0, MSG.measurement_station_type());
96 grid.setText(0, 1, type);
97 }
98
99 String riverside = station.getRiverSide();
100 if (riverside != null) {
101 grid.setText(1, 0, MSG.riverside());
102 grid.setText(1, 1, riverside);
103 }
104
105 String gaugename = station.getGaugeName();
106 if (gaugename != null) {
107 grid.setText(2, 0, MSG.measurement_station_gauge_name());
108 grid.setText(2, 1, gaugename);
109 }
110
111 DateTimeFormat df = DateTimeFormat.getFormat(
112 PredefinedFormat.DATE_MEDIUM);
113
114 Date starttime = station.getStartTime();
115 if (starttime != null) {
116 grid.setText(3, 0, MSG.measurement_station_start_time());
117 grid.setText(3, 1, df.format(starttime));
118 }
119
120 String moperator = station.getOperator();
121 if (moperator != null) {
122 grid.setText(4, 0, MSG.measurement_station_operator());
123 grid.setText(4, 1, moperator);
124 }
125
126 setWidget(grid);
127 }
128 }
129
130 @Override
131 public void open() {
132 }
133
134 @Override
135 protected Canvas getExpandPanel(ListGridRecord record) {
136 MeasurementStationRecord station = (MeasurementStationRecord)record;
137 return new WidgetCanvas(new MeasurementStationDecoratorPanel(station));
138 }
139 }

http://dive4elements.wald.intevation.org