comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java @ 519:77234b1d009c

ISSUE-90 & ISSUE-40 (part II/II) Former selected values are preselected after back jumps. flys-client/trunk@1998 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 24 May 2011 16:22:34 +0000
parents be842e36ce1c
children ec85bab86e7b
comparison
equal deleted inserted replaced
518:bac8e6ea277d 519:77234b1d009c
166 * @return the widget. 166 * @return the widget.
167 */ 167 */
168 public Canvas create(DataList data) { 168 public Canvas create(DataList data) {
169 initDefaults(data); 169 initDefaults(data);
170 170
171
172 Canvas widget = createWidget(data); 171 Canvas widget = createWidget(data);
173 Canvas submit = getNextButton(); 172 Canvas submit = getNextButton();
174 Label label = new Label(MESSAGE.wqTitle()); 173 Label label = new Label(MESSAGE.wqTitle());
175 174
176 label.setHeight(25); 175 label.setHeight(25);
179 layout.setMembersMargin(10); 178 layout.setMembersMargin(10);
180 179
181 layout.addMember(label); 180 layout.addMember(label);
182 layout.addMember(widget); 181 layout.addMember(widget);
183 layout.addMember(submit); 182 layout.addMember(submit);
183
184 initUserDefaults(data);
184 185
185 return layout; 186 return layout;
186 } 187 }
187 188
188 189
418 this.toQ = maxQ; 419 this.toQ = maxQ;
419 this.stepQ = stepQ; 420 this.stepQ = stepQ;
420 } 421 }
421 422
422 423
424 /**
425 * Initializes the form items with former inserted user data.
426 *
427 * @param list The DataList that contains the user data.
428 */
429 protected void initUserDefaults(DataList list) {
430 List<Data> allData = list.getAll();
431
432 Data m = getData(allData, "wq_mode");
433 DataItem modeItem = m != null ? m.getDefault() : null;
434 String theMode = modeItem != null
435 ? modeItem.getStringValue()
436 : null;
437
438 Data s = getData(allData, "wq_selection");
439 DataItem sI = s != null ? s.getDefault() : null;
440 String theSelection = sI != null ? sI.getStringValue() : null;
441
442 if (theMode == null || theMode.length() == 0) {
443 return;
444 }
445
446 initUserSingleValues(list, theMode);
447 initUserRangeValues(list, theMode);
448
449 modes.setValue(FIELD_WQ, theMode);
450
451 if (theSelection != null || theSelection.length() > 0) {
452 modes.setValue(FIELD_MODE, theSelection);
453 updatePanels(theMode, theSelection);
454 }
455 }
456
457
458 /**
459 * Initializes the single values of W or Q from DataList.
460 *
461 * @param list The DataList that contains the 'wq_single' object.
462 * @param theMode The W or Q mode.
463 */
464 protected void initUserSingleValues(DataList list, String theMode) {
465 List<Data> allData = list.getAll();
466
467 Data s = getData(allData, "wq_single");
468 DataItem i = s != null ? s.getDefault() : null;
469
470 if (i != null) {
471 String value = i.getStringValue();
472 String[] split = value.split(" ");
473
474 int num = split != null ? split.length : 0;
475
476 double[] values = new double[num];
477
478 for (int j = 0; j < num; j++) {
479 try {
480 values[j] = Double.valueOf(split[j]);
481 }
482 catch (NumberFormatException nfe) {
483 // nothing to do
484 }
485 }
486
487 if (theMode.equals("W")) {
488 setSingleW(values);
489 }
490 else {
491 setSingleQ(values);
492 }
493 }
494 }
495
496
497 /**
498 * Initializes the range values of W or Q from DataList.
499 *
500 * @param list The DataList that contains the 'wq_single' object.
501 * @param theMode The W or Q mode.
502 */
503 protected void initUserRangeValues(DataList list, String theMode) {
504 List<Data> allData = list.getAll();
505
506 // init range mode values
507 Data f = getData(allData, "wq_from");
508 Data t = getData(allData, "wq_to");
509 Data s = getData(allData, "wq_step");
510
511 if (f != null && t != null && s != null) {
512 DataItem dF = f.getDefault();
513 DataItem dT = t.getDefault();
514 DataItem dS = s.getDefault();
515
516 String fS = dF != null ? dF.getStringValue() : null;
517 String tS = dT != null ? dT.getStringValue() : null;
518 String sS = dS != null ? dS.getStringValue() : null;
519
520 try {
521 double from = Double.valueOf(fS);
522 double to = Double.valueOf(tS);
523 double step = Double.valueOf(sS);
524
525 if (theMode.equals("W")) {
526 setWRangeValues(from, to, step);
527 }
528 else {
529 setQRangeValues(from, to, step);
530 }
531 }
532 catch (NumberFormatException nfe) {
533 // do nothing
534 }
535 }
536 }
537
538
539 protected void setQRangeValues(double f, double t, double s) {
540 setFromQ(f);
541 setToQ(t);
542 setStepQ(s);
543 }
544
545
546 protected void setWRangeValues(double f, double t, double s) {
547 setFromW(f);
548 setToW(t);
549 setStepW(s);
550 }
551
552
423 protected String createWString(DataItem from, DataItem to, DataItem step) { 553 protected String createWString(DataItem from, DataItem to, DataItem step) {
424 StringBuilder sb = new StringBuilder(); 554 StringBuilder sb = new StringBuilder();
425 sb.append(from.getLabel()); 555 sb.append(from.getLabel());
426 sb.append(" " + MESSAGE.unitWFrom() + " "); 556 sb.append(" " + MESSAGE.unitWFrom() + " ");
427 sb.append(to.getLabel()); 557 sb.append(to.getLabel());
471 Canvas modeForm = createModePanel(); 601 Canvas modeForm = createModePanel();
472 602
473 container.setMembersMargin(30); 603 container.setMembersMargin(30);
474 createWQInputTable(); 604 createWQInputTable();
475 createWQInputPanel(); 605 createWQInputPanel();
606
476 // the initial panel is the Single-W panel. 607 // the initial panel is the Single-W panel.
477 double[] values = getSingleW(); 608 double[] values = getSingleQ();
478 wArrayPanel = new DoubleArrayPanel( 609 qArrayPanel = new DoubleArrayPanel(
479 MESSAGE.unitWSingle(), values, this); 610 MESSAGE.unitQSingle(), values, this);
480 container.addMember(wArrayPanel); 611 container.addMember(qArrayPanel);
612
481 helperContainer.addChild(wqTable); 613 helperContainer.addChild(wqTable);
482 layout.addMember(modeForm); 614 layout.addMember(modeForm);
483 layout.addMember(container); 615 layout.addMember(container);
484 616
485 return layout; 617 return layout;
522 modes.setFields(wq, mode); 654 modes.setFields(wq, mode);
523 modes.setWidth(WIDTH_LEFT); 655 modes.setWidth(WIDTH_LEFT);
524 modes.setNumCols(1); 656 modes.setNumCols(1);
525 657
526 LinkedHashMap initial = new LinkedHashMap(); 658 LinkedHashMap initial = new LinkedHashMap();
527 initial.put(FIELD_WQ, FIELD_WQ_W); 659 initial.put(FIELD_WQ, FIELD_WQ_Q);
528 initial.put(FIELD_MODE, FIELD_MODE_SINGLE); 660 initial.put(FIELD_MODE, FIELD_MODE_SINGLE);
529 modes.setValues(initial); 661 modes.setValues(initial);
530 662
531 return modes; 663 return modes;
532 } 664 }
798 } 930 }
799 931
800 932
801 protected void updatePanels(String wqMode, String inputMode) { 933 protected void updatePanels(String wqMode, String inputMode) {
802 container.removeMembers(container.getMembers()); 934 container.removeMembers(container.getMembers());
803 GWT.log("updating Panel and Table");
804 if (wqMode.equals(FIELD_WQ_W)) { 935 if (wqMode.equals(FIELD_WQ_W)) {
805 if (inputMode.equals(FIELD_MODE_SINGLE)) { 936 if (inputMode.equals(FIELD_MODE_SINGLE)) {
806 // Single W mode 937 // Single W mode
807 double[] values = getSingleW(); 938 double[] values = getSingleW();
808 939
1144 if (num == 0) { 1275 if (num == 0) {
1145 return; 1276 return;
1146 } 1277 }
1147 tableData = wqi; 1278 tableData = wqi;
1148 addWQInfo(wqi); 1279 addWQInfo(wqi);
1149 updatePanels(FIELD_WQ_W, FIELD_MODE_SINGLE); 1280
1281 String wq = (String) modes.getValue(FIELD_WQ);
1282 String sr = (String) modes.getValue(FIELD_MODE);
1283 updatePanels(wq, sr);
1150 } 1284 }
1151 } 1285 }
1152 ); 1286 );
1153 } 1287 }
1154 1288

http://dive4elements.wald.intevation.org