Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java @ 580:42512fce9b1b
#140, #122: Splitted the WQD table in the WQInputPanel into two tables: a table for QD values and a table for W values - only the QD table is selectable.
flys-client/trunk@2164 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 20 Jun 2011 10:32:54 +0000 |
parents | f1b977657880 |
children | 78907f0fb939 |
comparison
equal
deleted
inserted
replaced
579:f1b977657880 | 580:42512fce9b1b |
---|---|
20 import com.smartgwt.client.widgets.form.fields.events.BlurEvent; | 20 import com.smartgwt.client.widgets.form.fields.events.BlurEvent; |
21 import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; | 21 import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; |
22 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; | 22 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; |
23 import com.smartgwt.client.widgets.layout.HLayout; | 23 import com.smartgwt.client.widgets.layout.HLayout; |
24 import com.smartgwt.client.widgets.layout.VLayout; | 24 import com.smartgwt.client.widgets.layout.VLayout; |
25 import com.smartgwt.client.widgets.grid.ListGrid; | |
26 import com.smartgwt.client.widgets.grid.ListGridField; | |
27 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
28 import com.smartgwt.client.widgets.grid.events.CellClickHandler; | 25 import com.smartgwt.client.widgets.grid.events.CellClickHandler; |
29 import com.smartgwt.client.widgets.grid.events.CellClickEvent; | 26 import com.smartgwt.client.widgets.grid.events.CellClickEvent; |
27 import com.smartgwt.client.widgets.tab.TabSet; | |
28 import com.smartgwt.client.widgets.tab.Tab; | |
30 | 29 |
31 import de.intevation.flys.client.shared.model.Data; | 30 import de.intevation.flys.client.shared.model.Data; |
32 import de.intevation.flys.client.shared.model.DataItem; | 31 import de.intevation.flys.client.shared.model.DataItem; |
33 import de.intevation.flys.client.shared.model.DataList; | 32 import de.intevation.flys.client.shared.model.DataList; |
34 import de.intevation.flys.client.shared.model.DefaultData; | 33 import de.intevation.flys.client.shared.model.DefaultData; |
35 import de.intevation.flys.client.shared.model.DefaultDataItem; | 34 import de.intevation.flys.client.shared.model.DefaultDataItem; |
36 import de.intevation.flys.client.shared.model.WQInfoObject; | 35 import de.intevation.flys.client.shared.model.WQInfoObject; |
37 import de.intevation.flys.client.shared.model.WQInfoRecord; | 36 import de.intevation.flys.client.shared.model.WQInfoRecord; |
38 import de.intevation.flys.client.shared.model.ArtifactDescription; | 37 import de.intevation.flys.client.shared.model.ArtifactDescription; |
39 import com.smartgwt.client.types.ListGridFieldType; | 38 |
40 import com.smartgwt.client.types.SelectionStyle; | |
41 | |
42 import de.intevation.flys.client.client.services.WQInfoService; | |
43 import de.intevation.flys.client.client.services.WQInfoServiceAsync; | |
44 import de.intevation.flys.client.client.FLYSConstants; | 39 import de.intevation.flys.client.client.FLYSConstants; |
45 import de.intevation.flys.client.client.FLYSImages; | 40 import de.intevation.flys.client.client.FLYSImages; |
46 import de.intevation.flys.client.client.Config; | 41 import de.intevation.flys.client.client.Config; |
42 import de.intevation.flys.client.client.services.WQInfoService; | |
43 import de.intevation.flys.client.client.services.WQInfoServiceAsync; | |
44 import de.intevation.flys.client.client.ui.wq.WTable; | |
45 import de.intevation.flys.client.client.ui.wq.QDTable; | |
47 | 46 |
48 | 47 |
49 /** | 48 /** |
50 * This UIProvider creates a widget to enter W or Q data. | 49 * This UIProvider creates a widget to enter W or Q data. |
51 * | 50 * |
144 protected DoubleRangePanel wRangePanel; | 143 protected DoubleRangePanel wRangePanel; |
145 | 144 |
146 /** The input panel for q range*/ | 145 /** The input panel for q range*/ |
147 protected DoubleRangePanel qRangePanel; | 146 protected DoubleRangePanel qRangePanel; |
148 | 147 |
149 /** The WQ Data*/ | 148 protected QDTable qdTable; |
150 protected WQInfoObject[] tableData; | 149 |
151 | 150 protected WTable wTable; |
152 /** The WQ Input Table*/ | 151 |
153 protected ListGrid wqTable; | 152 protected TabSet tabs; |
154 | |
155 /** The WQ input table for ranges.*/ | |
156 protected ListGrid wqRangeTable; | |
157 | 153 |
158 /** | 154 /** |
159 * Creates a new WQInputPanel instance. | 155 * Creates a new WQInputPanel instance. |
160 */ | 156 */ |
161 public WQInputPanel() { | 157 public WQInputPanel() { |
162 wqTable = new ListGrid(); | 158 qdTable = new QDTable(); |
163 wqRangeTable = new ListGrid(); | 159 wTable = new WTable(); |
164 wqTable.setShowHeaderContextMenu(false); | 160 |
165 wqRangeTable.setShowHeaderContextMenu(false); | 161 initTableListeners(); |
162 } | |
163 | |
164 | |
165 /** | |
166 * Initializes the listeners of the WQD tables. | |
167 */ | |
168 protected void initTableListeners() { | |
169 CellClickHandler handler = new CellClickHandler() { | |
170 public void onCellClick(CellClickEvent e) { | |
171 | |
172 if (isWMode()) { | |
173 return; | |
174 } | |
175 | |
176 int idx = e.getColNum(); | |
177 Record r = e.getRecord (); | |
178 double val = r.getAttributeAsDouble("value"); | |
179 | |
180 if (idx == 0) { | |
181 if (isRangeMode()) { | |
182 qRangePanel.setFrom(val); | |
183 } | |
184 else { | |
185 qArrayPanel.addValue(val); | |
186 } | |
187 } | |
188 else if (idx == 1) { | |
189 if (isRangeMode()) { | |
190 qRangePanel.setTo(val); | |
191 } | |
192 else { | |
193 qArrayPanel.addValue(val); | |
194 } | |
195 } | |
196 } | |
197 }; | |
198 | |
199 qdTable.addCellClickHandler(handler); | |
166 } | 200 } |
167 | 201 |
168 | 202 |
169 /** | 203 /** |
170 * This method calls createWidget and puts a 'next' button to the bottom. | 204 * This method calls createWidget and puts a 'next' button to the bottom. |
187 | 221 |
188 layout.addMember(label); | 222 layout.addMember(label); |
189 layout.addMember(widget); | 223 layout.addMember(widget); |
190 layout.addMember(submit); | 224 layout.addMember(submit); |
191 | 225 |
226 initHelperPanel(); | |
192 initUserDefaults(data); | 227 initUserDefaults(data); |
193 | 228 |
194 return layout; | 229 return layout; |
230 } | |
231 | |
232 | |
233 protected void initHelperPanel() { | |
234 tabs = new TabSet(); | |
235 tabs.setWidth100(); | |
236 tabs.setHeight100(); | |
237 | |
238 // TODO i18n | |
239 Tab wTab = new Tab("W"); | |
240 Tab qTab = new Tab("Q / D"); | |
241 | |
242 wTab.setPane(wTable); | |
243 qTab.setPane(qdTable); | |
244 | |
245 tabs.addTab(wTab, 0); | |
246 tabs.addTab(qTab, 1); | |
247 | |
248 helperContainer.addChild(tabs); | |
249 | |
250 fetchWQData(); | |
195 } | 251 } |
196 | 252 |
197 | 253 |
198 public Canvas createOld(DataList dataList) { | 254 public Canvas createOld(DataList dataList) { |
199 List<Data> items = dataList.getAll(); | 255 List<Data> items = dataList.getAll(); |
249 layout.addMember(back); | 305 layout.addMember(back); |
250 | 306 |
251 return layout; | 307 return layout; |
252 } | 308 } |
253 | 309 |
254 | |
255 protected void createWQInputPanel() { | |
256 wqTable.setWidth100(); | |
257 wqTable.setShowRecordComponents(true); | |
258 wqTable.setShowRecordComponentsByCell(true); | |
259 wqTable.setHeight100(); | |
260 wqTable.setEmptyMessage(MESSAGE.empty_table()); | |
261 | |
262 wqRangeTable.setWidth100(); | |
263 wqRangeTable.setShowRecordComponents(true); | |
264 wqRangeTable.setShowRecordComponentsByCell(true); | |
265 wqRangeTable.setHeight100(); | |
266 wqRangeTable.setEmptyMessage(MESSAGE.empty_table()); | |
267 | |
268 ListGridField addWQ = new ListGridField("", ""); | |
269 addWQ.setType(ListGridFieldType.ICON); | |
270 addWQ.setWidth(30); | |
271 | |
272 CellClickHandler cch = new CellClickHandler() { | |
273 public void onCellClick(CellClickEvent e) { | |
274 if (e.getColNum() == 0 && e.getRecord().getEnabled ()) { | |
275 Record r = e.getRecord (); | |
276 double val = r.getAttributeAsDouble("value"); | |
277 if(isWMode() && !isRangeMode()) { | |
278 double[] in = wArrayPanel.getInputValues(); | |
279 int size = 0; | |
280 if (in == null) { | |
281 double[] vals = new double[1]; | |
282 vals[0] = val; | |
283 wArrayPanel.setValues(vals); | |
284 setSingleW(vals); | |
285 } | |
286 else { | |
287 double[] vals = new double[in.length+1]; | |
288 for(int i = 0; i < in.length; i++) { | |
289 vals[i] = in[i]; | |
290 } | |
291 vals[in.length] = val; | |
292 wArrayPanel.setValues(vals); | |
293 setSingleW(vals); | |
294 } | |
295 } | |
296 else if (!isWMode() && !isRangeMode()) { | |
297 double[] in = qArrayPanel.getInputValues(); | |
298 int size = 0; | |
299 if (in == null) { | |
300 double[] vals = new double[1]; | |
301 vals[0] = val; | |
302 qArrayPanel.setValues(vals); | |
303 setSingleQ(vals); | |
304 } | |
305 else { | |
306 double[] vals = new double[in.length+1]; | |
307 for(int i = 0; i < in.length; i++) { | |
308 vals[i] = in[i]; | |
309 } | |
310 vals[in.length] = val; | |
311 qArrayPanel.setValues(vals); | |
312 setSingleQ(vals); | |
313 } | |
314 } | |
315 } | |
316 } | |
317 }; | |
318 | |
319 CellClickHandler cchRange = new CellClickHandler() { | |
320 public void onCellClick(CellClickEvent e) { | |
321 if (e.getColNum() == 0 && e.getRecord().getEnabled ()) { | |
322 Record r = e.getRecord (); | |
323 double val = r.getAttributeAsDouble("value"); | |
324 if(isWMode() && isRangeMode()) { | |
325 wRangePanel.setValues( | |
326 val, | |
327 wRangePanel.getTo(), | |
328 wRangePanel. getStep()); | |
329 } | |
330 else if (!isWMode() && isRangeMode()) { | |
331 qRangePanel.setValues( | |
332 val, | |
333 qRangePanel.getTo(), | |
334 qRangePanel.getStep()); | |
335 } | |
336 } | |
337 if (e.getColNum() == 1 && e.getRecord().getEnabled()) { | |
338 Record r = e.getRecord (); | |
339 double val = r.getAttributeAsDouble("value"); | |
340 if (isWMode() && isRangeMode()) { | |
341 wRangePanel.setValues( | |
342 wRangePanel.getFrom(), | |
343 val, | |
344 wRangePanel.getStep()); | |
345 } | |
346 else if(!isWMode() && isRangeMode()) { | |
347 qRangePanel.setValues( | |
348 qRangePanel.getFrom(), | |
349 val, | |
350 qRangePanel.getStep()); | |
351 } | |
352 } | |
353 } | |
354 }; | |
355 wqTable.addCellClickHandler(cch); | |
356 wqRangeTable.addCellClickHandler(cchRange); | |
357 addWQ.setCellIcon (IMAGES.markerGreen().getURL()); | |
358 | |
359 ListGridField addWQMin = new ListGridField("", ""); | |
360 addWQMin.setType(ListGridFieldType.ICON); | |
361 addWQMin.setWidth(30); | |
362 ListGridField addWQMax = new ListGridField("", ""); | |
363 addWQMax.setType(ListGridFieldType.ICON); | |
364 addWQMax.setWidth(30); | |
365 | |
366 wqRangeTable.addCellClickHandler(cch); | |
367 addWQMin.setCellIcon(IMAGES.markerGreen().getURL()); | |
368 addWQMax.setCellIcon(IMAGES.markerRed().getURL()); | |
369 | |
370 ListGridField name = new ListGridField("name", MESSAGE.name()); | |
371 name.setType(ListGridFieldType.TEXT); | |
372 name.setWidth("*"); | |
373 ListGridField type = new ListGridField("type", MESSAGE.type()); | |
374 type.setType(ListGridFieldType.TEXT); | |
375 type.setWidth("50"); | |
376 ListGridField value = new ListGridField("value", MESSAGE.wq_value()); | |
377 value.setType(ListGridFieldType.TEXT); | |
378 type.setWidth("50"); | |
379 | |
380 ListGridField name_r = new ListGridField("name", MESSAGE.name()); | |
381 name_r.setType(ListGridFieldType.TEXT); | |
382 name_r.setWidth("*"); | |
383 ListGridField type_r = new ListGridField("type", MESSAGE.type()); | |
384 type_r.setType(ListGridFieldType.TEXT); | |
385 type_r.setWidth("50"); | |
386 ListGridField value_r = new ListGridField("value", MESSAGE.wq_value()); | |
387 value_r.setType(ListGridFieldType.TEXT); | |
388 type_r.setWidth("50"); | |
389 | |
390 wqTable.setSelectionType(SelectionStyle.SINGLE); | |
391 wqRangeTable.setSelectionType(SelectionStyle.SINGLE); | |
392 wqTable.setFields(addWQ, name, type, value); | |
393 wqRangeTable.setFields(addWQMin, addWQMax, name_r, type_r, value_r); | |
394 } | |
395 | 310 |
396 /** | 311 /** |
397 * This method reads the default values defined in the DataItems of the Data | 312 * This method reads the default values defined in the DataItems of the Data |
398 * objects in <i>list</i>. | 313 * objects in <i>list</i>. |
399 * | 314 * |
607 VLayout layout = new VLayout(); | 522 VLayout layout = new VLayout(); |
608 container = new HLayout(); | 523 container = new HLayout(); |
609 Canvas modeForm = createModePanel(); | 524 Canvas modeForm = createModePanel(); |
610 | 525 |
611 container.setMembersMargin(30); | 526 container.setMembersMargin(30); |
612 createWQInputTable(); | |
613 createWQInputPanel(); | |
614 | 527 |
615 // the initial panel is the Single-W panel. | 528 // the initial panel is the Single-W panel. |
616 double[] values = getSingleQ(); | 529 double[] values = getSingleQ(); |
617 qArrayPanel = new DoubleArrayPanel( | 530 qArrayPanel = new DoubleArrayPanel( |
618 MESSAGE.unitQSingle(), values, this); | 531 MESSAGE.unitQSingle(), values, this); |
619 container.addMember(qArrayPanel); | 532 container.addMember(qArrayPanel); |
620 | 533 |
621 helperContainer.addChild(wqTable); | |
622 layout.addMember(modeForm); | 534 layout.addMember(modeForm); |
623 layout.addMember(container); | 535 layout.addMember(container); |
624 | 536 |
625 return layout; | 537 return layout; |
626 } | 538 } |
1077 } | 989 } |
1078 | 990 |
1079 | 991 |
1080 protected void updatePanels(String wqMode, String inputMode) { | 992 protected void updatePanels(String wqMode, String inputMode) { |
1081 container.removeMembers(container.getMembers()); | 993 container.removeMembers(container.getMembers()); |
994 | |
1082 if (wqMode.equals(FIELD_WQ_W)) { | 995 if (wqMode.equals(FIELD_WQ_W)) { |
1083 if (inputMode.equals(FIELD_MODE_SINGLE)) { | 996 if (inputMode.equals(FIELD_MODE_SINGLE)) { |
1084 // Single W mode | 997 // Single W mode |
1085 double[] values = getSingleW(); | 998 double[] values = getSingleW(); |
1086 | 999 |
1087 wArrayPanel = new DoubleArrayPanel( | 1000 wArrayPanel = new DoubleArrayPanel( |
1088 MESSAGE.unitWSingle(), values, this); | 1001 MESSAGE.unitWSingle(), values, this); |
1089 | 1002 |
1090 container.addMember(wArrayPanel); | 1003 container.addMember(wArrayPanel); |
1091 helperContainer.addChild(wqTable); | |
1092 int size = wqTable.getRecords().length; | |
1093 for(int i = 0; i < size; i++) { | |
1094 ListGridRecord r = wqTable.getRecord(i); | |
1095 String type = r.getAttributeAsString("type"); | |
1096 if (type.equals("W")) { | |
1097 wqTable.getRecord(i).setEnabled(true); | |
1098 } | |
1099 else if(type.equals("D") || type.equals("Q")) { | |
1100 wqTable.getRecord(i).setEnabled(false); | |
1101 } | |
1102 } | |
1103 } | 1004 } |
1104 else { | 1005 else { |
1105 // Range W mode | 1006 // Range W mode |
1106 double from = getFromW(); | 1007 double from = getFromW(); |
1107 double to = getToW(); | 1008 double to = getToW(); |
1111 MESSAGE.unitWFrom(), MESSAGE.unitWTo(), MESSAGE.unitWStep(), | 1012 MESSAGE.unitWFrom(), MESSAGE.unitWTo(), MESSAGE.unitWStep(), |
1112 from, to, step, | 1013 from, to, step, |
1113 250, | 1014 250, |
1114 this); | 1015 this); |
1115 container.addMember(wRangePanel); | 1016 container.addMember(wRangePanel); |
1116 helperContainer.addChild(wqRangeTable); | 1017 } |
1117 int size = wqRangeTable.getRecords().length; | 1018 |
1118 for(int i = 0; i < size; i++) { | 1019 tabs.selectTab(0); |
1119 ListGridRecord r = wqRangeTable.getRecord(i); | |
1120 String type = r.getAttributeAsString("type"); | |
1121 if (type.equals("W")) { | |
1122 wqRangeTable.getRecord(i).setEnabled(true); | |
1123 } | |
1124 else if(type.equals("D") || type.equals("Q")) { | |
1125 wqRangeTable.getRecord(i).setEnabled(false); | |
1126 } | |
1127 } | |
1128 } | |
1129 } | 1020 } |
1130 else { | 1021 else { |
1131 if (inputMode.equals(FIELD_MODE_SINGLE)) { | 1022 if (inputMode.equals(FIELD_MODE_SINGLE)) { |
1132 // Single Q mode | 1023 // Single Q mode |
1133 double[] values = getSingleQ(); | 1024 double[] values = getSingleQ(); |
1134 | 1025 |
1135 qArrayPanel = new DoubleArrayPanel( | 1026 qArrayPanel = new DoubleArrayPanel( |
1136 MESSAGE.unitQSingle(), values, this); | 1027 MESSAGE.unitQSingle(), values, this); |
1137 container.addMember(qArrayPanel); | 1028 container.addMember(qArrayPanel); |
1138 helperContainer.addChild(wqTable); | |
1139 int size = wqTable.getRecords().length; | |
1140 for(int i = 0; i < size; i++) { | |
1141 ListGridRecord r = wqTable.getRecord(i); | |
1142 String type = r.getAttributeAsString("type"); | |
1143 if (type.equals("W")) { | |
1144 wqTable.getRecord(i).setEnabled(false); | |
1145 } | |
1146 else if(type.equals("D") || type.equals("Q")) { | |
1147 wqTable.getRecord(i).setEnabled(true); | |
1148 } | |
1149 } | |
1150 | |
1151 } | 1029 } |
1152 else { | 1030 else { |
1153 // Range Q mode | 1031 // Range Q mode |
1154 double from = getFromQ(); | 1032 double from = getFromQ(); |
1155 double to = getToQ(); | 1033 double to = getToQ(); |
1159 MESSAGE.unitQFrom(), MESSAGE.unitQTo(), MESSAGE.unitQStep(), | 1037 MESSAGE.unitQFrom(), MESSAGE.unitQTo(), MESSAGE.unitQStep(), |
1160 from, to, step, | 1038 from, to, step, |
1161 250, | 1039 250, |
1162 this); | 1040 this); |
1163 container.addMember(qRangePanel); | 1041 container.addMember(qRangePanel); |
1164 helperContainer.addChild(wqRangeTable); | 1042 } |
1165 int size = wqRangeTable.getRecords().length; | 1043 |
1166 for(int i = 0; i < size; i++) { | 1044 tabs.selectTab(1); |
1167 ListGridRecord r = wqRangeTable.getRecord(i); | |
1168 String type = r.getAttributeAsString("type"); | |
1169 if (type.equals("W")) { | |
1170 wqRangeTable.getRecord(i).setEnabled(false); | |
1171 } | |
1172 else if(type.equals("D") || type.equals("Q")) { | |
1173 wqRangeTable.getRecord(i).setEnabled(true); | |
1174 } | |
1175 } | |
1176 } | |
1177 } | 1045 } |
1178 } | 1046 } |
1179 | 1047 |
1180 /** | 1048 /** |
1181 * This method is called if the value of one of the input fields might have | 1049 * This method is called if the value of one of the input fields might have |
1439 | 1307 |
1440 return null; | 1308 return null; |
1441 } | 1309 } |
1442 | 1310 |
1443 | 1311 |
1444 protected void createWQInputTable() { | 1312 protected void fetchWQData() { |
1445 Config config = Config.getInstance(); | 1313 Config config = Config.getInstance(); |
1446 String url = config.getServerUrl(); | 1314 String url = config.getServerUrl(); |
1447 String locale = config.getLocale (); | 1315 String locale = config.getLocale (); |
1448 | 1316 |
1449 ArtifactDescription adescr = artifact.getArtifactDescription(); | 1317 ArtifactDescription adescr = artifact.getArtifactDescription(); |
1464 GWT.log("Recieved " + num + " wq informations."); | 1332 GWT.log("Recieved " + num + " wq informations."); |
1465 | 1333 |
1466 if (num == 0) { | 1334 if (num == 0) { |
1467 return; | 1335 return; |
1468 } | 1336 } |
1469 tableData = wqi; | 1337 |
1470 addWQInfo(wqi); | 1338 addWQInfo(wqi); |
1471 | 1339 |
1472 String wq = (String) modes.getValue(FIELD_WQ); | 1340 String wq = (String) modes.getValue(FIELD_WQ); |
1473 String sr = (String) modes.getValue(FIELD_MODE); | 1341 String sr = (String) modes.getValue(FIELD_MODE); |
1474 updatePanels(wq, sr); | 1342 updatePanels(wq, sr); |
1477 ); | 1345 ); |
1478 } | 1346 } |
1479 | 1347 |
1480 | 1348 |
1481 protected void addWQInfo (WQInfoObject[] wqi) { | 1349 protected void addWQInfo (WQInfoObject[] wqi) { |
1482 int i = 0; | |
1483 for(WQInfoObject wi: wqi) { | 1350 for(WQInfoObject wi: wqi) { |
1484 WQInfoRecord rec = new WQInfoRecord (wi); | 1351 WQInfoRecord rec = new WQInfoRecord(wi); |
1485 wqTable.addData(rec); | 1352 |
1486 wqRangeTable.addData(rec); | 1353 if (wi.getType().equals("W")) { |
1487 } | 1354 wTable.addData(rec); |
1488 return; | 1355 } |
1356 else { | |
1357 qdTable.addData(rec); | |
1358 } | |
1359 } | |
1489 } | 1360 } |
1490 } | 1361 } |
1491 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 1362 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |