Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java @ 248:ed90309ec608
Added table for WQ inputs.
flys-client/trunk@1834 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 05 May 2011 09:51:51 +0000 |
parents | 4a684d29404f |
children | 6c7133eb8c4c |
comparison
equal
deleted
inserted
replaced
247:4a684d29404f | 248:ed90309ec608 |
---|---|
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; | |
8 | |
9 import com.smartgwt.client.data.Record; | |
7 | 10 |
8 import com.smartgwt.client.widgets.Canvas; | 11 import com.smartgwt.client.widgets.Canvas; |
9 import com.smartgwt.client.widgets.Label; | 12 import com.smartgwt.client.widgets.Label; |
10 import com.smartgwt.client.widgets.form.DynamicForm; | 13 import com.smartgwt.client.widgets.form.DynamicForm; |
11 import com.smartgwt.client.widgets.form.fields.FormItem; | 14 import com.smartgwt.client.widgets.form.fields.FormItem; |
14 import com.smartgwt.client.widgets.form.fields.events.BlurEvent; | 17 import com.smartgwt.client.widgets.form.fields.events.BlurEvent; |
15 import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; | 18 import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; |
16 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; | 19 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; |
17 import com.smartgwt.client.widgets.layout.HLayout; | 20 import com.smartgwt.client.widgets.layout.HLayout; |
18 import com.smartgwt.client.widgets.layout.VLayout; | 21 import com.smartgwt.client.widgets.layout.VLayout; |
22 import com.smartgwt.client.widgets.grid.ListGrid; | |
23 import com.smartgwt.client.widgets.grid.ListGridField; | |
24 import com.smartgwt.client.widgets.grid.events.CellClickHandler; | |
25 import com.smartgwt.client.widgets.grid.events.CellClickEvent; | |
19 | 26 |
20 import de.intevation.flys.client.shared.model.Data; | 27 import de.intevation.flys.client.shared.model.Data; |
21 import de.intevation.flys.client.shared.model.DataItem; | 28 import de.intevation.flys.client.shared.model.DataItem; |
22 import de.intevation.flys.client.shared.model.DataList; | 29 import de.intevation.flys.client.shared.model.DataList; |
23 import de.intevation.flys.client.shared.model.DefaultData; | 30 import de.intevation.flys.client.shared.model.DefaultData; |
24 import de.intevation.flys.client.shared.model.DefaultDataItem; | 31 import de.intevation.flys.client.shared.model.DefaultDataItem; |
32 import de.intevation.flys.client.shared.model.WQInfoObject; | |
33 import de.intevation.flys.client.shared.model.WQInfoRecord; | |
34 import de.intevation.flys.client.shared.model.ArtifactDescription; | |
35 import com.smartgwt.client.types.ListGridFieldType; | |
36 | |
37 import de.intevation.flys.client.client.services.WQInfoService; | |
38 import de.intevation.flys.client.client.services.WQInfoServiceAsync; | |
25 import de.intevation.flys.client.client.FLYSConstants; | 39 import de.intevation.flys.client.client.FLYSConstants; |
40 import de.intevation.flys.client.client.FLYSImages; | |
41 import de.intevation.flys.client.client.Config; | |
26 | 42 |
27 | 43 |
28 /** | 44 /** |
29 * This UIProvider creates a widget to enter W or Q data. | 45 * This UIProvider creates a widget to enter W or Q data. |
30 * | 46 * |
33 public class WQInputPanel | 49 public class WQInputPanel |
34 extends AbstractUIProvider | 50 extends AbstractUIProvider |
35 implements ChangeHandler, BlurHandler | 51 implements ChangeHandler, BlurHandler |
36 { | 52 { |
37 /** The message class that provides i18n strings.*/ | 53 /** The message class that provides i18n strings.*/ |
38 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | 54 protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); |
39 | 55 |
56 /** The interface that provides the image resources. */ | |
57 private FLYSImages IMAGES = GWT.create(FLYSImages.class); | |
58 | |
59 /** The DistanceInfoService used to retrieve locations about rivers.*/ | |
60 protected WQInfoServiceAsync wqInfoService = | |
61 GWT.create(WQInfoService.class); | |
40 | 62 |
41 /** The constant field name for choosing w or q mode.*/ | 63 /** The constant field name for choosing w or q mode.*/ |
42 public static final String FIELD_WQ = "wq"; | 64 public static final String FIELD_WQ = "wq"; |
43 | 65 |
44 /** The constant field value for W input mode.*/ | 66 /** The constant field value for W input mode.*/ |
59 /** The constant value that determines the width of the left panel.*/ | 81 /** The constant value that determines the width of the left panel.*/ |
60 public static final int WIDTH_LEFT = 200; | 82 public static final int WIDTH_LEFT = 200; |
61 | 83 |
62 | 84 |
63 /** The container that manages the w and q panels.*/ | 85 /** The container that manages the w and q panels.*/ |
64 protected VLayout container; | 86 protected HLayout container; |
65 | 87 |
66 /** The RadioGroupItem that determines the w/q input mode.*/ | 88 /** The RadioGroupItem that determines the w/q input mode.*/ |
67 protected DynamicForm modes; | 89 protected DynamicForm modes; |
68 | 90 |
69 /** The min values for the 'from' property in the W-Range input mode.*/ | 91 /** The min values for the 'from' property in the W-Range input mode.*/ |
100 protected double stepQ; | 122 protected double stepQ; |
101 | 123 |
102 /** The values entered in the single Q mode.*/ | 124 /** The values entered in the single Q mode.*/ |
103 protected double[] valuesQ; | 125 protected double[] valuesQ; |
104 | 126 |
127 /** The WQ Data*/ | |
128 protected WQInfoObject[] tableData; | |
129 | |
130 /** The WQ Input Table*/ | |
131 protected ListGrid wqTable; | |
132 | |
133 /** The WQ input table for ranges.*/ | |
134 protected ListGrid wqRangeTable; | |
105 | 135 |
106 /** | 136 /** |
107 * Creates a new WQInputPanel instance. | 137 * Creates a new WQInputPanel instance. |
108 */ | 138 */ |
109 public WQInputPanel() { | 139 public WQInputPanel() { |
140 wqTable = new ListGrid(); | |
141 wqRangeTable = new ListGrid(); | |
110 } | 142 } |
111 | 143 |
112 | 144 |
113 /** | 145 /** |
114 * This method calls createWidget and puts a 'next' button to the bottom. | 146 * This method calls createWidget and puts a 'next' button to the bottom. |
118 * @return the widget. | 150 * @return the widget. |
119 */ | 151 */ |
120 public Canvas create(DataList data) { | 152 public Canvas create(DataList data) { |
121 initDefaults(data); | 153 initDefaults(data); |
122 | 154 |
155 | |
123 Canvas widget = createWidget(data); | 156 Canvas widget = createWidget(data); |
124 Canvas submit = getNextButton(); | 157 Canvas submit = getNextButton(); |
125 Label label = new Label(MSG.wqTitle()); | 158 Label label = new Label(MESSAGE.wqTitle()); |
126 | 159 |
127 label.setHeight(25); | 160 label.setHeight(25); |
128 widget.setHeight(65); | |
129 | 161 |
130 VLayout layout = new VLayout(); | 162 VLayout layout = new VLayout(); |
131 layout.setMembersMargin(10); | 163 layout.setMembersMargin(10); |
132 | 164 |
133 layout.addMember(label); | 165 layout.addMember(label); |
193 | 225 |
194 return layout; | 226 return layout; |
195 } | 227 } |
196 | 228 |
197 | 229 |
230 protected void createWQInputPanel() { | |
231 wqTable.setWidth(450); | |
232 wqTable.setShowRecordComponents(true); | |
233 wqTable.setShowRecordComponentsByCell(true); | |
234 wqTable.setHeight(300); | |
235 | |
236 wqRangeTable.setWidth(450); | |
237 wqRangeTable.setShowRecordComponents(true); | |
238 wqRangeTable.setShowRecordComponentsByCell(true); | |
239 wqRangeTable.setHeight(300); | |
240 | |
241 ListGridField addWQ = new ListGridField("", ""); | |
242 addWQ.setType(ListGridFieldType.ICON); | |
243 addWQ.setWidth(30); | |
244 wqTable.addCellClickHandler(new CellClickHandler() { | |
245 public void onCellClick(CellClickEvent e) { | |
246 if (e.getColNum() == 0 && e.getRecord().getEnabled ()) { | |
247 Record r = e.getRecord (); | |
248 double val = r.getAttributeAsDouble("value"); | |
249 // setValue(val); | |
250 } | |
251 } | |
252 }); | |
253 addWQ.setCellIcon (IMAGES.markerGreen().getURL()); | |
254 | |
255 ListGridField addWQMin = new ListGridField("", ""); | |
256 addWQMin.setType(ListGridFieldType.ICON); | |
257 addWQMin.setWidth(30); | |
258 ListGridField addWQMax = new ListGridField("", ""); | |
259 addWQMax.setType(ListGridFieldType.ICON); | |
260 addWQMax.setWidth(30); | |
261 | |
262 wqRangeTable.addCellClickHandler(new CellClickHandler() { | |
263 public void onCellClick(CellClickEvent e) { | |
264 if (e.getColNum() == 0 && e.getRecord().getEnabled ()) { | |
265 Record r = e.getRecord (); | |
266 double val = r.getAttributeAsDouble("value"); | |
267 // setValue(val); | |
268 } | |
269 else if (e.getColNum() == 1 && e.getRecord().getEnabled()) { | |
270 | |
271 } | |
272 } | |
273 }); | |
274 addWQMin.setCellIcon(IMAGES.markerGreen().getURL()); | |
275 addWQMax.setCellIcon(IMAGES.markerRed().getURL()); | |
276 | |
277 ListGridField name = new ListGridField("name", MESSAGE.name()); | |
278 name.setType(ListGridFieldType.TEXT); | |
279 name.setWidth("*"); | |
280 ListGridField type = new ListGridField("type", MESSAGE.type()); | |
281 type.setType(ListGridFieldType.TEXT); | |
282 type.setWidth("50"); | |
283 ListGridField value = new ListGridField("value", MESSAGE.wq_value()); | |
284 value.setType(ListGridFieldType.TEXT); | |
285 type.setWidth("50"); | |
286 | |
287 ListGridField name_r = new ListGridField("name", MESSAGE.name()); | |
288 name_r.setType(ListGridFieldType.TEXT); | |
289 name_r.setWidth("*"); | |
290 ListGridField type_r = new ListGridField("type", MESSAGE.type()); | |
291 type_r.setType(ListGridFieldType.TEXT); | |
292 type_r.setWidth("50"); | |
293 ListGridField value_r = new ListGridField("value", MESSAGE.wq_value()); | |
294 value_r.setType(ListGridFieldType.TEXT); | |
295 type_r.setWidth("50"); | |
296 | |
297 | |
298 wqTable.setFields(addWQ, name, type, value); | |
299 wqRangeTable.setFields(addWQMin, addWQMax, name_r, type_r, value_r); | |
300 } | |
301 | |
198 /** | 302 /** |
199 * This method reads the default values defined in the DataItems of the Data | 303 * This method reads the default values defined in the DataItems of the Data |
200 * objects in <i>list</i>. | 304 * objects in <i>list</i>. |
201 * | 305 * |
202 * @param list The DataList container that stores the Data objects. | 306 * @param list The DataList container that stores the Data objects. |
232 | 336 |
233 | 337 |
234 protected String createWString(DataItem from, DataItem to, DataItem step) { | 338 protected String createWString(DataItem from, DataItem to, DataItem step) { |
235 StringBuilder sb = new StringBuilder(); | 339 StringBuilder sb = new StringBuilder(); |
236 sb.append(from.getLabel()); | 340 sb.append(from.getLabel()); |
237 sb.append(" " + MSG.unitWFrom() + " "); | 341 sb.append(" " + MESSAGE.unitWFrom() + " "); |
238 sb.append(to.getLabel()); | 342 sb.append(to.getLabel()); |
239 sb.append(" " + MSG.unitWTo() + " "); | 343 sb.append(" " + MESSAGE.unitWTo() + " "); |
240 sb.append(step.getLabel()); | 344 sb.append(step.getLabel()); |
241 sb.append(" " + MSG.unitWStep()); | 345 sb.append(" " + MESSAGE.unitWStep()); |
242 | 346 |
243 return sb.toString(); | 347 return sb.toString(); |
244 } | 348 } |
245 | 349 |
246 | 350 |
250 | 354 |
251 | 355 |
252 protected String createQString(DataItem from, DataItem to, DataItem step) { | 356 protected String createQString(DataItem from, DataItem to, DataItem step) { |
253 StringBuilder sb = new StringBuilder(); | 357 StringBuilder sb = new StringBuilder(); |
254 sb.append(from.getLabel()); | 358 sb.append(from.getLabel()); |
255 sb.append(" " + MSG.unitQFrom() + " "); | 359 sb.append(" " + MESSAGE.unitQFrom() + " "); |
256 sb.append(to.getLabel()); | 360 sb.append(to.getLabel()); |
257 sb.append(" " + MSG.unitQTo() + " "); | 361 sb.append(" " + MESSAGE.unitQTo() + " "); |
258 sb.append(step.getLabel()); | 362 sb.append(step.getLabel()); |
259 sb.append(" " + MSG.unitQStep()); | 363 sb.append(" " + MESSAGE.unitQStep()); |
260 | 364 |
261 return sb.toString(); | 365 return sb.toString(); |
262 } | 366 } |
263 | 367 |
264 | 368 |
276 * | 380 * |
277 * @return the widget. | 381 * @return the widget. |
278 */ | 382 */ |
279 protected Canvas createWidget(DataList data) { | 383 protected Canvas createWidget(DataList data) { |
280 VLayout layout = new VLayout(); | 384 VLayout layout = new VLayout(); |
281 container = new VLayout(); | 385 container = new HLayout(); |
282 Canvas modeForm = createModePanel(); | 386 Canvas modeForm = createModePanel(); |
283 | 387 |
388 container.setMembersMargin(30); | |
389 createWQInputTable(); | |
390 createWQInputPanel(); | |
284 // the initial panel is the Single-W panel. | 391 // the initial panel is the Single-W panel. |
285 double[] values = getSingleW(); | 392 double[] values = getSingleW(); |
286 container.addMember(new DoubleArrayPanel( | 393 container.addMember(new DoubleArrayPanel( |
287 MSG.unitWSingle(), values, this)); | 394 MESSAGE.unitWSingle(), values, this)); |
288 | 395 |
396 container.addMember(wqTable); | |
289 layout.addMember(modeForm); | 397 layout.addMember(modeForm); |
290 layout.addMember(container); | 398 layout.addMember(container); |
291 | |
292 // TODO add a table on the right to select Q values | |
293 | 399 |
294 return layout; | 400 return layout; |
295 } | 401 } |
296 | 402 |
297 | 403 |
312 mode.setShowTitle(false); | 418 mode.setShowTitle(false); |
313 mode.setVertical(false); | 419 mode.setVertical(false); |
314 mode.setWidth(WIDTH_LEFT); | 420 mode.setWidth(WIDTH_LEFT); |
315 | 421 |
316 LinkedHashMap wqValues = new LinkedHashMap(); | 422 LinkedHashMap wqValues = new LinkedHashMap(); |
317 wqValues.put(FIELD_WQ_W, MSG.wqW()); | 423 wqValues.put(FIELD_WQ_W, MESSAGE.wqW()); |
318 wqValues.put(FIELD_WQ_Q, MSG.wqQ()); | 424 wqValues.put(FIELD_WQ_Q, MESSAGE.wqQ()); |
319 | 425 |
320 LinkedHashMap modeValues = new LinkedHashMap(); | 426 LinkedHashMap modeValues = new LinkedHashMap(); |
321 modeValues.put(FIELD_MODE_SINGLE, MSG.wqSingle()); | 427 modeValues.put(FIELD_MODE_SINGLE, MESSAGE.wqSingle()); |
322 modeValues.put(FIELD_MODE_RANGE, MSG.wqRange()); | 428 modeValues.put(FIELD_MODE_RANGE, MESSAGE.wqRange()); |
323 | 429 |
324 wq.setValueMap(wqValues); | 430 wq.setValueMap(wqValues); |
325 mode.setValueMap(modeValues); | 431 mode.setValueMap(modeValues); |
326 | 432 |
327 wq.addChangeHandler(this); | 433 wq.addChangeHandler(this); |
611 if (inputMode.equals(FIELD_MODE_SINGLE)) { | 717 if (inputMode.equals(FIELD_MODE_SINGLE)) { |
612 // Single W mode | 718 // Single W mode |
613 double[] values = getSingleW(); | 719 double[] values = getSingleW(); |
614 | 720 |
615 newPanel = new DoubleArrayPanel( | 721 newPanel = new DoubleArrayPanel( |
616 MSG.unitWSingle(), values, this); | 722 MESSAGE.unitWSingle(), values, this); |
723 | |
724 container.addMember(newPanel); | |
725 container.addMember(wqTable); | |
617 } | 726 } |
618 else { | 727 else { |
619 // Range W mode | 728 // Range W mode |
620 double from = getFromW(); | 729 double from = getFromW(); |
621 double to = getToW(); | 730 double to = getToW(); |
622 double step = getStepW(); | 731 double step = getStepW(); |
623 | 732 |
624 newPanel = new DoubleRangePanel( | 733 newPanel = new DoubleRangePanel( |
625 MSG.unitWFrom(), MSG.unitWTo(), MSG.unitWStep(), | 734 MESSAGE.unitWFrom(), MESSAGE.unitWTo(), MESSAGE.unitWStep(), |
626 from, to, step, | 735 from, to, step, |
627 250, | 736 250, |
628 this); | 737 this); |
738 container.addMember(newPanel); | |
739 container.addMember(wqRangeTable); | |
629 } | 740 } |
630 } | 741 } |
631 else { | 742 else { |
632 if (inputMode.equals(FIELD_MODE_SINGLE)) { | 743 if (inputMode.equals(FIELD_MODE_SINGLE)) { |
633 // Single Q mode | 744 // Single Q mode |
634 double[] values = getSingleQ(); | 745 double[] values = getSingleQ(); |
635 | 746 |
636 newPanel = new DoubleArrayPanel( | 747 newPanel = new DoubleArrayPanel( |
637 MSG.unitQSingle(), values, this); | 748 MESSAGE.unitQSingle(), values, this); |
749 container.addMember(newPanel); | |
750 container.addMember(wqTable); | |
638 } | 751 } |
639 else { | 752 else { |
640 // Range Q mode | 753 // Range Q mode |
641 double from = getFromQ(); | 754 double from = getFromQ(); |
642 double to = getToQ(); | 755 double to = getToQ(); |
643 double step = getStepQ(); | 756 double step = getStepQ(); |
644 | 757 |
645 newPanel = new DoubleRangePanel( | 758 newPanel = new DoubleRangePanel( |
646 MSG.unitQFrom(), MSG.unitQTo(), MSG.unitQStep(), | 759 MESSAGE.unitQFrom(), MESSAGE.unitQTo(), MESSAGE.unitQStep(), |
647 from, to, step, | 760 from, to, step, |
648 250, | 761 250, |
649 this); | 762 this); |
650 } | 763 container.addMember(newPanel); |
651 } | 764 container.addMember(wqRangeTable); |
652 | 765 } |
653 container.addMember(newPanel); | 766 } |
767 | |
654 } | 768 } |
655 | 769 |
656 | 770 |
657 /** | 771 /** |
658 * This method is called if the value of one of the input fields might have | 772 * This method is called if the value of one of the input fields might have |
838 | 952 |
839 | 953 |
840 protected void setStepW(double stepW) { | 954 protected void setStepW(double stepW) { |
841 this.stepW = stepW; | 955 this.stepW = stepW; |
842 } | 956 } |
957 | |
958 | |
959 protected void createWQInputTable() { | |
960 Config config = Config.getInstance(); | |
961 String url = config.getServerUrl(); | |
962 String locale = config.getLocale (); | |
963 String river = ""; | |
964 String value_min = ""; | |
965 String value_max = ""; | |
966 | |
967 ArtifactDescription adescr = artifact.getArtifactDescription(); | |
968 DataList[] data = adescr.getOldData(); | |
969 | |
970 //TODO: get the information about old data. | |
971 if (data != null && data.length > 0) { | |
972 for (int i = 0; i < data.length; i++) { | |
973 DataList dl = data[i]; | |
974 if (dl.getState().equals("state.winfo.river")) { | |
975 for (int j = 0; j < dl.size(); j++) { | |
976 Data d = dl.get(j); | |
977 DataItem[] di = d.getItems(); | |
978 if (di != null && di.length == 1) { | |
979 river = d.getItems()[0].getStringValue(); | |
980 } | |
981 } | |
982 } | |
983 else if (dl.getState().equals("state.winfo.location_distance")){ | |
984 for (int j = 0; j < dl.size(); j++) { | |
985 Data d = dl.get(j); | |
986 DataItem[] di = d.getItems(); | |
987 if (di != null && di.length >= 1 && j == 0) { | |
988 value_max = d.getItems()[0].getStringValue(); | |
989 } | |
990 else if (di != null && | |
991 di.length >= 1 && | |
992 j == dl.size() - 1) { | |
993 value_min = d.getItems()[0].getStringValue(); | |
994 } | |
995 } | |
996 } | |
997 } | |
998 } | |
999 | |
1000 double from = Double.valueOf(value_min); | |
1001 double to = Double.valueOf(value_max); | |
1002 wqInfoService.getWQInfo(url, locale, river, from, to, | |
1003 new AsyncCallback<WQInfoObject[]>() { | |
1004 public void onFailure(Throwable caught) { | |
1005 GWT.log("Could not recieve wq informations."); | |
1006 GWT.log(caught.getMessage()); | |
1007 } | |
1008 | |
1009 public void onSuccess(WQInfoObject[] wqi) { | |
1010 int num = wqi != null ? wqi.length :0; | |
1011 GWT.log("Recieved " + num + " wq informations."); | |
1012 | |
1013 if (num == 0) { | |
1014 return; | |
1015 } | |
1016 tableData = wqi; | |
1017 addWQInfo(wqi); | |
1018 } | |
1019 } | |
1020 ); | |
1021 } | |
1022 | |
1023 | |
1024 protected void addWQInfo (WQInfoObject[] wqi) { | |
1025 int i = 0; | |
1026 for(WQInfoObject wi: wqi) { | |
1027 WQInfoRecord rec = new WQInfoRecord (wi); | |
1028 wqTable.addData(rec); | |
1029 wqRangeTable.addData(rec); | |
1030 } | |
1031 return; | |
1032 } | |
843 } | 1033 } |
1034 | |
1035 | |
1036 | |
844 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 1037 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |