comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java @ 863:9bb8b7a751ec

Added filter for the "description" row of helper input tables. flys-client/trunk@2670 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 07 Sep 2011 17:22:21 +0000
parents dfbc6693247e
children d08cf5ed1bfc
comparison
equal deleted inserted replaced
862:c9549074ecd1 863:9bb8b7a751ec
19 import com.smartgwt.client.widgets.grid.ListGridField; 19 import com.smartgwt.client.widgets.grid.ListGridField;
20 import com.smartgwt.client.widgets.grid.ListGridRecord; 20 import com.smartgwt.client.widgets.grid.ListGridRecord;
21 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; 21 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
22 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; 22 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
23 23
24 import com.smartgwt.client.data.Criteria;
25 import com.smartgwt.client.data.Record;
24 import com.smartgwt.client.types.ListGridFieldType; 26 import com.smartgwt.client.types.ListGridFieldType;
25 27
26 import de.intevation.flys.client.shared.model.Data; 28 import de.intevation.flys.client.shared.model.Data;
27 import de.intevation.flys.client.shared.model.DataItem; 29 import de.intevation.flys.client.shared.model.DataItem;
28 import de.intevation.flys.client.shared.model.DataList; 30 import de.intevation.flys.client.shared.model.DataList;
35 import de.intevation.flys.client.client.services.DistanceInfoService; 37 import de.intevation.flys.client.client.services.DistanceInfoService;
36 import de.intevation.flys.client.client.services.DistanceInfoServiceAsync; 38 import de.intevation.flys.client.client.services.DistanceInfoServiceAsync;
37 import de.intevation.flys.client.client.FLYSConstants; 39 import de.intevation.flys.client.client.FLYSConstants;
38 import de.intevation.flys.client.client.FLYSImages; 40 import de.intevation.flys.client.client.FLYSImages;
39 import de.intevation.flys.client.client.Config; 41 import de.intevation.flys.client.client.Config;
42 import de.intevation.flys.client.client.ui.range.DistanceInfoDataSource;
43 import de.intevation.flys.client.client.event.FilterHandler;
44 import de.intevation.flys.client.client.event.StringFilterEvent;
40 45
41 46
42 /** 47 /**
43 * This UIProvider creates a widget to enter locations. 48 * This UIProvider creates a widget to enter locations.
44 * 49 *
45 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 50 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
46 */ 51 */
47 public class SingleLocationPanel 52 public class SingleLocationPanel
48 extends AbstractUIProvider 53 extends AbstractUIProvider
54 implements FilterHandler
49 { 55 {
50 /** The message class that provides i18n strings.*/ 56 /** The message class that provides i18n strings.*/
51 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); 57 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
52 58
53 /** The interface that provides the image resources. */ 59 /** The interface that provides the image resources. */
133 ListGridField addLocation = new ListGridField ("", ""); 139 ListGridField addLocation = new ListGridField ("", "");
134 addLocation.setType (ListGridFieldType.ICON); 140 addLocation.setType (ListGridFieldType.ICON);
135 addLocation.setWidth (20); 141 addLocation.setWidth (20);
136 addLocation.addRecordClickHandler (new RecordClickHandler () { 142 addLocation.addRecordClickHandler (new RecordClickHandler () {
137 public void onRecordClick (RecordClickEvent e) { 143 public void onRecordClick (RecordClickEvent e) {
138 ListGridRecord[] records = locationTable.getSelection(); 144 Record record = e.getRecord();
139 double[] selected = new double[1]; 145 double[] selected = new double[1];
140 selected[0] = records[0].getAttributeAsDouble("from"); 146 try {
147 selected[0] =
148 Double.parseDouble(record.getAttribute("from"));
149 }
150 catch(NumberFormatException nfe) {
151 // Is there anything else to do here?
152 }
141 setLocationValues(selected); 153 setLocationValues(selected);
142 } 154 }
143 }); 155 });
144 addLocation.setCellIcon (IMAGES.markerGreen ().getURL ()); 156 addLocation.setCellIcon (IMAGES.markerGreen ().getURL ());
145 157
262 // the initial view will display the location input mode 274 // the initial view will display the location input mode
263 locationPanel = new DoubleArrayPanel( 275 locationPanel = new DoubleArrayPanel(
264 MESSAGES.unitLocation(), 276 MESSAGES.unitLocation(),
265 getLocationValues(), 277 getLocationValues(),
266 new BlurHandler(){public void onBlur(BlurEvent be) {}}); 278 new BlurHandler(){public void onBlur(BlurEvent be) {}});
279
280 locationTable.setAutoFetchData(true);
281
267 container.addMember(locationPanel); 282 container.addMember(locationPanel);
268 283
269 layout.addMember(container); 284 layout.addMember(container);
270 285
271 container.setMembersMargin(30); 286 container.setMembersMargin(30);
272 287
288 TableFilter filter = new TableFilter();
289 filter.setHeight("30px");
290 filter.addFilterHandler(this);
291
273 helperContainer.addMember(locationTable); 292 helperContainer.addMember(locationTable);
293 helperContainer.addMember(filter);
274 createInputPanel(); 294 createInputPanel();
275 return layout; 295 return layout;
276 } 296 }
277 297
298 public void onFilterCriteriaChanged(StringFilterEvent event) {
299 String search = event.getFilter();
300
301 if (search != null && search.length() > 0) {
302 Criteria c = new Criteria("description", search);
303 locationTable.filterData(c);
304 }
305 else {
306 // TODO Remove filter
307 }
308 }
278 309
279 @Override 310 @Override
280 public List<String> validate() { 311 public List<String> validate() {
281 List<String> errors = new ArrayList<String>(); 312 List<String> errors = new ArrayList<String>();
282 NumberFormat nf = NumberFormat.getDecimalFormat(); 313 NumberFormat nf = NumberFormat.getDecimalFormat();
397 } 428 }
398 } 429 }
399 } 430 }
400 } 431 }
401 432
402 distanceInfoService.getDistanceInfo(url, locale, river, 433 locationTable.setDataSource(new DistanceInfoDataSource(
403 new AsyncCallback<DistanceInfoObject[]>() { 434 url, river, "locations"));
404 public void onFailure(Throwable caught) {
405 GWT.log("Could not recieve location informations.");
406 GWT.log(caught.getMessage());
407 }
408
409 public void onSuccess(DistanceInfoObject[] di) {
410 int num = di != null ? di.length :0;
411 GWT.log("Recieved " + num + " location informations.");
412
413 if (num == 0) {
414 return;
415 }
416 tableData = di;
417 updateLocationInfo(di);
418 }
419 }
420 );
421 }
422
423
424 protected void updateLocationInfo(DistanceInfoObject[] di) {
425 int i = 0;
426 for (DistanceInfoObject dio: di) {
427 if (dio.getTo() == null) {
428 locationTable.addData(new DistanceInfoRecord(dio));
429 }
430 }
431 return;
432 } 435 }
433 436
434 437
435 protected double[] getLocationValues() { 438 protected double[] getLocationValues() {
436 return values; 439 return values;

http://dive4elements.wald.intevation.org