comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeTimeRangePanel.java @ 1602:f30919997e57

Added helper input table to state 'timerange' input in hist. discharge curves. flys-client/trunk@3940 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Mon, 06 Feb 2012 16:11:10 +0000
parents
children 6a65694bdcc2
comparison
equal deleted inserted replaced
1601:42543705a857 1602:f30919997e57
1 package de.intevation.flys.client.client.ui;
2
3 import com.google.gwt.core.client.GWT;
4
5 import com.smartgwt.client.types.ListGridFieldType;
6
7 import com.smartgwt.client.data.Record;
8
9 import com.smartgwt.client.widgets.layout.VLayout;
10 import com.smartgwt.client.widgets.Canvas;
11 import com.smartgwt.client.widgets.grid.ListGrid;
12 import com.smartgwt.client.widgets.grid.ListGridField;
13 import com.smartgwt.client.widgets.grid.CellFormatter;
14 import com.smartgwt.client.widgets.grid.ListGridRecord;
15 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
16 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
17
18 import de.intevation.flys.client.client.FLYSConstants;
19 import de.intevation.flys.client.client.Config;
20
21 import de.intevation.flys.client.shared.model.DataList;
22 import de.intevation.flys.client.shared.model.DataItem;
23 import de.intevation.flys.client.shared.model.ArtifactDescription;
24 import de.intevation.flys.client.shared.model.Data;
25
26 import de.intevation.flys.client.client.ui.range.DischargeInfoDataSource;
27
28 /**
29 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
30 */
31 public class GaugeTimeRangePanel extends IntegerRangePanel {
32
33 /** The message class that provides i18n strings. */
34 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
35
36 protected ListGrid yearTable;
37
38 public GaugeTimeRangePanel() {
39 GWT.log("Creating YearInputPanel");
40 yearTable = new ListGrid();
41 yearTable.setAutoFetchData(true);
42 yearTable.setShowHeaderContextMenu(false);
43
44 }
45
46 public Canvas create(DataList data) {
47 setDataName(data);
48
49 VLayout root = new VLayout();
50
51 root.addMember(createLabel(data));
52 root.addMember(createForm(data));
53 root.addMember(getNextButton());
54
55 initDefaults(data);
56
57
58 initYearTable();
59
60 long gauge = getGaugeNumber();
61
62 Config config = Config.getInstance();
63 String url = config.getServerUrl();
64 yearTable.setDataSource(new DischargeInfoDataSource(url, gauge));
65
66 helperContainer.addMember(yearTable);
67 return root;
68 }
69
70
71 protected ListGrid initYearTable() {
72 String baseUrl = GWT.getHostPageBaseURL();
73
74 yearTable.setWidth100();
75 yearTable.setHeight100();
76 yearTable.setShowRecordComponents(true);
77 yearTable.setShowRecordComponentsByCell(true);
78 yearTable.setEmptyMessage(MESSAGES.empty_filter());
79 yearTable.setCanReorderFields(false);
80
81 CellFormatter cf = new CellFormatter() {
82 public String format(
83 Object value,
84 ListGridRecord record,
85 int rowNum, int colNum) {
86 if (value == null) return null;
87 if (value.toString().equals("-1")) {
88 return "";
89 }
90 return value.toString();
91 }
92 };
93
94
95 ListGridField addstart = new ListGridField ("", "");
96 addstart.setType (ListGridFieldType.ICON);
97 addstart.setWidth (20);
98 addstart.setCellIcon(baseUrl + MESSAGES.markerGreen());
99 addstart.addRecordClickHandler(new RecordClickHandler() {
100 public void onRecordClick(RecordClickEvent e) {
101 Record r = e.getRecord();
102 if (r.getAttribute("start").equals("-1")) {
103 return;
104 }
105 else {
106 setLower(r.getAttribute("start"));
107 }
108 }
109 });
110
111 ListGridField addend = new ListGridField ("", "");
112 addend.setType (ListGridFieldType.ICON);
113 addend.setWidth (20);
114 addend.setCellIcon(baseUrl + MESSAGES.markerRed());
115 addend.addRecordClickHandler(new RecordClickHandler() {
116 public void onRecordClick(RecordClickEvent e) {
117 Record r = e.getRecord();
118 if (r.getAttribute("end").equals("-1")) {
119 return;
120 }
121 else {
122 setUpper(r.getAttribute("end"));
123 }
124 }
125 });
126
127 ListGridField desc =
128 new ListGridField("description", MESSAGES.description());
129 desc.setType(ListGridFieldType.TEXT);
130 desc.setWidth("*");
131
132 ListGridField start =
133 new ListGridField("start", MESSAGES.start_year());
134 start.setType(ListGridFieldType.INTEGER);
135 start.setWidth(50);
136 start.setCellFormatter(cf);
137
138 ListGridField end =
139 new ListGridField("end", MESSAGES.end_year());
140 end.setType(ListGridFieldType.INTEGER);
141 end.setWidth(50);
142 end.setCellFormatter(cf);
143
144 yearTable.setFields(addstart, addend, desc, start, end);
145
146 return yearTable;
147 }
148
149
150 protected long getGaugeNumber() {
151 ArtifactDescription adescr = artifact.getArtifactDescription();
152 DataList[] data = adescr.getOldData();
153
154 String gauge = "";
155 if (data != null && data.length > 0) {
156 for (int i = 0; i < data.length; i++) {
157 DataList dl = data[i];
158 if (dl.getState().equals("state.winfo.historicalq.reference_gauge")) {
159 for (int j = 0; j < dl.size(); j++) {
160 Data d = dl.get(j);
161 DataItem[] di = d.getItems();
162 if (di != null && di.length == 1) {
163 gauge = d.getItems()[0].getStringValue();
164 }
165 }
166 }
167 }
168 }
169 try {
170 return Long.parseLong(gauge);
171 }
172 catch (NumberFormatException nfe) {
173 GWT.log("Error parsing gauge.");
174 return 0;
175 }
176 }
177 }

http://dive4elements.wald.intevation.org