changeset 3837:6b2ae2ec5b01

Open and close gauge tree folds that correspond to the selected WINFO calculation flys-client/trunk@5546 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 21 Sep 2012 08:57:18 +0000
parents 06c76de19b51
children 70976b711b7e
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java
diffstat 3 files changed, 206 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri Sep 21 07:59:25 2012 +0000
+++ b/flys-client/ChangeLog	Fri Sep 21 08:57:18 2012 +0000
@@ -1,3 +1,10 @@
+2012-09-21	Björn Ricks	<bjoern.ricks@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java,
+	  src/main/java/de/intevation/flys/client/client/ui/ParameterList.java:
+	  Open and close gauge tree folds that correspond to the selected WINFO
+	  calculation.
+
 2012-09-21	Björn Ricks	<bjoern.ricks@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java	Fri Sep 21 07:59:25 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java	Fri Sep 21 08:57:18 2012 +0000
@@ -25,6 +25,9 @@
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.services.GaugeOverviewInfoService;
 import de.intevation.flys.client.client.services.GaugeOverviewInfoServiceAsync;
+import de.intevation.flys.client.shared.model.Data;
+import de.intevation.flys.client.shared.model.DataItem;
+import de.intevation.flys.client.shared.model.DataList;
 import de.intevation.flys.client.shared.model.GaugeInfo;
 import de.intevation.flys.client.shared.model.RiverInfo;
 
@@ -76,6 +79,13 @@
     }
 
     /**
+     * Sets the data and closes not corresponding folds in the gauge tree
+     */
+    public void setData(DataList[] data) {
+        gaugetree.setData(data);
+    }
+
+    /**
      * Loads the river info and renders it afterwards
      */
     public void refresh() {
@@ -87,7 +97,6 @@
             public void onSuccess(RiverInfo riverinfo) {
                 GWT.log("Loaded river info");
                 renderGaugeOverviewInfo(riverinfo);
-                gaugetree.openAll();
             }
         });
     }
@@ -139,6 +148,7 @@
     class GaugeTree extends ScrollPanel {
 
         private Tree tree;
+        private DataList[] data;
 
         public GaugeTree() {
             tree = new Tree();
@@ -174,6 +184,8 @@
                 for (GaugeInfo gauge : emptygauges) {
                     addGauge(gauge);
                 }
+
+                open();
             }
         }
 
@@ -187,16 +199,186 @@
         }
 
         private void addGauge(GaugeInfo gauge) {
-            TreeItem gaugeitem = new GaugeInfoItem(gauge);
+            GaugeInfoItem gaugeitem = new GaugeInfoItem(gauge);
             tree.addItem(gaugeitem);
         }
 
         public void openAll() {
+            GWT.log("GaugeTree - openAll");
             for (Iterator<TreeItem> it = tree.treeItemIterator(); it.hasNext();) {
                 TreeItem item = it.next();
                 item.setState(true);
             }
         }
+
+        public void setData(DataList[] data) {
+            this.data = data;
+            if (tree.getItemCount() > 0) {
+                open();
+            }
+        }
+
+        public void open() {
+            ArrayList<Double> curvelocations = new ArrayList<Double>();
+
+            if (data != null && data.length > 0) {
+                for (int i = 0; i < data.length; i++) {
+                    DataList dl = data[i];
+                    String state = dl.getState();
+                    GWT.log("GaugeTree - setData " + state);
+                    if (state.equals("state.winfo.distance") ||
+                            state.equals("state.winfo.distance_only") ||
+                            state.equals("state.winfo.location_distance")) {
+                        Double ldfrom = null;
+                        Double ldto = null;
+
+                        for (int j = dl.size()-1; j >= 0; --j) {
+                            Data d = dl.get(j);
+                            String label = d.getLabel();
+                            GWT.log("GaugeTree - setData - label " + label + " " + d.getStringValue());
+                            if (label.equals("ld_from")) {
+                                String strfrom = d.getStringValue();
+                                if (strfrom != null) {
+                                    ldfrom = Double.valueOf(strfrom);
+                                }
+                            }
+                            else if (label.equals("ld_to")) {
+                                String strto = d.getStringValue();
+                                if (strto != null) {
+                                    ldto = Double.valueOf(strto);
+                                }
+                            }
+                        }
+
+                        if (ldfrom != null) {
+                            openOnDistance(ldfrom, ldto);
+                            return;
+                        }
+                    }
+                    else if (state.equals("state.winfo.location")) {
+                        ArrayList<Double> locations = new ArrayList<Double>();
+                        for (int j = dl.size()-1; j >= 0; --j) {
+                            Data d = dl.get(j);
+                            String label = d.getLabel();
+                            GWT.log("GaugeTree - setData - location label " +
+                                    label + " " + d.getStringValue());
+                            if (label.equals("ld_locations")) {
+                                DataItem[] items = d.getItems();
+                                for (int k = 0; k < items.length; k++) {
+                                    String tmp = items[k].getStringValue();
+                                    if (tmp != null) {
+                                        Double value = Double.valueOf(tmp);
+                                        if (value != null) {
+                                            locations.add(value);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                        openOnLocations(locations);
+                        return;
+                    }
+                    else if (state.equals("state.winfo.reference.curve.input.start")) {
+                        for (int j = dl.size()-1; j >= 0; --j) {
+                            Data d = dl.get(j);
+                            String label = d.getLabel();
+                            if (label.equals("reference_startpoint")) {
+                                DataItem[] items = d.getItems();
+                                for (int k = 0; k < items.length; k++) {
+                                    String tmp = items[k].getStringValue();
+                                    if (tmp != null) {
+                                        Double value = Double.valueOf(tmp);
+                                        if (value != null) {
+                                            curvelocations.add(value);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    else if (state.equals("state.winfo.reference.curve.input.end")) {
+                        for (int j = dl.size()-1; j >= 0; --j) {
+                            Data d = dl.get(j);
+                            String label = d.getLabel();
+                            if (label.equals("reference_endpoint")) {
+                                DataItem[] items = d.getItems();
+                                for (int k = 0; k < items.length; k++) {
+                                    String tmp = items[k].getStringValue();
+                                    if (tmp != null) {
+                                        Double value = Double.valueOf(tmp);
+                                        if (value != null) {
+                                            curvelocations.add(value);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            if (!curvelocations.isEmpty()) {
+                openOnLocations(curvelocations);
+            }
+            else {
+                openAll();
+            }
+        }
+
+        public void openOnDistance(Double start, Double end) {
+            GWT.log("GaugeTree - openOnDistance " + start + " " + end + " " +
+                    tree.getItemCount());
+
+            for (Iterator<TreeItem> it = tree.treeItemIterator(); it.hasNext();) {
+                TreeItem item = it.next();
+                /* Strange stuff is happening here:
+                 * GWT Tree.treeItemIterator returns another TreeItem for each
+                 * GaugeInfoItem */
+                if (item instanceof GaugeInfoItem) {
+                    boolean setstate = false;
+                    GaugeInfoItem gitem = (GaugeInfoItem)item;
+                    if (end == null) {
+                        if (gitem.getStart() >= start) {
+                            setstate = true;
+                        }
+                    }
+                    else {
+                        if ((gitem.getStart() >= start && gitem.getStart() <= end) ||
+                                (gitem.getEnd() >= start && gitem.getEnd() <= end)) {
+                            setstate = true;
+                        }
+                    }
+                    item.setState(setstate);
+                }
+            }
+        }
+
+        public void openOnLocations(List<Double> locations) {
+            GWT.log("GaugeTree - openOnLocations " + locations + " " +
+                    tree.getItemCount());
+
+            if (locations == null || locations.isEmpty()) {
+                return;
+            }
+
+            for (Iterator<TreeItem> it = tree.treeItemIterator(); it.hasNext();) {
+                TreeItem item = it.next();
+                if (item instanceof GaugeInfoItem) {
+                    GaugeInfoItem gitem = (GaugeInfoItem)item;
+                    boolean isset = false;
+                    for (Double location: locations) {
+                        if (locations == null) {
+                            continue;
+                        }
+                        if (location >= gitem.getStart() &&
+                                location <= gitem.getEnd()) {
+                            isset = true;
+                            break;
+                        }
+                    }
+                    item.setState(isset);
+                }
+            }
+        }
     }
 
     class RiverInfoPanel extends HorizontalPanel {
@@ -259,11 +441,23 @@
     }
 
     class GaugeInfoItem extends TreeItem {
+
+        private GaugeInfo gauge;
+
         public GaugeInfoItem(GaugeInfo gauge) {
             GaugeInfoHead gaugeinfohead = new GaugeInfoHead(gauge);
             GaugeInfoPanel gaugeinfopanel = new GaugeInfoPanel(gauge);
             setWidget(gaugeinfohead);
             addItem(gaugeinfopanel);
+            this.gauge = gauge;
+        }
+
+        public Double getStart() {
+            return gauge.getKmStart();
+        }
+
+        public Double getEnd() {
+            return gauge.getKmEnd();
         }
     }
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Fri Sep 21 07:59:25 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Fri Sep 21 08:57:18 2012 +0000
@@ -745,7 +745,7 @@
         if (art instanceof WINFOArtifact) {
             String river = desc.getRiver();
             if (river != null) {
-                renderGaugeInfo(desc.getRiver());
+                renderGaugeInfo(desc.getRiver(), desc.getOldData());
             }
             else {
                 gaugePanel.hide();
@@ -925,8 +925,9 @@
     }
 
 
-    private void renderGaugeInfo(String river) {
+    private void renderGaugeInfo(String river, DataList[] data) {
         gaugePanel.setRiver(river);
+        gaugePanel.setData(data);
         gaugePanel.show();
     }
 

http://dive4elements.wald.intevation.org