Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixPeriodPanel.java @ 3855:b6b2d9aad95d
Fix for #854
flys-client/trunk@5596 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Tue, 25 Sep 2012 13:24:23 +0000 |
parents | 0de61fc9d281 |
children | 65e369ac4f99 |
comparison
equal
deleted
inserted
replaced
3854:3228d65b0db9 | 3855:b6b2d9aad95d |
---|---|
1 package de.intevation.flys.client.client.ui.fixation; | 1 package de.intevation.flys.client.client.ui.fixation; |
2 | |
3 import java.util.List; | |
4 import java.util.ArrayList; | |
5 import java.util.Date; | |
6 | 2 |
7 import com.google.gwt.core.client.GWT; | 3 import com.google.gwt.core.client.GWT; |
8 import com.google.gwt.i18n.client.DateTimeFormat; | 4 import com.google.gwt.i18n.client.DateTimeFormat; |
9 import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; | |
10 | 5 |
11 import com.smartgwt.client.util.SC; | 6 import com.smartgwt.client.util.SC; |
12 | |
13 import com.smartgwt.client.widgets.Canvas; | 7 import com.smartgwt.client.widgets.Canvas; |
14 import com.smartgwt.client.widgets.Label; | 8 import com.smartgwt.client.widgets.Label; |
15 | 9 import com.smartgwt.client.widgets.form.DynamicForm; |
10 import com.smartgwt.client.widgets.form.fields.DateRangeItem; | |
16 import com.smartgwt.client.widgets.layout.HLayout; | 11 import com.smartgwt.client.widgets.layout.HLayout; |
17 import com.smartgwt.client.widgets.layout.VLayout; | 12 import com.smartgwt.client.widgets.layout.VLayout; |
18 | 13 |
19 import com.smartgwt.client.widgets.form.DynamicForm; | 14 import de.intevation.flys.client.client.Config; |
20 import com.smartgwt.client.widgets.form.fields.DateRangeItem; | |
21 | |
22 import de.intevation.flys.client.client.FLYSConstants; | 15 import de.intevation.flys.client.client.FLYSConstants; |
23 | |
24 import de.intevation.flys.client.shared.model.Data; | 16 import de.intevation.flys.client.shared.model.Data; |
25 import de.intevation.flys.client.shared.model.DataItem; | 17 import de.intevation.flys.client.shared.model.DataItem; |
26 import de.intevation.flys.client.shared.model.DataList; | 18 import de.intevation.flys.client.shared.model.DataList; |
27 import de.intevation.flys.client.shared.model.DefaultData; | 19 import de.intevation.flys.client.shared.model.DefaultData; |
28 import de.intevation.flys.client.shared.model.DefaultDataItem; | 20 import de.intevation.flys.client.shared.model.DefaultDataItem; |
29 import de.intevation.flys.client.shared.model.FixingsOverviewInfo.FixEvent; | 21 import de.intevation.flys.client.shared.model.FixingsOverviewInfo.FixEvent; |
22 | |
23 import java.util.ArrayList; | |
24 import java.util.Date; | |
25 import java.util.List; | |
30 | 26 |
31 /** | 27 /** |
32 * This UIProvider creates a panel for location or distance input. | 28 * This UIProvider creates a panel for location or distance input. |
33 * | 29 * |
34 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 30 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
55 this.startName = startName; | 51 this.startName = startName; |
56 this.endName = endName; | 52 this.endName = endName; |
57 htmlOverview = ""; | 53 htmlOverview = ""; |
58 } | 54 } |
59 | 55 |
56 @Override | |
60 public Canvas createWidget(DataList data) { | 57 public Canvas createWidget(DataList data) { |
61 instances.put(this.artifact.getUuid(), this); | 58 instances.put(this.artifact.getUuid(), this); |
62 | 59 |
63 VLayout layout = new VLayout(); | 60 VLayout layout = new VLayout(); |
64 | 61 |
131 /** | 128 /** |
132 * This method returns the selected data. | 129 * This method returns the selected data. |
133 * | 130 * |
134 * @return the selected/inserted data. | 131 * @return the selected/inserted data. |
135 */ | 132 */ |
133 @Override | |
136 public Data[] getData() { | 134 public Data[] getData() { |
137 List<Data> data = new ArrayList<Data>(); | 135 List<Data> data = new ArrayList<Data>(); |
138 | 136 |
139 boolean valid = saveDateValues(); | 137 boolean valid = saveDateValues(); |
140 if(valid) { | 138 if(valid) { |
168 public boolean renderCheckboxes() { | 166 public boolean renderCheckboxes() { |
169 // No selection, return false. | 167 // No selection, return false. |
170 return false; | 168 return false; |
171 } | 169 } |
172 | 170 |
173 | 171 protected String getLocaleDateFormat() { |
172 String loc = Config.getInstance().getLocale(); | |
173 if ("de".equals(loc)) { | |
174 return "yy.MM.yyyy"; | |
175 } | |
176 else { | |
177 return "MM/dd/yyyy"; | |
178 } | |
179 } | |
180 | |
181 @Override | |
174 public void success() { | 182 public void success() { |
175 List<FixEvent> list = fixInfo.getEvents(); | 183 List<FixEvent> list = fixInfo.getEvents(); |
176 DateTimeFormat df = DateTimeFormat.getFormat( | 184 |
177 DateTimeFormat.PredefinedFormat.DATE_MEDIUM); | 185 // The date in FixEvent is always "de" locale, so it seems... |
178 | 186 DateTimeFormat df = DateTimeFormat.getFormat("yy.MM.yyyy"); |
187 | |
188 if (!setFromAndToDate(list, df)) { | |
189 // or perhaps "en"? | |
190 df = DateTimeFormat.getFormat("MM/dd/yyyy"); | |
191 | |
192 if (!setFromAndToDate(list, df)) { | |
193 GWT.log("FixPeriodPanel::success(): could not set from and to dates!"); | |
194 } | |
195 } | |
196 } | |
197 | |
198 protected boolean setFromAndToDate(List<FixEvent> list, DateTimeFormat df) { | |
179 try { | 199 try { |
180 Date f = df.parse(list.get(0).getDate()); | 200 setFromDate(list.get(0).getDate(), df); |
181 Date t = df.parse(list.get(list.size() - 1).getDate()); | 201 setToDate(list.get(list.size() - 1).getDate(), df); |
182 this.inputPanel.setFromDate(f); | 202 return true; |
183 this.inputPanel.setToDate(t); | 203 } |
184 } | 204 catch(IllegalArgumentException ex) { |
185 catch(IllegalArgumentException pe) { | 205 GWT.log("FixPeriodPanel::setFromAndToDate(): " + ex.toString()); |
186 GWT.log(pe.toString()); | 206 return false; |
187 } | 207 } |
208 } | |
209 | |
210 protected void setFromDate(String date, DateTimeFormat df) | |
211 throws IllegalArgumentException | |
212 { | |
213 Date from = df.parse(date); | |
214 this.inputPanel.setFromDate(from); | |
215 } | |
216 | |
217 protected void setToDate(String date, DateTimeFormat df) | |
218 throws IllegalArgumentException | |
219 { | |
220 Date to = df.parse(date); | |
221 this.inputPanel.setToDate(to); | |
188 } | 222 } |
189 | 223 |
190 protected boolean saveDateValues() { | 224 protected boolean saveDateValues() { |
191 Date st = inputPanel.getFromDate(); | 225 Date st = inputPanel.getFromDate(); |
192 Date en = inputPanel.getToDate(); | 226 Date en = inputPanel.getToDate(); |