diff 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
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java	Wed Sep 07 13:57:28 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java	Wed Sep 07 17:22:21 2011 +0000
@@ -8,6 +8,7 @@
 import com.google.gwt.i18n.client.NumberFormat;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
+import com.smartgwt.client.data.Criteria;
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.form.DynamicForm;
@@ -47,6 +48,11 @@
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.FLYSImages;
 import de.intevation.flys.client.client.Config;
+import de.intevation.flys.client.client.event.FilterHandler;
+import de.intevation.flys.client.client.event.StringFilterEvent;
+import de.intevation.flys.client.client.ui.range.DistanceInfoDataSource;
+import de.intevation.flys.client.client.ui.range.RangeTable;
+import de.intevation.flys.client.client.ui.range.LocationsTable;
 
 
 /**
@@ -56,7 +62,7 @@
  */
 public class LocationDistancePanel
 extends      AbstractUIProvider
-implements   ChangeHandler, BlurHandler
+implements   ChangeHandler, BlurHandler, FilterHandler
 {
     /** The message class that provides i18n strings. */
     protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
@@ -139,8 +145,14 @@
      */
     public LocationDistancePanel() {
         distanceTable  = new ListGrid();
+        distanceTable.setAutoFetchData(true);
+
         locationsTable = new ListGrid();
+        locationsTable.setAutoFetchData(true);
+
         locationDistanceTable = new ListGrid();
+        locationDistanceTable.setAutoFetchData(true);
+
         locationDistanceTable.setShowHeaderContextMenu(false);
         distanceTable.setShowHeaderContextMenu(false);
         locationsTable.setShowHeaderContextMenu(false);
@@ -167,9 +179,9 @@
 
         initDefaults(data);
 
+        createLocationTableDistance ();
         createDistanceTable();
         createLocationTable();
-        createLocationTableDistance ();
 
         widget.setHeight(50);
         label.setHeight(25);
@@ -186,6 +198,7 @@
      * This method creates a table that contains the distance values.
      */
     protected void createDistanceTable() {
+
         distanceTable.setWidth100();
         distanceTable.setShowRecordComponents(true);
         distanceTable.setShowRecordComponentsByCell(true);
@@ -199,15 +212,26 @@
             public void onRecordClick (RecordClickEvent e) {
                 if (!isLocationMode ()) {
                     Record r = e.getRecord();
-                    double min = r.getAttributeAsDouble("from");
-                    double max = r.getAttributeAsDouble("to");
-                    setDistanceValues(min, max);
+                    try {
+                        double min = Double.parseDouble(r.getAttribute("from"));
+                        double max = Double.parseDouble(r.getAttribute("to"));
+                        setDistanceValues(min, max);
+                    }
+                    catch(NumberFormatException nfe) {
+                        // Is there anything to do?
+                    }
                 }
                 else {
                     double[] selected;
                     Record r = e.getRecord();
-                    double min = r.getAttributeAsDouble("from");
-                    double max = r.getAttributeAsDouble("to");
+                    double min = 0, max = 0;
+                    try {
+                        min = Double.parseDouble(r.getAttribute("from"));
+                        max = Double.parseDouble(r.getAttribute("to"));
+                    }
+                    catch(NumberFormatException nfe) {
+                        // Is there anything to do?
+                    }
                     if (getLocationValues() != null) {
                         double[] val = getLocationValues();
                         selected = new double[val.length + 2];
@@ -274,7 +298,7 @@
 
         addLocation.addRecordClickHandler (new RecordClickHandler () {
             public void onRecordClick (RecordClickEvent e) {
-                ListGridRecord[] records = locationsTable.getSelection();
+                Record record = e.getRecord();
                 double[] selected;
                 if (getLocationValues() != null) {
                     double[] val = getLocationValues();
@@ -282,12 +306,18 @@
                     for(int i = 0; i < val.length; i++){
                         selected[i] = val[i];
                     }
-                    selected[val.length] =
-                        records[0].getAttributeAsDouble("from");
+                    try {
+                        selected[val.length] =
+                            Double.parseDouble(record.getAttribute("from"));
+                    }
+                    catch(NumberFormatException nfe) {
+                        // Is there anything to do here?
+                    }
                 }
                 else {
                     selected = new double[1];
-                    selected[0] = records[0].getAttributeAsDouble("from");
+                    selected[0] =
+                        Double.parseDouble(record.getAttribute("from"));
                 }
                 setLocationValues(selected);
             }
@@ -324,8 +354,6 @@
      * This method creates a table that contains the location values.
      */
     protected void createLocationTableDistance (){
-        locationDistanceTable = null;
-        locationDistanceTable = new ListGrid ();
         locationDistanceTable.setWidth100();
         locationDistanceTable.setShowRecordComponents(true);
         locationDistanceTable.setShowRecordComponentsByCell(true);
@@ -342,6 +370,43 @@
         addto2.setWidth (20);
         addto2.setCellIcon (IMAGES.markerRed ().getURL ());
 
+        locationDistanceTable.addCellClickHandler (new CellClickHandler () {
+            public void onCellClick (CellClickEvent e) {
+                if (e.getColNum() == 0) {
+                    Record r = e.getRecord ();
+                    try {
+                        double fromvalue =
+                             Double.parseDouble(r.getAttribute("from"));
+                        double tovalue = getTo ();
+                        setDistanceValues (fromvalue, tovalue);
+                    }
+                    catch(NumberFormatException nfe) {
+                        // Is there anything to do in here?
+                    }
+                }
+                else if (e.getColNum() == 1) {
+                    Record r = e.getRecord ();
+                    try {
+                        double fromvalue = getFrom ();
+                        double tovalue =
+                            Double.parseDouble(r.getAttribute("from"));
+                        setDistanceValues (fromvalue, tovalue);
+                    }
+                    catch(NumberFormatException nfe) {
+                        // Is there anything to do in here?
+                    }
+                }
+            }
+        });
+        ListGridField bottom =
+            new ListGridField("bottom", MESSAGES.bottom_edge());
+        bottom.setType(ListGridFieldType.TEXT);
+        bottom.setWidth(30);
+
+        ListGridField top =
+            new ListGridField("top", MESSAGES.top_edge());
+        top.setType(ListGridFieldType.TEXT);
+        top.setWidth(30);
 
         ListGridField ldescr = new ListGridField("description",
                 MESSAGES.description());
@@ -354,31 +419,6 @@
         ListGridField loc = new ListGridField("from", MESSAGES.locations());
         loc.setType(ListGridFieldType.TEXT);
         loc.setWidth(40);
-        locationDistanceTable.addCellClickHandler (new CellClickHandler () {
-            public void onCellClick (CellClickEvent e) {
-                if (e.getColNum() == 0) {
-                    Record r = e.getRecord ();
-                    double fromvalue = r.getAttributeAsDouble ("from");
-                    double tovalue = getTo ();
-                    setDistanceValues (fromvalue, tovalue);
-                }
-                else if (e.getColNum() == 1) {
-                    Record r = e.getRecord ();
-                    double fromvalue = getFrom ();
-                    double tovalue = r.getAttributeAsDouble ("to");
-                    setDistanceValues (fromvalue, tovalue);
-                }
-            }
-        });
-        ListGridField bottom =
-            new ListGridField("bottom", MESSAGES.bottom_edge());
-        bottom.setType(ListGridFieldType.TEXT);
-        bottom.setWidth(30);
-
-        ListGridField top =
-            new ListGridField("top", MESSAGES.top_edge());
-        top.setType(ListGridFieldType.TEXT);
-        top.setWidth(30);
 
         locationDistanceTable.setFields(
             addfrom, addto2, ldescr, loc, lside, bottom, top);
@@ -562,18 +602,48 @@
         inputTables.setWidth100();
         inputTables.setHeight100();
 
-        locations.setPane(locationsTable);
+        locations.setPane(locationDistanceTable);
         distances.setPane(distanceTable);
 
         inputTables.addTab(locations);
         inputTables.addTab(distances);
 
-        helperContainer.addMember(inputTables);
+        TableFilter filter = new TableFilter();
+        filter.setHeight("30px");
+        filter.addFilterHandler(this);
+
+        inputTables.setHeight("*");
+
+        VLayout helper = new VLayout();
+        helper.addMember(inputTables);
+        helper.addMember(filter);
+        helper.setHeight100();
+        helper.setWidth100();
+
+        helperContainer.addChild(helper);
 
         return layout;
     }
 
 
+    public void onFilterCriteriaChanged(StringFilterEvent event) {
+        String search = event.getFilter();
+
+        if (search != null && search.length() > 0) {
+            Criteria c = new Criteria("description", search);
+
+            locationsTable.filterData(c);
+            distanceTable.filterData(c);
+            locationDistanceTable.filterData(c);
+        }
+        else {
+            // TODO Remove filter
+        }
+    }
+
+
+
+
     @Override
     public List<String> validate() {
         if (isLocationMode()) {
@@ -859,42 +929,32 @@
         }
         if (value.equals(FIELD_VALUE_LOCATION)) {
             enableLocationPanel();
+            // Remove the tab containing the locationDistanceTable.
+            // The 'updateTab()' avoids the tab content to be destroyed.
+            inputTables.updateTab(0, null);
+            inputTables.removeTab(0);
 
-            while (inputTables.getNumTabs() > 0) {
-                inputTables.removeTab(0);
-            }
+            // Create a new tab containing the locationTable
             Tab t1 = new Tab (MESSAGES.locations());
-            createLocationTable();
             t1.setPane(locationsTable);
-            inputTables.addTab(t1);
-            createDistanceTable();
-            Tab t2 = new Tab (MESSAGES.distance());
-            t2.setPane(distanceTable);
-            inputTables.addTab(t2);
-            updateDistanceInfo(tableData);
+            inputTables.addTab(t1, 0);
 
-            helperContainer.addMember(inputTables);
+            // Bring this tab to front.
             inputTables.selectTab(0);
         }
         else {
             enableDistancePanel();
+            // Remove the tab containing the locationTable.
+            // The 'updateTab()' avoids the tab content to be destroyed.
+            inputTables.updateTab(0, null);
+            inputTables.removeTab(0);
 
-            while (inputTables.getNumTabs () > 0) {
-                inputTables.removeTab(0);
-            }
+            //Create a new tab containing the locationDistanceTable.
             Tab t1 = new Tab(MESSAGES.locations());
-            createLocationTableDistance ();
             t1.setPane(locationDistanceTable);
-            inputTables.addTab(t1);
-            createDistanceTable ();
-            Tab t2 = new Tab(MESSAGES.distance ());
-            t2.setPane(distanceTable);
-            inputTables.addTab(t2);
-            if (tableData != null) {
-                updateDistanceInfo(tableData);
-            }
+            inputTables.addTab(t1, 0);
 
-            helperContainer.addMember(inputTables);
+            // Bring the distanceTable tab to front.
             inputTables.selectTab(1);
         }
     }
@@ -1040,29 +1100,16 @@
             }
         }
 
-        distanceInfoService.getDistanceInfo(url, locale, river,
-            new AsyncCallback<DistanceInfoObject[]>() {
-                public void onFailure(Throwable caught) {
-                    GWT.log("Could not recieve distance informations.");
-                    GWT.log(caught.getMessage());
-                }
-
-                public void onSuccess(DistanceInfoObject[] di) {
-                    int num = di != null ? di.length :0;
-                    GWT.log("Recieved " + num + " distance informations.");
-
-                    if (num == 0) {
-                        return;
-                    }
-                    tableData = di;
-                    updateDistanceInfo(di);
-                }
-            }
-        );
+        distanceTable.setDataSource(new DistanceInfoDataSource(
+            url, river, "distances"));
+        locationsTable.setDataSource(new DistanceInfoDataSource(
+            url, river, "locations"));
+        locationDistanceTable.setDataSource(new DistanceInfoDataSource(
+            url, river, "locations"));
     }
 
 
-    protected void updateDistanceInfo(DistanceInfoObject[] di) {
+/*    protected void updateDistanceInfo(DistanceInfoObject[] di) {
         int i = 0;
         for (DistanceInfoObject dio: di) {
             if (dio.getTo() != null) {
@@ -1074,7 +1121,7 @@
             }
         }
         return;
-    }
+    }*/
 
 
     protected double getFrom() {

http://dive4elements.wald.intevation.org