comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationPanel.java @ 4131:360e22afb98b

Cosmetics, warnings and minor TODOs.
author Christian Lins <christian.lins@intevation.de>
date Mon, 15 Oct 2012 00:04:35 +0200
parents 51ed89b754ae
children
comparison
equal deleted inserted replaced
4130:df8ac7ff6b1a 4131:360e22afb98b
1 package de.intevation.flys.client.client.ui; 1 package de.intevation.flys.client.client.ui;
2 2
3 import java.util.ArrayList; 3 import com.google.gwt.core.client.GWT;
4 import java.util.List;
5
6 import com.google.gwt.i18n.client.NumberFormat; 4 import com.google.gwt.i18n.client.NumberFormat;
7 5
6 import com.smartgwt.client.data.Record;
8 import com.smartgwt.client.util.SC; 7 import com.smartgwt.client.util.SC;
9 import com.smartgwt.client.widgets.Canvas; 8 import com.smartgwt.client.widgets.Canvas;
10 import com.smartgwt.client.widgets.Label; 9 import com.smartgwt.client.widgets.Label;
10 import com.smartgwt.client.widgets.form.fields.FormItem;
11 import com.smartgwt.client.widgets.form.fields.events.BlurEvent;
11 import com.smartgwt.client.widgets.form.fields.events.BlurHandler; 12 import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
12 import com.smartgwt.client.widgets.form.fields.events.BlurEvent; 13 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
13 import com.smartgwt.client.widgets.form.fields.FormItem;
14
15 import com.smartgwt.client.widgets.layout.HLayout; 14 import com.smartgwt.client.widgets.layout.HLayout;
16 import com.smartgwt.client.widgets.layout.VLayout; 15 import com.smartgwt.client.widgets.layout.VLayout;
17
18 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
19
20 import com.smartgwt.client.data.Record;
21 16
22 import de.intevation.flys.client.shared.model.Data; 17 import de.intevation.flys.client.shared.model.Data;
23 import de.intevation.flys.client.shared.model.DataItem; 18 import de.intevation.flys.client.shared.model.DataItem;
24 import de.intevation.flys.client.shared.model.DataList; 19 import de.intevation.flys.client.shared.model.DataList;
20
21 import java.util.ArrayList;
22 import java.util.List;
25 23
26 /** 24 /**
27 * This UIProvider serves as base for UI Providers to enter a single location (km). 25 * This UIProvider serves as base for UI Providers to enter a single location (km).
28 */ 26 */
29 public abstract class LocationPanel 27 public abstract class LocationPanel
30 extends AbstractUIProvider 28 extends AbstractUIProvider
31 { 29 {
30 private static final long serialVersionUID = -5306604428440015046L;
31
32 /** A container that will contain the location or the distance panel. */ 32 /** A container that will contain the location or the distance panel. */
33 protected HLayout inputLayout; 33 protected HLayout inputLayout;
34 34
35 /** The minimal value that the user is allowed to enter. */ 35 /** The minimal value that the user is allowed to enter. */
36 protected double min; 36 protected double min;
104 104
105 /** 105 /**
106 * This method creates a Canvas element showing the old Data objects in the 106 * This method creates a Canvas element showing the old Data objects in the
107 * DataList <i>data</i>. 107 * DataList <i>data</i>.
108 */ 108 */
109 @Override
109 public Canvas createOld(DataList dataList) { 110 public Canvas createOld(DataList dataList) {
110 findDataItemName(dataList); 111 findDataItemName(dataList);
111 112
112 List<Data> items = dataList.getAll(); 113 List<Data> items = dataList.getAll();
113 Data dLocation = getData(items, getDataItemName()); 114 Data dLocation = getData(items, getDataItemName());
140 * @param list The DataList container that stores the Data objects. 141 * @param list The DataList container that stores the Data objects.
141 */ 142 */
142 protected void initDefaults(DataList list) { 143 protected void initDefaults(DataList list) {
143 Data data = list.get(0); 144 Data data = list.get(0);
144 145
145 /* 146 DataItem[] items = data.getItems();
146 // Compatibility with MinMax- DataItems: 147 DataItem iMin = getDataItem(items, "min");
147 RangeData rangeData = null; 148 DataItem iMax = getDataItem(items, "max");
148 149
149 for (int i = 0, n = list.size(); i < n; i++) { 150 try {
150 Data tmp = list.get(i); 151 min = Double.parseDouble(iMin.getStringValue());
151 152 max = Double.parseDouble(iMax.getStringValue());
152 if (tmp instanceof RangeData) { 153 }
153 rangeData = (RangeData) tmp; 154 catch (NumberFormatException nfe) {
154 } 155 SC.warn(MSG.error_read_minmax_values());
155 } 156 min = -Double.MAX_VALUE;
156 157 max = Double.MAX_VALUE;
157 if (rangeData != null) {
158 min = Double.parseDouble(rangeData.getDefaultLower().toString());
159 max = Double.parseDouble(rangeData.getDefaultUpper().toString());
160 // catch ..?
161 }
162 */
163
164 if (false) {}
165 else {
166 DataItem[] items = data.getItems();
167 DataItem iMin = getDataItem(items, "min");
168 DataItem iMax = getDataItem(items, "max");
169
170 try {
171 min = Double.parseDouble(iMin.getStringValue());
172 max = Double.parseDouble(iMax.getStringValue());
173 }
174 catch (NumberFormatException nfe) {
175 SC.warn(MSG.error_read_minmax_values());
176 min = -Double.MAX_VALUE;
177 max = Double.MAX_VALUE;
178 }
179 } 158 }
180 159
181 DataItem def = data.getDefault(); 160 DataItem def = data.getDefault();
182 String value = def.getStringValue(); 161 String value = def.getStringValue();
183 162
184 try { 163 try {
185 double d = Double.parseDouble(value); 164 double d = Double.parseDouble(value);
186 setLocationValues(new double[] { d } ); 165 setLocationValues(new double[] { d } );
187 } 166 }
188 catch (NumberFormatException nfe) { 167 catch (NumberFormatException nfe) {
189 // could not parse, dont know what to do else 168 // could not parse, don't know what else to do
169 GWT.log("LocationPanel", nfe);
190 } 170 }
191 } 171 }
192 172
193 173
194 /** 174 /**
218 198
219 // The initial view will display the location input mode. 199 // The initial view will display the location input mode.
220 locationPanel = new DoubleArrayPanel( 200 locationPanel = new DoubleArrayPanel(
221 MSG.unitLocation(), 201 MSG.unitLocation(),
222 getLocationValues(), 202 getLocationValues(),
223 new BlurHandler(){public void onBlur(BlurEvent be) {}}); 203 new BlurHandler(){@Override
204 public void onBlur(BlurEvent be) {}});
224 205
225 // TODO Remove picker references, refactor such that subclasses can 206 // TODO Remove picker references, refactor such that subclasses can
226 // easily use their picker if they want. 207 // easily use their picker if they want.
227 //picker.getLocationTable().setAutoFetchData(true); 208 //picker.getLocationTable().setAutoFetchData(true);
228 209
282 263
283 return errors; 264 return errors;
284 } 265 }
285 266
286 267
287
288 /**
289 * This method returns the selected data.
290 *
291 * @return the selected/inserted data.
292 // TODO we are abstract because of this. Refactor to use DATA_NAME and
293 // similar fields for ld_mode .
294 public Data[] getData() {
295 saveLocationValues(locationPanel);
296 double[] values = getLocationValues();
297 Data[] data = new Data[values.length+1];
298
299 for (int i = 0; i < values.length; i++) {
300 data[i] = createDataArray(DATA_ITEM_NAME,
301 Double.valueOf(values[i]).toString());
302 }
303 data[values.length] = createDataArray("ld_mode", "locations");
304
305 return data;
306 }
307 */
308
309
310 /** 268 /**
311 * Validates and stores all values entered in the location mode. 269 * Validates and stores all values entered in the location mode.
312 * 270 *
313 * @param p The DoubleArrayPanel. 271 * @param p The DoubleArrayPanel.
314 */ 272 */
360 try { 318 try {
361 selected[0] = 319 selected[0] =
362 Double.parseDouble(record.getAttribute("from")); 320 Double.parseDouble(record.getAttribute("from"));
363 } 321 }
364 catch(NumberFormatException nfe) { 322 catch(NumberFormatException nfe) {
365 // Is there anything else to do here? 323 GWT.log("onRecordClick", nfe);
366 } 324 }
367 setLocationValues(selected); 325 setLocationValues(selected);
368 } 326 }
369 } 327 }
370 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 328 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org