Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/LocationDistancePanel.java @ 9175:34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
author | gernotbelger |
---|---|
date | Mon, 25 Jun 2018 17:58:11 +0200 |
parents | 5e38e2924c07 |
children | 7337034eb5d5 |
comparison
equal
deleted
inserted
replaced
9174:06bb3e94a927 | 9175:34dc0163ad2d |
---|---|
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; | 9 package org.dive4elements.river.client.client.ui; |
10 | 10 |
11 import java.util.ArrayList; | |
12 import java.util.LinkedHashMap; | |
13 import java.util.List; | |
14 | |
15 import org.dive4elements.river.client.client.Config; | |
16 import org.dive4elements.river.client.client.FLYSConstants; | |
17 import org.dive4elements.river.client.client.event.FilterHandler; | |
18 import org.dive4elements.river.client.client.event.RangeFilterEvent; | |
19 import org.dive4elements.river.client.client.event.StringFilterEvent; | |
20 import org.dive4elements.river.client.client.services.DistanceInfoService; | |
21 import org.dive4elements.river.client.client.services.DistanceInfoServiceAsync; | |
22 import org.dive4elements.river.client.client.ui.range.DistanceInfoDataSource; | |
23 import org.dive4elements.river.client.shared.model.ArtifactDescription; | |
24 import org.dive4elements.river.client.shared.model.Data; | |
25 import org.dive4elements.river.client.shared.model.DataItem; | |
26 import org.dive4elements.river.client.shared.model.DataList; | |
27 import org.dive4elements.river.client.shared.model.DefaultData; | |
28 import org.dive4elements.river.client.shared.model.DefaultDataItem; | |
29 import org.dive4elements.river.client.shared.model.DistanceInfoObject; | |
30 | |
11 import com.google.gwt.core.client.GWT; | 31 import com.google.gwt.core.client.GWT; |
12 import com.google.gwt.i18n.client.NumberFormat; | 32 import com.google.gwt.i18n.client.NumberFormat; |
13 | |
14 import com.smartgwt.client.data.AdvancedCriteria; | 33 import com.smartgwt.client.data.AdvancedCriteria; |
15 import com.smartgwt.client.data.Criteria; | 34 import com.smartgwt.client.data.Criteria; |
16 import com.smartgwt.client.data.Criterion; | 35 import com.smartgwt.client.data.Criterion; |
17 import com.smartgwt.client.data.Record; | 36 import com.smartgwt.client.data.Record; |
18 import com.smartgwt.client.types.Alignment; | 37 import com.smartgwt.client.types.Alignment; |
42 import com.smartgwt.client.widgets.tab.Tab; | 61 import com.smartgwt.client.widgets.tab.Tab; |
43 import com.smartgwt.client.widgets.tab.TabSet; | 62 import com.smartgwt.client.widgets.tab.TabSet; |
44 import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; | 63 import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; |
45 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; | 64 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; |
46 | 65 |
47 import org.dive4elements.river.client.client.Config; | |
48 import org.dive4elements.river.client.client.FLYSConstants; | |
49 import org.dive4elements.river.client.client.event.FilterHandler; | |
50 import org.dive4elements.river.client.client.event.RangeFilterEvent; | |
51 import org.dive4elements.river.client.client.event.StringFilterEvent; | |
52 import org.dive4elements.river.client.client.services.DistanceInfoService; | |
53 import org.dive4elements.river.client.client.services.DistanceInfoServiceAsync; | |
54 import org.dive4elements.river.client.client.ui.range.DistanceInfoDataSource; | |
55 import org.dive4elements.river.client.shared.model.ArtifactDescription; | |
56 import org.dive4elements.river.client.shared.model.Data; | |
57 import org.dive4elements.river.client.shared.model.DataItem; | |
58 import org.dive4elements.river.client.shared.model.DataList; | |
59 import org.dive4elements.river.client.shared.model.DefaultData; | |
60 import org.dive4elements.river.client.shared.model.DefaultDataItem; | |
61 import org.dive4elements.river.client.shared.model.DistanceInfoObject; | |
62 | |
63 import java.util.ArrayList; | |
64 import java.util.LinkedHashMap; | |
65 import java.util.List; | |
66 | |
67 | |
68 /** | 66 /** |
69 * This UIProvider creates a widget to enter locations or a distance. | 67 * This UIProvider creates a widget to enter locations or a distance. |
70 * | 68 * |
71 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 69 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
72 */ | 70 */ |
73 public class LocationDistancePanel | 71 public class LocationDistancePanel extends AbstractUIProvider implements ChangeHandler, BlurHandler, FilterHandler { |
74 extends AbstractUIProvider | |
75 implements ChangeHandler, BlurHandler, FilterHandler | |
76 { | |
77 private static final long serialVersionUID = -10820092176039372L; | 72 private static final long serialVersionUID = -10820092176039372L; |
78 | 73 |
79 /** The message class that provides i18n strings. */ | 74 /** The message class that provides i18n strings. */ |
80 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); | 75 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); |
81 | 76 |
82 /** The DistanceInfoService used to retrieve locations about rivers. */ | 77 /** The DistanceInfoService used to retrieve locations about rivers. */ |
83 protected DistanceInfoServiceAsync distanceInfoService = | 78 protected DistanceInfoServiceAsync distanceInfoService = GWT.create(DistanceInfoService.class); |
84 GWT.create(DistanceInfoService.class); | |
85 | 79 |
86 public static final String FIELD_MODE = "mode"; | 80 public static final String FIELD_MODE = "mode"; |
87 | 81 |
88 /** The constant name of the input field to enter the start of a distance.*/ | 82 /** The constant name of the input field to enter the start of a distance. */ |
89 public static final String FIELD_FROM = "from"; | 83 public static final String FIELD_FROM = "from"; |
90 | 84 |
91 /** The constant name of the input field to enter the end of a distance.*/ | 85 /** The constant name of the input field to enter the end of a distance. */ |
92 public static final String FIELD_TO = "to"; | 86 public static final String FIELD_TO = "to"; |
93 | 87 |
94 /** The constant name of the input field to enter locations.*/ | 88 /** The constant name of the input field to enter locations. */ |
95 public static final String FIELD_VALUE_LOCATION = "location"; | 89 public static final String FIELD_VALUE_LOCATION = "location"; |
96 | 90 |
97 /** The constant name of the input field to enter distance.*/ | 91 /** The constant name of the input field to enter distance. */ |
98 public static final String FIELD_VALUE_DISTANCE = "distance"; | 92 public static final String FIELD_VALUE_DISTANCE = "distance"; |
99 | 93 |
100 /** The constant name of the input field to enter the step width of a | 94 /** |
101 * distance.*/ | 95 * The constant name of the input field to enter the step width of a |
96 * distance. | |
97 */ | |
102 public static final String FIELD_WIDTH = "width"; | 98 public static final String FIELD_WIDTH = "width"; |
103 | 99 |
104 public static final int WIDTH = 250; | 100 public static final int WIDTH = 250; |
105 | 101 |
106 | 102 /** The radio group for input mode selection. */ |
107 /** The radio group for input mode selection.*/ | |
108 protected DynamicForm mode; | 103 protected DynamicForm mode; |
109 | 104 |
110 /** A container that will contain the location or the distance panel.*/ | 105 /** A container that will contain the location or the distance panel. */ |
111 protected HLayout container; | 106 protected HLayout container; |
112 | 107 |
113 /** The min value for a distance.*/ | 108 /** The min value for a distance. */ |
114 protected double min; | 109 protected double min; |
115 | 110 |
116 /** The max value for a distance.*/ | 111 /** The max value for a distance. */ |
117 protected double max; | 112 protected double max; |
118 | 113 |
119 /** The 'from' value entered in the distance mode.*/ | 114 /** The 'from' value entered in the distance mode. */ |
120 protected double from; | 115 protected double from; |
121 | 116 |
122 /** The 'to' value entered in the distance mode.*/ | 117 /** The 'to' value entered in the distance mode. */ |
123 protected double to; | 118 protected double to; |
124 | 119 |
125 /** The 'step' value entered in the distance mode.*/ | 120 /** The 'step' value entered in the distance mode. */ |
126 protected double step; | 121 protected double step; |
127 | 122 |
128 /** The values entered in the location mode.*/ | 123 /** The values entered in the location mode. */ |
129 protected double[] values; | 124 protected double[] values; |
130 | 125 |
131 /** The input panel for locations. */ | 126 /** The input panel for locations. */ |
132 protected DoubleArrayPanel locationPanel; | 127 protected DoubleArrayPanel locationPanel; |
133 | 128 |
144 protected ListGrid locationsTable; | 139 protected ListGrid locationsTable; |
145 | 140 |
146 /** The table data. */ | 141 /** The table data. */ |
147 protected DistanceInfoObject[] tableData; | 142 protected DistanceInfoObject[] tableData; |
148 | 143 |
149 /** The table filter.*/ | 144 /** The table filter. */ |
150 protected TableFilter filterDescription; | 145 protected TableFilter filterDescription; |
151 protected RangeTableFilter filterRange; | 146 protected RangeTableFilter filterRange; |
152 | 147 |
153 /** The Combobox for table filter criteria. */ | 148 /** The Combobox for table filter criteria. */ |
154 protected SelectItem filterCriteria; | 149 protected SelectItem filterCriteria; |
157 | 152 |
158 /** | 153 /** |
159 * Creates a new LocationDistancePanel instance. | 154 * Creates a new LocationDistancePanel instance. |
160 */ | 155 */ |
161 public LocationDistancePanel() { | 156 public LocationDistancePanel() { |
162 distanceTable = new ListGrid(); | 157 this.distanceTable = new ListGrid(); |
163 distanceTable.setAutoFetchData(true); | 158 this.distanceTable.setAutoFetchData(true); |
164 | 159 |
165 locationsTable = new ListGrid(); | 160 this.locationsTable = new ListGrid(); |
166 locationsTable.setAutoFetchData(true); | 161 this.locationsTable.setAutoFetchData(true); |
167 | 162 |
168 distanceTable.setShowHeaderContextMenu(false); | 163 this.distanceTable.setShowHeaderContextMenu(false); |
169 locationsTable.setShowHeaderContextMenu(false); | 164 this.locationsTable.setShowHeaderContextMenu(false); |
170 } | 165 } |
171 | |
172 | 166 |
173 /** | 167 /** |
174 * This method creates a widget that contains a label, a panel with | 168 * This method creates a widget that contains a label, a panel with |
175 * checkboxes to switch the input mode between location and distance input, | 169 * checkboxes to switch the input mode between location and distance input, |
176 * and a the mode specific panel. | 170 * and a the mode specific panel. |
177 * | 171 * |
178 * @param data The data that might be inserted. | 172 * @param data |
173 * The data that might be inserted. | |
179 * | 174 * |
180 * @return a panel. | 175 * @return a panel. |
181 */ | 176 */ |
182 @Override | 177 @Override |
183 public Canvas create(DataList data) { | 178 public Canvas create(final DataList data) { |
184 VLayout layout = new VLayout(); | 179 final VLayout layout = new VLayout(); |
185 layout.setMembersMargin(10); | 180 layout.setMembersMargin(10); |
186 | 181 |
187 Label label = new Label(MESSAGES.location_distance_state()); | 182 final Label label = getLabel(data);// new Label(MESSAGES.location_distance_state()); |
188 Canvas widget = createWidget(data); | 183 final Canvas widget = createWidget(data); |
189 Canvas submit = getNextButton(); | 184 final Canvas submit = getNextButton(); |
190 createDistanceInputPanel(); | 185 createDistanceInputPanel(); |
191 | 186 |
192 initDefaults(data); | 187 initDefaults(data); |
193 | 188 |
194 widget.setHeight(50); | 189 widget.setHeight(50); |
199 layout.addMember(submit); | 194 layout.addMember(submit); |
200 | 195 |
201 return layout; | 196 return layout; |
202 } | 197 } |
203 | 198 |
199 protected Label getLabel(final DataList data) { | |
200 final Data item = data.get(0); | |
201 return new Label(item.getDescription());// | |
202 // TODO: migrate distance_part_state to server | |
203 // item.getDescription()); // holt das Label vom Server (funktoniert schon sehr oft so!) | |
204 } | |
204 | 205 |
205 /** | 206 /** |
206 * Setup a table for a DistanceInfoDataSource. | 207 * Setup a table for a DistanceInfoDataSource. |
207 * | 208 * |
208 * Sets up a table to for input completion. The table | 209 * Sets up a table to for input completion. The table |
209 * can be used either for single locations or distances. | 210 * can be used either for single locations or distances. |
210 * Depending on the value of isDistance the table will | 211 * Depending on the value of isDistance the table will |
211 * have a to and a from column or a single location column. | 212 * have a to and a from column or a single location column. |
212 * | 213 * |
213 * @param table the ListGrid to set up. | 214 * @param table |
214 * @param doublePins wether or not to have. | 215 * the ListGrid to set up. |
215 * @param isDistance wether or not to and from should be included. | 216 * @param doublePins |
216 */ | 217 * wether or not to have. |
217 protected void setupDistanceInfoTable(ListGrid table, | 218 * @param isDistance |
218 boolean doublePins, | 219 * wether or not to and from should be included. |
219 boolean isDistance) { | 220 */ |
220 | 221 protected void setupDistanceInfoTable(final ListGrid table, final boolean doublePins, final boolean isDistance) { |
221 String baseUrl = GWT.getHostPageBaseURL(); | 222 |
223 final String baseUrl = GWT.getHostPageBaseURL(); | |
222 | 224 |
223 table.setWidth100(); | 225 table.setWidth100(); |
224 table.setShowRecordComponents(true); | 226 table.setShowRecordComponents(true); |
225 table.setShowRecordComponentsByCell(true); | 227 table.setShowRecordComponentsByCell(true); |
226 table.setHeight100(); | 228 table.setHeight100(); |
227 table.setEmptyMessage(MESSAGES.empty_filter()); | 229 table.setEmptyMessage(this.MESSAGES.empty_filter()); |
228 table.setCanReorderFields(false); | 230 table.setCanReorderFields(false); |
229 | 231 |
230 CellFormatter cf = new CellFormatter() { | 232 final CellFormatter cf = new CellFormatter() { |
231 @Override | 233 @Override |
232 public String format( | 234 public String format(final Object value, final ListGridRecord record, final int rowNum, final int colNum) { |
233 Object value, | 235 if (value == null) |
234 ListGridRecord record, | 236 return null; |
235 int rowNum, int colNum) { | 237 try { |
236 if (value == null) return null; | 238 NumberFormat nf; |
237 try { | 239 final double v = Double.parseDouble((String) value); |
238 NumberFormat nf; | 240 nf = NumberFormat.getFormat("###0.00##"); |
239 double v = Double.parseDouble((String)value); | 241 return nf.format(v); |
240 nf = NumberFormat.getFormat("###0.00##"); | 242 } |
241 return nf.format(v); | 243 catch (final Exception e) { |
242 } | 244 return value.toString(); |
243 catch (Exception e) { | 245 } |
244 return value.toString(); | |
245 } | |
246 } | 246 } |
247 }; | 247 }; |
248 ListGridField pin1 = null; | 248 ListGridField pin1 = null; |
249 ListGridField pin2 = null; | 249 ListGridField pin2 = null; |
250 | 250 |
251 if (doublePins) { | 251 if (doublePins) { |
252 pin1 = new ListGridField ("fromIcon", MESSAGES.from()); | 252 pin1 = new ListGridField("fromIcon", this.MESSAGES.from()); |
253 pin1.setWidth (30); | 253 pin1.setWidth(30); |
254 } else { | 254 } else { |
255 pin1 = new ListGridField ("fromIcon", MESSAGES.selection()); | 255 pin1 = new ListGridField("fromIcon", this.MESSAGES.selection()); |
256 pin1.setWidth (60); | 256 pin1.setWidth(60); |
257 } | 257 } |
258 pin1.setType (ListGridFieldType.ICON); | 258 pin1.setType(ListGridFieldType.ICON); |
259 pin1.setCellIcon(baseUrl + MESSAGES.markerGreen()); | 259 pin1.setCellIcon(baseUrl + this.MESSAGES.markerGreen()); |
260 | 260 |
261 if (doublePins) { | 261 if (doublePins) { |
262 pin2 = new ListGridField ("toIcon", MESSAGES.to()); | 262 pin2 = new ListGridField("toIcon", this.MESSAGES.to()); |
263 pin2.setType (ListGridFieldType.ICON); | 263 pin2.setType(ListGridFieldType.ICON); |
264 pin2.setWidth (30); | 264 pin2.setWidth(30); |
265 pin2.setCellIcon(baseUrl + MESSAGES.markerRed()); | 265 pin2.setCellIcon(baseUrl + this.MESSAGES.markerRed()); |
266 } | 266 } |
267 | 267 |
268 if (isDistance) { | 268 if (isDistance) { |
269 /* We have from / to fields */ | 269 /* We have from / to fields */ |
270 pin1.addRecordClickHandler (new RecordClickHandler () { | 270 pin1.addRecordClickHandler(new RecordClickHandler() { |
271 @Override | 271 @Override |
272 public void onRecordClick (RecordClickEvent e) { | 272 public void onRecordClick(final RecordClickEvent e) { |
273 Record r = e.getRecord(); | 273 final Record r = e.getRecord(); |
274 if (!isLocationMode ()) { | 274 if (!isLocationMode()) { |
275 /* distance panel and distance mode */ | 275 /* distance panel and distance mode */ |
276 setFrom(r.getAttribute("from")); | 276 setFrom(r.getAttribute("from")); |
277 setTo(r.getAttribute("to")); | 277 setTo(r.getAttribute("to")); |
278 } else { | 278 } else { |
279 /* distance panel and location mode */ | 279 /* distance panel and location mode */ |
281 appendLocation(r.getAttribute("from")); | 281 appendLocation(r.getAttribute("from")); |
282 } | 282 } |
283 } | 283 } |
284 }); | 284 }); |
285 if (doublePins) { | 285 if (doublePins) { |
286 pin2.addRecordClickHandler (new RecordClickHandler () { | 286 pin2.addRecordClickHandler(new RecordClickHandler() { |
287 @Override | 287 @Override |
288 public void onRecordClick (RecordClickEvent e) { | 288 public void onRecordClick(final RecordClickEvent e) { |
289 Record r = e.getRecord(); | 289 final Record r = e.getRecord(); |
290 if (isLocationMode ()) { | 290 if (isLocationMode()) { |
291 appendLocation(r.getAttribute("to")); | 291 appendLocation(r.getAttribute("to")); |
292 } else { | 292 } else { |
293 /* Distance and double pin behavior is only | 293 /* |
294 * defined for location mode. */ | 294 * Distance and double pin behavior is only |
295 * defined for location mode. | |
296 */ | |
295 GWT.log("Unhandled input state."); | 297 GWT.log("Unhandled input state."); |
296 } | 298 } |
297 } | 299 } |
298 }); | 300 }); |
299 } | 301 } |
300 } else { | 302 } else { |
301 /* We only have the from field */ | 303 /* We only have the from field */ |
302 pin1.addRecordClickHandler (new RecordClickHandler () { | 304 pin1.addRecordClickHandler(new RecordClickHandler() { |
303 @Override | 305 @Override |
304 public void onRecordClick (RecordClickEvent e) { | 306 public void onRecordClick(final RecordClickEvent e) { |
305 Record r = e.getRecord(); | 307 final Record r = e.getRecord(); |
306 if (!isLocationMode ()) { | 308 if (!isLocationMode()) { |
307 /* Location panel and distance mode */ | 309 /* Location panel and distance mode */ |
308 setFrom(r.getAttribute("from")); | 310 setFrom(r.getAttribute("from")); |
309 } else { | 311 } else { |
310 /* Location panel and location mode */ | 312 /* Location panel and location mode */ |
311 appendLocation(r.getAttribute("from")); | 313 appendLocation(r.getAttribute("from")); |
312 } | 314 } |
313 } | 315 } |
314 }); | 316 }); |
315 if (doublePins) { | 317 if (doublePins) { |
316 pin2.addRecordClickHandler (new RecordClickHandler () { | 318 pin2.addRecordClickHandler(new RecordClickHandler() { |
317 @Override | 319 @Override |
318 public void onRecordClick (RecordClickEvent e) { | 320 public void onRecordClick(final RecordClickEvent e) { |
319 Record r = e.getRecord(); | 321 final Record r = e.getRecord(); |
320 if (!isLocationMode ()) { | 322 if (!isLocationMode()) { |
321 setTo(r.getAttribute("from")); | 323 setTo(r.getAttribute("from")); |
322 } else { | 324 } else { |
323 /* Distance and double pin behavior is only | 325 /* |
324 * defined for location mode. */ | 326 * Distance and double pin behavior is only |
327 * defined for location mode. | |
328 */ | |
325 GWT.log("Unhandled input state."); | 329 GWT.log("Unhandled input state."); |
326 } | 330 } |
327 } | 331 } |
328 }); | 332 }); |
329 } | 333 } |
330 } | 334 } |
331 | 335 |
332 ListGridField ddescr = new ListGridField("description", | 336 final ListGridField ddescr = new ListGridField("description", this.MESSAGES.description()); |
333 MESSAGES.description()); | |
334 ddescr.setType(ListGridFieldType.TEXT); | 337 ddescr.setType(ListGridFieldType.TEXT); |
335 ddescr.setWidth("*"); | 338 ddescr.setWidth("*"); |
336 | 339 |
337 ListGridField from; | 340 ListGridField from; |
338 ListGridField to = null; | 341 ListGridField to = null; |
339 | 342 |
340 if (isDistance) { | 343 if (isDistance) { |
341 from = new ListGridField("from", MESSAGES.from()); | 344 from = new ListGridField("from", this.MESSAGES.from()); |
342 to = new ListGridField("to", MESSAGES.to()); | 345 to = new ListGridField("to", this.MESSAGES.to()); |
343 to.setType(ListGridFieldType.FLOAT); | 346 to.setType(ListGridFieldType.FLOAT); |
344 to.setCellFormatter(cf); | 347 to.setCellFormatter(cf); |
345 | 348 |
346 to.setWidth("12%"); | 349 to.setWidth("12%"); |
347 to.setAlign(Alignment.LEFT); | 350 to.setAlign(Alignment.LEFT); |
348 } else { | 351 } else { |
349 from = new ListGridField("from", MESSAGES.locations()); | 352 from = new ListGridField("from", this.MESSAGES.locations()); |
350 } | 353 } |
351 from.setCellFormatter(cf); | 354 from.setCellFormatter(cf); |
352 from.setWidth("12%"); | 355 from.setWidth("12%"); |
353 | 356 |
354 ListGridField dside = new ListGridField("riverside", | 357 final ListGridField dside = new ListGridField("riverside", this.MESSAGES.riverside()); |
355 MESSAGES.riverside()); | |
356 dside.setType(ListGridFieldType.TEXT); | 358 dside.setType(ListGridFieldType.TEXT); |
357 dside.setWidth("12%"); | 359 dside.setWidth("12%"); |
358 | 360 |
359 ListGridField bottom = | 361 final ListGridField bottom = new ListGridField("bottom", this.MESSAGES.bottom_edge()); |
360 new ListGridField("bottom", MESSAGES.bottom_edge()); | |
361 bottom.setType(ListGridFieldType.TEXT); | 362 bottom.setType(ListGridFieldType.TEXT); |
362 bottom.setWidth("10%"); | 363 bottom.setWidth("10%"); |
363 bottom.setCellFormatter(cf); | 364 bottom.setCellFormatter(cf); |
364 | 365 |
365 ListGridField top = | 366 final ListGridField top = new ListGridField("top", this.MESSAGES.top_edge()); |
366 new ListGridField("top", MESSAGES.top_edge()); | |
367 top.setType(ListGridFieldType.TEXT); | 367 top.setType(ListGridFieldType.TEXT); |
368 top.setWidth("10%"); | 368 top.setWidth("10%"); |
369 top.setCellFormatter(cf); | 369 top.setCellFormatter(cf); |
370 | 370 |
371 if (doublePins && isDistance) { | 371 if (doublePins && isDistance) { |
378 table.setFields(pin1, ddescr, from, dside, bottom, top); | 378 table.setFields(pin1, ddescr, from, dside, bottom, top); |
379 } | 379 } |
380 } | 380 } |
381 | 381 |
382 @Override | 382 @Override |
383 public Canvas createOld(DataList dataList) { | 383 public Canvas createOld(final DataList dataList) { |
384 List<Data> items = dataList.getAll(); | 384 final List<Data> items = dataList.getAll(); |
385 | 385 |
386 Data dMode = getData(items, "ld_mode"); | 386 final Data dMode = getData(items, "ld_mode"); |
387 DataItem[] dItems = dMode.getItems(); | 387 final DataItem[] dItems = dMode.getItems(); |
388 | 388 |
389 boolean rangeMode = true; | 389 boolean rangeMode = true; |
390 if (dItems != null && dItems[0] != null) { | 390 if (dItems != null && dItems[0] != null) { |
391 rangeMode = FIELD_VALUE_DISTANCE.equals(dItems[0].getStringValue()); | 391 rangeMode = FIELD_VALUE_DISTANCE.equals(dItems[0].getStringValue()); |
392 } | 392 } |
393 | 393 |
394 HLayout layout = new HLayout(); | 394 final HLayout layout = new HLayout(); |
395 layout.setWidth("400px"); | 395 layout.setWidth("400px"); |
396 | 396 |
397 Label label = new Label(dataList.getLabel()); | 397 final Label label = new Label(dataList.getLabel()); |
398 label.setWidth("200px"); | 398 label.setWidth("200px"); |
399 | 399 |
400 Canvas back = getBackButton(dataList.getState()); | 400 final Canvas back = getBackButton(dataList.getState()); |
401 | 401 |
402 layout.addMember(label); | 402 layout.addMember(label); |
403 | 403 |
404 if (rangeMode) { | 404 if (rangeMode) { |
405 layout.addMember(getOldRangeSelection(dataList)); | 405 layout.addMember(getOldRangeSelection(dataList)); |
406 } | 406 } else { |
407 else { | |
408 layout.addMember(getOldLocationSelection(dataList)); | 407 layout.addMember(getOldLocationSelection(dataList)); |
409 } | 408 } |
410 | 409 |
411 layout.addMember(back); | 410 layout.addMember(back); |
412 | 411 |
413 return layout; | 412 return layout; |
414 } | 413 } |
415 | 414 |
416 | |
417 /** | 415 /** |
418 * Creates a label for the selected range. | 416 * Creates a label for the selected range. |
419 * | 417 * |
420 * @param dataList The DataList containing all values for this state. | 418 * @param dataList |
419 * The DataList containing all values for this state. | |
421 * | 420 * |
422 * @return A label displaying the selected values. | 421 * @return A label displaying the selected values. |
423 */ | 422 */ |
424 protected Label getOldRangeSelection(DataList dataList) { | 423 protected Label getOldRangeSelection(final DataList dataList) { |
425 List<Data> items = dataList.getAll(); | 424 final List<Data> items = dataList.getAll(); |
426 | 425 |
427 Data dFrom = getData(items, "ld_from"); | 426 final Data dFrom = getData(items, "ld_from"); |
428 Data dTo = getData(items, "ld_to"); | 427 final Data dTo = getData(items, "ld_to"); |
429 Data dStep = getData(items, "ld_step"); | 428 final Data dStep = getData(items, "ld_step"); |
430 | 429 |
431 DataItem[] from = dFrom.getItems(); | 430 final DataItem[] from = dFrom.getItems(); |
432 DataItem[] to = dTo.getItems(); | 431 final DataItem[] to = dTo.getItems(); |
433 DataItem[] step = dStep.getItems(); | 432 final DataItem[] step = dStep.getItems(); |
434 | 433 |
435 StringBuilder sb = new StringBuilder(); | 434 final StringBuilder sb = new StringBuilder(); |
436 sb.append(from[0].getLabel()); | 435 sb.append(from[0].getLabel()); |
437 sb.append(" " + MESSAGES.unitFrom() + " "); | 436 sb.append(" " + this.MESSAGES.unitFrom() + " "); |
438 sb.append(to[0].getLabel()); | 437 sb.append(to[0].getLabel()); |
439 sb.append(" " + MESSAGES.unitTo() + " "); | 438 sb.append(" " + this.MESSAGES.unitTo() + " "); |
440 sb.append(step[0].getLabel()); | 439 sb.append(step[0].getLabel()); |
441 sb.append(" " + MESSAGES.unitWidth()); | 440 sb.append(" " + this.MESSAGES.unitWidth()); |
442 | 441 |
443 Label selected = new Label(sb.toString()); | 442 final Label selected = new Label(sb.toString()); |
444 selected.setWidth("130px"); | 443 selected.setWidth("130px"); |
445 | 444 |
446 return selected; | 445 return selected; |
447 } | 446 } |
448 | 447 |
449 | |
450 /** | 448 /** |
451 * Creates a label for the selected locations. | 449 * Creates a label for the selected locations. |
452 * | 450 * |
453 * @param dataList The DataList containing all values for this state. | 451 * @param dataList |
452 * The DataList containing all values for this state. | |
454 * | 453 * |
455 * @return A label displaying the selected values. | 454 * @return A label displaying the selected values. |
456 */ | 455 */ |
457 protected Label getOldLocationSelection(DataList dataList) { | 456 protected Label getOldLocationSelection(final DataList dataList) { |
458 List<Data> items = dataList.getAll(); | 457 final List<Data> items = dataList.getAll(); |
459 | 458 |
460 Data dLocations = getData(items, "ld_locations"); | 459 final Data dLocations = getData(items, "ld_locations"); |
461 DataItem[] lItems = dLocations.getItems(); | 460 final DataItem[] lItems = dLocations.getItems(); |
462 | 461 |
463 String[] splitted = lItems[0].getStringValue().split(" "); | 462 final String[] splitted = lItems[0].getStringValue().split(" "); |
464 String value = ""; | 463 String value = ""; |
465 for (int i = 0; i < splitted.length; i++) { | 464 for (final String element : splitted) { |
466 try { | 465 try { |
467 NumberFormat nf = NumberFormat.getDecimalFormat(); | 466 final NumberFormat nf = NumberFormat.getDecimalFormat(); |
468 double dv = Double.parseDouble(splitted[i]); | 467 final double dv = Double.parseDouble(element); |
469 value += nf.format(dv) + " "; | 468 value += nf.format(dv) + " "; |
470 } | 469 } |
471 catch(NumberFormatException nfe) { | 470 catch (final NumberFormatException nfe) { |
472 value += splitted[i] + " "; | 471 value += element + " "; |
473 } | 472 } |
474 } | 473 } |
475 | 474 |
476 Label selected = new Label(value); | 475 final Label selected = new Label(value); |
477 selected.setWidth(130); | 476 selected.setWidth(130); |
478 | 477 |
479 return selected; | 478 return selected; |
480 } | 479 } |
481 | |
482 | 480 |
483 /** | 481 /** |
484 * This method reads the default values defined in the DataItems of the Data | 482 * This method reads the default values defined in the DataItems of the Data |
485 * objects in <i>list</i>. | 483 * objects in <i>list</i>. |
486 * | 484 * |
487 * @param list The DataList container that stores the Data objects. | 485 * @param list |
488 */ | 486 * The DataList container that stores the Data objects. |
489 protected void initDefaults(DataList list) { | 487 */ |
490 Data m = getData(list.getAll(), "ld_mode"); | 488 protected void initDefaults(final DataList list) { |
491 Data l = getData(list.getAll(), "ld_locations"); | 489 final Data m = getData(list.getAll(), "ld_mode"); |
492 Data f = getData(list.getAll(), "ld_from"); | 490 final Data l = getData(list.getAll(), "ld_locations"); |
493 Data t = getData(list.getAll(), "ld_to"); | 491 final Data f = getData(list.getAll(), "ld_from"); |
494 Data s = getData(list.getAll(), "ld_step"); | 492 final Data t = getData(list.getAll(), "ld_to"); |
495 | 493 final Data s = getData(list.getAll(), "ld_step"); |
496 DataItem[] fItems = f.getItems(); | 494 |
497 DataItem[] tItems = t.getItems(); | 495 final DataItem[] fItems = f.getItems(); |
498 DataItem[] sItems = s.getItems(); | 496 final DataItem[] tItems = t.getItems(); |
499 | 497 final DataItem[] sItems = s.getItems(); |
500 min = Double.valueOf(fItems[0].getStringValue()); | 498 |
501 max = Double.valueOf(tItems[0].getStringValue()); | 499 this.min = Double.valueOf(fItems[0].getStringValue()); |
502 step = Double.valueOf(sItems[0].getStringValue()); | 500 this.max = Double.valueOf(tItems[0].getStringValue()); |
503 | 501 this.step = Double.valueOf(sItems[0].getStringValue()); |
504 DataItem mDef = m.getDefault(); | 502 |
505 DataItem lDef = l.getDefault(); | 503 final DataItem mDef = m.getDefault(); |
506 DataItem fDef = f.getDefault(); | 504 final DataItem lDef = l.getDefault(); |
507 DataItem tDef = t.getDefault(); | 505 final DataItem fDef = f.getDefault(); |
508 DataItem sDef = s.getDefault(); | 506 final DataItem tDef = t.getDefault(); |
509 | 507 final DataItem sDef = s.getDefault(); |
510 String mDefValue = mDef != null ? mDef.getStringValue() : null; | 508 |
511 String theMode = mDefValue != null && mDefValue.length() > 0 | 509 final String mDefValue = mDef != null ? mDef.getStringValue() : null; |
512 ? mDef.getStringValue() | 510 final String theMode = mDefValue != null && mDefValue.length() > 0 ? mDef.getStringValue() : FIELD_VALUE_DISTANCE; |
513 : FIELD_VALUE_DISTANCE; | 511 |
514 | 512 this.mode.setValue(FIELD_MODE, theMode); |
515 mode.setValue(FIELD_MODE, theMode); | 513 |
516 | 514 final String fDefValue = fDef != null ? fDef.getStringValue() : null; |
517 String fDefValue = fDef != null ? fDef.getStringValue() : null; | 515 setFrom(fDefValue != null && fDefValue.length() > 0 ? Double.valueOf(fDef.getStringValue()) : this.min); |
518 setFrom(fDefValue != null && fDefValue.length() > 0 | 516 |
519 ? Double.valueOf(fDef.getStringValue()) | 517 final String tDefValue = tDef != null ? tDef.getStringValue() : null; |
520 : min); | 518 setTo(tDefValue != null && tDefValue.length() > 0 ? Double.valueOf(tDef.getStringValue()) : this.max); |
521 | 519 |
522 String tDefValue = tDef != null ? tDef.getStringValue() : null; | 520 final String sDefValue = sDef != null ? sDef.getStringValue() : null; |
523 setTo(tDefValue != null && tDefValue.length() > 0 | 521 setStep(sDefValue != null && sDefValue.length() > 0 ? Double.valueOf(sDef.getStringValue()) : this.step); |
524 ? Double.valueOf(tDef.getStringValue()) | |
525 : max); | |
526 | |
527 String sDefValue = sDef != null ? sDef.getStringValue() : null; | |
528 setStep(sDefValue != null && sDefValue.length() > 0 | |
529 ? Double.valueOf(sDef.getStringValue()) | |
530 : step); | |
531 | 522 |
532 if (lDef != null) { | 523 if (lDef != null) { |
533 String lDefValue = lDef != null ? lDef.getStringValue() : null; | 524 final String lDefValue = lDef != null ? lDef.getStringValue() : null; |
534 | 525 |
535 if (lDefValue != null && lDefValue.length() > 0) { | 526 if (lDefValue != null && lDefValue.length() > 0) { |
536 setLocationValues(lDef.getStringValue()); | 527 setLocationValues(lDef.getStringValue()); |
537 } | 528 } |
538 } | 529 } |
539 | 530 |
540 if (theMode.equals(FIELD_VALUE_DISTANCE)) { | 531 if (theMode.equals(FIELD_VALUE_DISTANCE)) { |
541 enableDistanceMode(); | 532 enableDistanceMode(); |
542 inputTables.selectTab(1); | 533 this.inputTables.selectTab(1); |
543 } else { | 534 } else { |
544 enableLocationMode(); | 535 enableLocationMode(); |
545 } | 536 } |
546 currentFiltered = (ListGrid)inputTables.getSelectedTab().getPane(); | 537 this.currentFiltered = (ListGrid) this.inputTables.getSelectedTab().getPane(); |
547 | 538 |
548 distancePanel.setValues(getFrom(), getTo(), getStep()); | 539 this.distancePanel.setValues(getFrom(), getTo(), getStep()); |
549 } | 540 } |
550 | 541 |
551 | 542 protected Canvas createWidget(final DataList data) { |
552 protected Canvas createWidget(DataList data) { | 543 final VLayout layout = new VLayout(); |
553 VLayout layout = new VLayout(); | 544 this.container = new HLayout(); |
554 container = new HLayout(); | 545 final Canvas checkboxPanel = createRadioButtonPanel(); |
555 Canvas checkboxPanel = createRadioButtonPanel(); | 546 |
556 | 547 this.locationPanel = new DoubleArrayPanel(this.MESSAGES.unitLocation(), getLocationValues(), this); |
557 locationPanel = new DoubleArrayPanel( | 548 |
558 MESSAGES.unitLocation(), | 549 this.distancePanel = new DoubleRangePanel(this.MESSAGES.unitFrom(), this.MESSAGES.unitTo(), this.MESSAGES.unitWidth(), 0, 0, 0, /* |
559 getLocationValues(), | 550 * initDefaults set the |
560 this); | 551 * default values for |
561 | 552 * this. |
562 distancePanel = new DoubleRangePanel( | 553 */ |
563 MESSAGES.unitFrom(), MESSAGES.unitTo(), MESSAGES.unitWidth(), | 554 400, this); |
564 0, 0, 0, /* initDefaults set the default values for this. */ | 555 |
565 400, | 556 this.container.addMember(this.locationPanel); |
566 this); | 557 this.container.addMember(this.distancePanel); |
567 | 558 this.container.hideMember(this.locationPanel); |
568 container.addMember(locationPanel); | |
569 container.addMember(distancePanel); | |
570 container.hideMember(locationPanel); | |
571 | 559 |
572 layout.addMember(checkboxPanel); | 560 layout.addMember(checkboxPanel); |
573 layout.addMember(container); | 561 layout.addMember(this.container); |
574 | 562 |
575 container.setMembersMargin(30); | 563 this.container.setMembersMargin(30); |
576 | 564 |
577 inputTables = new TabSet(); | 565 this.inputTables = new TabSet(); |
578 inputTables.addTabSelectedHandler(new TabSelectedHandler() { | 566 this.inputTables.addTabSelectedHandler(new TabSelectedHandler() { |
579 @Override | 567 @Override |
580 public void onTabSelected(TabSelectedEvent evt) { | 568 public void onTabSelected(final TabSelectedEvent evt) { |
581 filterDescription.clear(); | 569 LocationDistancePanel.this.filterDescription.clear(); |
582 filterRange.clear(); | 570 LocationDistancePanel.this.filterRange.clear(); |
583 filterResultCount.setValue(""); | 571 LocationDistancePanel.this.filterResultCount.setValue(""); |
584 | 572 |
585 // The assumption is that location is tab 0 and distance tab 1 | 573 // The assumption is that location is tab 0 and distance tab 1 |
586 | 574 |
587 Canvas c = evt.getTabPane(); | 575 final Canvas c = evt.getTabPane(); |
588 if(c instanceof ListGrid) { | 576 if (c instanceof ListGrid) { |
589 currentFiltered = (ListGrid)c; | 577 LocationDistancePanel.this.currentFiltered = (ListGrid) c; |
590 } | 578 } |
591 } | 579 } |
592 }); | 580 }); |
593 | 581 |
594 Tab locations = new Tab(MESSAGES.locations()); | 582 final Tab locations = new Tab(this.MESSAGES.locations()); |
595 Tab distances = new Tab(MESSAGES.distance()); | 583 final Tab distances = new Tab(this.MESSAGES.distance()); |
596 | 584 |
597 inputTables.setWidth100(); | 585 this.inputTables.setWidth100(); |
598 inputTables.setHeight100(); | 586 this.inputTables.setHeight100(); |
599 | 587 |
600 locations.setPane(locationsTable); | 588 locations.setPane(this.locationsTable); |
601 distances.setPane(distanceTable); | 589 distances.setPane(this.distanceTable); |
602 | 590 |
603 inputTables.addTab(locations); | 591 this.inputTables.addTab(locations); |
604 inputTables.addTab(distances); | 592 this.inputTables.addTab(distances); |
605 | 593 |
606 filterResultCount = new StaticTextItem(MESSAGES.resultCount()); | 594 this.filterResultCount = new StaticTextItem(this.MESSAGES.resultCount()); |
607 filterResultCount.setTitleAlign(Alignment.LEFT); | 595 this.filterResultCount.setTitleAlign(Alignment.LEFT); |
608 filterResultCount.setTitleStyle("color: #000"); | 596 this.filterResultCount.setTitleStyle("color: #000"); |
609 | 597 |
610 filterDescription = new TableFilter(); | 598 this.filterDescription = new TableFilter(); |
611 filterDescription.setHeight("30px"); | 599 this.filterDescription.setHeight("30px"); |
612 filterDescription.addFilterHandler(this); | 600 this.filterDescription.addFilterHandler(this); |
613 | 601 |
614 filterRange = new RangeTableFilter(); | 602 this.filterRange = new RangeTableFilter(); |
615 filterRange.setHeight("30px"); | 603 this.filterRange.setHeight("30px"); |
616 filterRange.addFilterHandler(this); | 604 this.filterRange.addFilterHandler(this); |
617 filterRange.setVisible(false); | 605 this.filterRange.setVisible(false); |
618 | 606 |
619 filterCriteria = new SelectItem(); | 607 this.filterCriteria = new SelectItem(); |
620 filterCriteria.setShowTitle(false); | 608 this.filterCriteria.setShowTitle(false); |
621 filterCriteria.setWidth(100); | 609 this.filterCriteria.setWidth(100); |
622 filterCriteria.addChangedHandler(new ChangedHandler() { | 610 this.filterCriteria.addChangedHandler(new ChangedHandler() { |
623 @Override | 611 @Override |
624 public void onChanged(ChangedEvent e) { | 612 public void onChanged(final ChangedEvent e) { |
625 if(e.getValue().toString().equals("range")) { | 613 if (e.getValue().toString().equals("range")) { |
626 filterRange.setVisible(true); | 614 LocationDistancePanel.this.filterRange.setVisible(true); |
627 filterDescription.setVisible(false); | 615 LocationDistancePanel.this.filterDescription.setVisible(false); |
628 filterDescription.clear(); | 616 LocationDistancePanel.this.filterDescription.clear(); |
629 filterResultCount.setValue(""); | 617 LocationDistancePanel.this.filterResultCount.setValue(""); |
618 } else { | |
619 LocationDistancePanel.this.filterRange.setVisible(false); | |
620 LocationDistancePanel.this.filterRange.clear(); | |
621 LocationDistancePanel.this.filterDescription.setVisible(true); | |
622 LocationDistancePanel.this.filterResultCount.setValue(""); | |
630 } | 623 } |
631 else { | |
632 filterRange.setVisible(false); | |
633 filterRange.clear(); | |
634 filterDescription.setVisible(true); | |
635 filterResultCount.setValue(""); | |
636 } | |
637 } | 624 } |
638 }); | 625 }); |
639 | 626 |
640 LinkedHashMap<String, String> filterMap = | 627 final LinkedHashMap<String, String> filterMap = new LinkedHashMap<String, String>(); |
641 new LinkedHashMap<String, String>(); | 628 filterMap.put("description", this.MESSAGES.description()); |
642 filterMap.put("description", MESSAGES.description()); | 629 filterMap.put("range", this.MESSAGES.range()); |
643 filterMap.put("range", MESSAGES.range()); | 630 this.filterCriteria.setValueMap(filterMap); |
644 filterCriteria.setValueMap(filterMap); | 631 this.filterCriteria.setValue("description"); |
645 filterCriteria.setValue("description"); | 632 |
646 | 633 final DynamicForm form = new DynamicForm(); |
647 DynamicForm form = new DynamicForm(); | 634 form.setFields(this.filterCriteria); |
648 form.setFields(filterCriteria); | 635 this.inputTables.setHeight("*"); |
649 inputTables.setHeight("*"); | 636 final DynamicForm form2 = new DynamicForm(); |
650 DynamicForm form2 = new DynamicForm(); | 637 form2.setFields(this.filterResultCount); |
651 form2.setFields(filterResultCount); | 638 |
652 | 639 final VLayout helper = new VLayout(); |
653 VLayout helper = new VLayout(); | 640 final HLayout filterLayout = new HLayout(); |
654 HLayout filterLayout = new HLayout(); | |
655 | 641 |
656 filterLayout.addMember(form); | 642 filterLayout.addMember(form); |
657 filterLayout.addMember(filterDescription); | 643 filterLayout.addMember(this.filterDescription); |
658 filterLayout.addMember(filterRange); | 644 filterLayout.addMember(this.filterRange); |
659 filterLayout.setHeight("30px"); | 645 filterLayout.setHeight("30px"); |
660 helper.addMember(inputTables); | 646 helper.addMember(this.inputTables); |
661 helper.addMember(filterLayout); | 647 helper.addMember(filterLayout); |
662 helper.addMember(form2); | 648 helper.addMember(form2); |
663 helper.setHeight100(); | 649 helper.setHeight100(); |
664 helper.setWidth100(); | 650 helper.setWidth100(); |
665 | 651 |
666 helperContainer.addMember(helper); | 652 this.helperContainer.addMember(helper); |
667 filterLayout.setWidth("200"); | 653 filterLayout.setWidth("200"); |
668 | 654 |
669 return layout; | 655 return layout; |
670 } | 656 } |
671 | 657 |
672 | |
673 @Override | 658 @Override |
674 public void onFilterCriteriaChanged(StringFilterEvent event) { | 659 public void onFilterCriteriaChanged(final StringFilterEvent event) { |
675 String search = event.getFilter(); | 660 final String search = event.getFilter(); |
676 | 661 |
677 if (search != null && search.length() > 0) { | 662 if (search != null && search.length() > 0) { |
678 Criteria c = new Criteria("description", search); | 663 final Criteria c = new Criteria("description", search); |
679 | 664 |
680 locationsTable.filterData(c); | 665 this.locationsTable.filterData(c); |
681 distanceTable.filterData(c); | 666 this.distanceTable.filterData(c); |
682 filterResultCount.setValue(currentFiltered.getRecords().length); | 667 this.filterResultCount.setValue(this.currentFiltered.getRecords().length); |
683 } | 668 } else { |
684 else { | 669 this.locationsTable.clearCriteria(); |
685 locationsTable.clearCriteria(); | 670 this.distanceTable.clearCriteria(); |
686 distanceTable.clearCriteria(); | 671 this.filterResultCount.setValue(""); |
687 filterResultCount.setValue(""); | 672 } |
688 } | 673 } |
689 } | |
690 | |
691 | 674 |
692 @Override | 675 @Override |
693 public void onFilterCriteriaChanged(RangeFilterEvent event) { | 676 public void onFilterCriteriaChanged(final RangeFilterEvent event) { |
694 Float from = event.getFrom() - 0.001f; | 677 final Float from = event.getFrom() - 0.001f; |
695 Float to = event.getTo() + 0.001f; | 678 final Float to = event.getTo() + 0.001f; |
696 GWT.log("filtering range: " + from + " to " + to); | 679 GWT.log("filtering range: " + from + " to " + to); |
697 | |
698 | 680 |
699 Criterion combinedFilter = null; | 681 Criterion combinedFilter = null; |
700 Criterion locationFilter = null; | 682 Criterion locationFilter = null; |
701 if (from.equals(Float.NaN) && to.equals(Float.NaN)) { | 683 if (from.equals(Float.NaN) && to.equals(Float.NaN)) { |
702 locationsTable.clearCriteria(); | 684 this.locationsTable.clearCriteria(); |
703 distanceTable.clearCriteria(); | 685 this.distanceTable.clearCriteria(); |
704 filterResultCount.setValue(""); | 686 this.filterResultCount.setValue(""); |
705 return; | 687 return; |
706 } | 688 } else if (from.equals(Float.NaN)) { |
707 else if (from.equals(Float.NaN)) { | |
708 combinedFilter = new Criterion("to", OperatorId.LESS_OR_EQUAL, to); | 689 combinedFilter = new Criterion("to", OperatorId.LESS_OR_EQUAL, to); |
709 locationFilter = | 690 locationFilter = new Criterion("from", OperatorId.LESS_OR_EQUAL, to); |
710 new Criterion("from", OperatorId.LESS_OR_EQUAL, to); | 691 this.locationsTable.filterData(locationFilter); |
711 locationsTable.filterData(locationFilter); | 692 this.distanceTable.filterData(combinedFilter); |
712 distanceTable.filterData(combinedFilter); | 693 this.filterResultCount.setValue(this.currentFiltered.getRecords().length); |
713 filterResultCount.setValue(currentFiltered.getRecords().length); | |
714 return; | 694 return; |
715 } | 695 } else if (to.equals(Float.NaN)) { |
716 else if (to.equals(Float.NaN)) { | 696 combinedFilter = new Criterion("from", OperatorId.GREATER_OR_EQUAL, from); |
717 combinedFilter = | 697 this.locationsTable.filterData(combinedFilter); |
718 new Criterion("from", OperatorId.GREATER_OR_EQUAL, from); | 698 this.distanceTable.filterData(combinedFilter); |
719 locationsTable.filterData(combinedFilter); | 699 } else { |
720 distanceTable.filterData(combinedFilter); | 700 final AdvancedCriteria c1 = new AdvancedCriteria(OperatorId.AND, |
721 } | 701 new Criterion[] { new Criterion("from", OperatorId.GREATER_OR_EQUAL, from), new Criterion("from", OperatorId.LESS_OR_EQUAL, to) }); |
722 else { | 702 |
723 AdvancedCriteria c1 = | 703 final AdvancedCriteria c2 = new AdvancedCriteria(OperatorId.AND, |
724 new AdvancedCriteria(OperatorId.AND, new Criterion[] { | 704 new Criterion[] { new Criterion("to", OperatorId.GREATER_OR_EQUAL, from), new Criterion("to", OperatorId.LESS_OR_EQUAL, to) }); |
725 new Criterion("from", OperatorId.GREATER_OR_EQUAL, from), | 705 |
726 new Criterion("from", OperatorId.LESS_OR_EQUAL, to) | 706 final AdvancedCriteria c3 = new AdvancedCriteria(OperatorId.AND, |
727 }); | 707 new Criterion[] { new Criterion("from", OperatorId.LESS_OR_EQUAL, to), new Criterion("to", OperatorId.GREATER_OR_EQUAL, from) }); |
728 | 708 |
729 AdvancedCriteria c2 = | 709 combinedFilter = new AdvancedCriteria(OperatorId.OR, new Criterion[] { c1, c2, c3 }); |
730 new AdvancedCriteria(OperatorId.AND, new Criterion[] { | 710 } |
731 new Criterion("to", OperatorId.GREATER_OR_EQUAL, from), | 711 this.locationsTable.filterData(combinedFilter); |
732 new Criterion("to", OperatorId.LESS_OR_EQUAL, to) | 712 this.distanceTable.filterData(combinedFilter); |
733 }); | 713 this.filterResultCount.setValue(this.currentFiltered.getRecords().length); |
734 | 714 } |
735 AdvancedCriteria c3 = | |
736 new AdvancedCriteria(OperatorId.AND, new Criterion[] { | |
737 new Criterion("from", OperatorId.LESS_OR_EQUAL, to), | |
738 new Criterion("to", OperatorId.GREATER_OR_EQUAL, from) | |
739 }); | |
740 | |
741 combinedFilter = | |
742 new AdvancedCriteria(OperatorId.OR, new Criterion[] { | |
743 c1, c2, c3 | |
744 }); | |
745 } | |
746 locationsTable.filterData(combinedFilter); | |
747 distanceTable.filterData(combinedFilter); | |
748 filterResultCount.setValue(currentFiltered.getRecords().length); | |
749 } | |
750 | |
751 | 715 |
752 @Override | 716 @Override |
753 public List<String> validate() { | 717 public List<String> validate() { |
754 if (isLocationMode()) { | 718 if (isLocationMode()) { |
755 return validateLocations(); | 719 return validateLocations(); |
756 } | 720 } else { |
757 else { | |
758 return validateRange(); | 721 return validateRange(); |
759 } | 722 } |
760 } | 723 } |
761 | 724 |
762 | |
763 protected List<String> validateLocations() { | 725 protected List<String> validateLocations() { |
764 List<String> errors = new ArrayList<String>(); | 726 final List<String> errors = new ArrayList<String>(); |
765 NumberFormat nf = NumberFormat.getDecimalFormat(); | 727 final NumberFormat nf = NumberFormat.getDecimalFormat(); |
766 | 728 |
767 try { | 729 try { |
768 saveLocationValues(locationPanel); | 730 saveLocationValues(this.locationPanel); |
769 } | 731 } |
770 catch (Exception e) { | 732 catch (final Exception e) { |
771 errors.add(MESSAGES.wrongFormat()); | 733 errors.add(this.MESSAGES.wrongFormat()); |
772 } | 734 } |
773 | 735 |
774 double[] values = getLocationValues(); | 736 final double[] values = getLocationValues(); |
775 double[] good = new double[values.length]; | 737 final double[] good = new double[values.length]; |
776 int idx = 0; | 738 int idx = 0; |
777 | 739 |
778 for (double value: values) { | 740 for (final double value : values) { |
779 if (value < min || value > max) { | 741 if (value < this.min || value > this.max) { |
780 String tmp = MESSAGES.error_validate_range(); | 742 String tmp = this.MESSAGES.error_validate_range(); |
781 tmp = tmp.replace("$1", nf.format(value)); | 743 tmp = tmp.replace("$1", nf.format(value)); |
782 tmp = tmp.replace("$2", nf.format(min)); | 744 tmp = tmp.replace("$2", nf.format(this.min)); |
783 tmp = tmp.replace("$3", nf.format(max)); | 745 tmp = tmp.replace("$3", nf.format(this.max)); |
784 errors.add(tmp); | 746 errors.add(tmp); |
785 } | 747 } else { |
786 else { | |
787 good[idx++] = value; | 748 good[idx++] = value; |
788 } | 749 } |
789 } | 750 } |
790 | 751 |
791 double[] justGood = new double[idx]; | 752 final double[] justGood = new double[idx]; |
792 for (int i = 0; i < justGood.length; i++) { | 753 for (int i = 0; i < justGood.length; i++) { |
793 justGood[i] = good[i]; | 754 justGood[i] = good[i]; |
794 } | 755 } |
795 | 756 |
796 if (!errors.isEmpty()) { | 757 if (!errors.isEmpty()) { |
797 locationPanel.setValues(justGood); | 758 this.locationPanel.setValues(justGood); |
798 } | 759 } |
799 | 760 |
800 return errors; | 761 return errors; |
801 } | 762 } |
802 | 763 |
803 | |
804 protected List<String> validateRange() { | 764 protected List<String> validateRange() { |
805 List<String> errors = new ArrayList<String>(); | 765 final List<String> errors = new ArrayList<String>(); |
806 NumberFormat nf = NumberFormat.getDecimalFormat(); | 766 final NumberFormat nf = NumberFormat.getDecimalFormat(); |
807 | 767 |
808 try { | 768 try { |
809 saveDistanceValues(distancePanel); | 769 saveDistanceValues(this.distancePanel); |
810 } | 770 } |
811 catch (Exception e) { | 771 catch (final Exception e) { |
812 errors.add(MESSAGES.wrongFormat()); | 772 errors.add(this.MESSAGES.wrongFormat()); |
813 } | 773 } |
814 | 774 |
815 double from = getFrom(); | 775 double from = getFrom(); |
816 double to = getTo(); | 776 double to = getTo(); |
817 double step = getStep(); | 777 final double step = getStep(); |
818 | 778 |
819 if (from < min || from > max) { | 779 if (from < this.min || from > this.max) { |
820 String tmp = MESSAGES.error_validate_range(); | 780 String tmp = this.MESSAGES.error_validate_range(); |
821 tmp = tmp.replace("$1", nf.format(from)); | 781 tmp = tmp.replace("$1", nf.format(from)); |
822 tmp = tmp.replace("$2", nf.format(min)); | 782 tmp = tmp.replace("$2", nf.format(this.min)); |
823 tmp = tmp.replace("$3", nf.format(max)); | 783 tmp = tmp.replace("$3", nf.format(this.max)); |
824 errors.add(tmp); | 784 errors.add(tmp); |
825 from = min; | 785 from = this.min; |
826 } | 786 } |
827 | 787 |
828 if (to < min || to > max) { | 788 if (to < this.min || to > this.max) { |
829 String tmp = MESSAGES.error_validate_range(); | 789 String tmp = this.MESSAGES.error_validate_range(); |
830 tmp = tmp.replace("$1", nf.format(to)); | 790 tmp = tmp.replace("$1", nf.format(to)); |
831 tmp = tmp.replace("$2", nf.format(min)); | 791 tmp = tmp.replace("$2", nf.format(this.min)); |
832 tmp = tmp.replace("$3", nf.format(max)); | 792 tmp = tmp.replace("$3", nf.format(this.max)); |
833 errors.add(tmp); | 793 errors.add(tmp); |
834 to = max; | 794 to = this.max; |
835 } | 795 } |
836 | 796 |
837 if (!errors.isEmpty()) { | 797 if (!errors.isEmpty()) { |
838 distancePanel.setValues(from, to, step); | 798 this.distancePanel.setValues(from, to, step); |
839 } | 799 } |
840 | 800 |
841 return errors; | 801 return errors; |
842 } | 802 } |
843 | |
844 | 803 |
845 /** | 804 /** |
846 * This method returns the selected data. | 805 * This method returns the selected data. |
847 * | 806 * |
848 * @return the selected/inserted data. | 807 * @return the selected/inserted data. |
849 */ | 808 */ |
850 @Override | 809 @Override |
851 public Data[] getData() { | 810 public Data[] getData() { |
852 List<Data> data = new ArrayList<Data>(); | 811 final List<Data> data = new ArrayList<Data>(); |
853 | 812 |
854 // If we have entered a value and click right afterwards on the | 813 // If we have entered a value and click right afterwards on the |
855 // 'next' button, the BlurEvent is not fired, and the values are not | 814 // 'next' button, the BlurEvent is not fired, and the values are not |
856 // saved. So, we gonna save those values explicitly. | 815 // saved. So, we gonna save those values explicitly. |
857 if (isLocationMode()) { | 816 if (isLocationMode()) { |
858 Canvas member = container.getMember(0); | 817 final Canvas member = this.container.getMember(0); |
859 if (member instanceof DoubleArrayPanel) { | 818 if (member instanceof DoubleArrayPanel) { |
860 DoubleArrayPanel form = (DoubleArrayPanel) member; | 819 final DoubleArrayPanel form = (DoubleArrayPanel) member; |
861 saveLocationValues(form); | 820 saveLocationValues(form); |
862 } | 821 } |
863 | 822 |
864 Data dLocations = getDataLocations(); | 823 final Data dLocations = getDataLocations(); |
865 DataItem dFrom = new DefaultDataItem("ld_from", "ld_from", ""); | 824 final DataItem dFrom = new DefaultDataItem("ld_from", "ld_from", ""); |
866 DataItem dTo = new DefaultDataItem("ld_to", "ld_to", ""); | 825 final DataItem dTo = new DefaultDataItem("ld_to", "ld_to", ""); |
867 DataItem dStep = new DefaultDataItem("ld_step", "ld_step", ""); | 826 final DataItem dStep = new DefaultDataItem("ld_step", "ld_step", ""); |
868 | 827 |
869 data.add(dLocations); | 828 data.add(dLocations); |
870 data.add(new DefaultData( | 829 data.add(new DefaultData("ld_from", null, null, new DataItem[] { dFrom })); |
871 "ld_from", null, null, new DataItem[] { dFrom } )); | 830 data.add(new DefaultData("ld_to", null, null, new DataItem[] { dTo })); |
872 data.add(new DefaultData( | 831 data.add(new DefaultData("ld_step", null, null, new DataItem[] { dStep })); |
873 "ld_to", null, null, new DataItem[] { dTo } )); | 832 } else { |
874 data.add(new DefaultData( | 833 final Canvas member = this.container.getMember(0); |
875 "ld_step", null, null, new DataItem[] { dStep } )); | |
876 } | |
877 else { | |
878 Canvas member = container.getMember(0); | |
879 if (member instanceof DoubleRangePanel) { | 834 if (member instanceof DoubleRangePanel) { |
880 DoubleRangePanel form = (DoubleRangePanel) member; | 835 final DoubleRangePanel form = (DoubleRangePanel) member; |
881 saveDistanceValues(form); | 836 saveDistanceValues(form); |
882 } | 837 } |
883 | 838 |
884 Data dFrom = getDataFrom(); | 839 final Data dFrom = getDataFrom(); |
885 Data dTo = getDataTo(); | 840 final Data dTo = getDataTo(); |
886 Data dStep = getDataStep(); | 841 final Data dStep = getDataStep(); |
887 DataItem loc = new DefaultDataItem( | 842 final DataItem loc = new DefaultDataItem("ld_locations", "ld_locations", ""); |
888 "ld_locations", "ld_locations",""); | |
889 | 843 |
890 data.add(dFrom); | 844 data.add(dFrom); |
891 data.add(dTo); | 845 data.add(dTo); |
892 data.add(dStep); | 846 data.add(dStep); |
893 data.add(new DefaultData( | 847 data.add(new DefaultData("ld_locations", null, null, new DataItem[] { loc })); |
894 "ld_locations", null, null, new DataItem[] { loc } )); | 848 } |
895 } | 849 |
896 | 850 final Data dMode = getDataMode(); |
897 Data dMode = getDataMode(); | |
898 if (dMode != null) { | 851 if (dMode != null) { |
899 data.add(dMode); | 852 data.add(dMode); |
900 } | 853 } |
901 | 854 |
902 return data.toArray(new Data[data.size()]); | 855 return data.toArray(new Data[data.size()]); |
903 } | 856 } |
904 | 857 |
905 | |
906 /** | 858 /** |
907 * Returns the Data object for the 'mode' attribute. | 859 * Returns the Data object for the 'mode' attribute. |
908 * | 860 * |
909 * @return the Data object for the 'mode' attribute. | 861 * @return the Data object for the 'mode' attribute. |
910 */ | 862 */ |
911 protected Data getDataMode() { | 863 protected Data getDataMode() { |
912 String value = mode.getValueAsString(FIELD_MODE); | 864 final String value = this.mode.getValueAsString(FIELD_MODE); |
913 DataItem item = new DefaultDataItem("ld_mode", "ld_mode", value); | 865 final DataItem item = new DefaultDataItem("ld_mode", "ld_mode", value); |
914 return new DefaultData("ld_mode", null, null, new DataItem[] { item }); | 866 return new DefaultData("ld_mode", null, null, new DataItem[] { item }); |
915 } | 867 } |
916 | 868 |
917 | |
918 protected Data getDataLocations() { | 869 protected Data getDataLocations() { |
919 double[] locations = getLocationValues(); | 870 final double[] locations = getLocationValues(); |
920 boolean first = true; | 871 boolean first = true; |
921 | 872 |
922 if (locations == null) { | 873 if (locations == null) { |
923 return null; | 874 return null; |
924 } | 875 } |
925 | 876 |
926 StringBuilder sb = new StringBuilder(); | 877 final StringBuilder sb = new StringBuilder(); |
927 | 878 |
928 for (double l: locations) { | 879 for (final double l : locations) { |
929 if (!first) { | 880 if (!first) { |
930 sb.append(" "); | 881 sb.append(" "); |
931 } | 882 } |
932 | 883 |
933 sb.append(l); | 884 sb.append(l); |
934 | 885 |
935 first = false; | 886 first = false; |
936 } | 887 } |
937 | 888 |
938 DataItem item = new DefaultDataItem( | 889 final DataItem item = new DefaultDataItem("ld_locations", "ld_locations", sb.toString()); |
939 "ld_locations", | 890 |
940 "ld_locations", | 891 return new DefaultData("ld_locations", null, null, new DataItem[] { item }); |
941 sb.toString()); | 892 } |
942 | |
943 return new DefaultData( | |
944 "ld_locations", | |
945 null, | |
946 null, | |
947 new DataItem[] { item }); | |
948 } | |
949 | |
950 | 893 |
951 /** | 894 /** |
952 * Returns the Data object for the 'from' attribute. | 895 * Returns the Data object for the 'from' attribute. |
953 * | 896 * |
954 * @return the Data object for the 'from' attribute. | 897 * @return the Data object for the 'from' attribute. |
955 */ | 898 */ |
956 protected Data getDataFrom() { | 899 protected Data getDataFrom() { |
957 String value = Double.valueOf(getFrom()).toString(); | 900 final String value = Double.valueOf(getFrom()).toString(); |
958 DataItem item = new DefaultDataItem("ld_from", "ld_from", value); | 901 final DataItem item = new DefaultDataItem("ld_from", "ld_from", value); |
959 return new DefaultData( | 902 return new DefaultData("ld_from", null, null, new DataItem[] { item }); |
960 "ld_from", null, null, new DataItem[] { item }); | 903 } |
961 } | |
962 | |
963 | 904 |
964 /** | 905 /** |
965 * Returns the Data object for the 'to' attribute. | 906 * Returns the Data object for the 'to' attribute. |
966 * | 907 * |
967 * @return the Data object for the 'to' attribute. | 908 * @return the Data object for the 'to' attribute. |
968 */ | 909 */ |
969 protected Data getDataTo() { | 910 protected Data getDataTo() { |
970 String value = Double.valueOf(getTo()).toString(); | 911 final String value = Double.valueOf(getTo()).toString(); |
971 DataItem item = new DefaultDataItem("ld_to", "ld_to", value); | 912 final DataItem item = new DefaultDataItem("ld_to", "ld_to", value); |
972 return new DefaultData( | 913 return new DefaultData("ld_to", null, null, new DataItem[] { item }); |
973 "ld_to", null, null, new DataItem[] { item }); | 914 } |
974 } | |
975 | |
976 | 915 |
977 /** | 916 /** |
978 * Returns the Data object for the 'step' attribute. | 917 * Returns the Data object for the 'step' attribute. |
979 * | 918 * |
980 * @return the Data object for the 'step' attribute. | 919 * @return the Data object for the 'step' attribute. |
981 */ | 920 */ |
982 protected Data getDataStep() { | 921 protected Data getDataStep() { |
983 String value = Double.valueOf(getStep()).toString(); | 922 final String value = Double.valueOf(getStep()).toString(); |
984 DataItem item = new DefaultDataItem("ld_step","ld_step", value); | 923 final DataItem item = new DefaultDataItem("ld_step", "ld_step", value); |
985 return new DefaultData( | 924 return new DefaultData("ld_step", null, null, new DataItem[] { item }); |
986 "ld_step", null, null, new DataItem[] { item }); | 925 } |
987 } | |
988 | |
989 | 926 |
990 /** | 927 /** |
991 * Determines the current input mode. | 928 * Determines the current input mode. |
992 * | 929 * |
993 * @return true, if 'location' is the current input mode, otherwise false. | 930 * @return true, if 'location' is the current input mode, otherwise false. |
994 */ | 931 */ |
995 public boolean isLocationMode() { | 932 public boolean isLocationMode() { |
996 String inputMode = mode.getValueAsString(FIELD_MODE); | 933 final String inputMode = this.mode.getValueAsString(FIELD_MODE); |
997 | 934 |
998 return inputMode.equals(FIELD_VALUE_LOCATION) ? true : false; | 935 return inputMode.equals(FIELD_VALUE_LOCATION) ? true : false; |
999 } | 936 } |
1000 | 937 |
1001 | |
1002 /** | 938 /** |
1003 * Activates the location panel. | 939 * Activates the location panel. |
1004 */ | 940 */ |
1005 protected void enableLocationMode() { | 941 protected void enableLocationMode() { |
1006 mode.setValue(FIELD_MODE, FIELD_VALUE_LOCATION); | 942 this.mode.setValue(FIELD_MODE, FIELD_VALUE_LOCATION); |
1007 container.hideMember(distancePanel); | 943 this.container.hideMember(this.distancePanel); |
1008 container.showMember(locationPanel); | 944 this.container.showMember(this.locationPanel); |
1009 setupDistanceInfoTable(locationsTable, false, false); | 945 setupDistanceInfoTable(this.locationsTable, false, false); |
1010 setupDistanceInfoTable(distanceTable, true, true); | 946 setupDistanceInfoTable(this.distanceTable, true, true); |
1011 inputTables.updateTab(0, locationsTable); | 947 this.inputTables.updateTab(0, this.locationsTable); |
1012 inputTables.updateTab(1, distanceTable); | 948 this.inputTables.updateTab(1, this.distanceTable); |
1013 } | 949 } |
1014 | |
1015 | 950 |
1016 /** | 951 /** |
1017 * Activates the distance panel. | 952 * Activates the distance panel. |
1018 */ | 953 */ |
1019 protected void enableDistanceMode() { | 954 protected void enableDistanceMode() { |
1020 mode.setValue(FIELD_MODE, FIELD_VALUE_DISTANCE); | 955 this.mode.setValue(FIELD_MODE, FIELD_VALUE_DISTANCE); |
1021 container.hideMember(locationPanel); | 956 this.container.hideMember(this.locationPanel); |
1022 container.showMember(distancePanel); | 957 this.container.showMember(this.distancePanel); |
1023 setupDistanceInfoTable(locationsTable, true, false); | 958 setupDistanceInfoTable(this.locationsTable, true, false); |
1024 setupDistanceInfoTable(distanceTable, false, true); | 959 setupDistanceInfoTable(this.distanceTable, false, true); |
1025 inputTables.updateTab(0, locationsTable); | 960 this.inputTables.updateTab(0, this.locationsTable); |
1026 inputTables.updateTab(1, distanceTable); | 961 this.inputTables.updateTab(1, this.distanceTable); |
1027 } | 962 } |
1028 | |
1029 | 963 |
1030 /** | 964 /** |
1031 * This method switches the input mode between location and distance input. | 965 * This method switches the input mode between location and distance input. |
1032 * | 966 * |
1033 * @param event The click event fired by a RadioButtonGroupItem. | 967 * @param event |
968 * The click event fired by a RadioButtonGroupItem. | |
1034 */ | 969 */ |
1035 @Override | 970 @Override |
1036 public void onChange(ChangeEvent event) { | 971 public void onChange(final ChangeEvent event) { |
1037 String value = (String) event.getValue(); | 972 final String value = (String) event.getValue(); |
1038 | 973 |
1039 if (value == null) { | 974 if (value == null) { |
1040 return; | 975 return; |
1041 } | 976 } |
1042 if (value.equals(FIELD_VALUE_LOCATION)) { | 977 if (value.equals(FIELD_VALUE_LOCATION)) { |
1043 enableLocationMode(); | 978 enableLocationMode(); |
1044 filterDescription.clear(); | 979 this.filterDescription.clear(); |
1045 filterRange.clear(); | 980 this.filterRange.clear(); |
1046 filterResultCount.setValue(""); | 981 this.filterResultCount.setValue(""); |
1047 | 982 |
1048 // Bring this tab to front. | 983 // Bring this tab to front. |
1049 inputTables.selectTab(0); | 984 this.inputTables.selectTab(0); |
1050 } | 985 } else { |
1051 else { | |
1052 enableDistanceMode(); | 986 enableDistanceMode(); |
1053 filterDescription.clear(); | 987 this.filterDescription.clear(); |
1054 filterRange.clear(); | 988 this.filterRange.clear(); |
1055 filterResultCount.setValue(""); | 989 this.filterResultCount.setValue(""); |
1056 | 990 |
1057 // Bring the distanceTable tab to front. | 991 // Bring the distanceTable tab to front. |
1058 inputTables.selectTab(1); | 992 this.inputTables.selectTab(1); |
1059 } | 993 } |
1060 } | 994 } |
1061 | |
1062 | 995 |
1063 /** | 996 /** |
1064 * This method is used to validate the inserted data in the form fields. | 997 * This method is used to validate the inserted data in the form fields. |
1065 * | 998 * |
1066 * @param event The BlurEvent that gives information about the FormItem that | 999 * @param event |
1067 * has been modified and its value. | 1000 * The BlurEvent that gives information about the FormItem that |
1001 * has been modified and its value. | |
1068 */ | 1002 */ |
1069 @Override | 1003 @Override |
1070 public void onBlur(BlurEvent event) { | 1004 public void onBlur(final BlurEvent event) { |
1071 FormItem item = event.getItem(); | 1005 final FormItem item = event.getItem(); |
1072 String field = item.getFieldName(); | 1006 final String field = item.getFieldName(); |
1073 | 1007 |
1074 if (field == null) { | 1008 if (field == null) { |
1075 return; | 1009 return; |
1076 } | 1010 } |
1077 | 1011 |
1078 if (field.equals(DoubleArrayPanel.FIELD_NAME)) { | 1012 if (field.equals(DoubleArrayPanel.FIELD_NAME)) { |
1079 DoubleArrayPanel p = (DoubleArrayPanel) event.getForm(); | 1013 final DoubleArrayPanel p = (DoubleArrayPanel) event.getForm(); |
1080 | 1014 |
1081 saveLocationValue(p, item); | 1015 saveLocationValue(p, item); |
1082 } | 1016 } else { |
1083 else { | 1017 final DoubleRangePanel p = (DoubleRangePanel) event.getForm(); |
1084 DoubleRangePanel p = (DoubleRangePanel) event.getForm(); | |
1085 | 1018 |
1086 saveDistanceValue(p, item); | 1019 saveDistanceValue(p, item); |
1087 } | 1020 } |
1088 } | 1021 } |
1089 | 1022 |
1090 | |
1091 | |
1092 /** | 1023 /** |
1093 * Validates and stores all values entered in the location mode. | 1024 * Validates and stores all values entered in the location mode. |
1094 * | 1025 * |
1095 * @param p The DoubleArrayPanel. | 1026 * @param p |
1096 */ | 1027 * The DoubleArrayPanel. |
1097 protected void saveLocationValues(DoubleArrayPanel p) { | 1028 */ |
1098 FormItem[] formItems = p.getFields(); | 1029 protected void saveLocationValues(final DoubleArrayPanel p) { |
1099 | 1030 final FormItem[] formItems = p.getFields(); |
1100 for (FormItem item: formItems) { | 1031 |
1032 for (final FormItem item : formItems) { | |
1101 if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { | 1033 if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { |
1102 saveLocationValue(p, item); | 1034 saveLocationValue(p, item); |
1103 } | 1035 } |
1104 } | 1036 } |
1105 } | 1037 } |
1106 | 1038 |
1107 | |
1108 /** | 1039 /** |
1109 * Validates and stores all values entered in the distance mode. | 1040 * Validates and stores all values entered in the distance mode. |
1110 * | 1041 * |
1111 * @param p The DoubleRangePanel. | 1042 * @param p |
1112 */ | 1043 * The DoubleRangePanel. |
1113 protected void saveDistanceValues(DoubleRangePanel p) { | 1044 */ |
1114 FormItem[] formItems = p.getFields(); | 1045 protected void saveDistanceValues(final DoubleRangePanel p) { |
1115 | 1046 final FormItem[] formItems = p.getFields(); |
1116 for (FormItem item: formItems) { | 1047 |
1048 for (final FormItem item : formItems) { | |
1117 saveDistanceValue(p, item); | 1049 saveDistanceValue(p, item); |
1118 } | 1050 } |
1119 } | 1051 } |
1120 | 1052 |
1121 | |
1122 /** | 1053 /** |
1123 * Validates and stores a value entered in the location mode. | 1054 * Validates and stores a value entered in the location mode. |
1124 * | 1055 * |
1125 * @param p The DoubleArrayPanel. | 1056 * @param p |
1126 * @param item The item that needs to be validated. | 1057 * The DoubleArrayPanel. |
1127 */ | 1058 * @param item |
1128 protected void saveLocationValue(DoubleArrayPanel p, FormItem item) { | 1059 * The item that needs to be validated. |
1060 */ | |
1061 protected void saveLocationValue(final DoubleArrayPanel p, final FormItem item) { | |
1129 if (p.validateForm(item)) { | 1062 if (p.validateForm(item)) { |
1130 setLocationValues(p.getInputValues(item)); | 1063 setLocationValues(p.getInputValues(item)); |
1131 } | 1064 } |
1132 } | 1065 } |
1133 | 1066 |
1134 | |
1135 /** | 1067 /** |
1136 * Validates and stores value entered in the distance mode. | 1068 * Validates and stores value entered in the distance mode. |
1137 * | 1069 * |
1138 * @param p The DoubleRangePanel. | 1070 * @param p |
1139 * @param item The item that needs to be validated. | 1071 * The DoubleRangePanel. |
1140 */ | 1072 * @param item |
1141 protected void saveDistanceValue(DoubleRangePanel p, FormItem item) { | 1073 * The item that needs to be validated. |
1074 */ | |
1075 protected void saveDistanceValue(final DoubleRangePanel p, final FormItem item) { | |
1142 if (p.validateForm(item)) { | 1076 if (p.validateForm(item)) { |
1143 setFrom(p.getFrom()); | 1077 setFrom(p.getFrom()); |
1144 setTo(p.getTo()); | 1078 setTo(p.getTo()); |
1145 setStep(p.getStep()); | 1079 setStep(p.getStep()); |
1146 } | 1080 } |
1147 } | 1081 } |
1148 | 1082 |
1149 | |
1150 /** | 1083 /** |
1151 * This method creates the panel that contains the checkboxes to switch | 1084 * This method creates the panel that contains the checkboxes to switch |
1152 * between the input mode 'location' and 'distance'. | 1085 * between the input mode 'location' and 'distance'. |
1153 * | 1086 * |
1154 * @return the checkbox panel. | 1087 * @return the checkbox panel. |
1155 */ | 1088 */ |
1156 protected Canvas createRadioButtonPanel() { | 1089 protected Canvas createRadioButtonPanel() { |
1157 mode = new DynamicForm(); | 1090 this.mode = new DynamicForm(); |
1158 | 1091 |
1159 RadioGroupItem radio = new RadioGroupItem(FIELD_MODE); | 1092 final RadioGroupItem radio = new RadioGroupItem(FIELD_MODE); |
1160 radio.setShowTitle(false); | 1093 radio.setShowTitle(false); |
1161 radio.setVertical(false); | 1094 radio.setVertical(false); |
1162 radio.setWrap(false); | 1095 radio.setWrap(false); |
1163 | 1096 |
1164 LinkedHashMap<String, String> values = | 1097 final LinkedHashMap<String, String> values = new LinkedHashMap<String, String>(); |
1165 new LinkedHashMap<String, String>(); | 1098 values.put(FIELD_VALUE_LOCATION, this.MESSAGES.location()); |
1166 values.put(FIELD_VALUE_LOCATION, MESSAGES.location()); | 1099 values.put(FIELD_VALUE_DISTANCE, this.MESSAGES.distance()); |
1167 values.put(FIELD_VALUE_DISTANCE, MESSAGES.distance()); | 1100 |
1168 | 1101 final LinkedHashMap<String, String> initial = new LinkedHashMap<String, String>(); |
1169 LinkedHashMap<String, String> initial = | |
1170 new LinkedHashMap<String, String>(); | |
1171 initial.put(FIELD_MODE, FIELD_VALUE_DISTANCE); | 1102 initial.put(FIELD_MODE, FIELD_VALUE_DISTANCE); |
1172 | 1103 |
1173 radio.setValueMap(values); | 1104 radio.setValueMap(values); |
1174 radio.addChangeHandler(this); | 1105 radio.addChangeHandler(this); |
1175 | 1106 |
1176 mode.setFields(radio); | 1107 this.mode.setFields(radio); |
1177 mode.setValues(initial); | 1108 this.mode.setValues(initial); |
1178 | 1109 |
1179 return mode; | 1110 return this.mode; |
1180 } | 1111 } |
1181 | |
1182 | 1112 |
1183 protected void createDistanceInputPanel() { | 1113 protected void createDistanceInputPanel() { |
1184 Config config = Config.getInstance(); | 1114 final Config config = Config.getInstance(); |
1185 String url = config.getServerUrl(); | 1115 final String url = config.getServerUrl(); |
1186 String river = ""; | 1116 String river = ""; |
1187 | 1117 |
1188 ArtifactDescription adescr = artifact.getArtifactDescription(); | 1118 final ArtifactDescription adescr = this.artifact.getArtifactDescription(); |
1189 DataList[] data = adescr.getOldData(); | 1119 final DataList[] data = adescr.getOldData(); |
1190 | 1120 |
1191 if (data != null && data.length > 0) { | 1121 if (data != null && data.length > 0) { |
1192 for (int i = 0; i < data.length; i++) { | 1122 for (final DataList dl : data) { |
1193 DataList dl = data[i]; | |
1194 if (dl.getState().endsWith("river")) { | 1123 if (dl.getState().endsWith("river")) { |
1195 for (int j = 0; j < dl.size(); j++) { | 1124 for (int j = 0; j < dl.size(); j++) { |
1196 Data d = dl.get(j); | 1125 final Data d = dl.get(j); |
1197 DataItem[] di = d.getItems(); | 1126 final DataItem[] di = d.getItems(); |
1198 if (di != null && di.length == 1) { | 1127 if (di != null && di.length == 1) { |
1199 river = d.getItems()[0].getStringValue(); | 1128 river = d.getItems()[0].getStringValue(); |
1200 } | 1129 } |
1201 } | 1130 } |
1202 } | 1131 } |
1203 } | 1132 } |
1204 } | 1133 } |
1205 | 1134 |
1206 distanceTable.setDataSource(new DistanceInfoDataSource( | 1135 this.distanceTable.setDataSource(new DistanceInfoDataSource(url, river, "distances")); |
1207 url, river, "distances")); | 1136 this.locationsTable.setDataSource(new DistanceInfoDataSource(url, river, "locations")); |
1208 locationsTable.setDataSource(new DistanceInfoDataSource( | |
1209 url, river, "locations")); | |
1210 } | 1137 } |
1211 | 1138 |
1212 protected double getFrom() { | 1139 protected double getFrom() { |
1213 return from; | 1140 return this.from; |
1214 } | 1141 } |
1215 | 1142 |
1216 protected void setTo(String to) { | 1143 protected void setTo(final String to) { |
1217 try { | 1144 try { |
1218 double toValue = Double.parseDouble(to); | 1145 final double toValue = Double.parseDouble(to); |
1219 setTo(toValue); | 1146 setTo(toValue); |
1220 } | 1147 } |
1221 catch(NumberFormatException nfe) { | 1148 catch (final NumberFormatException nfe) { |
1222 // Is there anything to do? | 1149 // Is there anything to do? |
1223 } | 1150 } |
1224 } | 1151 } |
1225 | 1152 |
1226 protected void setFrom(String from) { | 1153 protected void setFrom(final String from) { |
1227 try { | 1154 try { |
1228 double fromValue = Double.parseDouble(from); | 1155 final double fromValue = Double.parseDouble(from); |
1229 setFrom(fromValue); | 1156 setFrom(fromValue); |
1230 } | 1157 } |
1231 catch(NumberFormatException nfe) { | 1158 catch (final NumberFormatException nfe) { |
1232 // Is there anything to do? | 1159 // Is there anything to do? |
1233 } | 1160 } |
1234 } | 1161 } |
1235 | 1162 |
1236 protected void setFrom(double from) { | 1163 protected void setFrom(final double from) { |
1237 this.from = from; | 1164 this.from = from; |
1238 /* The doubling should be removed and this.from abolished */ | 1165 /* The doubling should be removed and this.from abolished */ |
1239 distancePanel.setFrom(from); | 1166 this.distancePanel.setFrom(from); |
1240 } | 1167 } |
1241 | |
1242 | 1168 |
1243 protected double getTo() { | 1169 protected double getTo() { |
1244 return to; | 1170 return this.to; |
1245 } | 1171 } |
1246 | 1172 |
1247 | 1173 protected void setTo(final double to) { |
1248 protected void setTo(double to) { | |
1249 this.to = to; | 1174 this.to = to; |
1250 /* The doubling should be removed and this.to abolished */ | 1175 /* The doubling should be removed and this.to abolished */ |
1251 distancePanel.setTo(to); | 1176 this.distancePanel.setTo(to); |
1252 } | 1177 } |
1253 | |
1254 | 1178 |
1255 protected double getStep() { | 1179 protected double getStep() { |
1256 return step; | 1180 return this.step; |
1257 } | 1181 } |
1258 | 1182 |
1259 | 1183 protected void setStep(final double step) { |
1260 protected void setStep(double step) { | |
1261 this.step = step; | 1184 this.step = step; |
1262 } | 1185 } |
1263 | 1186 |
1264 | |
1265 protected double[] getLocationValues() { | 1187 protected double[] getLocationValues() { |
1266 return values; | 1188 return this.values; |
1267 } | 1189 } |
1268 | 1190 |
1269 protected void appendLocation(String loc) { | 1191 protected void appendLocation(final String loc) { |
1270 double[] selected; | 1192 double[] selected; |
1271 if (getLocationValues() != null) { | 1193 if (getLocationValues() != null) { |
1272 double[] val = getLocationValues(); | 1194 final double[] val = getLocationValues(); |
1273 selected = new double[val.length + 1]; | 1195 selected = new double[val.length + 1]; |
1274 for(int i = 0; i < val.length; i++){ | 1196 for (int i = 0; i < val.length; i++) { |
1275 selected[i] = val[i]; | 1197 selected[i] = val[i]; |
1276 } | 1198 } |
1277 try { | 1199 try { |
1278 selected[val.length] = Double.parseDouble(loc); | 1200 selected[val.length] = Double.parseDouble(loc); |
1279 } | 1201 } |
1280 catch(NumberFormatException nfe) { | 1202 catch (final NumberFormatException nfe) { |
1281 // Is there anything to do here? | 1203 // Is there anything to do here? |
1282 } | 1204 } |
1283 } | 1205 } else { |
1284 else { | |
1285 selected = new double[1]; | 1206 selected = new double[1]; |
1286 selected[0] = Double.parseDouble(loc); | 1207 selected[0] = Double.parseDouble(loc); |
1287 } | 1208 } |
1288 setLocationValues(selected); | 1209 setLocationValues(selected); |
1289 } | 1210 } |
1290 | 1211 |
1291 protected void setLocationValues(double[] values) { | 1212 protected void setLocationValues(final double[] values) { |
1292 this.values = values; | 1213 this.values = values; |
1293 locationPanel.setValues(values); | 1214 this.locationPanel.setValues(values); |
1294 } | 1215 } |
1295 | 1216 |
1296 | 1217 protected void setLocationValues(final String values) { |
1297 protected void setLocationValues(String values) { | 1218 final String[] vs = values.split(" "); |
1298 String[] vs = values.split(" "); | |
1299 | 1219 |
1300 if (vs == null) { | 1220 if (vs == null) { |
1301 return; | 1221 return; |
1302 } | 1222 } |
1303 | 1223 |
1304 double[] ds = new double[vs.length]; | 1224 final double[] ds = new double[vs.length]; |
1305 int idx = 0; | 1225 int idx = 0; |
1306 | 1226 |
1307 for (String s: vs) { | 1227 for (final String s : vs) { |
1308 try { | 1228 try { |
1309 ds[idx++] = Double.valueOf(s); | 1229 ds[idx++] = Double.valueOf(s); |
1310 } | 1230 } |
1311 catch (NumberFormatException nfe) { | 1231 catch (final NumberFormatException nfe) { |
1312 // do nothing | 1232 // do nothing |
1313 } | 1233 } |
1314 } | 1234 } |
1315 | 1235 |
1316 setLocationValues(ds); | 1236 setLocationValues(ds); |
1317 } | 1237 } |
1318 | 1238 |
1319 | 1239 protected void setDistanceValues(final double from, final double to) { |
1320 protected void setDistanceValues (double from, double to) { | |
1321 setFrom(from); | 1240 setFrom(from); |
1322 setTo(to); | 1241 setTo(to); |
1323 distancePanel.setValues(from, to, getStep()); | 1242 this.distancePanel.setValues(from, to, getStep()); |
1324 } | 1243 } |
1325 } | 1244 } |
1326 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 1245 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |