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