Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java @ 235:d3f8d6966c20
Added location and distance tables.
flys-client/trunk@1791 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 02 May 2011 14:47:12 +0000 |
parents | b92281182c6b |
children | cf25f235b7b6 |
comparison
equal
deleted
inserted
replaced
234:27f5afc4dbde | 235:d3f8d6966c20 |
---|---|
2 | 2 |
3 import java.util.LinkedHashMap; | 3 import java.util.LinkedHashMap; |
4 import java.util.List; | 4 import java.util.List; |
5 | 5 |
6 import com.google.gwt.core.client.GWT; | 6 import com.google.gwt.core.client.GWT; |
7 import com.google.gwt.user.client.rpc.AsyncCallback; | |
7 | 8 |
8 import com.smartgwt.client.widgets.Canvas; | 9 import com.smartgwt.client.widgets.Canvas; |
9 import com.smartgwt.client.widgets.Label; | 10 import com.smartgwt.client.widgets.Label; |
10 import com.smartgwt.client.widgets.form.DynamicForm; | 11 import com.smartgwt.client.widgets.form.DynamicForm; |
11 import com.smartgwt.client.widgets.form.fields.events.BlurHandler; | 12 import com.smartgwt.client.widgets.form.fields.events.BlurHandler; |
14 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; | 15 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; |
15 import com.smartgwt.client.widgets.form.fields.FormItem; | 16 import com.smartgwt.client.widgets.form.fields.FormItem; |
16 import com.smartgwt.client.widgets.form.fields.RadioGroupItem; | 17 import com.smartgwt.client.widgets.form.fields.RadioGroupItem; |
17 import com.smartgwt.client.widgets.layout.HLayout; | 18 import com.smartgwt.client.widgets.layout.HLayout; |
18 import com.smartgwt.client.widgets.layout.VLayout; | 19 import com.smartgwt.client.widgets.layout.VLayout; |
20 import com.smartgwt.client.widgets.grid.ListGrid; | |
21 import com.smartgwt.client.widgets.grid.ListGridField; | |
22 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
23 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; | |
24 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; | |
25 import com.smartgwt.client.widgets.grid.events.CellClickHandler; | |
26 import com.smartgwt.client.widgets.grid.events.CellClickEvent; | |
27 | |
28 import com.smartgwt.client.widgets.tab.TabSet; | |
29 import com.smartgwt.client.widgets.tab.Tab; | |
30 import com.smartgwt.client.data.Record; | |
31 | |
32 import com.smartgwt.client.types.Alignment; | |
33 import com.smartgwt.client.types.ListGridFieldType; | |
34 import com.smartgwt.client.types.SelectionAppearance; | |
35 import com.smartgwt.client.types.SelectionStyle; | |
36 import com.smartgwt.client.widgets.grid.events.SelectionChangedHandler; | |
37 import com.smartgwt.client.widgets.grid.events.SelectionEvent; | |
19 | 38 |
20 import de.intevation.flys.client.shared.model.Data; | 39 import de.intevation.flys.client.shared.model.Data; |
21 import de.intevation.flys.client.shared.model.DataItem; | 40 import de.intevation.flys.client.shared.model.DataItem; |
22 import de.intevation.flys.client.shared.model.DataList; | 41 import de.intevation.flys.client.shared.model.DataList; |
23 import de.intevation.flys.client.shared.model.DefaultData; | 42 import de.intevation.flys.client.shared.model.DefaultData; |
24 import de.intevation.flys.client.shared.model.DefaultDataItem; | 43 import de.intevation.flys.client.shared.model.DefaultDataItem; |
44 import de.intevation.flys.client.shared.model.DistanceInfoObject; | |
45 import de.intevation.flys.client.shared.model.DistanceInfoObjectImpl; | |
46 import de.intevation.flys.client.shared.model.DistanceInfoRecord; | |
47 import de.intevation.flys.client.shared.model.ArtifactDescription; | |
48 | |
49 import de.intevation.flys.client.server.DistanceInfoServiceImpl; | |
50 import de.intevation.flys.client.client.services.DistanceInfoService; | |
51 import de.intevation.flys.client.client.services.DistanceInfoServiceAsync; | |
25 import de.intevation.flys.client.client.FLYSConstants; | 52 import de.intevation.flys.client.client.FLYSConstants; |
53 import de.intevation.flys.client.client.FLYSImages; | |
54 import de.intevation.flys.client.client.Config; | |
26 | 55 |
27 | 56 |
28 /** | 57 /** |
29 * This UIProvider creates a widget to enter locations or a distance. | 58 * This UIProvider creates a widget to enter locations or a distance. |
30 * | 59 * |
35 implements ChangeHandler, BlurHandler | 64 implements ChangeHandler, BlurHandler |
36 { | 65 { |
37 /** The message class that provides i18n strings.*/ | 66 /** The message class that provides i18n strings.*/ |
38 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); | 67 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); |
39 | 68 |
69 /** The interface that provides the image resources. */ | |
70 private FLYSImages IMAGES = GWT.create(FLYSImages.class); | |
71 | |
72 /** The DistanceInfoService used to retrieve locations about rivers.*/ | |
73 protected DistanceInfoServiceAsync distanceInfoService = | |
74 GWT.create(DistanceInfoService.class); | |
40 | 75 |
41 /** The constant name of the input field to enter locations.*/ | 76 /** The constant name of the input field to enter locations.*/ |
42 public static final String FIELD_LOCATION = "location"; | 77 public static final String FIELD_LOCATION = "location"; |
43 | 78 |
44 /** The constant name of the input field to enter distance.*/ | 79 /** The constant name of the input field to enter distance.*/ |
79 protected double step; | 114 protected double step; |
80 | 115 |
81 /** The values entered in the location mode.*/ | 116 /** The values entered in the location mode.*/ |
82 protected double[] values; | 117 protected double[] values; |
83 | 118 |
119 /** The input panel for locations */ | |
120 protected DoubleArrayPanel locationPanel; | |
121 | |
122 /** The input panel for distances */ | |
123 protected DoubleRangePanel distancePanel; | |
124 | |
125 /** The tab set containing the location and distance table*/ | |
126 protected TabSet inputTables; | |
127 | |
128 /** The distance table. */ | |
129 protected ListGrid distanceTable; | |
130 | |
131 /** The locations table */ | |
132 protected ListGrid locationsTable; | |
133 | |
134 /** The locations table for distance input. */ | |
135 protected ListGrid locationDistanceTable; | |
84 | 136 |
85 /** | 137 /** |
86 * Creates a new LocationDistancePanel instance. | 138 * Creates a new LocationDistancePanel instance. |
87 */ | 139 */ |
88 public LocationDistancePanel() { | 140 public LocationDistancePanel() { |
141 distanceTable = new ListGrid(); | |
142 locationsTable = new ListGrid(); | |
143 locationDistanceTable = new ListGrid(); | |
89 } | 144 } |
90 | 145 |
91 | 146 |
92 /** | 147 /** |
93 * This method creates a widget that contains a label, a panel with | 148 * This method creates a widget that contains a label, a panel with |
105 initDefaults(data); | 160 initDefaults(data); |
106 | 161 |
107 Label label = new Label(MESSAGES.location_distance_state()); | 162 Label label = new Label(MESSAGES.location_distance_state()); |
108 Canvas widget = createWidget(data); | 163 Canvas widget = createWidget(data); |
109 Canvas submit = getNextButton(); | 164 Canvas submit = getNextButton(); |
165 createDistanceInputPanel(); | |
166 | |
167 createDistanceTable(); | |
168 createLocationTable(); | |
110 | 169 |
111 widget.setHeight(50); | 170 widget.setHeight(50); |
112 label.setHeight(25); | 171 label.setHeight(25); |
113 | 172 |
114 layout.addMember(label); | 173 layout.addMember(label); |
115 layout.addMember(widget); | 174 layout.addMember(widget); |
116 layout.addMember(submit); | 175 layout.addMember(submit); |
117 | 176 |
118 return layout; | 177 return layout; |
178 } | |
179 | |
180 | |
181 /** | |
182 * This method creates a table that contains the distance values. | |
183 */ | |
184 protected void createDistanceTable() { | |
185 distanceTable.setWidth100(); | |
186 distanceTable.setShowRecordComponents(true); | |
187 distanceTable.setShowRecordComponentsByCell(true); | |
188 distanceTable.setHeight100(); | |
189 | |
190 ListGridField addDistance = new ListGridField ("", ""); | |
191 addDistance.setType (ListGridFieldType.ICON); | |
192 addDistance.setWidth ("30"); | |
193 addDistance.addRecordClickHandler (new RecordClickHandler () { | |
194 public void onRecordClick (RecordClickEvent e) { | |
195 if (!isLocationMode ()) { | |
196 Record r = e.getRecord(); | |
197 double min = r.getAttributeAsDouble("from"); | |
198 double max = r.getAttributeAsDouble("to"); | |
199 setDistanceValues(min, max); | |
200 } | |
201 else { | |
202 double[] selected; | |
203 if (getLocationValues() != null) { | |
204 double[] val = getLocationValues(); | |
205 selected = new double[val.length + 2]; | |
206 for(int i = 0; i < val.length; i++){ | |
207 selected[i] = val[i]; | |
208 } | |
209 selected[val.length] = min; | |
210 selected[val.length + 1] = max; | |
211 } | |
212 else { | |
213 selected = new double[2]; | |
214 selected[0] = min; | |
215 selected[1] = max; | |
216 } | |
217 setLocationValues(selected); | |
218 } | |
219 } | |
220 }); | |
221 addDistance.setCellIcon (IMAGES.markerGreen ().getURL ()); | |
222 | |
223 ListGridField ddescr = new ListGridField("description", | |
224 MESSAGES.description()); | |
225 ddescr.setType(ListGridFieldType.TEXT); | |
226 ddescr.setWidth("*"); | |
227 ListGridField from = new ListGridField("from", MESSAGES.from()); | |
228 from.setType(ListGridFieldType.TEXT); | |
229 from.setWidth(75); | |
230 ListGridField to = new ListGridField("to", MESSAGES.to()); | |
231 to.setType(ListGridFieldType.TEXT); | |
232 to.setWidth(75); | |
233 ListGridField dside = new ListGridField("riverside", | |
234 MESSAGES.riverside()); | |
235 dside.setType(ListGridFieldType.TEXT); | |
236 dside.setWidth(60); | |
237 | |
238 distanceTable.setFields(addDistance, ddescr, from, to, dside); | |
239 } | |
240 | |
241 | |
242 /** | |
243 * This method creates a table that contains the location values. | |
244 */ | |
245 protected void createLocationTable() { | |
246 locationsTable.setWidth100(); | |
247 locationsTable.setShowRecordComponents(true); | |
248 locationsTable.setShowRecordComponentsByCell(true); | |
249 locationsTable.setHeight100(); | |
250 | |
251 ListGridField addLocation = new ListGridField ("", ""); | |
252 addLocation.setType (ListGridFieldType.ICON); | |
253 addLocation.setWidth ("30"); | |
254 addLocation.addRecordClickHandler (new RecordClickHandler () { | |
255 public void onRecordClick (RecordClickEvent e) { | |
256 ListGridRecord[] records = locationsTable.getSelection(); | |
257 double[] selected; | |
258 if (getLocationValues() != null) { | |
259 double[] val = getLocationValues(); | |
260 selected = new double[val.length + 1]; | |
261 for(int i = 0; i < val.length; i++){ | |
262 selected[i] = val[i]; | |
263 } | |
264 selected[val.length] = | |
265 records[0].getAttributeAsDouble("from"); | |
266 } | |
267 else { | |
268 selected = new double[1]; | |
269 selected[0] = records[0].getAttributeAsDouble("from"); | |
270 } | |
271 setLocationValues(selected); | |
272 } | |
273 }); | |
274 addLocation.setCellIcon (IMAGES.markerGreen ().getURL ()); | |
275 | |
276 ListGridField ldescr = new ListGridField("description", | |
277 MESSAGES.description()); | |
278 ldescr.setType(ListGridFieldType.TEXT); | |
279 ldescr.setWidth("*"); | |
280 ListGridField lside = new ListGridField("riverside", | |
281 MESSAGES.riverside()); | |
282 lside.setType(ListGridFieldType.TEXT); | |
283 lside.setWidth(60); | |
284 ListGridField loc = new ListGridField("from", MESSAGES.location()); | |
285 loc.setType(ListGridFieldType.TEXT); | |
286 loc.setWidth(80); | |
287 locationsTable.setFields(addLocation, ldescr, loc, lside); | |
288 } | |
289 | |
290 | |
291 /** | |
292 * This method creates a table that contains the location values. | |
293 */ | |
294 protected void createLocationTableDistance (){ | |
295 locationDistanceTable.setWidth100(); | |
296 locationDistanceTable.setShowRecordComponents(true); | |
297 locationDistanceTable.setShowRecordComponentsByCell(true); | |
298 locationDistanceTable.setHeight100(); | |
299 | |
300 ListGridField addfrom = new ListGridField ("", ""); | |
301 addfrom.setType (ListGridFieldType.ICON); | |
302 addfrom.setWidth ("30"); | |
303 addfrom.setCellIcon (IMAGES.markerGreen ().getURL ()); | |
304 | |
305 ListGridField addto2 = new ListGridField ("", ""); | |
306 addto2.setType (ListGridFieldType.ICON); | |
307 addto2.setWidth ("30"); | |
308 addto2.setCellIcon (IMAGES.markerRed ().getURL ()); | |
309 | |
310 | |
311 ListGridField ldescr = new ListGridField("description", | |
312 MESSAGES.description()); | |
313 ldescr.setType(ListGridFieldType.TEXT); | |
314 ldescr.setWidth("*"); | |
315 ListGridField lside = new ListGridField("riverside", | |
316 MESSAGES.riverside()); | |
317 lside.setType(ListGridFieldType.TEXT); | |
318 lside.setWidth(60); | |
319 ListGridField loc = new ListGridField("from", MESSAGES.location()); | |
320 loc.setType(ListGridFieldType.TEXT); | |
321 loc.setWidth(80); | |
322 locationDistanceTable.addCellClickHandler (new CellClickHandler () { | |
323 public void onCellClick (CellClickEvent e) { | |
324 if (e.getColNum() == 0) { | |
325 Record r = e.getRecord (); | |
326 double fromvalue = r.getAttributeAsDouble ("from"); | |
327 double tovalue = getTo (); | |
328 setDistanceValues (fromvalue, tovalue); | |
329 } | |
330 else if (e.getColNum() == 1) { | |
331 Record r = e.getRecord (); | |
332 double fromvalue = getFrom (); | |
333 double tovalue = r.getAttributeAsDouble ("to"); | |
334 setDistanceValues (fromvalue, tovalue); | |
335 } | |
336 } | |
337 }); | |
338 locationDistanceTable.setFields(addfrom, addto2, ldescr, loc, lside); | |
119 } | 339 } |
120 | 340 |
121 | 341 |
122 public Canvas createOld(DataList dataList) { | 342 public Canvas createOld(DataList dataList) { |
123 List<Data> items = dataList.getAll(); | 343 List<Data> items = dataList.getAll(); |
206 VLayout layout = new VLayout(); | 426 VLayout layout = new VLayout(); |
207 container = new HLayout(); | 427 container = new HLayout(); |
208 Canvas checkboxPanel = createRadioButtonPanel(); | 428 Canvas checkboxPanel = createRadioButtonPanel(); |
209 | 429 |
210 // the initial view will display the location input mode | 430 // the initial view will display the location input mode |
211 Canvas locationPanel = new DoubleArrayPanel( | 431 locationPanel = new DoubleArrayPanel( |
212 MESSAGES.unitLocation(), | 432 MESSAGES.unitLocation(), |
213 getLocationValues(), | 433 getLocationValues(), |
214 this); | 434 this); |
215 container.addMember(locationPanel); | 435 container.addMember(locationPanel); |
216 | 436 |
217 layout.addMember(checkboxPanel); | 437 layout.addMember(checkboxPanel); |
218 layout.addMember(container); | 438 layout.addMember(container); |
219 | 439 |
220 // TODO Add a table on the right to select locations by mouse click | 440 createDistanceInputPanel(); |
441 container.setMembersMargin(30); | |
442 | |
443 inputTables = new TabSet(); | |
444 Tab locations = new Tab(MESSAGES.location()); | |
445 Tab distances = new Tab(MESSAGES.distance()); | |
446 | |
447 inputTables.setWidth(500); | |
448 inputTables.setHeight(350); | |
449 | |
450 locations.setPane(locationsTable); | |
451 distances.setPane(distanceTable); | |
452 | |
453 inputTables.addTab(locations); | |
454 inputTables.addTab(distances); | |
455 | |
456 container.addMember(inputTables); | |
221 | 457 |
222 return layout; | 458 return layout; |
223 } | 459 } |
224 | 460 |
225 | 461 |
372 String value = (String) event.getValue(); | 608 String value = (String) event.getValue(); |
373 | 609 |
374 if (value == null) { | 610 if (value == null) { |
375 return; | 611 return; |
376 } | 612 } |
377 | 613 createDistanceInputPanel(); |
378 if (value.equals(FIELD_LOCATION)) { | 614 if (value.equals(FIELD_LOCATION)) { |
379 Canvas locationPanel = new DoubleArrayPanel( | 615 locationPanel = new DoubleArrayPanel( |
380 MESSAGES.unitLocation(), | 616 MESSAGES.unitLocation(), |
381 getLocationValues(), | 617 getLocationValues(), |
382 this); | 618 this); |
383 | 619 |
384 container.removeMembers(container.getMembers()); | 620 container.removeMembers(container.getMembers()); |
385 container.addMember(locationPanel); | 621 container.addMember(locationPanel); |
622 inputTables.removeTab(1); | |
623 inputTables.removeTab(0); | |
624 Tab t1 = new Tab (MESSAGES.location()); | |
625 createLocationTable(); | |
626 t1.setPane(locationsTable); | |
627 inputTables.addTab(t1); | |
628 createDistanceTable(); | |
629 Tab t2 = new Tab (MESSAGES.distance()); | |
630 t2.setPane(distanceTable); | |
631 inputTables.addTab(t2); | |
632 container.addMember(inputTables); | |
633 inputTables.selectTab(0); | |
386 } | 634 } |
387 else { | 635 else { |
388 Canvas distancePanel = new DoubleRangePanel( | 636 distancePanel = new DoubleRangePanel( |
389 MESSAGES.unitFrom(), MESSAGES.unitTo(), MESSAGES.unitWidth(), | 637 MESSAGES.unitFrom(), MESSAGES.unitTo(), MESSAGES.unitWidth(), |
390 getFrom(), getTo(), getStep(), | 638 getFrom(), getTo(), getStep(), |
391 250, | 639 250, |
392 this); | 640 this); |
393 | 641 |
394 container.removeMembers(container.getMembers()); | 642 container.removeMembers(container.getMembers()); |
395 container.addMember(distancePanel); | 643 container.addMember(distancePanel); |
644 inputTables.removeTab(1); | |
645 inputTables.removeTab(0); | |
646 Tab t1 = new Tab(MESSAGES.location ()); | |
647 createLocationTableDistance (); | |
648 t1.setPane(locationDistanceTable); | |
649 inputTables.addTab(t1); | |
650 createDistanceTable (); | |
651 Tab t2 = new Tab(MESSAGES.distance ()); | |
652 t2.setPane(distanceTable); | |
653 inputTables.addTab(t2); | |
654 container.addMember(inputTables); | |
655 inputTables.selectTab(1); | |
396 } | 656 } |
397 } | 657 } |
398 | 658 |
399 | 659 |
400 /** | 660 /** |
420 DoubleRangePanel p = (DoubleRangePanel) event.getForm(); | 680 DoubleRangePanel p = (DoubleRangePanel) event.getForm(); |
421 | 681 |
422 saveDistanceValue(p, item); | 682 saveDistanceValue(p, item); |
423 } | 683 } |
424 } | 684 } |
685 | |
425 | 686 |
426 | 687 |
427 /** | 688 /** |
428 * Validates and stores all values entered in the location mode. | 689 * Validates and stores all values entered in the location mode. |
429 * | 690 * |
510 | 771 |
511 return mode; | 772 return mode; |
512 } | 773 } |
513 | 774 |
514 | 775 |
776 protected void createDistanceInputPanel() { | |
777 Config config = Config.getInstance(); | |
778 String url = config.getServerUrl(); | |
779 String locale = config.getLocale (); | |
780 String river = ""; | |
781 | |
782 ArtifactDescription adescr = artifact.getArtifactDescription(); | |
783 DataList[] data = adescr.getOldData(); | |
784 | |
785 if (data != null && data.length > 0) { | |
786 for (int i = 0; i < data.length; i++) { | |
787 DataList dl = data[i]; | |
788 if (dl.getState().equals("state.winfo.river")) { | |
789 for (int j = 0; j < dl.size(); j++) { | |
790 Data d = dl.get(j); | |
791 DataItem[] di = d.getItems(); | |
792 if (di != null && di.length == 1) { | |
793 river = d.getItems()[0].getStringValue(); | |
794 } | |
795 } | |
796 } | |
797 } | |
798 } | |
799 | |
800 distanceInfoService.getDistanceInfo(url, locale, river, | |
801 new AsyncCallback<DistanceInfoObject[]>() { | |
802 public void onFailure(Throwable caught) { | |
803 GWT.log("Could not recieve distance informations."); | |
804 GWT.log(caught.getMessage()); | |
805 } | |
806 | |
807 public void onSuccess(DistanceInfoObject[] di) { | |
808 int num = di != null ? di.length :0; | |
809 | |
810 if (num == 0) { | |
811 return; | |
812 } | |
813 updateDistanceInfo(di); | |
814 } | |
815 } | |
816 ); | |
817 } | |
818 | |
819 | |
820 protected void updateDistanceInfo(DistanceInfoObject[] di) { | |
821 int i = 0; | |
822 for (DistanceInfoObject dio: di) { | |
823 if (dio.getTo() != null) { | |
824 distanceTable.addData(new DistanceInfoRecord(dio)); | |
825 } | |
826 else { | |
827 locationsTable.addData(new DistanceInfoRecord(dio)); | |
828 locationDistanceTable.addData(new DistanceInfoRecord(dio)); | |
829 } | |
830 } | |
831 return; | |
832 } | |
833 | |
834 | |
515 protected double getFrom() { | 835 protected double getFrom() { |
516 return from; | 836 return from; |
517 } | 837 } |
518 | 838 |
519 | 839 |
547 } | 867 } |
548 | 868 |
549 | 869 |
550 protected void setLocationValues(double[] values) { | 870 protected void setLocationValues(double[] values) { |
551 this.values = values; | 871 this.values = values; |
872 locationPanel.setValues(values); | |
873 } | |
874 | |
875 | |
876 protected void setDistanceValues (double from, double to) { | |
877 setFrom(from); | |
878 setTo(to); | |
879 distancePanel.setValues(from, to, getStep()); | |
552 } | 880 } |
553 } | 881 } |
554 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 882 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |