Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/CollisionLoadEpochPanel.java @ 9079:aafae1ab25f0
epoch-panels, single-input-panels
author | gernotbelger |
---|---|
date | Wed, 23 May 2018 17:30:24 +0200 |
parents | fc02833dbcc1 |
children |
comparison
equal
deleted
inserted
replaced
9078:fc02833dbcc1 | 9079:aafae1ab25f0 |
---|---|
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.sinfo; | 9 package org.dive4elements.river.client.client.ui.sinfo; |
10 | 10 |
11 import java.util.ArrayList; | 11 import org.dive4elements.river.client.client.ui.AbstractEpochPanel; |
12 import java.util.List; | |
13 | |
14 import org.dive4elements.river.client.client.services.SedimentLoadInfoService; | |
15 import org.dive4elements.river.client.client.services.SedimentLoadInfoServiceAsync; | |
16 import org.dive4elements.river.client.client.ui.AbstractUIProvider; | |
17 import org.dive4elements.river.client.client.ui.FromToTableHelperPanel; | |
18 import org.dive4elements.river.client.client.ui.FromToTableHelperPanel.IColumnClickHandler; | |
19 import org.dive4elements.river.client.shared.model.Data; | |
20 import org.dive4elements.river.client.shared.model.DataItem; | |
21 import org.dive4elements.river.client.shared.model.DataList; | 12 import org.dive4elements.river.client.shared.model.DataList; |
22 import org.dive4elements.river.client.shared.model.DefaultData; | |
23 import org.dive4elements.river.client.shared.model.DefaultDataItem; | |
24 | 13 |
25 import com.google.gwt.core.client.GWT; | 14 import com.google.gwt.core.client.GWT; |
26 import com.smartgwt.client.data.Record; | |
27 import com.smartgwt.client.types.ListGridFieldType; | 15 import com.smartgwt.client.types.ListGridFieldType; |
28 import com.smartgwt.client.widgets.Button; | 16 import com.smartgwt.client.widgets.Button; |
29 import com.smartgwt.client.widgets.Canvas; | 17 import com.smartgwt.client.widgets.Canvas; |
30 import com.smartgwt.client.widgets.Label; | 18 import com.smartgwt.client.widgets.Label; |
31 import com.smartgwt.client.widgets.events.ClickEvent; | 19 import com.smartgwt.client.widgets.events.ClickEvent; |
32 import com.smartgwt.client.widgets.events.ClickHandler; | 20 import com.smartgwt.client.widgets.events.ClickHandler; |
33 import com.smartgwt.client.widgets.form.DynamicForm; | 21 import com.smartgwt.client.widgets.form.DynamicForm; |
34 import com.smartgwt.client.widgets.form.fields.TextItem; | 22 import com.smartgwt.client.widgets.form.fields.TextItem; |
35 import com.smartgwt.client.widgets.form.validator.IsIntegerValidator; | |
36 import com.smartgwt.client.widgets.grid.ListGrid; | 23 import com.smartgwt.client.widgets.grid.ListGrid; |
37 import com.smartgwt.client.widgets.grid.ListGridField; | 24 import com.smartgwt.client.widgets.grid.ListGridField; |
38 import com.smartgwt.client.widgets.grid.ListGridRecord; | 25 import com.smartgwt.client.widgets.grid.ListGridRecord; |
39 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; | 26 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; |
40 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; | 27 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; |
41 import com.smartgwt.client.widgets.layout.HLayout; | 28 import com.smartgwt.client.widgets.layout.HLayout; |
42 import com.smartgwt.client.widgets.layout.VLayout; | 29 import com.smartgwt.client.widgets.layout.VLayout; |
43 | 30 |
44 // FIXME: copy of SedLoadEpochPanel | 31 public class CollisionLoadEpochPanel extends AbstractEpochPanel { |
45 public class CollisionLoadEpochPanel extends AbstractUIProvider { | |
46 protected SedimentLoadInfoServiceAsync sedLoadInfoService = GWT.create(SedimentLoadInfoService.class); | |
47 | 32 |
48 protected ListGrid elements; | 33 private static final long serialVersionUID = 1L; |
49 private TextItem start; | |
50 private TextItem end; | |
51 | 34 |
52 private final String getDatakey() { | 35 @Override |
36 protected String getDatakey() { | |
53 return "epochs"; | 37 return "epochs"; |
54 } | 38 } |
55 | 39 |
56 protected List<String> validYears = new ArrayList<String>(); | 40 public CollisionLoadEpochPanel() { |
41 super(Type.multi); | |
42 } | |
57 | 43 |
58 public Canvas createWidget(final DataList data) { | 44 @Override |
45 protected Canvas createWidget(final DataList data) { | |
59 final HLayout input = new HLayout(); | 46 final HLayout input = new HLayout(); |
60 final VLayout root = new VLayout(); | 47 final VLayout root = new VLayout(); |
61 final VLayout grid = new VLayout(); | 48 final VLayout grid = new VLayout(); |
62 final VLayout intFields = new VLayout(); | 49 final VLayout intFields = new VLayout(); |
63 final Button add = new Button(this.MSG.add_date()); | 50 final Button add = new Button(this.MSG.add_date()); |
64 this.elements = new ListGrid(); | 51 final ListGrid elements = createListGrid(); |
52 elements.setWidth(185); | |
53 elements.setHeight(120); | |
65 | 54 |
66 final Label title = new Label(data.get(0).getDescription()); | 55 final Label title = new Label(data.get(0).getDescription()); |
67 title.setHeight("25px"); | 56 title.setHeight("25px"); |
68 | 57 |
69 final DynamicForm form = new DynamicForm(); | 58 final DynamicForm form = new DynamicForm(); |
70 form.setNumCols(4); | 59 form.setNumCols(4); |
71 this.start = new TextItem(this.MSG.from()); | 60 final TextItem start = createStartInputItem(this.MSG.from()); |
72 this.start.setWidth(60); | 61 final TextItem end = createEndInputItem(this.MSG.to()); |
73 this.start.setValidators(new IsIntegerValidator()); | 62 |
74 this.end = new TextItem(this.MSG.to()); | 63 form.setFields(start, end); |
75 this.end.setWidth(60); | |
76 this.end.setValidators(new IsIntegerValidator()); | |
77 form.setFields(this.start, this.end); | |
78 add.addClickHandler(new ClickHandler() { | 64 add.addClickHandler(new ClickHandler() { |
79 @Override | 65 @Override |
80 public void onClick(final ClickEvent ce) { | 66 public void onClick(final ClickEvent ce) { |
81 final String v1 = CollisionLoadEpochPanel.this.start.getValueAsString(); | 67 final String v1 = start.getValueAsString(); |
82 final String v2 = CollisionLoadEpochPanel.this.end.getValueAsString(); | 68 final String v2 = end.getValueAsString(); |
83 if (v1 == null || v2 == null) { | 69 if (v1 == null || v2 == null) { |
84 return; | 70 return; |
85 } | 71 } |
86 if (!isValidEpoch(v1, v2)) { | 72 if (!isValidEpoch(v1, v2)) { |
87 return; | 73 return; |
88 } | 74 } |
89 final ListGridRecord r = new ListGridRecord(); | 75 final ListGridRecord r = new ListGridRecord(); |
90 r.setAttribute("from", v1); | 76 r.setAttribute("from", v1); |
91 r.setAttribute("to", v2); | 77 r.setAttribute("to", v2); |
92 CollisionLoadEpochPanel.this.elements.addData(r); | 78 elements.addData(r); |
93 } | 79 } |
94 }); | 80 }); |
95 | 81 |
96 final Label sel = new Label(this.MSG.select()); | 82 final Label sel = new Label(this.MSG.select()); |
97 sel.setHeight(25); | 83 sel.setHeight(25); |
98 this.elements.setWidth(185); | 84 |
99 this.elements.setHeight(120); | |
100 this.elements.setShowHeaderContextMenu(false); | |
101 this.elements.setCanReorderFields(false); | |
102 this.elements.setCanSort(false); | |
103 this.elements.setCanEdit(false); | |
104 final ListGridField from = new ListGridField("from", this.MSG.from()); | 85 final ListGridField from = new ListGridField("from", this.MSG.from()); |
105 final ListGridField to = new ListGridField("to", this.MSG.to()); | 86 final ListGridField to = new ListGridField("to", this.MSG.to()); |
106 from.setWidth(70); | 87 from.setWidth(70); |
107 to.setWidth(70); | 88 to.setWidth(70); |
108 | 89 |
117 setCanFreeze(false); | 98 setCanFreeze(false); |
118 setWidth(25); | 99 setWidth(25); |
119 } | 100 } |
120 }; | 101 }; |
121 | 102 |
122 this.elements.addRecordClickHandler(new RecordClickHandler() { | 103 elements.addRecordClickHandler(new RecordClickHandler() { |
123 @Override | 104 @Override |
124 public void onRecordClick(final RecordClickEvent event) { | 105 public void onRecordClick(final RecordClickEvent event) { |
125 // Just handle remove-clicks | 106 // Just handle remove-clicks |
126 if (!event.getField().getName().equals(removeField.getName())) { | 107 if (!event.getField().getName().equals(removeField.getName())) { |
127 return; | 108 return; |
128 } | 109 } |
129 event.getViewer().removeData(event.getRecord()); | 110 event.getViewer().removeData(event.getRecord()); |
130 } | 111 } |
131 }); | 112 }); |
132 | 113 |
133 this.elements.setFields(from, to, removeField); | 114 elements.setFields(from, to, removeField); |
134 | 115 |
135 intFields.addMember(form); | 116 intFields.addMember(form); |
136 intFields.addMember(add); | 117 intFields.addMember(add); |
137 grid.addMember(sel); | 118 grid.addMember(sel); |
138 grid.addMember(this.elements); | 119 grid.addMember(elements); |
139 input.addMember(intFields); | 120 input.addMember(intFields); |
140 input.addMember(grid); | 121 input.addMember(grid); |
141 root.addMember(title); | 122 root.addMember(title); |
142 root.addMember(input); | 123 root.addMember(input); |
143 | 124 |
144 return root; | 125 return root; |
145 } | 126 } |
146 | 127 |
147 @Override | |
148 public Canvas createOld(final DataList dataList) { | |
149 final HLayout layout = new HLayout(); | |
150 layout.setWidth("400px"); | |
151 final VLayout vLayout = new VLayout(); | |
152 vLayout.setWidth(130); | |
153 final Label label = new Label(dataList.getLabel()); | |
154 label.setWidth("200px"); | |
155 label.setHeight(25); | |
156 | |
157 final List<Data> items = dataList.getAll(); | |
158 final Data str = getData(items, getDatakey()); | |
159 final DataItem[] strItems = str.getItems(); | |
160 | |
161 final String[] pairs = strItems[0].getLabel().split(";"); | |
162 for (final String pair : pairs) { | |
163 final String[] vals = pair.split(","); | |
164 final Label dateLabel = new Label(vals[0] + " - " + vals[1]); | |
165 dateLabel.setHeight(20); | |
166 vLayout.addMember(dateLabel); | |
167 } | |
168 final Canvas back = getBackButton(dataList.getState()); | |
169 layout.addMember(label); | |
170 layout.addMember(vLayout); | |
171 layout.addMember(back); | |
172 | |
173 return layout; | |
174 } | |
175 | |
176 @Override | |
177 public Canvas create(final DataList data) { | |
178 final VLayout layout = new VLayout(); | |
179 final Canvas submit = getNextButton(); | |
180 final Canvas widget = createWidget(data); | |
181 | |
182 layout.addMember(widget); | |
183 layout.addMember(submit); | |
184 | |
185 final IColumnClickHandler fromHandler = createHandler(this.start); | |
186 final IColumnClickHandler toHandler = createHandler(this.end); | |
187 | |
188 final FromToTableHelperPanel helper = new FromToTableHelperPanel(data, getDatakey(), this.MSG, fromHandler, toHandler); | |
189 this.validYears = helper.getKeycolEntries(); | |
190 final Canvas table = helper.getTable(); | |
191 | |
192 this.helperContainer.addMember(table); | |
193 return layout; | |
194 } | |
195 | |
196 private IColumnClickHandler createHandler(final TextItem field) { | |
197 final IColumnClickHandler handler = new IColumnClickHandler() { | |
198 | |
199 @Override | |
200 public void columnClicked(final String value) { | |
201 field.setValue(value); | |
202 } | |
203 }; | |
204 | |
205 return handler; | |
206 } | |
207 | |
208 @Override | |
209 protected Data[] getData() { | |
210 final List<Data> data = new ArrayList<Data>(); | |
211 | |
212 final ListGridRecord[] lgr = this.elements.getRecords(); | |
213 if (lgr.length == 0) { | |
214 return new Data[0]; | |
215 } | |
216 String d = ""; | |
217 for (final ListGridRecord element : lgr) { | |
218 final Record r = element; | |
219 d += r.getAttribute("from") + "," + r.getAttribute("to"); | |
220 d += ";"; | |
221 } | |
222 | |
223 final DataItem item = new DefaultDataItem(getDatakey(), null, d); | |
224 data.add(new DefaultData(getDatakey(), null, null, new DataItem[] { item })); | |
225 return data.toArray(new Data[data.size()]); | |
226 } | |
227 | |
228 /* | |
229 * Validate the epoch input. We do this here and not in an overridden | |
230 * validate method as we want to validate before an epoch is added | |
231 * to the list of epochs. | |
232 */ | |
233 protected boolean isValidEpoch(final String y1, final String y2) { | |
234 // First check that both are integer | |
235 int iY1; | |
236 int iY2; | |
237 final List<String> errors = new ArrayList<String>(); | |
238 try { | |
239 iY1 = Integer.parseInt(y1); | |
240 } | |
241 catch (final NumberFormatException e) { | |
242 errors.add(this.MSG.wrongFormat() + ": " + y1); | |
243 } | |
244 try { | |
245 iY2 = Integer.parseInt(y2); | |
246 } | |
247 catch (final NumberFormatException e) { | |
248 errors.add(this.MSG.wrongFormat() + ": " + y2); | |
249 } | |
250 if (!errors.isEmpty()) { | |
251 showErrors(errors); | |
252 return false; | |
253 } | |
254 boolean startIsGood = false; | |
255 boolean endIsGood = false; | |
256 for (final String validYear : this.validYears) { | |
257 if (startIsGood || y1.equals(validYear)) { | |
258 startIsGood = true; | |
259 } | |
260 if (endIsGood || y2.equals(validYear)) { | |
261 endIsGood = true; | |
262 } | |
263 if (startIsGood && endIsGood) { | |
264 break; | |
265 } | |
266 /* | |
267 * alternative check if data lies in between | |
268 * int aYear = Integer.parseInt(validYear); | |
269 * if (aYear >= iY1 && aYear <= iY2) { | |
270 * isGood = true; | |
271 * break; | |
272 * } | |
273 */ | |
274 } | |
275 if (!startIsGood) { | |
276 String tmp = this.MSG.no_data_for_year(); | |
277 tmp = tmp.replace("$1", y1); | |
278 errors.add(tmp); | |
279 } | |
280 if (!endIsGood) { | |
281 String tmp = this.MSG.no_data_for_year(); | |
282 tmp = tmp.replace("$1", y2); | |
283 errors.add(tmp); | |
284 } | |
285 if (!errors.isEmpty()) { | |
286 showErrors(errors); | |
287 return false; | |
288 } | |
289 return true; | |
290 } | |
291 } | 128 } |