Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java @ 4131:360e22afb98b
Cosmetics, warnings and minor TODOs.
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Mon, 15 Oct 2012 00:04:35 +0200 |
parents | 738010779c74 |
children | b296d435fc69 |
comparison
equal
deleted
inserted
replaced
4130:df8ac7ff6b1a | 4131:360e22afb98b |
---|---|
1 package de.intevation.flys.client.client.ui; | 1 package de.intevation.flys.client.client.ui; |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.LinkedHashMap; | |
5 import java.util.List; | |
6 | 2 |
7 import com.google.gwt.core.client.GWT; | 3 import com.google.gwt.core.client.GWT; |
8 import com.google.gwt.i18n.client.NumberFormat; | 4 import com.google.gwt.i18n.client.NumberFormat; |
9 | 5 |
6 import com.smartgwt.client.data.AdvancedCriteria; | |
10 import com.smartgwt.client.data.Criteria; | 7 import com.smartgwt.client.data.Criteria; |
11 import com.smartgwt.client.data.Criterion; | 8 import com.smartgwt.client.data.Criterion; |
12 import com.smartgwt.client.data.AdvancedCriteria; | 9 import com.smartgwt.client.data.Record; |
10 import com.smartgwt.client.types.Alignment; | |
11 import com.smartgwt.client.types.ListGridFieldType; | |
13 import com.smartgwt.client.types.OperatorId; | 12 import com.smartgwt.client.types.OperatorId; |
14 | |
15 import com.smartgwt.client.widgets.Canvas; | 13 import com.smartgwt.client.widgets.Canvas; |
16 import com.smartgwt.client.widgets.Label; | 14 import com.smartgwt.client.widgets.Label; |
17 import com.smartgwt.client.widgets.form.DynamicForm; | 15 import com.smartgwt.client.widgets.form.DynamicForm; |
16 import com.smartgwt.client.widgets.form.fields.FormItem; | |
17 import com.smartgwt.client.widgets.form.fields.RadioGroupItem; | |
18 import com.smartgwt.client.widgets.form.fields.SelectItem; | |
19 import com.smartgwt.client.widgets.form.fields.StaticTextItem; | |
20 import com.smartgwt.client.widgets.form.fields.events.BlurEvent; | |
18 import com.smartgwt.client.widgets.form.fields.events.BlurHandler; | 21 import com.smartgwt.client.widgets.form.fields.events.BlurHandler; |
19 import com.smartgwt.client.widgets.form.fields.events.BlurEvent; | 22 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; |
20 import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; | 23 import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; |
21 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; | 24 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; |
22 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; | 25 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; |
23 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; | 26 import com.smartgwt.client.widgets.grid.CellFormatter; |
24 | |
25 import com.smartgwt.client.widgets.form.fields.FormItem; | |
26 import com.smartgwt.client.widgets.form.fields.SelectItem; | |
27 import com.smartgwt.client.widgets.form.fields.RadioGroupItem; | |
28 import com.smartgwt.client.widgets.form.fields.StaticTextItem; | |
29 import com.smartgwt.client.widgets.layout.HLayout; | |
30 import com.smartgwt.client.widgets.layout.VLayout; | |
31 import com.smartgwt.client.widgets.grid.ListGrid; | 27 import com.smartgwt.client.widgets.grid.ListGrid; |
32 import com.smartgwt.client.widgets.grid.ListGridField; | 28 import com.smartgwt.client.widgets.grid.ListGridField; |
33 import com.smartgwt.client.widgets.grid.ListGridRecord; | 29 import com.smartgwt.client.widgets.grid.ListGridRecord; |
34 import com.smartgwt.client.widgets.grid.CellFormatter; | 30 import com.smartgwt.client.widgets.grid.events.CellClickEvent; |
31 import com.smartgwt.client.widgets.grid.events.CellClickHandler; | |
32 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; | |
35 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; | 33 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; |
36 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; | 34 import com.smartgwt.client.widgets.layout.HLayout; |
37 import com.smartgwt.client.widgets.grid.events.CellClickHandler; | 35 import com.smartgwt.client.widgets.layout.VLayout; |
38 import com.smartgwt.client.widgets.grid.events.CellClickEvent; | 36 import com.smartgwt.client.widgets.tab.Tab; |
37 import com.smartgwt.client.widgets.tab.TabSet; | |
38 import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; | |
39 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; | 39 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; |
40 import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; | 40 |
41 | 41 import de.intevation.flys.client.client.Config; |
42 import com.smartgwt.client.widgets.tab.TabSet; | 42 import de.intevation.flys.client.client.FLYSConstants; |
43 import com.smartgwt.client.widgets.tab.Tab; | 43 import de.intevation.flys.client.client.event.FilterHandler; |
44 import com.smartgwt.client.data.Record; | 44 import de.intevation.flys.client.client.event.RangeFilterEvent; |
45 | 45 import de.intevation.flys.client.client.event.StringFilterEvent; |
46 import com.smartgwt.client.types.ListGridFieldType; | 46 import de.intevation.flys.client.client.services.DistanceInfoService; |
47 import com.smartgwt.client.types.Alignment; | 47 import de.intevation.flys.client.client.services.DistanceInfoServiceAsync; |
48 | 48 import de.intevation.flys.client.client.ui.range.DistanceInfoDataSource; |
49 import de.intevation.flys.client.shared.model.ArtifactDescription; | |
49 import de.intevation.flys.client.shared.model.Data; | 50 import de.intevation.flys.client.shared.model.Data; |
50 import de.intevation.flys.client.shared.model.DataItem; | 51 import de.intevation.flys.client.shared.model.DataItem; |
51 import de.intevation.flys.client.shared.model.DataList; | 52 import de.intevation.flys.client.shared.model.DataList; |
52 import de.intevation.flys.client.shared.model.DefaultData; | 53 import de.intevation.flys.client.shared.model.DefaultData; |
53 import de.intevation.flys.client.shared.model.DefaultDataItem; | 54 import de.intevation.flys.client.shared.model.DefaultDataItem; |
54 import de.intevation.flys.client.shared.model.DistanceInfoObject; | 55 import de.intevation.flys.client.shared.model.DistanceInfoObject; |
55 import de.intevation.flys.client.shared.model.ArtifactDescription; | 56 |
56 | 57 import java.util.ArrayList; |
57 import de.intevation.flys.client.client.services.DistanceInfoService; | 58 import java.util.LinkedHashMap; |
58 import de.intevation.flys.client.client.services.DistanceInfoServiceAsync; | 59 import java.util.List; |
59 import de.intevation.flys.client.client.FLYSConstants; | |
60 import de.intevation.flys.client.client.Config; | |
61 import de.intevation.flys.client.client.event.FilterHandler; | |
62 import de.intevation.flys.client.client.event.StringFilterEvent; | |
63 import de.intevation.flys.client.client.event.RangeFilterEvent; | |
64 import de.intevation.flys.client.client.ui.range.DistanceInfoDataSource; | |
65 | 60 |
66 | 61 |
67 /** | 62 /** |
68 * This UIProvider creates a widget to enter locations or a distance. | 63 * This UIProvider creates a widget to enter locations or a distance. |
69 * | 64 * |
71 */ | 66 */ |
72 public class LocationDistancePanel | 67 public class LocationDistancePanel |
73 extends AbstractUIProvider | 68 extends AbstractUIProvider |
74 implements ChangeHandler, BlurHandler, FilterHandler | 69 implements ChangeHandler, BlurHandler, FilterHandler |
75 { | 70 { |
71 private static final long serialVersionUID = -10820092176039372L; | |
72 | |
76 /** The message class that provides i18n strings. */ | 73 /** The message class that provides i18n strings. */ |
77 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); | 74 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); |
78 | 75 |
79 /** The DistanceInfoService used to retrieve locations about rivers. */ | 76 /** The DistanceInfoService used to retrieve locations about rivers. */ |
80 protected DistanceInfoServiceAsync distanceInfoService = | 77 protected DistanceInfoServiceAsync distanceInfoService = |
181 * | 178 * |
182 * @param data The data that might be inserted. | 179 * @param data The data that might be inserted. |
183 * | 180 * |
184 * @return a panel. | 181 * @return a panel. |
185 */ | 182 */ |
183 @Override | |
186 public Canvas create(DataList data) { | 184 public Canvas create(DataList data) { |
187 VLayout layout = new VLayout(); | 185 VLayout layout = new VLayout(); |
188 layout.setMembersMargin(10); | 186 layout.setMembersMargin(10); |
189 | 187 |
190 Label label = new Label(MESSAGES.location_distance_state()); | 188 Label label = new Label(MESSAGES.location_distance_state()); |
222 distanceTable.setHeight100(); | 220 distanceTable.setHeight100(); |
223 distanceTable.setEmptyMessage(MESSAGES.empty_filter()); | 221 distanceTable.setEmptyMessage(MESSAGES.empty_filter()); |
224 distanceTable.setCanReorderFields(false); | 222 distanceTable.setCanReorderFields(false); |
225 | 223 |
226 CellFormatter cf = new CellFormatter() { | 224 CellFormatter cf = new CellFormatter() { |
225 @Override | |
227 public String format( | 226 public String format( |
228 Object value, | 227 Object value, |
229 ListGridRecord record, | 228 ListGridRecord record, |
230 int rowNum, int colNum) { | 229 int rowNum, int colNum) { |
231 if (value == null) return null; | 230 if (value == null) return null; |
243 | 242 |
244 ListGridField addDistance = new ListGridField ("", ""); | 243 ListGridField addDistance = new ListGridField ("", ""); |
245 addDistance.setType (ListGridFieldType.ICON); | 244 addDistance.setType (ListGridFieldType.ICON); |
246 addDistance.setWidth (20); | 245 addDistance.setWidth (20); |
247 addDistance.addRecordClickHandler (new RecordClickHandler () { | 246 addDistance.addRecordClickHandler (new RecordClickHandler () { |
247 @Override | |
248 public void onRecordClick (RecordClickEvent e) { | 248 public void onRecordClick (RecordClickEvent e) { |
249 if (!isLocationMode ()) { | 249 if (!isLocationMode ()) { |
250 Record r = e.getRecord(); | 250 Record r = e.getRecord(); |
251 try { | 251 try { |
252 double min = Double.parseDouble(r.getAttribute("from")); | 252 double min = Double.parseDouble(r.getAttribute("from")); |
337 locationsTable.setHeight100(); | 337 locationsTable.setHeight100(); |
338 locationsTable.setEmptyMessage(MESSAGES.empty_filter()); | 338 locationsTable.setEmptyMessage(MESSAGES.empty_filter()); |
339 locationsTable.setCanReorderFields(false); | 339 locationsTable.setCanReorderFields(false); |
340 | 340 |
341 CellFormatter cf = new CellFormatter() { | 341 CellFormatter cf = new CellFormatter() { |
342 @Override | |
342 public String format( | 343 public String format( |
343 Object value, | 344 Object value, |
344 ListGridRecord record, | 345 ListGridRecord record, |
345 int rowNum, int colNum) { | 346 int rowNum, int colNum) { |
346 if (value == null) return null; | 347 if (value == null) return null; |
361 ListGridField addLocation = new ListGridField ("", ""); | 362 ListGridField addLocation = new ListGridField ("", ""); |
362 addLocation.setType (ListGridFieldType.ICON); | 363 addLocation.setType (ListGridFieldType.ICON); |
363 addLocation.setWidth (20); | 364 addLocation.setWidth (20); |
364 | 365 |
365 addLocation.addRecordClickHandler (new RecordClickHandler () { | 366 addLocation.addRecordClickHandler (new RecordClickHandler () { |
367 @Override | |
366 public void onRecordClick (RecordClickEvent e) { | 368 public void onRecordClick (RecordClickEvent e) { |
367 Record record = e.getRecord(); | 369 Record record = e.getRecord(); |
368 double[] selected; | 370 double[] selected; |
369 if (getLocationValues() != null) { | 371 if (getLocationValues() != null) { |
370 double[] val = getLocationValues(); | 372 double[] val = getLocationValues(); |
433 locationDistanceTable.setHeight100(); | 435 locationDistanceTable.setHeight100(); |
434 locationDistanceTable.setEmptyMessage(MESSAGES.empty_filter()); | 436 locationDistanceTable.setEmptyMessage(MESSAGES.empty_filter()); |
435 locationDistanceTable.setCanReorderFields(false); | 437 locationDistanceTable.setCanReorderFields(false); |
436 | 438 |
437 CellFormatter cf = new CellFormatter() { | 439 CellFormatter cf = new CellFormatter() { |
440 @Override | |
438 public String format( | 441 public String format( |
439 Object value, | 442 Object value, |
440 ListGridRecord record, | 443 ListGridRecord record, |
441 int rowNum, int colNum) { | 444 int rowNum, int colNum) { |
442 if (value == null) return null; | 445 if (value == null) return null; |
461 addto2.setType (ListGridFieldType.ICON); | 464 addto2.setType (ListGridFieldType.ICON); |
462 addto2.setWidth (30); | 465 addto2.setWidth (30); |
463 addto2.setCellIcon(baseUrl + MESSAGES.markerRed()); | 466 addto2.setCellIcon(baseUrl + MESSAGES.markerRed()); |
464 | 467 |
465 locationDistanceTable.addCellClickHandler (new CellClickHandler () { | 468 locationDistanceTable.addCellClickHandler (new CellClickHandler () { |
469 @Override | |
466 public void onCellClick (CellClickEvent e) { | 470 public void onCellClick (CellClickEvent e) { |
467 if (e.getColNum() == 0) { | 471 if (e.getColNum() == 0) { |
468 Record r = e.getRecord (); | 472 Record r = e.getRecord (); |
469 try { | 473 try { |
470 double fromvalue = | 474 double fromvalue = |
519 locationDistanceTable.setFields( | 523 locationDistanceTable.setFields( |
520 addfrom, addto2, ldescr, loc, lside, bottom, top); | 524 addfrom, addto2, ldescr, loc, lside, bottom, top); |
521 } | 525 } |
522 | 526 |
523 | 527 |
528 @Override | |
524 public Canvas createOld(DataList dataList) { | 529 public Canvas createOld(DataList dataList) { |
525 List<Data> items = dataList.getAll(); | 530 List<Data> items = dataList.getAll(); |
526 | 531 |
527 Data dMode = getData(items, "ld_mode"); | 532 Data dMode = getData(items, "ld_mode"); |
528 DataItem[] dItems = dMode.getItems(); | 533 DataItem[] dItems = dMode.getItems(); |
703 | 708 |
704 container.setMembersMargin(30); | 709 container.setMembersMargin(30); |
705 | 710 |
706 inputTables = new TabSet(); | 711 inputTables = new TabSet(); |
707 inputTables.addTabSelectedHandler(new TabSelectedHandler() { | 712 inputTables.addTabSelectedHandler(new TabSelectedHandler() { |
713 @Override | |
708 public void onTabSelected(TabSelectedEvent evt) { | 714 public void onTabSelected(TabSelectedEvent evt) { |
709 filterDescription.clear(); | 715 filterDescription.clear(); |
710 filterRange.clear(); | 716 filterRange.clear(); |
711 filterResultCount.setValue(""); | 717 filterResultCount.setValue(""); |
712 | 718 |
744 | 750 |
745 filterCriteria = new SelectItem(); | 751 filterCriteria = new SelectItem(); |
746 filterCriteria.setShowTitle(false); | 752 filterCriteria.setShowTitle(false); |
747 filterCriteria.setWidth(100); | 753 filterCriteria.setWidth(100); |
748 filterCriteria.addChangedHandler(new ChangedHandler() { | 754 filterCriteria.addChangedHandler(new ChangedHandler() { |
755 @Override | |
749 public void onChanged(ChangedEvent e) { | 756 public void onChanged(ChangedEvent e) { |
750 if(e.getValue().toString().equals("range")) { | 757 if(e.getValue().toString().equals("range")) { |
751 filterRange.setVisible(true); | 758 filterRange.setVisible(true); |
752 filterDescription.setVisible(false); | 759 filterDescription.setVisible(false); |
753 filterDescription.clear(); | 760 filterDescription.clear(); |
793 | 800 |
794 return layout; | 801 return layout; |
795 } | 802 } |
796 | 803 |
797 | 804 |
805 @Override | |
798 public void onFilterCriteriaChanged(StringFilterEvent event) { | 806 public void onFilterCriteriaChanged(StringFilterEvent event) { |
799 String search = event.getFilter(); | 807 String search = event.getFilter(); |
800 | 808 |
801 if (search != null && search.length() > 0) { | 809 if (search != null && search.length() > 0) { |
802 Criteria c = new Criteria("description", search); | 810 Criteria c = new Criteria("description", search); |
813 filterResultCount.setValue(""); | 821 filterResultCount.setValue(""); |
814 } | 822 } |
815 } | 823 } |
816 | 824 |
817 | 825 |
826 @Override | |
818 public void onFilterCriteriaChanged(RangeFilterEvent event) { | 827 public void onFilterCriteriaChanged(RangeFilterEvent event) { |
819 Float from = event.getFrom() - 0.001f; | 828 Float from = event.getFrom() - 0.001f; |
820 Float to = event.getTo() + 0.001f; | 829 Float to = event.getTo() + 0.001f; |
821 GWT.log("filtering range: " + from + " to " + to); | 830 GWT.log("filtering range: " + from + " to " + to); |
822 | 831 |
972 /** | 981 /** |
973 * This method returns the selected data. | 982 * This method returns the selected data. |
974 * | 983 * |
975 * @return the selected/inserted data. | 984 * @return the selected/inserted data. |
976 */ | 985 */ |
986 @Override | |
977 public Data[] getData() { | 987 public Data[] getData() { |
978 List<Data> data = new ArrayList<Data>(); | 988 List<Data> data = new ArrayList<Data>(); |
979 | 989 |
980 // XXX If we have entered a value and click right afterwards on the | 990 // If we have entered a value and click right afterwards on the |
981 // 'next' button, the BlurEvent is not fired, and the values are not | 991 // 'next' button, the BlurEvent is not fired, and the values are not |
982 // saved. So, we gonna save those values explicitly. | 992 // saved. So, we gonna save those values explicitly. |
983 if (isLocationMode()) { | 993 if (isLocationMode()) { |
984 Canvas member = container.getMember(0); | 994 Canvas member = container.getMember(0); |
985 if (member instanceof DoubleArrayPanel) { | 995 if (member instanceof DoubleArrayPanel) { |
1156 /** | 1166 /** |
1157 * This method switches the input mode between location and distance input. | 1167 * This method switches the input mode between location and distance input. |
1158 * | 1168 * |
1159 * @param event The click event fired by a RadioButtonGroupItem. | 1169 * @param event The click event fired by a RadioButtonGroupItem. |
1160 */ | 1170 */ |
1171 @Override | |
1161 public void onChange(ChangeEvent event) { | 1172 public void onChange(ChangeEvent event) { |
1162 String value = (String) event.getValue(); | 1173 String value = (String) event.getValue(); |
1163 | 1174 |
1164 if (value == null) { | 1175 if (value == null) { |
1165 return; | 1176 return; |
1209 * This method is used to validate the inserted data in the form fields. | 1220 * This method is used to validate the inserted data in the form fields. |
1210 * | 1221 * |
1211 * @param event The BlurEvent that gives information about the FormItem that | 1222 * @param event The BlurEvent that gives information about the FormItem that |
1212 * has been modified and its value. | 1223 * has been modified and its value. |
1213 */ | 1224 */ |
1225 @Override | |
1214 public void onBlur(BlurEvent event) { | 1226 public void onBlur(BlurEvent event) { |
1215 FormItem item = event.getItem(); | 1227 FormItem item = event.getItem(); |
1216 String field = item.getFieldName(); | 1228 String field = item.getFieldName(); |
1217 | 1229 |
1218 if (field == null) { | 1230 if (field == null) { |
1303 RadioGroupItem radio = new RadioGroupItem(FIELD_MODE); | 1315 RadioGroupItem radio = new RadioGroupItem(FIELD_MODE); |
1304 radio.setShowTitle(false); | 1316 radio.setShowTitle(false); |
1305 radio.setVertical(false); | 1317 radio.setVertical(false); |
1306 radio.setWrap(false); | 1318 radio.setWrap(false); |
1307 | 1319 |
1308 LinkedHashMap values = new LinkedHashMap(); | 1320 LinkedHashMap<String, String> values = new LinkedHashMap<String, String>(); |
1309 values.put(FIELD_VALUE_LOCATION, MESSAGES.location()); | 1321 values.put(FIELD_VALUE_LOCATION, MESSAGES.location()); |
1310 values.put(FIELD_VALUE_DISTANCE, MESSAGES.distance()); | 1322 values.put(FIELD_VALUE_DISTANCE, MESSAGES.distance()); |
1311 | 1323 |
1312 LinkedHashMap initial = new LinkedHashMap(); | 1324 LinkedHashMap<String, String> initial = new LinkedHashMap<String, String>(); |
1313 initial.put(FIELD_MODE, FIELD_VALUE_DISTANCE); | 1325 initial.put(FIELD_MODE, FIELD_VALUE_DISTANCE); |
1314 | 1326 |
1315 radio.setValueMap(values); | 1327 radio.setValueMap(values); |
1316 radio.addChangeHandler(this); | 1328 radio.addChangeHandler(this); |
1317 | 1329 |
1323 | 1335 |
1324 | 1336 |
1325 protected void createDistanceInputPanel() { | 1337 protected void createDistanceInputPanel() { |
1326 Config config = Config.getInstance(); | 1338 Config config = Config.getInstance(); |
1327 String url = config.getServerUrl(); | 1339 String url = config.getServerUrl(); |
1328 String locale = config.getLocale (); | |
1329 String river = ""; | 1340 String river = ""; |
1330 | 1341 |
1331 ArtifactDescription adescr = artifact.getArtifactDescription(); | 1342 ArtifactDescription adescr = artifact.getArtifactDescription(); |
1332 DataList[] data = adescr.getOldData(); | 1343 DataList[] data = adescr.getOldData(); |
1333 | 1344 |
1353 locationDistanceTable.setDataSource(new DistanceInfoDataSource( | 1364 locationDistanceTable.setDataSource(new DistanceInfoDataSource( |
1354 url, river, "locations")); | 1365 url, river, "locations")); |
1355 } | 1366 } |
1356 | 1367 |
1357 | 1368 |
1358 /* protected void updateDistanceInfo(DistanceInfoObject[] di) { | |
1359 int i = 0; | |
1360 for (DistanceInfoObject dio: di) { | |
1361 if (dio.getTo() != null) { | |
1362 distanceTable.addData(new DistanceInfoRecord(dio)); | |
1363 } | |
1364 else { | |
1365 locationsTable.addData(new DistanceInfoRecord(dio)); | |
1366 locationDistanceTable.addData(new DistanceInfoRecord(dio)); | |
1367 } | |
1368 } | |
1369 return; | |
1370 }*/ | |
1371 | |
1372 | |
1373 protected double getFrom() { | 1369 protected double getFrom() { |
1374 return from; | 1370 return from; |
1375 } | 1371 } |
1376 | 1372 |
1377 | 1373 |