comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeTimeRangePanel.java @ 2468:6a65694bdcc2

Issue 506. Gauge time range panel now accepts dates. The dates are stored as long values. flys-client/trunk@4176 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 20 Mar 2012 14:53:42 +0000
parents f30919997e57
children 8d27d2d33d70
comparison
equal deleted inserted replaced
2467:070321cf17e1 2468:6a65694bdcc2
1 package de.intevation.flys.client.client.ui; 1 package de.intevation.flys.client.client.ui;
2 2
3 import java.util.List;
4 import java.util.ArrayList;
5 import java.util.Date;
6 import java.util.Calendar;
7 import java.text.ParseException;
8
3 import com.google.gwt.core.client.GWT; 9 import com.google.gwt.core.client.GWT;
10 import com.google.gwt.i18n.client.DateTimeFormat;
4 11
5 import com.smartgwt.client.types.ListGridFieldType; 12 import com.smartgwt.client.types.ListGridFieldType;
6 13
7 import com.smartgwt.client.data.Record; 14 import com.smartgwt.client.data.Record;
15 import com.smartgwt.client.widgets.layout.HLayout;
16 import com.smartgwt.client.widgets.form.DynamicForm;
17 import com.smartgwt.client.widgets.form.fields.DateRangeItem;
18 import com.smartgwt.client.widgets.Label;
8 19
9 import com.smartgwt.client.widgets.layout.VLayout; 20 import com.smartgwt.client.widgets.layout.VLayout;
10 import com.smartgwt.client.widgets.Canvas; 21 import com.smartgwt.client.widgets.Canvas;
11 import com.smartgwt.client.widgets.grid.ListGrid; 22 import com.smartgwt.client.widgets.grid.ListGrid;
12 import com.smartgwt.client.widgets.grid.ListGridField; 23 import com.smartgwt.client.widgets.grid.ListGridField;
20 31
21 import de.intevation.flys.client.shared.model.DataList; 32 import de.intevation.flys.client.shared.model.DataList;
22 import de.intevation.flys.client.shared.model.DataItem; 33 import de.intevation.flys.client.shared.model.DataItem;
23 import de.intevation.flys.client.shared.model.ArtifactDescription; 34 import de.intevation.flys.client.shared.model.ArtifactDescription;
24 import de.intevation.flys.client.shared.model.Data; 35 import de.intevation.flys.client.shared.model.Data;
36 import de.intevation.flys.client.shared.model.RangeData;
37 import de.intevation.flys.client.shared.model.LongRangeData;
25 38
26 import de.intevation.flys.client.client.ui.range.DischargeInfoDataSource; 39 import de.intevation.flys.client.client.ui.range.DischargeInfoDataSource;
27 40
28 /** 41 /**
29 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 42 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
30 */ 43 */
31 public class GaugeTimeRangePanel extends IntegerRangePanel { 44 public class GaugeTimeRangePanel extends RangePanel {
32 45
33 /** The message class that provides i18n strings. */ 46 /** The message class that provides i18n strings. */
34 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); 47 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
35 48
36 protected ListGrid yearTable; 49 protected ListGrid yearTable;
50
51 protected DateRangeItem dateRange;
37 52
38 public GaugeTimeRangePanel() { 53 public GaugeTimeRangePanel() {
39 GWT.log("Creating YearInputPanel"); 54 GWT.log("Creating YearInputPanel");
40 yearTable = new ListGrid(); 55 yearTable = new ListGrid();
41 yearTable.setAutoFetchData(true); 56 yearTable.setAutoFetchData(true);
63 String url = config.getServerUrl(); 78 String url = config.getServerUrl();
64 yearTable.setDataSource(new DischargeInfoDataSource(url, gauge)); 79 yearTable.setDataSource(new DischargeInfoDataSource(url, gauge));
65 80
66 helperContainer.addMember(yearTable); 81 helperContainer.addMember(yearTable);
67 return root; 82 return root;
83 }
84
85
86 @Override
87 protected void initDefaults(DataList dataList) {
88 RangeData data = findRangeData(dataList);
89
90 if(data != null) {
91 GWT.log("data: " + data);
92 }
93 }
94
95
96 @Override
97 public Canvas createOld(DataList dataList) {
98 GWT.log("create old date.");
99 Data data = dataList.get(0);
100 DataItem[] items = data.getItems();
101 GWT.log(data.getClass().toString());
102 HLayout layout = new HLayout();
103
104 Label label = new Label(dataList.getLabel());
105 label.setWidth(200);
106 label.setHeight(20);
107
108 Date dl = new Date((Long)((LongRangeData)data).getLower());
109 Date du = new Date((Long)((LongRangeData)data).getUpper());
110 DateTimeFormat dtf = DateTimeFormat.getMediumDateFormat();
111 Label value = new Label(dtf.format(dl) + " - " + dtf.format(du));
112 value.setHeight(20);
113
114 layout.addMember(label);
115 layout.addMember(value);
116 layout.addMember(getBackButton(dataList.getState()));
117
118 return layout;
119 }
120
121
122 @Override
123 protected Data[] getData() {
124 long lo = getLowerAsLong();
125 long up = getUpperAsLong();
126
127 return new Data[] { new LongRangeData(getDataName(), null, lo, up) };
128 }
129
130
131 @Override
132 protected Canvas createForm(DataList dataList) {
133 HLayout layout = new HLayout();
134 DynamicForm form = new DynamicForm();
135 dateRange = new DateRangeItem();
136 dateRange.setToTitle(MESSAGES.to());
137 dateRange.setFromTitle(MESSAGES.from());
138 dateRange.setShowTitle(false);
139 form.setFields(dateRange);
140
141 layout.addMember(form);
142 return layout;
143
144 }
145
146
147 @Override
148 public Object getMaxLower() {
149 Date d = dateRange.getFromDate();
150 return new Long(d.getTime());
151 }
152
153
154 protected long getLowerAsLong() {
155 Date d = dateRange.getFromDate();
156 return d.getTime();
157 }
158
159
160 protected long getUpperAsLong() {
161 Date d = dateRange.getToDate();
162 return d.getTime();
163 }
164
165
166 @Override
167 public Object getMaxUpper() {
168 Date d = dateRange.getToDate();
169 return new Long(d.getTime());
170 }
171
172
173 @Override
174 public void setLower(String lower) {
175 try {
176 DateTimeFormat dtf =
177 DateTimeFormat.getFormat("yyyy");
178 Date dy = dtf.parse(lower);
179 dy.setMonth(0);
180 dy.setDate(1);
181 dateRange.setFromDate(dy);
182 }
183 catch(IllegalArgumentException iae) {
184 GWT.log("could not parse lower date.");
185 //TODO: Messagebox with error.
186 }
187 }
188
189
190 @Override
191 public void setUpper(String upper) {
192 try {
193 DateTimeFormat dtf =
194 DateTimeFormat.getFormat("yyyy");
195 Date dy = dtf.parse(upper);
196 dy.setMonth(0);
197 dy.setDate(1);
198 dateRange.setToDate(dy);
199 }
200 catch(IllegalArgumentException iae) {
201 GWT.log("could not parse upper date.");
202 //TODO: Messagebox with error.
203 }
68 } 204 }
69 205
70 206
71 protected ListGrid initYearTable() { 207 protected ListGrid initYearTable() {
72 String baseUrl = GWT.getHostPageBaseURL(); 208 String baseUrl = GWT.getHostPageBaseURL();
172 catch (NumberFormatException nfe) { 308 catch (NumberFormatException nfe) {
173 GWT.log("Error parsing gauge."); 309 GWT.log("Error parsing gauge.");
174 return 0; 310 return 0;
175 } 311 }
176 } 312 }
313
314
315 @Override
316 public List<String> validate() {
317 List<String> errors = new ArrayList<String>();
318 if (dateRange.getFromDate() == null ||
319 dateRange.getToDate() == null ||
320 !dateRange.getFromDate().before(dateRange.getToDate()))
321 {
322 String msg = MSG.error_validate_date_range();
323 errors.add(msg);
324 }
325 return errors;
326 }
177 } 327 }

http://dive4elements.wald.intevation.org