Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeListGrid.java @ 9093:280c5b44f219
2.3.4.1.8 Pegelauswahl nach range einschränken
author | gernotbelger |
---|---|
date | Fri, 25 May 2018 15:05:30 +0200 |
parents | 5e38e2924c07 |
children | 7337034eb5d5 |
comparison
equal
deleted
inserted
replaced
9092:50cfc90ac5b0 | 9093:280c5b44f219 |
---|---|
8 | 8 |
9 package org.dive4elements.river.client.client.ui.stationinfo; | 9 package org.dive4elements.river.client.client.ui.stationinfo; |
10 | 10 |
11 import java.util.ArrayList; | 11 import java.util.ArrayList; |
12 import java.util.List; | 12 import java.util.List; |
13 | |
14 import com.google.gwt.core.client.GWT; | |
15 import com.google.gwt.user.client.rpc.AsyncCallback; | |
16 import com.smartgwt.client.util.SC; | |
17 import com.smartgwt.client.widgets.Canvas; | |
18 import com.smartgwt.client.widgets.grid.ListGridField; | |
19 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
20 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; | |
21 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; | |
22 | 13 |
23 import org.dive4elements.river.client.client.Config; | 14 import org.dive4elements.river.client.client.Config; |
24 import org.dive4elements.river.client.client.FLYS; | 15 import org.dive4elements.river.client.client.FLYS; |
25 import org.dive4elements.river.client.client.services.AdvanceService; | 16 import org.dive4elements.river.client.client.services.AdvanceService; |
26 import org.dive4elements.river.client.client.services.AdvanceServiceAsync; | 17 import org.dive4elements.river.client.client.services.AdvanceServiceAsync; |
39 import org.dive4elements.river.client.shared.model.DefaultData; | 30 import org.dive4elements.river.client.shared.model.DefaultData; |
40 import org.dive4elements.river.client.shared.model.DefaultDataItem; | 31 import org.dive4elements.river.client.shared.model.DefaultDataItem; |
41 import org.dive4elements.river.client.shared.model.GaugeInfo; | 32 import org.dive4elements.river.client.shared.model.GaugeInfo; |
42 import org.dive4elements.river.client.shared.model.RiverInfo; | 33 import org.dive4elements.river.client.shared.model.RiverInfo; |
43 | 34 |
35 import com.google.gwt.core.client.GWT; | |
36 import com.google.gwt.user.client.rpc.AsyncCallback; | |
37 import com.smartgwt.client.util.SC; | |
38 import com.smartgwt.client.widgets.Canvas; | |
39 import com.smartgwt.client.widgets.grid.ListGridField; | |
40 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
41 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; | |
42 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; | |
44 | 43 |
45 /** | 44 /** |
46 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> | 45 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> |
47 */ | 46 */ |
48 public class GaugeListGrid extends InfoListGrid implements RecordClickHandler { | 47 public class GaugeListGrid extends InfoListGrid implements RecordClickHandler { |
49 | 48 |
49 public static enum DisappearType { | |
50 remove, collapse, stayVisible | |
51 } | |
52 | |
50 private static final int ABFLUSSTAFEL_COLUMN = 6; | 53 private static final int ABFLUSSTAFEL_COLUMN = 6; |
51 | 54 |
52 /** The ArtifactService used to communicate with the Artifact server. */ | 55 /** The ArtifactService used to communicate with the Artifact server. */ |
53 protected ArtifactServiceAsync artifactService = | 56 protected ArtifactServiceAsync artifactService = GWT.create(ArtifactService.class); |
54 GWT.create(ArtifactService.class); | |
55 | 57 |
56 /** The StepForwardService used to put data into an existing artifact. */ | 58 /** The StepForwardService used to put data into an existing artifact. */ |
57 protected StepForwardServiceAsync forwardService = | 59 protected StepForwardServiceAsync forwardService = GWT.create(StepForwardService.class); |
58 GWT.create(StepForwardService.class); | |
59 | 60 |
60 /** The ArtifactService used to communicate with the Artifact server. */ | 61 /** The ArtifactService used to communicate with the Artifact server. */ |
61 protected CreateCollectionServiceAsync createCollectionService = | 62 protected CreateCollectionServiceAsync createCollectionService = GWT.create(CreateCollectionService.class); |
62 GWT.create(CreateCollectionService.class); | |
63 | 63 |
64 /** The StepForwardService used to put data into an existing artifact. */ | 64 /** The StepForwardService used to put data into an existing artifact. */ |
65 protected AdvanceServiceAsync advanceService = | 65 protected AdvanceServiceAsync advanceService = GWT.create(AdvanceService.class); |
66 GWT.create(AdvanceService.class); | 66 |
67 | 67 private final List<GaugeInfo> gauges = new ArrayList<GaugeInfo>(); |
68 public GaugeListGrid(FLYS flys) { | 68 |
69 public GaugeListGrid(final FLYS flys) { | |
69 super(flys); | 70 super(flys); |
70 //TODO i18n!!! | 71 // TODO i18n!!! |
71 ListGridField nfield = new ListGridField("name", "Pegel"); | 72 final ListGridField nfield = new ListGridField("name", "Pegel"); |
72 ListGridField sfield = new ListGridField("kmstart", "Start [km]", 60); | 73 final ListGridField sfield = new ListGridField("kmstart", "Start [km]", 60); |
73 ListGridField efield = new ListGridField("kmend", "Ende [km]", 60); | 74 final ListGridField efield = new ListGridField("kmend", "Ende [km]", 60); |
74 ListGridField stfield = new ListGridField("station", "Station [km]"); | 75 final ListGridField stfield = new ListGridField("station", "Station [km]"); |
75 ListGridField lfield = new ListGridField("infolink", "Info"); | 76 final ListGridField lfield = new ListGridField("infolink", "Info"); |
76 ListGridField cfield = new ListGridField( | 77 final ListGridField cfield = new ListGridField("curvelink", this.MSG.gauge_curve_link()); |
77 "curvelink", MSG.gauge_curve_link()); | |
78 cfield.addRecordClickHandler(this); | 78 cfield.addRecordClickHandler(this); |
79 | 79 |
80 this.setShowRecordComponents(true); | 80 this.setShowRecordComponents(true); |
81 this.setShowRecordComponentsByCell(true); | 81 this.setShowRecordComponentsByCell(true); |
82 this.setFields(nfield, sfield, efield, stfield, lfield, cfield); | 82 this.setFields(nfield, sfield, efield, stfield, lfield, cfield); |
83 } | 83 } |
84 | 84 |
85 public void setRiverInfo(RiverInfo riverinfo) { | 85 @Override |
86 List<GaugeInfo> gauges = riverinfo.getGauges(); | 86 public void setRiverInfo(final RiverInfo riverinfo) { |
87 final List<GaugeInfo> gauges = riverinfo.getGauges(); | |
87 | 88 |
88 if (gauges != null && !gauges.isEmpty()) { | 89 if (gauges != null && !gauges.isEmpty()) { |
89 | 90 |
90 ArrayList<GaugeInfo> emptygauges = new ArrayList<GaugeInfo>(); | 91 final ArrayList<GaugeInfo> emptygauges = new ArrayList<GaugeInfo>(); |
91 | 92 |
92 if (!riverinfo.isKmUp()) { | 93 if (!riverinfo.isKmUp()) { |
93 for (GaugeInfo gauge : gauges) { | 94 for (final GaugeInfo gauge : gauges) { |
94 addGauge(gauge, emptygauges); | 95 addGauge(gauge, emptygauges); |
95 } | 96 } |
96 } | 97 } else { |
97 else { | 98 for (int i = gauges.size() - 1; i >= 0; i--) { |
98 for (int i = gauges.size()-1; i >= 0; i--) { | 99 final GaugeInfo gauge = gauges.get(i); |
99 GaugeInfo gauge = gauges.get(i); | |
100 addGauge(gauge, emptygauges); | 100 addGauge(gauge, emptygauges); |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 // put empty gauges to the end | 104 // put empty gauges to the end |
105 for (GaugeInfo gauge : emptygauges) { | 105 for (final GaugeInfo gauge : emptygauges) { |
106 addGauge(gauge); | 106 addGauge(gauge); |
107 } | 107 } |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 private void addGauge(GaugeInfo gauge, List<GaugeInfo> empty) { | 111 private void addGauge(final GaugeInfo gauge, final List<GaugeInfo> empty) { |
112 if (gauge.getKmStart() != null && gauge.getKmEnd() != null) { | 112 if (gauge.getKmStart() != null && gauge.getKmEnd() != null) { |
113 addGauge(gauge); | 113 addGauge(gauge); |
114 } | 114 } else { |
115 else { | |
116 empty.add(gauge); | 115 empty.add(gauge); |
117 } | 116 } |
118 } | 117 } |
119 | 118 |
120 private void addGauge(GaugeInfo gauge) { | 119 private void addGauge(final GaugeInfo gauge) { |
121 this.addData(new GaugeRecord(gauge)); | 120 |
122 } | 121 this.gauges.add(gauge); |
123 | 122 |
123 // this.addData(new GaugeRecord(gauge)); | |
124 | |
125 } | |
126 | |
127 @Override | |
124 public void open() { | 128 public void open() { |
125 ArrayList<Double> locations = new ArrayList<Double>(); | 129 final ArrayList<Double> locations = new ArrayList<Double>(); |
126 | 130 |
127 if (data != null && data.length > 0) { | 131 if (this.data != null && this.data.length > 0) { |
128 for (int i = 0; i < data.length; i++) { | 132 for (final DataList dl : this.data) { |
129 DataList dl = data[i]; | 133 |
130 String state = dl.getState(); | 134 final String state = dl.getState(); |
135 DisappearType type = DisappearType.collapse; | |
136 if (state.contains("state.bundu.") || state.contains("state.fix.")) { | |
137 type = DisappearType.remove; | |
138 } | |
139 | |
131 GWT.log("GaugeListGrid - open " + state); | 140 GWT.log("GaugeListGrid - open " + state); |
132 if (state.equals("state.winfo.location_distance")) { | 141 if (state.contains(".location_distance")) { |
133 Double ldfrom = null; | 142 Double ldfrom = null; |
134 Double ldto = null; | 143 Double ldto = null; |
135 | 144 |
136 for (int j = dl.size()-1; j >= 0; --j) { | 145 for (int j = dl.size() - 1; j >= 0; --j) { |
137 Data d = dl.get(j); | 146 final Data d = dl.get(j); |
138 String label = d.getLabel(); | 147 final String label = d.getLabel(); |
139 GWT.log("GaugeListGrid - setData - label " | 148 GWT.log("GaugeListGrid - setData - label " + label + " " + d.getStringValue()); |
140 + label + " " + d.getStringValue()); | |
141 if (label.equals("ld_from")) { | 149 if (label.equals("ld_from")) { |
142 ldfrom = getDoubleValue(d); | 150 ldfrom = getDoubleValue(d); |
143 } | 151 } else if (label.equals("ld_to")) { |
144 else if (label.equals("ld_to")) { | |
145 ldto = getDoubleValue(d); | 152 ldto = getDoubleValue(d); |
146 } | 153 } else if (label.equals("ld_locations")) { |
147 else if (label.equals("ld_locations")) { | |
148 getLocationsFromData(locations, d); | 154 getLocationsFromData(locations, d); |
149 openOnLocations(locations); | 155 openOnLocations(locations); |
150 return; | 156 return; |
151 } | 157 } |
152 } | 158 } |
153 if (ldfrom != null) { | 159 if (ldfrom != null) { |
154 openOnDistance(ldfrom, ldto); | 160 |
161 openOnDistance(ldfrom, ldto, type); | |
155 return; | 162 return; |
156 } | 163 } |
157 } | 164 } else if (state.contains(".distance_only") || state.contains(".distance") |
158 else if(state.equals("state.winfo.distance_only") || | 165 || state.contains(".location") && !state.contains(".location_distance")) { |
159 state.equals("state.winfo.distance")) { | |
160 Double ldfrom = null; | 166 Double ldfrom = null; |
161 Double ldto = null; | 167 Double ldto = null; |
162 | 168 |
163 for (int j = dl.size()-1; j >= 0; --j) { | 169 for (int j = dl.size() - 1; j >= 0; --j) { |
164 Data d = dl.get(j); | 170 final Data d = dl.get(j); |
165 String label = d.getLabel(); | 171 final String label = d.getLabel(); |
166 GWT.log("GaugeListGrid - setData - label " | 172 GWT.log("GaugeListGrid - setData - label " + label + " " + d.getStringValue()); |
167 + label + " " + d.getStringValue()); | |
168 if (label.equals("ld_from")) { | 173 if (label.equals("ld_from")) { |
169 ldfrom = getDoubleValue(d); | 174 ldfrom = getDoubleValue(d); |
170 } | 175 } else if (label.equals("ld_to")) { |
171 else if (label.equals("ld_to")) { | |
172 ldto = getDoubleValue(d); | 176 ldto = getDoubleValue(d); |
173 } | 177 } |
174 } | 178 } |
175 | 179 |
176 if (ldfrom != null) { | 180 if (ldfrom != null) { |
177 openOnDistance(ldfrom, ldto); | 181 openOnDistance(ldfrom, ldto, type); |
178 return; | 182 return; |
179 } | 183 } |
180 } | 184 } else if (state.equals("state.winfo.location")) { |
181 else if (state.equals("state.winfo.location")) { | |
182 getLocations("ld_locations", locations, dl); | 185 getLocations("ld_locations", locations, dl); |
183 openOnLocations(locations); | 186 openOnLocations(locations); |
184 return; | 187 return; |
185 } | 188 } else if (state.equals("state.winfo.reference.curve.input.start")) { |
186 else if (state | |
187 .equals("state.winfo.reference.curve.input.start") | |
188 ) { | |
189 getLocations("reference_startpoint", locations, dl); | 189 getLocations("reference_startpoint", locations, dl); |
190 } | 190 } else if (state.equals("state.winfo.reference.curve.input.end")) { |
191 else if (state | |
192 .equals("state.winfo.reference.curve.input.end") | |
193 ) { | |
194 getLocations("reference_endpoint", locations, dl); | 191 getLocations("reference_endpoint", locations, dl); |
195 } | 192 } else if (state.equals("state.winfo.historicalq.reference_gauge")) { |
196 else if (state | 193 for (int j = dl.size() - 1; j >= 0; --j) { |
197 .equals("state.winfo.historicalq.reference_gauge") | 194 final Data d = dl.get(j); |
198 ) { | 195 final String label = d.getLabel(); |
199 for (int j = dl.size()-1; j >= 0; --j) { | |
200 Data d = dl.get(j); | |
201 String label = d.getLabel(); | |
202 if (label.equals("reference_gauge")) { | 196 if (label.equals("reference_gauge")) { |
203 String tmp = d.getStringValue(); | 197 final String tmp = d.getStringValue(); |
204 if (tmp != null) { | 198 if (tmp != null) { |
205 Long gaugereference = Long.valueOf(tmp); | 199 final Long gaugereference = Long.valueOf(tmp); |
206 if (gaugereference != null) { | 200 if (gaugereference != null) { |
207 openOnReference(gaugereference); | 201 openOnReference(gaugereference); |
208 return; | 202 return; |
209 } | 203 } |
210 } | 204 } |
213 } | 207 } |
214 } | 208 } |
215 } | 209 } |
216 if (!locations.isEmpty()) { | 210 if (!locations.isEmpty()) { |
217 openOnLocations(locations); | 211 openOnLocations(locations); |
218 } | 212 } else { |
219 else { | |
220 openAll(); | 213 openAll(); |
221 } | 214 } |
222 } | 215 } |
223 | 216 |
224 void getLocations(String labelname, List<Double> locations, DataList dl) { | 217 @Override |
225 for (int j = dl.size()-1; j >= 0; --j) { | 218 public void openAll() { |
226 Data d = dl.get(j); | 219 |
227 String label = d.getLabel(); | 220 GWT.log("InfoListGrid - openAll"); |
221 | |
222 setData(new ListGridRecord[] {}); | |
223 for (final GaugeInfo gauge : this.gauges) { | |
224 addExpandedRecord(gauge); | |
225 } | |
226 } | |
227 | |
228 void getLocations(final String labelname, final List<Double> locations, final DataList dl) { | |
229 for (int j = dl.size() - 1; j >= 0; --j) { | |
230 final Data d = dl.get(j); | |
231 final String label = d.getLabel(); | |
228 if (label.equals(labelname)) { | 232 if (label.equals(labelname)) { |
229 getLocationsFromData(locations, d); | 233 getLocationsFromData(locations, d); |
230 } | 234 } |
231 } | 235 } |
232 } | 236 } |
233 | 237 |
234 void getLocationsFromData(List<Double> locations, Data data) { | 238 void getLocationsFromData(final List<Double> locations, final Data data) { |
235 DataItem[] items = data.getItems(); | 239 final DataItem[] items = data.getItems(); |
236 for (int k = 0; k < items.length; k++) { | 240 for (final DataItem item : items) { |
237 String tmp = items[k].getStringValue(); | 241 final String tmp = item.getStringValue(); |
238 GWT.log("GaugeListGrid - getLocationsFromData " + tmp); | 242 GWT.log("GaugeListGrid - getLocationsFromData " + tmp); |
239 if (tmp != null) { | 243 if (tmp != null) { |
240 if (tmp.contains(" ")) { | 244 if (tmp.contains(" ")) { |
241 // string contains several values ... | 245 // string contains several values ... |
242 String[] values = tmp.split(" "); | 246 final String[] values = tmp.split(" "); |
243 for(int i=0; i < values.length; i++) { | 247 for (final String value2 : values) { |
244 Double value = Double.valueOf(values[i]); | 248 final Double value = Double.valueOf(value2); |
245 if (value != null) { | 249 if (value != null) { |
246 locations.add(value); | 250 locations.add(value); |
247 } | 251 } |
248 } | 252 } |
249 } | 253 } else { |
250 else { | 254 final Double value = Double.valueOf(tmp); |
251 Double value = Double.valueOf(tmp); | |
252 if (value != null) { | 255 if (value != null) { |
253 locations.add(value); | 256 locations.add(value); |
254 } | 257 } |
255 } | 258 } |
256 } | 259 } |
257 } | 260 } |
258 } | 261 } |
259 | 262 |
260 public void openOnReference(Long number) { | 263 public void openOnReference(final Long number) { |
261 GWT.log("GaugeListGrid - openOnReference " + number); | 264 GWT.log("GaugeListGrid - openOnReference " + number); |
262 for (ListGridRecord record: this.getRecords()) { | 265 |
263 GaugeRecord item = (GaugeRecord)record; | 266 setData(new ListGridRecord[] {}); |
264 if (item.getOfficialNumber().equals(number)) { | 267 |
265 expandRecord(item); | 268 for (final GaugeInfo gauge : this.gauges) { |
266 } | 269 |
267 else { | 270 if (gauge.getOfficialNumber().equals(number)) { |
268 collapseRecord(item); | 271 this.addExpandedRecord(gauge);// (gauge); |
269 } | 272 } else { |
270 } | 273 this.addCollapsedRecord(gauge); |
271 } | 274 } |
272 | 275 } |
273 public void openOnDistance(Double start, Double end) { | 276 } |
277 | |
278 public void openOnDistance(final Double start, final Double end, final DisappearType type) { | |
274 GWT.log("GaugeListGrid - openOnDistance " + start + " " + end); | 279 GWT.log("GaugeListGrid - openOnDistance " + start + " " + end); |
275 | 280 |
276 for (ListGridRecord record: this.getRecords()) { | 281 setData(new ListGridRecord[] {}); |
277 GaugeRecord item = (GaugeRecord)record; | 282 |
278 if (end == null && item.getKmStart() != null) { | 283 for (final GaugeInfo gauge : this.gauges) { |
279 if (item.getKmStart() >= start) { | 284 |
280 expandRecord(item); | 285 if (end == null && gauge.getKmStart() != null) { |
281 } | 286 if (gauge.getKmStart() >= start) { |
282 else { | 287 addExpandedRecord(gauge); |
283 collapseRecord(item); | 288 } else { |
284 } | 289 removeOrCollapse(gauge, type); |
285 } | 290 } |
286 else if (item.getKmStart() != null && item.getKmEnd() != null) { | 291 } else if (gauge.getKmStart() != null && gauge.getKmEnd() != null) { |
287 // as getStart()/getEnd() return Double objects, | 292 // as getStart()/getEnd() return Double objects, |
288 // they can be null and | 293 // they can be null and |
289 // can cause NPEs when comparing with double... strange... | 294 // can cause NPEs when comparing with double... strange... |
290 GWT.log("GaugeListGrid - openOnDistance item " | 295 GWT.log("GaugeListGrid - openOnDistance item " + gauge.getKmStart() + " " + gauge.getKmEnd()); |
291 + item.getKmStart() + " " + item.getKmEnd()); | 296 if ((start >= gauge.getKmStart() && start <= gauge.getKmEnd()) || (end >= gauge.getKmStart() && end <= gauge.getKmEnd()) |
292 if ((start >= item.getKmStart() && start <= item.getKmEnd()) || | 297 || (start <= gauge.getKmStart() && end >= gauge.getKmEnd())) { |
293 (end >= item.getKmStart() && end <= item.getKmEnd()) || | 298 addExpandedRecord(gauge); |
294 (start <= item.getKmStart() && end >= item.getKmEnd())) { | 299 } else { |
295 expandRecord(item); | 300 removeOrCollapse(gauge, type); |
296 } | 301 } |
297 else { | 302 } else { |
298 collapseRecord(item); | 303 removeOrCollapse(gauge, type); |
299 } | 304 } |
300 } | 305 } |
301 else { | 306 } |
302 collapseRecord(item); | 307 |
303 } | 308 private void removeOrCollapse(final GaugeInfo gauge, final DisappearType type) { |
304 } | 309 switch (type) { |
310 case remove: | |
311 // Remove: gauge wird der datasource nicht hinzugefügt | |
312 break; | |
313 case collapse: | |
314 addCollapsedRecord(gauge); | |
315 break; | |
316 case stayVisible: // TODO: check | |
317 addExpandedRecord(gauge); | |
318 break; | |
319 } | |
320 | |
305 } | 321 } |
306 | 322 |
307 /** | 323 /** |
308 * Open Gauge entry if a location fits to the gauge. | 324 * Open Gauge entry if a location fits to the gauge. |
309 */ | 325 */ |
310 public void openOnLocations(List<Double> locations) { | 326 public void openOnLocations(final List<Double> locations) { |
311 GWT.log("GaugeListGrid - openOnLocations " + locations); | 327 GWT.log("GaugeListGrid - openOnLocations " + locations); |
328 | |
329 setData(new ListGridRecord[] {}); | |
312 | 330 |
313 if (locations == null || locations.isEmpty()) { | 331 if (locations == null || locations.isEmpty()) { |
314 return; | 332 return; |
315 } | 333 } |
316 | 334 |
317 for (ListGridRecord record: this.getRecords()) { | 335 for (final GaugeInfo gauge : this.gauges) { |
318 GaugeRecord item = (GaugeRecord)record; | |
319 boolean isset = false; | 336 boolean isset = false; |
320 for (Double location: locations) { | 337 for (final Double location : locations) { |
321 if (locations == null) { | 338 if (locations == null) { |
322 continue; | 339 continue; |
323 } | 340 } |
324 | 341 |
325 Double start = item.getKmStart(); | 342 final Double start = gauge.getKmStart(); |
326 Double end = item.getKmEnd(); | 343 final Double end = gauge.getKmEnd(); |
327 if (start == null || end == null) { | 344 if (start == null || end == null) { |
328 // should not occur but avoid NullPointerException | 345 // should not occur but avoid NullPointerException |
329 continue; | 346 continue; |
330 } | 347 } |
331 | 348 |
333 isset = true; | 350 isset = true; |
334 break; | 351 break; |
335 } | 352 } |
336 } | 353 } |
337 if (isset) { | 354 if (isset) { |
338 expandRecord(item); | 355 addExpandedRecord(gauge); |
339 } | 356 } else { |
340 else { | 357 addCollapsedRecord(gauge); |
341 collapseRecord(item); | 358 } |
342 } | 359 } |
343 } | 360 } |
344 } | 361 |
345 | 362 private void addExpandedRecord(final GaugeInfo gauge) { |
346 @Override | 363 final GaugeRecord record = new GaugeRecord(gauge); |
347 protected Canvas getExpandPanel(ListGridRecord record) { | 364 |
348 GaugeRecord item = (GaugeRecord)record; | 365 this.addData(record); |
349 return new GaugeInfoPanel(item, flys); | 366 |
367 expandRecord(record); | |
368 } | |
369 | |
370 private void addCollapsedRecord(final GaugeInfo gauge) { | |
371 final GaugeRecord record = new GaugeRecord(gauge); | |
372 | |
373 this.addData(record); | |
374 | |
375 collapseRecord(record); | |
376 } | |
377 | |
378 @Override | |
379 protected Canvas getExpandPanel(final ListGridRecord record) { | |
380 final GaugeRecord item = (GaugeRecord) record; | |
381 return new GaugeInfoPanel(item, this.flys); | |
350 } | 382 } |
351 | 383 |
352 /** | 384 /** |
353 * When clicked on the gauge discharge link, open new Gauge Discharge | 385 * When clicked on the gauge discharge link, open new Gauge Discharge |
354 * Curve view. | 386 * Curve view. |
355 */ | 387 */ |
356 @Override | 388 @Override |
357 public void onRecordClick(RecordClickEvent event) { | 389 public void onRecordClick(final RecordClickEvent event) { |
358 final GaugeRecord gauge = (GaugeRecord)event.getRecord(); | 390 final GaugeRecord gauge = (GaugeRecord) event.getRecord(); |
359 Config config = Config.getInstance(); | 391 final Config config = Config.getInstance(); |
360 final String locale = config.getLocale(); | 392 final String locale = config.getLocale(); |
361 createCollectionService.create( | 393 this.createCollectionService.create(locale, this.flys.getCurrentUser().identifier(), new AsyncCallback<Collection>() { |
362 locale, | 394 @Override |
363 flys.getCurrentUser().identifier(), | 395 public void onFailure(final Throwable caught) { |
364 new AsyncCallback<Collection>() { | 396 GWT.log("Could not create the new collection."); |
397 SC.warn(FLYS.getExceptionString(GaugeListGrid.this.MSG, caught)); | |
398 } | |
399 | |
400 @Override | |
401 public void onSuccess(final Collection collection) { | |
402 GWT.log("Successfully created a new collection."); | |
403 createArtifact(collection, locale, gauge); | |
404 } | |
405 }); | |
406 } | |
407 | |
408 private void createArtifact(final Collection collection, final String locale, final GaugeRecord gauge) { | |
409 this.artifactService.create(locale, "gaugedischargecurve", null, new AsyncCallback<Artifact>() { | |
410 @Override | |
411 public void onFailure(final Throwable caught) { | |
412 GWT.log("Could not create the new artifact."); | |
413 SC.warn(FLYS.getExceptionString(GaugeListGrid.this.MSG, caught)); | |
414 } | |
415 | |
416 @Override | |
417 public void onSuccess(final Artifact artifact) { | |
418 GWT.log("Successfully created a new artifact."); | |
419 | |
420 final DataItem riverItem = new DefaultDataItem("river", "river", gauge.getRiverName()); | |
421 final Data river = new DefaultData("river", null, null, new DataItem[] { riverItem }); | |
422 | |
423 final DataItem refItem = new DefaultDataItem("reference_gauge", "reference_gauge", gauge.getOfficialNumber().toString()); | |
424 final Data ref = new DefaultData("reference_gauge", null, null, new DataItem[] { refItem }); | |
425 | |
426 final DataItem locItem = new DefaultDataItem("ld_locations", "ld_locations", gauge.getStation().toString()); | |
427 final Data loc = new DefaultData("ld_locations", null, null, new DataItem[] { locItem }); | |
428 | |
429 final DataItem nameItem = new DefaultDataItem("gauge_name", "gauge_name", gauge.getName()); | |
430 final Data name = new DefaultData("gauge_name", null, null, new DataItem[] { nameItem }); | |
431 | |
432 final Data[] data = new Data[] { river, ref, loc, name }; | |
433 GaugeListGrid.this.forwardService.go(locale, artifact, data, new AsyncCallback<Artifact>() { | |
365 @Override | 434 @Override |
366 public void onFailure(Throwable caught) { | 435 public void onFailure(final Throwable caught) { |
367 GWT.log("Could not create the new collection."); | 436 GWT.log("Could not feed the artifact."); |
368 SC.warn(FLYS.getExceptionString(MSG, caught)); | 437 SC.warn(caught.getMessage()); |
369 } | 438 } |
370 | 439 |
371 @Override | 440 @Override |
372 public void onSuccess(Collection collection) { | 441 public void onSuccess(final Artifact artifact) { |
373 GWT.log("Successfully created a new collection."); | 442 GWT.log("Successfully feed the artifact."); |
374 createArtifact(collection, locale, gauge); | 443 final CollectionView view = new CollectionView(GaugeListGrid.this.flys, collection, artifact); |
375 } | 444 GaugeListGrid.this.flys.getWorkspace().addView(collection.identifier(), view); |
376 } | 445 view.addArtifactToCollection(artifact); |
377 ); | 446 } |
378 } | 447 }); |
379 | 448 } |
380 private void createArtifact( | 449 }); |
381 final Collection collection, | 450 } |
382 final String locale, | 451 |
383 final GaugeRecord gauge | 452 @Override |
384 ) { | 453 public String getCellCSSText(final ListGridRecord record, final int rowNum, final int colNum) { |
385 artifactService.create( | |
386 locale, "gaugedischargecurve", null, | |
387 new AsyncCallback<Artifact>() { | |
388 @Override | |
389 public void onFailure(Throwable caught) { | |
390 GWT.log("Could not create the new artifact."); | |
391 SC.warn(FLYS.getExceptionString(MSG, caught)); | |
392 } | |
393 | |
394 @Override | |
395 public void onSuccess(Artifact artifact) { | |
396 GWT.log("Successfully created a new artifact."); | |
397 | |
398 DataItem riverItem = new DefaultDataItem( | |
399 "river", | |
400 "river", | |
401 gauge.getRiverName()); | |
402 Data river = new DefaultData( | |
403 "river", | |
404 null, | |
405 null, | |
406 new DataItem[]{riverItem}); | |
407 | |
408 DataItem refItem = new DefaultDataItem( | |
409 "reference_gauge", | |
410 "reference_gauge", | |
411 gauge.getOfficialNumber().toString()); | |
412 Data ref = new DefaultData( | |
413 "reference_gauge", | |
414 null, | |
415 null, | |
416 new DataItem[]{refItem}); | |
417 | |
418 DataItem locItem = new DefaultDataItem( | |
419 "ld_locations", | |
420 "ld_locations", | |
421 gauge.getStation().toString()); | |
422 Data loc = new DefaultData( | |
423 "ld_locations", | |
424 null, | |
425 null, | |
426 new DataItem[]{locItem}); | |
427 | |
428 DataItem nameItem = new DefaultDataItem( | |
429 "gauge_name", | |
430 "gauge_name", | |
431 gauge.getName()); | |
432 Data name = new DefaultData( | |
433 "gauge_name", | |
434 null, | |
435 null, | |
436 new DataItem[]{nameItem}); | |
437 | |
438 Data[] data = new Data[]{river, ref, loc, name}; | |
439 forwardService.go(locale, artifact, data, | |
440 new AsyncCallback<Artifact>() { | |
441 @Override | |
442 public void onFailure(Throwable caught) { | |
443 GWT.log("Could not feed the artifact."); | |
444 SC.warn(caught.getMessage()); | |
445 } | |
446 | |
447 @Override | |
448 public void onSuccess(Artifact artifact) { | |
449 GWT.log("Successfully feed the artifact."); | |
450 CollectionView view = new CollectionView( | |
451 flys, | |
452 collection, | |
453 artifact); | |
454 flys.getWorkspace().addView( | |
455 collection.identifier(), | |
456 view); | |
457 view.addArtifactToCollection(artifact); | |
458 } | |
459 }); | |
460 } | |
461 }); | |
462 } | |
463 | |
464 @Override | |
465 public String getCellCSSText(ListGridRecord record, int rowNum, | |
466 int colNum) { | |
467 if (colNum == ABFLUSSTAFEL_COLUMN) { | 454 if (colNum == ABFLUSSTAFEL_COLUMN) { |
468 // display the ablfusstafel cell like a link | 455 // display the ablfusstafel cell like a link |
469 return "text-decoration: underline; color: #0000EE; " | 456 return "text-decoration: underline; color: #0000EE; " + "cursor: pointer;"; |
470 + "cursor: pointer;"; | 457 } else { |
471 } | |
472 else { | |
473 return super.getCellCSSText(record, rowNum, colNum); | 458 return super.getCellCSSText(record, rowNum, colNum); |
474 } | 459 } |
475 } | 460 } |
476 } | 461 } |