changeset 3828:9cbc8311e820

Improve the GaugePanel Be locale aware and only load the gauge info if the river name changes. flys-client/trunk@5523 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Wed, 19 Sep 2012 12:51:02 +0000 (2012-09-19)
parents ed978af1f089
children e6186ab00553
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java
diffstat 6 files changed, 152 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Sep 19 12:43:43 2012 +0000
+++ b/flys-client/ChangeLog	Wed Sep 19 12:51:02 2012 +0000
@@ -1,3 +1,14 @@
+2012-09-19	Bj�rn Ricks	<bjoern.ricks@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.java,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties,
+	  src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java:
+	  Add locale aware formatting of the gauge values.
+	  Don't reload the gauges if the river doesn't change.
+	  Correctly handle kmup of the river.
+
 2012-09-19	Bj�rn Ricks	<bjoern.ricks@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/ParameterList.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Wed Sep 19 12:43:43 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Wed Sep 19 12:51:02 2012 +0000
@@ -1008,5 +1008,9 @@
     String fix_parameters();
 
     String sq_overview();
+
+    String gauge_zero();
+
+    String gauge_q_unit();
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Wed Sep 19 12:43:43 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Wed Sep 19 12:51:02 2012 +0000
@@ -524,3 +524,6 @@
 fix_parameters = CSV
 
 sq_overview=Overview
+
+gauge_zero = Gauge zero ground
+gauge_q_unit = m\u00b3/s
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Wed Sep 19 12:43:43 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Wed Sep 19 12:51:02 2012 +0000
@@ -523,3 +523,6 @@
 fix_parameters_export = Angepasste Koeffizienten
 fix_parameters = CSV
 sq_overview=\u00dcbersicht
+
+gauge_zero = Pegelnullpunkt
+gauge_q_unit = m\u00b3/s
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Wed Sep 19 12:43:43 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Wed Sep 19 12:51:02 2012 +0000
@@ -524,3 +524,6 @@
 fix_parameters_export = Adjusted coefficient
 fix_parameters = CSV
 sq_overview=Overview
+
+gauge_zero = Gauge zero ground
+gauge_q_unit = m\u00b3/s
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java	Wed Sep 19 12:43:43 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java	Wed Sep 19 12:51:02 2012 +0000
@@ -1,24 +1,27 @@
 package de.intevation.flys.client.client.ui;
 
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.NumberFormat;
 import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.DecoratorPanel;
+import com.google.gwt.user.client.ui.Grid;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.ScrollPanel;
 import com.google.gwt.user.client.ui.Tree;
 import com.google.gwt.user.client.ui.TreeItem;
-import com.google.gwt.user.client.ui.Grid;
-import com.google.gwt.user.client.ui.DecoratorPanel;
-import com.google.gwt.user.client.ui.ScrollPanel;
-import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.HorizontalPanel;
 
+import com.smartgwt.client.types.Alignment;
 import com.smartgwt.client.types.Overflow;
-import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.widgets.events.ResizedEvent;
+import com.smartgwt.client.widgets.events.ResizedHandler;
+import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.layout.SectionStackSection;
-import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.layout.VLayout;
-import com.smartgwt.client.widgets.events.ResizedHandler;
-import com.smartgwt.client.widgets.events.ResizedEvent;
 
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.services.GaugeOverviewInfoService;
@@ -56,15 +59,21 @@
      */
     public GaugePanel(SectionStackSection sectionStack) {
         setOverflow(Overflow.HIDDEN);
+        sectionStack.setHidden(true);
         sectionStack.setItems(this);
         this.sectionStack = sectionStack;
         setStyleName("gaugepanel");
         addResizedHandler(this);
     }
 
+    /**
+     * Sets and loads the river data if river is not the current set river
+     */
     public void setRiver(String river) {
-        this.river = river;
-        this.refresh();
+        if (!river.equals(this.river)) {
+            this.river = river;
+            this.refresh();
+        }
     }
 
     /**
@@ -79,6 +88,7 @@
             public void onSuccess(RiverInfo riverinfo) {
                 GWT.log("Loaded river info");
                 renderGaugeOverviewInfo(riverinfo);
+                gaugetree.openAll();
             }
         });
     }
@@ -90,7 +100,7 @@
         addMember(riverinfopanel);
         addMember(gaugetree);
 
-        gaugetree.setGauges(riverinfo.getGauges());
+        gaugetree.setGauges(riverinfo);
     }
 
     @Override
@@ -140,15 +150,52 @@
          * Resets the items of the tree.
          * If the list of gauges is empty or null the tree will be empty.
          */
-        public void setGauges(List<GaugeInfo> gauges) {
+        public void setGauges(RiverInfo riverinfo) {
             tree.clear();
 
+            List<GaugeInfo> gauges = riverinfo.getGauges();
+
             if (gauges != null && !gauges.isEmpty()) {
 
-                for (GaugeInfo gauge : gauges) {
-                    TreeItem gaugeitem = new GaugeInfoItem(gauge);
-                    tree.addItem(gaugeitem);
+                ArrayList<GaugeInfo> emptygauges = new ArrayList<GaugeInfo>();
+
+                if (!riverinfo.isKmUp()) {
+                    for (GaugeInfo gauge : gauges) {
+                        addGauge(gauge, emptygauges);
+                    }
                 }
+                else {
+                    for (int i = gauges.size(); i >= 0; i--) {
+                        GaugeInfo gauge = gauges.get(i);
+                        addGauge(gauge, emptygauges);
+                    }
+                }
+
+                // put empty gauges to the end
+                for (GaugeInfo gauge : emptygauges) {
+                    addGauge(gauge);
+                }
+            }
+        }
+
+        private void addGauge(GaugeInfo gauge, List<GaugeInfo> empty) {
+            if (gauge.getKmStart() != null && gauge.getKmEnd() != null) {
+                addGauge(gauge);
+            }
+            else {
+                empty.add(gauge);
+            }
+        }
+
+        private void addGauge(GaugeInfo gauge) {
+            TreeItem gaugeitem = new GaugeInfoItem(gauge);
+            tree.addItem(gaugeitem);
+        }
+
+        public void openAll() {
+            for (Iterator<TreeItem> it = tree.treeItemIterator(); it.hasNext();) {
+                TreeItem item = it.next();
+                item.setState(true);
             }
         }
     }
@@ -165,6 +212,8 @@
             setHeight("" + HEIGHT + "px");
             setVerticalAlignment(ALIGN_MIDDLE);
 
+            NumberFormat nf = NumberFormat.getDecimalFormat();
+
             addLabel(riverinfo.getName(), false);
 
             String kmtext = "";
@@ -177,11 +226,11 @@
                 start = tmp;
             }
             if (end != null) {
-                kmtext += end.toString();
+                kmtext += nf.format(end);
                 kmtext += " - ";
             }
             if (start != null) {
-                kmtext += start.toString();
+                kmtext += nf.format(start);
             }
             kmtext += " km";
 
@@ -191,13 +240,13 @@
             Double qmin = riverinfo.getMinQ();
             Double qmax = riverinfo.getMaxQ();
             if (qmin != null) {
-                qtext += qmin.toString();
-                qtext += " qm/s";
+                qtext += nf.format(qmin);
+                qtext += " " + MSG.gauge_q_unit();
                 qtext += " - ";
             }
             if (qmax != null) {
-                qtext += qmax.toString();
-                qtext += " qm/s";
+                qtext += nf.format(qmax);
+                qtext += " " + MSG.gauge_q_unit();
             }
 
             addLabel(qtext, false);
@@ -226,40 +275,84 @@
             setAutoHeight();
             setAutoWidth();
 
+            NumberFormat nf = NumberFormat.getDecimalFormat();
+
             Label label = new Label(gauge.getName(), true);
             addMember(label);
 
-            Double start = gauge.getKmStart();
-            Double end   = gauge.getKmEnd();
+            Double start;
+            Double end;
+
+            if (!gauge.isKmUp()) {
+                start = gauge.getKmStart();
+                end   = gauge.getKmEnd();
+            }
+            else {
+                start = gauge.getKmEnd();
+                end   = gauge.getKmStart();
+            }
+
             String kmtext = "";
             if (start != null) {
-                kmtext += start.toString();
+                kmtext += nf.format(start);
                 kmtext += " - ";
             }
             if (end != null) {
-                kmtext += end.toString();
+                kmtext += nf.format(end);
             }
-            kmtext +=" km";
+            if (start != null || end != null) {
+                kmtext += " km";
+            }
 
             label = new Label(kmtext);
 
             addMember(label);
+
+            Double station = gauge.getStation();
+            if (station != null) {
+                String stext = nf.format(station);
+                stext += " km";
+                label = new Label(stext);
+                addMember(label);
+            }
         }
     }
 
     class GaugeInfoPanel extends DecoratorPanel {
+
         public GaugeInfoPanel(GaugeInfo gauge) {
             setStyleName("gaugeinfopanel");
             Grid grid = new Grid(4, 2);
 
-            grid.setText(0, 0, "W-Bereich [cm]");
-            grid.setText(0, 1, "" + gauge.getMinW() + " - " + gauge.getMaxW());
-            grid.setText(1, 0, "Q-Bereich [m²/s]");
-            grid.setText(1, 1, "" + gauge.getMinQ() + " - " + gauge.getMaxQ());
-            grid.setText(2, 0, "AEO [km²]");
-            grid.setText(2, 1, "" + gauge.getAeo());
-            grid.setText(3, 0, "Pegelnullpunk [NN+m]");
-            grid.setText(3, 1, "" + gauge.getDatum());
+            NumberFormat nf = NumberFormat.getDecimalFormat();
+
+            Double minw = gauge.getMinW();
+            Double maxw = gauge.getMaxW();
+            if (minw != null && maxw != null) {
+                grid.setText(0, 0, MSG.wq_value_q());
+                grid.setText(0, 1, "" + nf.format(minw) +
+                        " - " + nf.format(maxw));
+            }
+
+            Double minq = gauge.getMinQ();
+            Double maxq = gauge.getMaxQ();
+            if (minq != null && maxq != null) {
+                grid.setText(1, 0, MSG.wq_value_w());
+                grid.setText(1, 1, "" + nf.format(minq) +
+                        " - " + nf.format(maxq));
+            }
+
+            Double aeo = gauge.getAeo();
+            if (aeo != null) {
+                grid.setText(2, 0, "AEO [km²]");
+                grid.setText(2, 1, "" + nf.format(aeo));
+            }
+
+            Double datum = gauge.getDatum();
+            if (datum != null) {
+                grid.setText(3, 0, MSG.gauge_zero() + " [NN+m]");
+                grid.setText(3, 1, "" + nf.format(datum));
+            }
 
             setWidget(grid);
         }

http://dive4elements.wald.intevation.org