comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeListGrid.java @ 5834:f507086aa94b

Repaired internal references.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:31:32 +0200
parents flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/GaugeListGrid.java@76d40d257c8c
children 821a02bbfb4e
comparison
equal deleted inserted replaced
5833:a2bdc0f524e8 5834:f507086aa94b
1 package de.intevation.flys.client.client.ui.stationinfo;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import com.google.gwt.core.client.GWT;
7 import com.smartgwt.client.types.ListGridFieldType;
8 import com.smartgwt.client.widgets.Canvas;
9 import com.smartgwt.client.widgets.WidgetCanvas;
10 import com.smartgwt.client.widgets.grid.ListGridField;
11 import com.smartgwt.client.widgets.grid.ListGridRecord;
12 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
13 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
14
15 import de.intevation.flys.client.client.FLYS;
16 import de.intevation.flys.client.shared.model.Data;
17 import de.intevation.flys.client.shared.model.DataItem;
18 import de.intevation.flys.client.shared.model.DataList;
19 import de.intevation.flys.client.shared.model.GaugeInfo;
20 import de.intevation.flys.client.shared.model.RiverInfo;
21
22
23 /**
24 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
25 */
26 public class GaugeListGrid extends InfoListGrid implements RecordClickHandler {
27
28 private static final int ABFLUSSTAFEL_COLUMN = 6;
29
30 public GaugeListGrid(FLYS flys) {
31 super(flys);
32 //TODO i18n!!!
33 ListGridField nfield = new ListGridField("name", "Pegel");
34 ListGridField sfield = new ListGridField("kmstart", "Start [km]", 60);
35 ListGridField efield = new ListGridField("kmend", "Ende [km]", 60);
36 ListGridField stfield = new ListGridField("station", "Station [km]");
37 ListGridField lfield = new ListGridField("link", "Info");
38 lfield.setType(ListGridFieldType.LINK);
39 ListGridField cfield = new ListGridField("curvelink", MSG.gauge_curve_link());
40 cfield.addRecordClickHandler(this);
41
42 this.setFields(nfield, sfield, efield, stfield, lfield, cfield);
43 }
44
45 public void setRiverInfo(RiverInfo riverinfo) {
46 List<GaugeInfo> gauges = riverinfo.getGauges();
47
48 if (gauges != null && !gauges.isEmpty()) {
49
50 ArrayList<GaugeInfo> emptygauges = new ArrayList<GaugeInfo>();
51
52 if (!riverinfo.isKmUp()) {
53 for (GaugeInfo gauge : gauges) {
54 addGauge(gauge, emptygauges);
55 }
56 }
57 else {
58 for (int i = gauges.size()-1; i >= 0; i--) {
59 GaugeInfo gauge = gauges.get(i);
60 addGauge(gauge, emptygauges);
61 }
62 }
63
64 // put empty gauges to the end
65 for (GaugeInfo gauge : emptygauges) {
66 addGauge(gauge);
67 }
68 }
69 }
70
71 private void addGauge(GaugeInfo gauge, List<GaugeInfo> empty) {
72 if (gauge.getKmStart() != null && gauge.getKmEnd() != null) {
73 addGauge(gauge);
74 }
75 else {
76 empty.add(gauge);
77 }
78 }
79
80 private void addGauge(GaugeInfo gauge) {
81 this.addData(new GaugeRecord(gauge));
82 }
83
84 public void open() {
85 ArrayList<Double> locations = new ArrayList<Double>();
86
87 if (data != null && data.length > 0) {
88 for (int i = 0; i < data.length; i++) {
89 DataList dl = data[i];
90 String state = dl.getState();
91 GWT.log("GaugeListGrid - open " + state);
92 if (state.equals("state.winfo.location_distance")) {
93 Double ldfrom = null;
94 Double ldto = null;
95
96 for (int j = dl.size()-1; j >= 0; --j) {
97 Data d = dl.get(j);
98 String label = d.getLabel();
99 GWT.log("GaugeListGrid - setData - label " + label + " " + d.getStringValue());
100 if (label.equals("ld_from")) {
101 ldfrom = getDoubleValue(d);
102 }
103 else if (label.equals("ld_to")) {
104 ldto = getDoubleValue(d);
105 }
106 else if (label.equals("ld_locations")) {
107 getLocationsFromData(locations, d);
108 openOnLocations(locations);
109 return;
110 }
111 }
112 if (ldfrom != null) {
113 openOnDistance(ldfrom, ldto);
114 return;
115 }
116 }
117 else if(state.equals("state.winfo.distance_only") ||
118 state.equals("state.winfo.distance")) {
119 Double ldfrom = null;
120 Double ldto = null;
121
122 for (int j = dl.size()-1; j >= 0; --j) {
123 Data d = dl.get(j);
124 String label = d.getLabel();
125 GWT.log("GaugeListGrid - setData - label " + label + " " + d.getStringValue());
126 if (label.equals("ld_from")) {
127 ldfrom = getDoubleValue(d);
128 }
129 else if (label.equals("ld_to")) {
130 ldto = getDoubleValue(d);
131 }
132 }
133
134 if (ldfrom != null) {
135 openOnDistance(ldfrom, ldto);
136 return;
137 }
138 }
139 else if (state.equals("state.winfo.location")) {
140 getLocations("ld_locations", locations, dl);
141 openOnLocations(locations);
142 return;
143 }
144 else if (state.equals("state.winfo.reference.curve.input.start")) {
145 getLocations("reference_startpoint", locations, dl);
146 }
147 else if (state.equals("state.winfo.reference.curve.input.end")) {
148 getLocations("reference_endpoint", locations, dl);
149 }
150 else if (state.equals("state.winfo.historicalq.reference_gauge")) {
151 for (int j = dl.size()-1; j >= 0; --j) {
152 Data d = dl.get(j);
153 String label = d.getLabel();
154 if (label.equals("reference_gauge")) {
155 String tmp = d.getStringValue();
156 if (tmp != null) {
157 Long gaugereference = Long.valueOf(tmp);
158 if (gaugereference != null) {
159 openOnReference(gaugereference);
160 return;
161 }
162 }
163 }
164 }
165 }
166 }
167 }
168 if (!locations.isEmpty()) {
169 openOnLocations(locations);
170 }
171 else {
172 openAll();
173 }
174 }
175
176 void getLocations(String labelname, List<Double> locations, DataList dl) {
177 for (int j = dl.size()-1; j >= 0; --j) {
178 Data d = dl.get(j);
179 String label = d.getLabel();
180 if (label.equals(labelname)) {
181 getLocationsFromData(locations, d);
182 }
183 }
184 }
185
186 void getLocationsFromData(List<Double> locations, Data data) {
187 DataItem[] items = data.getItems();
188 for (int k = 0; k < items.length; k++) {
189 String tmp = items[k].getStringValue();
190 GWT.log("GaugeListGrid - getLocationsFromData " + tmp);
191 if (tmp != null) {
192 if (tmp.contains(" ")) {
193 // string contains several values ...
194 String[] values = tmp.split(" ");
195 for(int i=0; i < values.length; i++) {
196 Double value = Double.valueOf(values[i]);
197 if (value != null) {
198 locations.add(value);
199 }
200 }
201 }
202 else {
203 Double value = Double.valueOf(tmp);
204 if (value != null) {
205 locations.add(value);
206 }
207 }
208 }
209 }
210 }
211
212 public void openOnReference(Long number) {
213 GWT.log("GaugeListGrid - openOnReference " + number);
214 for (ListGridRecord record: this.getRecords()) {
215 GaugeRecord item = (GaugeRecord)record;
216 if (item.getOfficialNumber().equals(number)) {
217 expandRecord(item);
218 }
219 else {
220 collapseRecord(item);
221 }
222 }
223 }
224
225 public void openOnDistance(Double start, Double end) {
226 GWT.log("GaugeListGrid - openOnDistance " + start + " " + end);
227
228 for (ListGridRecord record: this.getRecords()) {
229 GaugeRecord item = (GaugeRecord)record;
230 if (end == null && item.getKmStart() != null) {
231 if (item.getKmStart() >= start) {
232 expandRecord(item);
233 }
234 else {
235 collapseRecord(item);
236 }
237 }
238 else if (item.getKmStart() != null && item.getKmEnd() != null) {
239 // as getStart()/getEnd() return Double objects, they can be null and
240 // can cause NPEs when comparing with double... strange...
241 GWT.log("GaugeListGrid - openOnDistance item " + item.getKmStart() + " " + item.getKmEnd());
242 if ((start >= item.getKmStart() && start <= item.getKmEnd()) ||
243 (end >= item.getKmStart() && end <= item.getKmEnd()) ||
244 (start <= item.getKmStart() && end >= item.getKmEnd())) {
245 expandRecord(item);
246 }
247 else {
248 collapseRecord(item);
249 }
250 }
251 else {
252 collapseRecord(item);
253 }
254 }
255 }
256
257 /**
258 * Open Gauge entry if a location fits to the gauge.
259 */
260 public void openOnLocations(List<Double> locations) {
261 GWT.log("GaugeListGrid - openOnLocations " + locations);
262
263 if (locations == null || locations.isEmpty()) {
264 return;
265 }
266
267 for (ListGridRecord record: this.getRecords()) {
268 GaugeRecord item = (GaugeRecord)record;
269 boolean isset = false;
270 for (Double location: locations) {
271 if (locations == null) {
272 continue;
273 }
274
275 Double start = item.getKmStart();
276 Double end = item.getKmEnd();
277 if (start == null || end == null) {
278 // should not occur but avoid NullPointerException
279 continue;
280 }
281
282 if (location >= start && location <= end) {
283 isset = true;
284 break;
285 }
286 }
287 if (isset) {
288 expandRecord(item);
289 }
290 else {
291 collapseRecord(item);
292 }
293 }
294 }
295
296 @Override
297 protected Canvas getExpandPanel(ListGridRecord record) {
298 GaugeRecord item = (GaugeRecord)record;
299 return new WidgetCanvas(new GaugeInfoPanel(item, flys));
300 }
301
302 @Override
303 public void onRecordClick(RecordClickEvent event) {
304 GaugeRecord gauge = (GaugeRecord)event.getRecord();
305 flys.newGaugeDischargeCurve(gauge.getRiverName(),
306 gauge.getOfficialNumber());
307 }
308
309 @Override
310 public String getCellCSSText(ListGridRecord record, int rowNum,
311 int colNum) {
312 if (colNum == ABFLUSSTAFEL_COLUMN) {
313 // display the ablfusstafel cell like a link
314 return "text-decoration: underline; color: #0000EE; cursor: pointer;";
315 }
316 else {
317 return super.getCellCSSText(record, rowNum, colNum);
318 }
319 }
320 }

http://dive4elements.wald.intevation.org