Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/LoadSingleYearPanel.java @ 9066:b5d7a9d79837
uinfo.inundation_duration ui
author | gernotbelger |
---|---|
date | Fri, 11 May 2018 17:04:35 +0200 |
parents | b6919e3c2d86 |
children | 2b13de1b0897 |
comparison
equal
deleted
inserted
replaced
9065:58af9b81a97b | 9066:b5d7a9d79837 |
---|---|
8 | 8 |
9 package org.dive4elements.river.client.client.ui.uinfo; | 9 package org.dive4elements.river.client.client.ui.uinfo; |
10 | 10 |
11 import java.util.ArrayList; | 11 import java.util.ArrayList; |
12 import java.util.List; | 12 import java.util.List; |
13 | |
14 import com.google.gwt.core.client.GWT; | |
15 import com.google.gwt.i18n.client.NumberFormat; | |
16 import com.google.gwt.user.client.rpc.AsyncCallback; | |
17 import com.smartgwt.client.data.Record; | |
18 import com.smartgwt.client.types.ListGridFieldType; | |
19 import com.smartgwt.client.util.SC; | |
20 import com.smartgwt.client.widgets.Canvas; | |
21 import com.smartgwt.client.widgets.Label; | |
22 import com.smartgwt.client.widgets.form.DynamicForm; | |
23 import com.smartgwt.client.widgets.form.fields.TextItem; | |
24 import com.smartgwt.client.widgets.form.validator.IsIntegerValidator; | |
25 import com.smartgwt.client.widgets.grid.ListGrid; | |
26 import com.smartgwt.client.widgets.grid.ListGridField; | |
27 import com.smartgwt.client.widgets.layout.HLayout; | |
28 import com.smartgwt.client.widgets.layout.VLayout; | |
29 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; | |
30 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; | |
31 | 13 |
32 import org.dive4elements.river.client.client.Config; | 14 import org.dive4elements.river.client.client.Config; |
33 import org.dive4elements.river.client.client.FLYSConstants; | 15 import org.dive4elements.river.client.client.FLYSConstants; |
34 import org.dive4elements.river.client.client.services.SedimentLoadInfoService; | 16 import org.dive4elements.river.client.client.services.SedimentLoadInfoService; |
35 import org.dive4elements.river.client.client.services.SedimentLoadInfoServiceAsync; | 17 import org.dive4elements.river.client.client.services.SedimentLoadInfoServiceAsync; |
41 import org.dive4elements.river.client.shared.model.DefaultData; | 23 import org.dive4elements.river.client.shared.model.DefaultData; |
42 import org.dive4elements.river.client.shared.model.DefaultDataItem; | 24 import org.dive4elements.river.client.shared.model.DefaultDataItem; |
43 import org.dive4elements.river.client.shared.model.SedimentLoadInfoObject; | 25 import org.dive4elements.river.client.shared.model.SedimentLoadInfoObject; |
44 import org.dive4elements.river.client.shared.model.SedimentLoadInfoRecord; | 26 import org.dive4elements.river.client.shared.model.SedimentLoadInfoRecord; |
45 | 27 |
46 | 28 import com.google.gwt.core.client.GWT; |
47 public class LoadSingleYearPanel | 29 import com.google.gwt.i18n.client.NumberFormat; |
48 extends AbstractUIProvider | 30 import com.google.gwt.user.client.rpc.AsyncCallback; |
49 { | 31 import com.smartgwt.client.data.Record; |
50 protected SedimentLoadInfoServiceAsync sedLoadInfoService = | 32 import com.smartgwt.client.types.ListGridFieldType; |
51 GWT.create(SedimentLoadInfoService.class); | 33 import com.smartgwt.client.util.SC; |
52 | 34 import com.smartgwt.client.widgets.Canvas; |
35 import com.smartgwt.client.widgets.Label; | |
36 import com.smartgwt.client.widgets.form.DynamicForm; | |
37 import com.smartgwt.client.widgets.form.fields.IntegerItem; | |
38 import com.smartgwt.client.widgets.form.fields.TextItem; | |
39 import com.smartgwt.client.widgets.grid.ListGrid; | |
40 import com.smartgwt.client.widgets.grid.ListGridField; | |
41 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; | |
42 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; | |
43 import com.smartgwt.client.widgets.layout.HLayout; | |
44 import com.smartgwt.client.widgets.layout.VLayout; | |
45 | |
46 public class LoadSingleYearPanel extends AbstractUIProvider { | |
47 protected SedimentLoadInfoServiceAsync sedLoadInfoService = GWT.create(SedimentLoadInfoService.class); // TODO: find right datasource | |
48 | |
49 private static final String datakey = "singleyear"; | |
53 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); | 50 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); |
54 | 51 |
55 private TextItem yearsItem; | 52 private TextItem inputItem; |
56 | 53 |
57 private ListGrid sedLoadTable; | 54 private ListGrid sedLoadTable; |
58 | 55 |
59 protected List<String> validYears; | 56 protected List<String> validInputs; |
60 | 57 |
61 public LoadSingleYearPanel () { | 58 public LoadSingleYearPanel() { |
62 } | 59 } |
63 | 60 |
64 @Override | 61 @Override |
65 public Canvas createOld(DataList dataList) { | 62 public Canvas createOld(final DataList dataList) { |
66 List<Data> items = dataList.getAll(); | 63 final List<Data> items = dataList.getAll(); |
67 Data years = getData(items, "years"); | 64 final Data item = getData(items, datakey); |
68 DataItem[] yearsItems = years.getItems(); | 65 final DataItem[] alreadySetItems = item.getItems(); |
69 | 66 |
70 String v1 = yearsItems[0].getStringValue().replace(" ", ", "); | 67 final String v1 = alreadySetItems[0].getStringValue().replace(" ", ", "); |
71 | 68 |
72 Label old = new Label(v1); | 69 final Label old = new Label(v1); |
73 HLayout layout = new HLayout(); | 70 final HLayout layout = new HLayout(); |
74 layout.setWidth("400px"); | 71 layout.setWidth("400px"); |
75 | 72 |
76 Label label = new Label(dataList.getLabel()); | 73 final Label label = new Label(dataList.getLabel()); |
77 label.setWidth("200px"); | 74 label.setWidth("200px"); |
78 | 75 |
79 Canvas back = getBackButton(dataList.getState()); | 76 final Canvas back = getBackButton(dataList.getState()); |
80 | 77 |
81 layout.addMember(label); | 78 layout.addMember(label); |
82 layout.addMember(old); | 79 layout.addMember(old); |
83 layout.addMember(back); | 80 layout.addMember(back); |
84 | 81 |
89 public List<String> validate() { | 86 public List<String> validate() { |
90 return validateYears(); | 87 return validateYears(); |
91 } | 88 } |
92 | 89 |
93 @Override | 90 @Override |
94 public Canvas create(DataList data) { | 91 public Canvas create(final DataList data) { |
95 VLayout layout = new VLayout(); | 92 final VLayout layout = new VLayout(); |
96 | 93 |
97 Canvas helper = createHelper(); | 94 final Canvas helper = createHelper(); |
98 this.helperContainer.addMember(helper); | 95 this.helperContainer.addMember(helper); |
99 | 96 |
100 Canvas submit = getNextButton(); | 97 final Canvas submit = getNextButton(); |
101 Canvas widget = createWidget(data); | 98 final Canvas widget = createWidget(data); |
102 | 99 |
103 layout.addMember(widget); | 100 layout.addMember(widget); |
104 layout.addMember(submit); | 101 layout.addMember(submit); |
105 | 102 |
106 fetchSedimentLoadData(); | 103 fetchSedimentLoadData(); |
107 | 104 |
108 return layout; | 105 return layout; |
109 } | 106 } |
110 | 107 |
111 private Canvas createHelper() { | 108 private Canvas createHelper() { |
112 sedLoadTable = new ListGrid(); | 109 this.sedLoadTable = new ListGrid(); |
113 sedLoadTable.setShowHeaderContextMenu(false); | 110 this.sedLoadTable.setShowHeaderContextMenu(false); |
114 sedLoadTable.setWidth100(); | 111 this.sedLoadTable.setWidth100(); |
115 sedLoadTable.setShowRecordComponents(true); | 112 this.sedLoadTable.setShowRecordComponents(true); |
116 sedLoadTable.setShowRecordComponentsByCell(true); | 113 this.sedLoadTable.setShowRecordComponentsByCell(true); |
117 sedLoadTable.setHeight100(); | 114 this.sedLoadTable.setHeight100(); |
118 sedLoadTable.setEmptyMessage(MSG.empty_table()); | 115 this.sedLoadTable.setEmptyMessage(this.MSG.empty_table()); |
119 sedLoadTable.setCanReorderFields(false); | 116 this.sedLoadTable.setCanReorderFields(false); |
120 | 117 |
121 ListGridField date = new ListGridField("date", MSG.year()); | 118 final ListGridField date = new ListGridField("date", this.MSG.year()); |
122 date.setType(ListGridFieldType.TEXT); | 119 date.setType(ListGridFieldType.TEXT); |
123 date.setWidth(100); | 120 date.setWidth(100); |
124 | 121 |
125 ListGridField descr = | 122 final ListGridField descr = new ListGridField("description", this.MSG.description()); |
126 new ListGridField("description", MSG.description()); | |
127 descr.setType(ListGridFieldType.TEXT); | 123 descr.setType(ListGridFieldType.TEXT); |
128 descr.setWidth("*"); | 124 descr.setWidth("*"); |
129 | 125 |
130 String baseUrl = GWT.getHostPageBaseURL(); | 126 final String baseUrl = GWT.getHostPageBaseURL(); |
131 ListGridField pinFrom = new ListGridField( | 127 final ListGridField pinFrom = new ListGridField("fromIcon", this.MESSAGES.selection()); |
132 "fromIcon", MESSAGES.selection()); | 128 pinFrom.setWidth(60); |
133 pinFrom.setWidth (60); | 129 pinFrom.setType(ListGridFieldType.ICON); |
134 pinFrom.setType (ListGridFieldType.ICON); | 130 pinFrom.setCellIcon(baseUrl + this.MESSAGES.markerGreen()); |
135 pinFrom.setCellIcon(baseUrl + MESSAGES.markerGreen()); | 131 |
136 | 132 pinFrom.addRecordClickHandler(new RecordClickHandler() { |
137 pinFrom.addRecordClickHandler (new RecordClickHandler () { | |
138 @Override | 133 @Override |
139 public void onRecordClick (RecordClickEvent e) { | 134 public void onRecordClick(final RecordClickEvent e) { |
140 Record r = e.getRecord(); | 135 final Record r = e.getRecord(); |
141 appendYear(r.getAttribute("date")); | 136 appendValue(r.getAttribute("date")); |
142 } | 137 } |
143 }); | 138 }); |
144 | 139 |
145 sedLoadTable.setFields(pinFrom, date, descr); | 140 this.sedLoadTable.setFields(pinFrom, date, descr); |
146 return sedLoadTable; | 141 return this.sedLoadTable; |
147 } | 142 } |
148 | 143 |
149 public Canvas createWidget(DataList data) { | 144 public Canvas createWidget(final DataList data) { |
150 VLayout layout = new VLayout(); | 145 final VLayout layout = new VLayout(); |
151 | 146 |
152 Label title = new Label(data.get(0).getDescription()); | 147 final Label title = new Label(data.get(0).getDescription()); |
153 title.setHeight("25px"); | 148 title.setHeight("25px"); |
154 | 149 |
155 DynamicForm form = new DynamicForm(); | 150 final DynamicForm form = new DynamicForm(); |
156 form.setNumCols(4); | 151 form.setNumCols(4); |
157 yearsItem = new TextItem(MSG.years()); | 152 this.inputItem = new IntegerItem(this.MSG.year()); |
158 yearsItem.setValidators(new IsIntegerValidator()); | 153 this.inputItem.setShowTitle(false); |
159 form.setFields(yearsItem); | 154 form.setFields(this.inputItem); |
160 | 155 |
161 layout.addMember(title); | 156 layout.addMember(title); |
162 layout.addMember(form); | 157 layout.addMember(form); |
163 | 158 |
164 return layout; | 159 return layout; |
165 } | 160 } |
166 | 161 |
167 @Override | 162 @Override |
168 protected Data[] getData() { | 163 protected Data[] getData() { |
169 validateYears(); | 164 validateYears(); |
170 if (yearsItem != null && !yearsItem.getValueAsString().isEmpty()) { | 165 if (this.inputItem != null && !this.inputItem.getValueAsString().isEmpty()) { |
171 List<Data> data = new ArrayList<Data>(); | 166 final List<Data> data = new ArrayList<Data>(); |
172 | 167 |
173 DataItem yearsdata = new DefaultDataItem( | 168 final DataItem yearsdata = new DefaultDataItem(datakey, datakey, this.inputItem.getValueAsString().trim()); // DATA-STRING: years (in |
174 "years", "years", yearsItem.getValueAsString().trim()); | 169 // uinfo.xml) |
175 data.add(new DefaultData( | 170 data.add(new DefaultData(datakey, null, null, new DataItem[] { yearsdata })); |
176 "years", | |
177 null, | |
178 null, | |
179 new DataItem[] { yearsdata })); | |
180 | 171 |
181 return data.toArray(new Data[data.size()]); | 172 return data.toArray(new Data[data.size()]); |
182 } | 173 } |
183 return new Data[0]; | 174 return new Data[0]; |
184 } | 175 } |
185 | 176 |
186 protected List<String> validateYears() { | 177 protected List<String> validateYears() { |
187 List<String> errors = new ArrayList<String>(); | 178 final List<String> errors = new ArrayList<String>(); |
188 NumberFormat nf = NumberFormat.getDecimalFormat(); | 179 final NumberFormat nf = NumberFormat.getDecimalFormat(); |
189 | 180 |
190 if (yearsItem.getValueAsString() == null || | 181 if (this.inputItem.getValueAsString() == null || this.inputItem.getValueAsString().trim().isEmpty()) { |
191 yearsItem.getValueAsString().trim().isEmpty()) { | 182 errors.add(this.MESSAGES.empty_filter()); |
192 errors.add(MESSAGES.empty_filter()); | |
193 return errors; | 183 return errors; |
194 } | 184 } |
195 | 185 |
196 String [] sValues = yearsItem.getValueAsString().trim().split(" "); | 186 final String sValue = this.inputItem.getValueAsString();// .trim().split(" "); |
197 String filtered = ""; | 187 String filtered = ""; |
198 int goodValues = 0; | 188 int goodValues = 0; |
199 for (String sValue: sValues) { | 189 |
200 int value; | 190 int value = 0; |
201 try { | 191 try { |
202 value = Integer.parseInt(sValue); | 192 value = Integer.parseInt(sValue); |
203 } catch (NumberFormatException e) { | 193 } |
204 errors.add(MESSAGES.wrongFormat() + ": " + sValue); | 194 catch (final NumberFormatException e) { |
205 continue; | 195 errors.add(this.MESSAGES.wrongFormat() + ": " + sValue); |
206 } | 196 |
207 boolean isGood = false; | 197 } |
208 for (String validYear: validYears) { | 198 boolean isGood = false; |
209 /* No list contains for strings? */ | 199 for (final String validYear : this.validInputs) { |
210 if (sValue.equals(validYear)) { | 200 /* No list contains for strings? */ |
211 isGood = true; | 201 if (sValue.equals(validYear)) { |
212 break; | 202 isGood = true; |
213 } | 203 break; |
214 } | 204 } |
215 if (!isGood) { | 205 } |
216 String tmp = MESSAGES.no_data_for_year(); | 206 if (!isGood) { |
217 tmp = tmp.replace("$1", sValue); | 207 String tmp = this.MESSAGES.no_data_for_year(); |
218 errors.add(tmp); | 208 tmp = tmp.replace("$1", sValue); |
219 continue; | 209 errors.add(tmp); |
220 } | 210 // continue; |
221 goodValues++; | 211 } |
222 if (goodValues > 1) { | 212 goodValues++; |
223 filtered += " " + Integer.toString(value); | 213 if (goodValues > 1) { |
224 } else { | 214 filtered += " " + Integer.toString(value); |
225 filtered = Integer.toString(value); | 215 } else { |
226 } | 216 filtered = Integer.toString(value); |
227 } | 217 } |
228 | 218 |
229 return errors; | 219 return errors; |
230 } | 220 } |
231 | 221 |
232 protected void fetchSedimentLoadData() { | 222 protected void fetchSedimentLoadData() { |
233 Config config = Config.getInstance(); | 223 final Config config = Config.getInstance(); |
234 String locale = config.getLocale (); | 224 final String locale = config.getLocale(); |
235 | 225 |
236 ArtifactDescription adescr = artifact.getArtifactDescription(); | 226 final ArtifactDescription adescr = this.artifact.getArtifactDescription(); |
237 DataList[] data = adescr.getOldData(); | 227 final DataList[] data = adescr.getOldData(); |
238 | 228 |
239 double[] km = artifact.getArtifactDescription().getKMRange(); | 229 final double[] km = this.artifact.getArtifactDescription().getKMRange(); |
240 String river = artifact.getArtifactDescription().getRiver(); | 230 final String river = this.artifact.getArtifactDescription().getRiver(); |
241 | 231 |
242 String sq_ti_id = ""; | 232 String sq_ti_id = ""; |
243 validYears = new ArrayList<String>(data.length); | 233 this.validInputs = new ArrayList<String>(data.length); |
244 for (int i = 0; i < data.length; i++) { | 234 for (final DataList element : data) { |
245 Data str = getData(data[i].getAll(), "sq_ti_id"); | 235 final Data str = getData(element.getAll(), "sq_ti_id"); |
246 if (str != null) { | 236 if (str != null) { |
247 DataItem[] strItems = str.getItems(); | 237 final DataItem[] strItems = str.getItems(); |
248 sq_ti_id = strItems[0].getStringValue(); | 238 sq_ti_id = strItems[0].getStringValue(); |
249 break; | 239 break; |
250 } | 240 } |
251 } | 241 } |
252 | 242 |
253 if (sq_ti_id.isEmpty()){ | 243 if (sq_ti_id.isEmpty()) { |
254 GWT.log("Failed to find sq time interval id in data."); | 244 GWT.log("Failed to find sq time interval id in data."); |
255 } | 245 } |
256 | 246 |
257 sedLoadInfoService.getSedimentLoadInfo( | 247 this.sedLoadInfoService.getSedimentLoadInfo(locale, river, "single", km[0], km[1], sq_ti_id, new AsyncCallback<SedimentLoadInfoObject[]>() { |
258 locale, river, "single", km[0], km[1], sq_ti_id, | 248 @Override |
259 new AsyncCallback<SedimentLoadInfoObject[]>() { | 249 public void onFailure(final Throwable caught) { |
260 public void onFailure(Throwable caught) { | 250 GWT.log("Could not recieve sediment load informations."); |
261 GWT.log("Could not recieve sediment load informations."); | 251 SC.warn(LoadSingleYearPanel.this.MSG.getString(caught.getMessage())); |
262 SC.warn(MSG.getString(caught.getMessage())); | 252 } |
253 | |
254 @Override | |
255 public void onSuccess(final SedimentLoadInfoObject[] sedLoad) { | |
256 final int num = sedLoad != null ? sedLoad.length : 0; | |
257 GWT.log("Recieved " + num + " sediment load informations."); | |
258 | |
259 if (num == 0) { | |
260 return; | |
263 } | 261 } |
264 | 262 |
265 public void onSuccess(SedimentLoadInfoObject[] sedLoad) { | 263 addSedimentLoadInfo(sedLoad); |
266 int num = sedLoad != null ? sedLoad.length :0; | 264 } |
267 GWT.log("Recieved " + num + " sediment load informations."); | 265 }); |
268 | 266 } |
269 if (num == 0) { | 267 |
270 return; | 268 protected void addSedimentLoadInfo(final SedimentLoadInfoObject[] sedLoad) { |
271 } | 269 for (final SedimentLoadInfoObject sl : sedLoad) { |
272 | 270 final SedimentLoadInfoRecord rec = new SedimentLoadInfoRecord(sl); |
273 addSedimentLoadInfo(sedLoad); | 271 this.sedLoadTable.addData(rec); |
274 } | 272 this.validInputs.add(rec.getDate()); |
275 } | 273 } |
276 ); | 274 } |
277 } | 275 |
278 | 276 protected void appendValue(final String year) { // SINGLE-Input |
279 | 277 final String oldYears = this.inputItem.getValueAsString(); |
280 protected void addSedimentLoadInfo (SedimentLoadInfoObject[] sedLoad) { | 278 this.inputItem.setValue(year); |
281 for(SedimentLoadInfoObject sl: sedLoad) { | |
282 SedimentLoadInfoRecord rec = new SedimentLoadInfoRecord(sl); | |
283 sedLoadTable.addData(rec); | |
284 validYears.add(rec.getDate()); | |
285 } | |
286 } | |
287 | |
288 protected void appendYear (String year) { | |
289 String oldYears = yearsItem.getValueAsString(); | |
290 if (oldYears != null && !oldYears.isEmpty()) { | |
291 yearsItem.setValue(oldYears.trim() + " " + year); | |
292 } else { | |
293 yearsItem.setValue(year); | |
294 } | |
295 } | 279 } |
296 } | 280 } |