comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java @ 2456:60ab1054069d

Issue 630. Added input helper panel to wq selection. flys-client/trunk@4147 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 15 Mar 2012 15:02:29 +0000
parents 61c8e517671e
children 8490faba00e7
comparison
equal deleted inserted replaced
2455:0b7535e2e9aa 2456:60ab1054069d
7 import java.util.List; 7 import java.util.List;
8 import java.util.Map; 8 import java.util.Map;
9 9
10 import com.google.gwt.core.client.GWT; 10 import com.google.gwt.core.client.GWT;
11 import com.google.gwt.i18n.client.NumberFormat; 11 import com.google.gwt.i18n.client.NumberFormat;
12 import com.google.gwt.user.client.rpc.AsyncCallback;
12 13
13 import com.smartgwt.client.types.TitleOrientation; 14 import com.smartgwt.client.types.TitleOrientation;
14 import com.smartgwt.client.types.VerticalAlignment; 15 import com.smartgwt.client.types.VerticalAlignment;
15 import com.smartgwt.client.util.SC; 16 import com.smartgwt.client.util.SC;
16 import com.smartgwt.client.widgets.Canvas; 17 import com.smartgwt.client.widgets.Canvas;
21 import com.smartgwt.client.widgets.form.fields.events.BlurEvent; 22 import com.smartgwt.client.widgets.form.fields.events.BlurEvent;
22 import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; 23 import com.smartgwt.client.widgets.form.fields.events.ChangeHandler;
23 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; 24 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
24 import com.smartgwt.client.widgets.layout.HLayout; 25 import com.smartgwt.client.widgets.layout.HLayout;
25 import com.smartgwt.client.widgets.layout.VLayout; 26 import com.smartgwt.client.widgets.layout.VLayout;
27 import com.smartgwt.client.widgets.tab.TabSet;
28 import com.smartgwt.client.widgets.tab.Tab;
26 29
27 import de.intevation.flys.client.shared.model.Data; 30 import de.intevation.flys.client.shared.model.Data;
28 import de.intevation.flys.client.shared.model.DataItem; 31 import de.intevation.flys.client.shared.model.DataItem;
29 import de.intevation.flys.client.shared.model.DataList; 32 import de.intevation.flys.client.shared.model.DataList;
30 import de.intevation.flys.client.shared.model.DefaultData; 33 import de.intevation.flys.client.shared.model.DefaultData;
31 import de.intevation.flys.client.shared.model.DefaultDataItem; 34 import de.intevation.flys.client.shared.model.DefaultDataItem;
32 import de.intevation.flys.client.shared.model.WQDataItem; 35 import de.intevation.flys.client.shared.model.WQDataItem;
36 import de.intevation.flys.client.shared.model.WQInfoObject;
37 import de.intevation.flys.client.shared.model.WQInfoRecord;
38 import de.intevation.flys.client.shared.model.ArtifactDescription;
39
33 40
34 import de.intevation.flys.client.client.FLYSConstants; 41 import de.intevation.flys.client.client.FLYSConstants;
42 import de.intevation.flys.client.client.Config;
43 import de.intevation.flys.client.client.services.WQInfoService;
44 import de.intevation.flys.client.client.services.WQInfoServiceAsync;
45 import de.intevation.flys.client.client.ui.wq.WTable;
46 import de.intevation.flys.client.client.ui.wq.QDTable;
35 47
36 48
37 /** 49 /**
38 * This UIProvider creates a widget to enter W or Q data for discharge 50 * This UIProvider creates a widget to enter W or Q data for discharge
39 * longitudinal section computations. 51 * longitudinal section computations.
54 66
55 public static final String VALUE_SEPARATOR = ","; 67 public static final String VALUE_SEPARATOR = ",";
56 68
57 public static final int ROW_HEIGHT = 20; 69 public static final int ROW_HEIGHT = 20;
58 70
71 /** The constant field name for choosing w or q mode.*/
72 public static final String FIELD_WQ = "wq";
73
74 /** The constant field name for choosing single values or range.*/
75 public static final String FIELD_MODE = "mode";
76
77 /** The constant field value for range input mode.*/
78 public static final String FIELD_MODE_RANGE = "range";
79
80 protected WQInfoServiceAsync wqInfoService =
81 GWT.create(WQInfoService.class);
59 82
60 /** The message class that provides i18n strings.*/ 83 /** The message class that provides i18n strings.*/
61 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); 84 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
62 85
63 /** Stores the input panels related to their keys.*/ 86 /** Stores the input panels related to their keys.*/
70 protected Map<String, double[]> wranges; 93 protected Map<String, double[]> wranges;
71 94
72 /** The RadioGroupItem that determines the w/q input mode.*/ 95 /** The RadioGroupItem that determines the w/q input mode.*/
73 protected DynamicForm modes; 96 protected DynamicForm modes;
74 97
98 protected QDTable qdTable;
99
100 protected WTable wTable;
101
102 protected TabSet tabs;
75 103
76 104
77 public WQAdaptedInputPanel() { 105 public WQAdaptedInputPanel() {
78 wqranges = new HashMap<String, DoubleArrayPanel>(); 106 wqranges = new HashMap<String, DoubleArrayPanel>();
79 qranges = new HashMap<String, double[]>(); 107 qranges = new HashMap<String, double[]>();
80 wranges = new HashMap<String, double[]>(); 108 wranges = new HashMap<String, double[]>();
109 qdTable = new QDTable();
110 wTable = new WTable();
81 } 111 }
82 112
83 113
84 public Canvas create(DataList data) { 114 public Canvas create(DataList data) {
115 initHelperPanel();
116
85 Canvas submit = getNextButton(); 117 Canvas submit = getNextButton();
86 Canvas widget = createWidget(data); 118 Canvas widget = createWidget(data);
87 Label label = new Label(MSG.wqadaptedTitle()); 119 Label label = new Label(MSG.wqadaptedTitle());
88 120
89 label.setHeight(25); 121 label.setHeight(25);
94 126
95 layout.addMember(label); 127 layout.addMember(label);
96 layout.addMember(widget); 128 layout.addMember(widget);
97 layout.addMember(submit); 129 layout.addMember(submit);
98 130
131
99 return layout; 132 return layout;
133 }
134
135
136 protected void initHelperPanel() {
137 tabs = new TabSet();
138 tabs.setWidth100();
139 tabs.setHeight100();
140
141 // TODO i18n
142 Tab wTab = new Tab("W");
143 Tab qTab = new Tab("Q / D");
144
145 wTab.setPane(wTable);
146 qTab.setPane(qdTable);
147 qdTable.hideIconFields();
148
149 tabs.addTab(wTab, 0);
150 tabs.addTab(qTab, 1);
151
152 helperContainer.addMember(tabs);
153
154 fetchWQData();
100 } 155 }
101 156
102 157
103 public Canvas createOld(DataList dataList) { 158 public Canvas createOld(DataList dataList) {
104 List<Data> all = dataList.getAll(); 159 List<Data> all = dataList.getAll();
416 if (item instanceof WQDataItem) { 471 if (item instanceof WQDataItem) {
417 WQDataItem wq = (WQDataItem) item; 472 WQDataItem wq = (WQDataItem) item;
418 double[] mmQ = wq.getQRange(); 473 double[] mmQ = wq.getQRange();
419 double[] mmW = wq.getWRange(); 474 double[] mmW = wq.getWRange();
420 475
421 GWT.log(title + " Q: " + mmQ[0] + " - " + mmQ[1]);
422 GWT.log(title + " W: " + mmW[0] + " - " + mmW[1]);
423
424 qranges.put(title, mmQ); 476 qranges.put(title, mmQ);
425 wranges.put(title, mmW); 477 wranges.put(title, mmW);
426 } 478 }
427 479
428 layout.addMember(dap); 480 layout.addMember(dap);
464 wq.setValueMap(wqValues); 516 wq.setValueMap(wqValues);
465 517
466 modes = new DynamicForm(); 518 modes = new DynamicForm();
467 modes.setFields(wq); 519 modes.setFields(wq);
468 modes.setWidth(200); 520 modes.setWidth(200);
521 wq.addChangeHandler(new ChangeHandler() {
522 public void onChange(ChangeEvent e) {
523 DynamicForm form = e.getForm();
524
525 if(form.getValueAsString(FIELD_WQ_MODE).contains("Q")) {
526 tabs.selectTab(0);
527 }
528 else {
529 tabs.selectTab(1);
530 }
531 }
532 });
533
469 534
470 LinkedHashMap initial = new LinkedHashMap(); 535 LinkedHashMap initial = new LinkedHashMap();
471 initial.put(FIELD_WQ_MODE, FIELD_WQ_Q); 536 initial.put(FIELD_WQ_MODE, FIELD_WQ_Q);
472 modes.setValues(initial); 537 modes.setValues(initial);
473 538 tabs.selectTab(1);
474 return modes; 539 return modes;
475 } 540 }
476 541
477 542
478 public String createLineTitle(String key) { 543 public String createLineTitle(String key) {
563 628
564 public void onBlur(BlurEvent event) { 629 public void onBlur(BlurEvent event) {
565 DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm(); 630 DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm();
566 dap.validateForm(event.getItem()); 631 dap.validateForm(event.getItem());
567 } 632 }
633
634
635 protected void fetchWQData() {
636 Config config = Config.getInstance();
637 String locale = config.getLocale ();
638
639 ArtifactDescription adescr = artifact.getArtifactDescription();
640 DataList[] data = adescr.getOldData();
641
642 double[] mm = getMinMaxKM(data);
643 String river = getRiverName(data);
644
645 wqInfoService.getWQInfo(locale, river, mm[0], mm[0],
646 new AsyncCallback<WQInfoObject[]>() {
647 public void onFailure(Throwable caught) {
648 GWT.log("Could not recieve wq informations.");
649 SC.warn(caught.getMessage());
650 }
651
652 public void onSuccess(WQInfoObject[] wqi) {
653 int num = wqi != null ? wqi.length :0;
654 GWT.log("Recieved " + num + " wq informations.");
655
656 if (num == 0) {
657 return;
658 }
659
660 addWQInfo(wqi);
661
662 }
663 }
664 );
665 }
666
667
668 protected void addWQInfo (WQInfoObject[] wqi) {
669 for(WQInfoObject wi: wqi) {
670 WQInfoRecord rec = new WQInfoRecord(wi);
671
672 if (wi.getType().equals("W")) {
673 wTable.addData(rec);
674 }
675 else {
676 qdTable.addData(rec);
677 }
678 }
679 }
680
681
682 /**
683 * Determines the min and max kilometer value selected in a former state. A
684 * bit silly, but we need to run over each value of the "old data" to find
685 * such values because it is not available here.
686 *
687 * @param data The DataList which contains the whole data inserted for the
688 * current artifact.
689 *
690 * @return a double array with [min, max].
691 */
692 protected double[] getMinMaxKM(DataList[] data) {
693 ArtifactDescription adesc = artifact.getArtifactDescription();
694 return adesc.getKMRange();
695 }
696
697
698 /**
699 * Returns the name of the selected river.
700 *
701 * @param data The DataList with all data.
702 *
703 * @return the name of the current river.
704 */
705 protected String getRiverName(DataList[] data) {
706 ArtifactDescription adesc = artifact.getArtifactDescription();
707 return adesc.getRiver();
708 }
709
710
711 protected void updatePanels(boolean isQ) {
712
713 }
714
715
568 } 716 }
569 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 717 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org