comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.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 a5e96a36478c
children 94d9c8353ca9
comparison
equal deleted inserted replaced
862:c9549074ecd1 863:9bb8b7a751ec
6 6
7 import com.google.gwt.core.client.GWT; 7 import com.google.gwt.core.client.GWT;
8 import com.google.gwt.i18n.client.NumberFormat; 8 import com.google.gwt.i18n.client.NumberFormat;
9 import com.google.gwt.user.client.rpc.AsyncCallback; 9 import com.google.gwt.user.client.rpc.AsyncCallback;
10 10
11 import com.smartgwt.client.data.Criteria;
11 import com.smartgwt.client.widgets.Canvas; 12 import com.smartgwt.client.widgets.Canvas;
12 import com.smartgwt.client.widgets.Label; 13 import com.smartgwt.client.widgets.Label;
13 import com.smartgwt.client.widgets.form.DynamicForm; 14 import com.smartgwt.client.widgets.form.DynamicForm;
14 import com.smartgwt.client.widgets.form.fields.events.BlurHandler; 15 import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
15 import com.smartgwt.client.widgets.form.fields.events.BlurEvent; 16 import com.smartgwt.client.widgets.form.fields.events.BlurEvent;
45 import de.intevation.flys.client.client.services.DistanceInfoService; 46 import de.intevation.flys.client.client.services.DistanceInfoService;
46 import de.intevation.flys.client.client.services.DistanceInfoServiceAsync; 47 import de.intevation.flys.client.client.services.DistanceInfoServiceAsync;
47 import de.intevation.flys.client.client.FLYSConstants; 48 import de.intevation.flys.client.client.FLYSConstants;
48 import de.intevation.flys.client.client.FLYSImages; 49 import de.intevation.flys.client.client.FLYSImages;
49 import de.intevation.flys.client.client.Config; 50 import de.intevation.flys.client.client.Config;
51 import de.intevation.flys.client.client.event.FilterHandler;
52 import de.intevation.flys.client.client.event.StringFilterEvent;
53 import de.intevation.flys.client.client.ui.range.DistanceInfoDataSource;
54 import de.intevation.flys.client.client.ui.range.RangeTable;
55 import de.intevation.flys.client.client.ui.range.LocationsTable;
50 56
51 57
52 /** 58 /**
53 * This UIProvider creates a widget to enter locations or a distance. 59 * This UIProvider creates a widget to enter locations or a distance.
54 * 60 *
55 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 61 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
56 */ 62 */
57 public class LocationDistancePanel 63 public class LocationDistancePanel
58 extends AbstractUIProvider 64 extends AbstractUIProvider
59 implements ChangeHandler, BlurHandler 65 implements ChangeHandler, BlurHandler, FilterHandler
60 { 66 {
61 /** The message class that provides i18n strings. */ 67 /** The message class that provides i18n strings. */
62 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); 68 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
63 69
64 /** The interface that provides the image resources. */ 70 /** The interface that provides the image resources. */
137 /** 143 /**
138 * Creates a new LocationDistancePanel instance. 144 * Creates a new LocationDistancePanel instance.
139 */ 145 */
140 public LocationDistancePanel() { 146 public LocationDistancePanel() {
141 distanceTable = new ListGrid(); 147 distanceTable = new ListGrid();
148 distanceTable.setAutoFetchData(true);
149
142 locationsTable = new ListGrid(); 150 locationsTable = new ListGrid();
151 locationsTable.setAutoFetchData(true);
152
143 locationDistanceTable = new ListGrid(); 153 locationDistanceTable = new ListGrid();
154 locationDistanceTable.setAutoFetchData(true);
155
144 locationDistanceTable.setShowHeaderContextMenu(false); 156 locationDistanceTable.setShowHeaderContextMenu(false);
145 distanceTable.setShowHeaderContextMenu(false); 157 distanceTable.setShowHeaderContextMenu(false);
146 locationsTable.setShowHeaderContextMenu(false); 158 locationsTable.setShowHeaderContextMenu(false);
147 } 159 }
148 160
165 Canvas submit = getNextButton(); 177 Canvas submit = getNextButton();
166 createDistanceInputPanel(); 178 createDistanceInputPanel();
167 179
168 initDefaults(data); 180 initDefaults(data);
169 181
182 createLocationTableDistance ();
170 createDistanceTable(); 183 createDistanceTable();
171 createLocationTable(); 184 createLocationTable();
172 createLocationTableDistance ();
173 185
174 widget.setHeight(50); 186 widget.setHeight(50);
175 label.setHeight(25); 187 label.setHeight(25);
176 188
177 layout.addMember(label); 189 layout.addMember(label);
184 196
185 /** 197 /**
186 * This method creates a table that contains the distance values. 198 * This method creates a table that contains the distance values.
187 */ 199 */
188 protected void createDistanceTable() { 200 protected void createDistanceTable() {
201
189 distanceTable.setWidth100(); 202 distanceTable.setWidth100();
190 distanceTable.setShowRecordComponents(true); 203 distanceTable.setShowRecordComponents(true);
191 distanceTable.setShowRecordComponentsByCell(true); 204 distanceTable.setShowRecordComponentsByCell(true);
192 distanceTable.setHeight100(); 205 distanceTable.setHeight100();
193 distanceTable.setEmptyMessage(MESSAGES.empty_table()); 206 distanceTable.setEmptyMessage(MESSAGES.empty_table());
197 addDistance.setWidth (20); 210 addDistance.setWidth (20);
198 addDistance.addRecordClickHandler (new RecordClickHandler () { 211 addDistance.addRecordClickHandler (new RecordClickHandler () {
199 public void onRecordClick (RecordClickEvent e) { 212 public void onRecordClick (RecordClickEvent e) {
200 if (!isLocationMode ()) { 213 if (!isLocationMode ()) {
201 Record r = e.getRecord(); 214 Record r = e.getRecord();
202 double min = r.getAttributeAsDouble("from"); 215 try {
203 double max = r.getAttributeAsDouble("to"); 216 double min = Double.parseDouble(r.getAttribute("from"));
204 setDistanceValues(min, max); 217 double max = Double.parseDouble(r.getAttribute("to"));
218 setDistanceValues(min, max);
219 }
220 catch(NumberFormatException nfe) {
221 // Is there anything to do?
222 }
205 } 223 }
206 else { 224 else {
207 double[] selected; 225 double[] selected;
208 Record r = e.getRecord(); 226 Record r = e.getRecord();
209 double min = r.getAttributeAsDouble("from"); 227 double min = 0, max = 0;
210 double max = r.getAttributeAsDouble("to"); 228 try {
229 min = Double.parseDouble(r.getAttribute("from"));
230 max = Double.parseDouble(r.getAttribute("to"));
231 }
232 catch(NumberFormatException nfe) {
233 // Is there anything to do?
234 }
211 if (getLocationValues() != null) { 235 if (getLocationValues() != null) {
212 double[] val = getLocationValues(); 236 double[] val = getLocationValues();
213 selected = new double[val.length + 2]; 237 selected = new double[val.length + 2];
214 for(int i = 0; i < val.length; i++){ 238 for(int i = 0; i < val.length; i++){
215 selected[i] = val[i]; 239 selected[i] = val[i];
272 addLocation.setType (ListGridFieldType.ICON); 296 addLocation.setType (ListGridFieldType.ICON);
273 addLocation.setWidth (20); 297 addLocation.setWidth (20);
274 298
275 addLocation.addRecordClickHandler (new RecordClickHandler () { 299 addLocation.addRecordClickHandler (new RecordClickHandler () {
276 public void onRecordClick (RecordClickEvent e) { 300 public void onRecordClick (RecordClickEvent e) {
277 ListGridRecord[] records = locationsTable.getSelection(); 301 Record record = e.getRecord();
278 double[] selected; 302 double[] selected;
279 if (getLocationValues() != null) { 303 if (getLocationValues() != null) {
280 double[] val = getLocationValues(); 304 double[] val = getLocationValues();
281 selected = new double[val.length + 1]; 305 selected = new double[val.length + 1];
282 for(int i = 0; i < val.length; i++){ 306 for(int i = 0; i < val.length; i++){
283 selected[i] = val[i]; 307 selected[i] = val[i];
284 } 308 }
285 selected[val.length] = 309 try {
286 records[0].getAttributeAsDouble("from"); 310 selected[val.length] =
311 Double.parseDouble(record.getAttribute("from"));
312 }
313 catch(NumberFormatException nfe) {
314 // Is there anything to do here?
315 }
287 } 316 }
288 else { 317 else {
289 selected = new double[1]; 318 selected = new double[1];
290 selected[0] = records[0].getAttributeAsDouble("from"); 319 selected[0] =
320 Double.parseDouble(record.getAttribute("from"));
291 } 321 }
292 setLocationValues(selected); 322 setLocationValues(selected);
293 } 323 }
294 }); 324 });
295 addLocation.setCellIcon (IMAGES.markerGreen ().getURL ()); 325 addLocation.setCellIcon (IMAGES.markerGreen ().getURL ());
322 352
323 /** 353 /**
324 * This method creates a table that contains the location values. 354 * This method creates a table that contains the location values.
325 */ 355 */
326 protected void createLocationTableDistance (){ 356 protected void createLocationTableDistance (){
327 locationDistanceTable = null;
328 locationDistanceTable = new ListGrid ();
329 locationDistanceTable.setWidth100(); 357 locationDistanceTable.setWidth100();
330 locationDistanceTable.setShowRecordComponents(true); 358 locationDistanceTable.setShowRecordComponents(true);
331 locationDistanceTable.setShowRecordComponentsByCell(true); 359 locationDistanceTable.setShowRecordComponentsByCell(true);
332 locationDistanceTable.setHeight100(); 360 locationDistanceTable.setHeight100();
333 locationDistanceTable.setEmptyMessage(MESSAGES.empty_table()); 361 locationDistanceTable.setEmptyMessage(MESSAGES.empty_table());
340 ListGridField addto2 = new ListGridField ("", ""); 368 ListGridField addto2 = new ListGridField ("", "");
341 addto2.setType (ListGridFieldType.ICON); 369 addto2.setType (ListGridFieldType.ICON);
342 addto2.setWidth (20); 370 addto2.setWidth (20);
343 addto2.setCellIcon (IMAGES.markerRed ().getURL ()); 371 addto2.setCellIcon (IMAGES.markerRed ().getURL ());
344 372
373 locationDistanceTable.addCellClickHandler (new CellClickHandler () {
374 public void onCellClick (CellClickEvent e) {
375 if (e.getColNum() == 0) {
376 Record r = e.getRecord ();
377 try {
378 double fromvalue =
379 Double.parseDouble(r.getAttribute("from"));
380 double tovalue = getTo ();
381 setDistanceValues (fromvalue, tovalue);
382 }
383 catch(NumberFormatException nfe) {
384 // Is there anything to do in here?
385 }
386 }
387 else if (e.getColNum() == 1) {
388 Record r = e.getRecord ();
389 try {
390 double fromvalue = getFrom ();
391 double tovalue =
392 Double.parseDouble(r.getAttribute("from"));
393 setDistanceValues (fromvalue, tovalue);
394 }
395 catch(NumberFormatException nfe) {
396 // Is there anything to do in here?
397 }
398 }
399 }
400 });
401 ListGridField bottom =
402 new ListGridField("bottom", MESSAGES.bottom_edge());
403 bottom.setType(ListGridFieldType.TEXT);
404 bottom.setWidth(30);
405
406 ListGridField top =
407 new ListGridField("top", MESSAGES.top_edge());
408 top.setType(ListGridFieldType.TEXT);
409 top.setWidth(30);
345 410
346 ListGridField ldescr = new ListGridField("description", 411 ListGridField ldescr = new ListGridField("description",
347 MESSAGES.description()); 412 MESSAGES.description());
348 ldescr.setType(ListGridFieldType.TEXT); 413 ldescr.setType(ListGridFieldType.TEXT);
349 ldescr.setWidth("*"); 414 ldescr.setWidth("*");
352 lside.setType(ListGridFieldType.TEXT); 417 lside.setType(ListGridFieldType.TEXT);
353 lside.setWidth(40); 418 lside.setWidth(40);
354 ListGridField loc = new ListGridField("from", MESSAGES.locations()); 419 ListGridField loc = new ListGridField("from", MESSAGES.locations());
355 loc.setType(ListGridFieldType.TEXT); 420 loc.setType(ListGridFieldType.TEXT);
356 loc.setWidth(40); 421 loc.setWidth(40);
357 locationDistanceTable.addCellClickHandler (new CellClickHandler () {
358 public void onCellClick (CellClickEvent e) {
359 if (e.getColNum() == 0) {
360 Record r = e.getRecord ();
361 double fromvalue = r.getAttributeAsDouble ("from");
362 double tovalue = getTo ();
363 setDistanceValues (fromvalue, tovalue);
364 }
365 else if (e.getColNum() == 1) {
366 Record r = e.getRecord ();
367 double fromvalue = getFrom ();
368 double tovalue = r.getAttributeAsDouble ("to");
369 setDistanceValues (fromvalue, tovalue);
370 }
371 }
372 });
373 ListGridField bottom =
374 new ListGridField("bottom", MESSAGES.bottom_edge());
375 bottom.setType(ListGridFieldType.TEXT);
376 bottom.setWidth(30);
377
378 ListGridField top =
379 new ListGridField("top", MESSAGES.top_edge());
380 top.setType(ListGridFieldType.TEXT);
381 top.setWidth(30);
382 422
383 locationDistanceTable.setFields( 423 locationDistanceTable.setFields(
384 addfrom, addto2, ldescr, loc, lside, bottom, top); 424 addfrom, addto2, ldescr, loc, lside, bottom, top);
385 } 425 }
386 426
560 Tab distances = new Tab(MESSAGES.distance()); 600 Tab distances = new Tab(MESSAGES.distance());
561 601
562 inputTables.setWidth100(); 602 inputTables.setWidth100();
563 inputTables.setHeight100(); 603 inputTables.setHeight100();
564 604
565 locations.setPane(locationsTable); 605 locations.setPane(locationDistanceTable);
566 distances.setPane(distanceTable); 606 distances.setPane(distanceTable);
567 607
568 inputTables.addTab(locations); 608 inputTables.addTab(locations);
569 inputTables.addTab(distances); 609 inputTables.addTab(distances);
570 610
571 helperContainer.addMember(inputTables); 611 TableFilter filter = new TableFilter();
612 filter.setHeight("30px");
613 filter.addFilterHandler(this);
614
615 inputTables.setHeight("*");
616
617 VLayout helper = new VLayout();
618 helper.addMember(inputTables);
619 helper.addMember(filter);
620 helper.setHeight100();
621 helper.setWidth100();
622
623 helperContainer.addChild(helper);
572 624
573 return layout; 625 return layout;
574 } 626 }
627
628
629 public void onFilterCriteriaChanged(StringFilterEvent event) {
630 String search = event.getFilter();
631
632 if (search != null && search.length() > 0) {
633 Criteria c = new Criteria("description", search);
634
635 locationsTable.filterData(c);
636 distanceTable.filterData(c);
637 locationDistanceTable.filterData(c);
638 }
639 else {
640 // TODO Remove filter
641 }
642 }
643
644
575 645
576 646
577 @Override 647 @Override
578 public List<String> validate() { 648 public List<String> validate() {
579 if (isLocationMode()) { 649 if (isLocationMode()) {
857 if (value == null) { 927 if (value == null) {
858 return; 928 return;
859 } 929 }
860 if (value.equals(FIELD_VALUE_LOCATION)) { 930 if (value.equals(FIELD_VALUE_LOCATION)) {
861 enableLocationPanel(); 931 enableLocationPanel();
862 932 // Remove the tab containing the locationDistanceTable.
863 while (inputTables.getNumTabs() > 0) { 933 // The 'updateTab()' avoids the tab content to be destroyed.
864 inputTables.removeTab(0); 934 inputTables.updateTab(0, null);
865 } 935 inputTables.removeTab(0);
936
937 // Create a new tab containing the locationTable
866 Tab t1 = new Tab (MESSAGES.locations()); 938 Tab t1 = new Tab (MESSAGES.locations());
867 createLocationTable();
868 t1.setPane(locationsTable); 939 t1.setPane(locationsTable);
869 inputTables.addTab(t1); 940 inputTables.addTab(t1, 0);
870 createDistanceTable(); 941
871 Tab t2 = new Tab (MESSAGES.distance()); 942 // Bring this tab to front.
872 t2.setPane(distanceTable);
873 inputTables.addTab(t2);
874 updateDistanceInfo(tableData);
875
876 helperContainer.addMember(inputTables);
877 inputTables.selectTab(0); 943 inputTables.selectTab(0);
878 } 944 }
879 else { 945 else {
880 enableDistancePanel(); 946 enableDistancePanel();
881 947 // Remove the tab containing the locationTable.
882 while (inputTables.getNumTabs () > 0) { 948 // The 'updateTab()' avoids the tab content to be destroyed.
883 inputTables.removeTab(0); 949 inputTables.updateTab(0, null);
884 } 950 inputTables.removeTab(0);
951
952 //Create a new tab containing the locationDistanceTable.
885 Tab t1 = new Tab(MESSAGES.locations()); 953 Tab t1 = new Tab(MESSAGES.locations());
886 createLocationTableDistance ();
887 t1.setPane(locationDistanceTable); 954 t1.setPane(locationDistanceTable);
888 inputTables.addTab(t1); 955 inputTables.addTab(t1, 0);
889 createDistanceTable (); 956
890 Tab t2 = new Tab(MESSAGES.distance ()); 957 // Bring the distanceTable tab to front.
891 t2.setPane(distanceTable);
892 inputTables.addTab(t2);
893 if (tableData != null) {
894 updateDistanceInfo(tableData);
895 }
896
897 helperContainer.addMember(inputTables);
898 inputTables.selectTab(1); 958 inputTables.selectTab(1);
899 } 959 }
900 } 960 }
901 961
902 962
1038 } 1098 }
1039 } 1099 }
1040 } 1100 }
1041 } 1101 }
1042 1102
1043 distanceInfoService.getDistanceInfo(url, locale, river, 1103 distanceTable.setDataSource(new DistanceInfoDataSource(
1044 new AsyncCallback<DistanceInfoObject[]>() { 1104 url, river, "distances"));
1045 public void onFailure(Throwable caught) { 1105 locationsTable.setDataSource(new DistanceInfoDataSource(
1046 GWT.log("Could not recieve distance informations."); 1106 url, river, "locations"));
1047 GWT.log(caught.getMessage()); 1107 locationDistanceTable.setDataSource(new DistanceInfoDataSource(
1048 } 1108 url, river, "locations"));
1049 1109 }
1050 public void onSuccess(DistanceInfoObject[] di) { 1110
1051 int num = di != null ? di.length :0; 1111
1052 GWT.log("Recieved " + num + " distance informations."); 1112 /* protected void updateDistanceInfo(DistanceInfoObject[] di) {
1053
1054 if (num == 0) {
1055 return;
1056 }
1057 tableData = di;
1058 updateDistanceInfo(di);
1059 }
1060 }
1061 );
1062 }
1063
1064
1065 protected void updateDistanceInfo(DistanceInfoObject[] di) {
1066 int i = 0; 1113 int i = 0;
1067 for (DistanceInfoObject dio: di) { 1114 for (DistanceInfoObject dio: di) {
1068 if (dio.getTo() != null) { 1115 if (dio.getTo() != null) {
1069 distanceTable.addData(new DistanceInfoRecord(dio)); 1116 distanceTable.addData(new DistanceInfoRecord(dio));
1070 } 1117 }
1072 locationsTable.addData(new DistanceInfoRecord(dio)); 1119 locationsTable.addData(new DistanceInfoRecord(dio));
1073 locationDistanceTable.addData(new DistanceInfoRecord(dio)); 1120 locationDistanceTable.addData(new DistanceInfoRecord(dio));
1074 } 1121 }
1075 } 1122 }
1076 return; 1123 return;
1077 } 1124 }*/
1078 1125
1079 1126
1080 protected double getFrom() { 1127 protected double getFrom() {
1081 return from; 1128 return from;
1082 } 1129 }

http://dive4elements.wald.intevation.org