changeset 3705:f84ed73311f2

Added UI for minfo bed quality calculation and added new services for overview charts. flys-client/trunk@5444 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 12 Sep 2012 14:32:17 +0000
parents 1ea53a363db4
children b7e93531322f
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/ParameterMatrix.java flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/BedCampaignChart.java flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/BedMultiPeriodPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/BedloadCampaignChart.java flys-client/src/main/java/de/intevation/flys/client/server/BedKMChartServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/server/BedloadKMChartServiceImpl.java flys-client/src/main/webapp/WEB-INF/web.xml
diffstat 13 files changed, 469 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Sep 12 14:15:25 2012 +0000
+++ b/flys-client/ChangeLog	Wed Sep 12 14:32:17 2012 +0000
@@ -1,3 +1,32 @@
+2012-09-12  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/minfo/BedCampaignChart.java,
+	  src/main/java/de/intevation/flys/client/client/ui/minfo/BedloadCampaignChart.java:
+	  New. Container for overview charts.
+
+	* src/main/java/de/intevation/flys/client/server/BedKMChartServiceImpl.java,
+	  src/main/java/de/intevation/flys/client/server/BedloadKMChartServiceImpl.java:
+	  New. Services for overview charts.
+
+	* src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java:
+	  Show i18n strings in column titles.
+
+	* src/main/java/de/intevation/flys/client/client/ui/minfo/BedMultiPeriodPanel.java:
+	  New. UI provider that allows multiple period input and displays the overview
+	  charts.
+
+	* src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java:
+	  Added new ui provider.
+
+	* src/main/webapp/WEB-INF/web.xml:
+	  Added new services.
+
+	* 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_en.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties:
+	  Added i18n strings.
+
 2012-09-12  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/shared/model/StringOptionsData.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Wed Sep 12 14:15:25 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Wed Sep 12 14:32:17 2012 +0000
@@ -519,6 +519,10 @@
 
     String exportATTooltip();
 
+    String load_diameter();
+
+    String bed_diameter();
+
     // ERRORS
 
     String error_read_minmax_values();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Wed Sep 12 14:15:25 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Wed Sep 12 14:32:17 2012 +0000
@@ -220,6 +220,8 @@
 fix_derivate_curve = Derivate
 fix_vollmer_wq_curve = W/Q
 datacage_add_pair = Add difference pair
+load_diameter = Bedload Diameter
+bed_diameter = Bed Diameter
 
 exportATTooltip = Export as AT file
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Wed Sep 12 14:15:25 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Wed Sep 12 14:32:17 2012 +0000
@@ -220,6 +220,8 @@
 fix_derivate_curve = Ableitungskurve
 fix_vollmer_wq_curve = W/Q
 datacage_add_pair = Differenzenpaar hinzuf\u00fcgen
+load_diameter = Geschiebedurchmesser
+bed_diameter = Sohldurchmesser
 
 waterlevel_export = Wasserstand/Wasserspiegellagen Export
 waterlevel_report = Wasserstand/Wasserspiegellagen Bericht
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Wed Sep 12 14:15:25 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Wed Sep 12 14:32:17 2012 +0000
@@ -221,6 +221,8 @@
 fix_derivate_curve = Derivate
 fix_vollmer_wq_curve = W/Q
 datacage_add_pair = Add difference pair
+load_diameter = Bedload Diameter
+bed_diameter = Bed Diameter
 
 exportATTooltip = Export as AT file
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java	Wed Sep 12 14:15:25 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java	Wed Sep 12 14:32:17 2012 +0000
@@ -15,6 +15,7 @@
 
 import com.smartgwt.client.widgets.Label;
 
+import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.shared.model.DataItem;
 import de.intevation.flys.client.shared.model.IntegerOptionsData;
 import de.intevation.flys.client.shared.model.StringOptionsData;
@@ -44,6 +45,8 @@
         }
     } // end of class Column
 
+    /** The message class that provides i18n strings.*/
+    protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class);
 
     public static final int CELL_HEIGHT = 25;
 
@@ -123,7 +126,7 @@
 
             selected.put(columnName, new ArrayList<String>());
 
-            grid.setWidget(0, i+1, createLabel(columnName));
+            grid.setWidget(0, i+1, createLabel(MESSAGE.getString(columnName)));
 
             for (int j = 0, o = valueNames.size(); j < o; j++) {
                 String valueName = valueNames.get(j);
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Wed Sep 12 14:15:25 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Wed Sep 12 14:32:17 2012 +0000
@@ -9,6 +9,7 @@
 import de.intevation.flys.client.client.ui.fixation.FixQSelectPanel;
 import de.intevation.flys.client.client.ui.sq.SQPeriodPanel;
 import de.intevation.flys.client.client.ui.minfo.BedHeightsDatacagePanel;
+import de.intevation.flys.client.client.ui.minfo.BedMultiPeriodPanel;
 import de.intevation.flys.client.client.ui.minfo.CheckboxPanel;
 import de.intevation.flys.client.shared.model.User;
 
@@ -136,6 +137,9 @@
         else if (uiProvider.equals("minfo.bed.year_epoch")) {
             return new RadioPanel();
         }
+        else if (uiProvider.equals("bedquality_periods_select")) {
+            return new BedMultiPeriodPanel();
+        }
         else if (uiProvider.equals("bedheights_twin_panel")) {
             return new BedHeightsDatacagePanel(user);
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/BedCampaignChart.java	Wed Sep 12 14:32:17 2012 +0000
@@ -0,0 +1,78 @@
+package de.intevation.flys.client.client.ui.minfo;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.json.client.JSONNumber;
+import com.google.gwt.json.client.JSONObject;
+import com.google.gwt.json.client.JSONString;
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.widgets.Img;
+import com.smartgwt.client.widgets.events.ResizedHandler;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import de.intevation.flys.client.client.Config;
+import de.intevation.flys.client.shared.model.Artifact;
+
+public class BedCampaignChart extends VLayout {
+
+    private final Artifact artifact;
+
+    protected Img chartImg;
+
+    public BedCampaignChart(Artifact artifact, ResizedHandler resizeHandler) {
+        super();
+
+        this.artifact = artifact;
+        this.chartImg = new Img();
+
+        addResizedHandler(resizeHandler);
+        setAlign(Alignment.CENTER);
+    }
+
+    public void update() {
+        Config config = Config.getInstance();
+        String locale = config.getLocale();
+
+        int hWidth = getWidth() - 12;
+        int hHeight = getHeight() - 12;
+
+        if ((int) (hHeight * 4f / 3) < hWidth) {
+            hWidth = (int) (hHeight * 4f / 3);
+        }
+        else {
+            hHeight = (int) (hWidth * 3f / 4);
+        }
+
+        String river = artifact.getArtifactDescription().getRiver();
+
+        JSONObject jfix = new JSONObject();
+        JSONObject jfilter = new JSONObject();
+        JSONObject jrName = new JSONObject();
+        JSONString jrValue = new JSONString(river);
+        JSONObject jextent = new JSONObject();
+        JSONNumber jwidth = new JSONNumber(hWidth);
+        JSONNumber jheight = new JSONNumber(hHeight);
+
+        jrName.put("name", jrValue);
+        jfilter.put("river", jrName);
+        jextent.put("width", jwidth);
+        jextent.put("height", jheight);
+        jfilter.put("extent", jextent);
+        jfix.put("bed", jfilter);
+        String filter = jfix.toString();
+
+        String imgUrl = GWT.getModuleBaseURL();
+        imgUrl += "bed-km-chart";
+        imgUrl += "?locale=" + locale;
+        imgUrl += "&filter=" + filter;
+
+        if (chartImg != null && hasMember(chartImg)) {
+            chartImg.setWidth(hWidth);
+            chartImg.setHeight(hHeight);
+            chartImg.setSrc(imgUrl);
+        }
+        else {
+            chartImg = new Img(imgUrl, hWidth, hHeight);
+            addMember(chartImg);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/BedMultiPeriodPanel.java	Wed Sep 12 14:32:17 2012 +0000
@@ -0,0 +1,34 @@
+package de.intevation.flys.client.client.ui.minfo;
+
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.events.ResizedEvent;
+import com.smartgwt.client.widgets.events.ResizedHandler;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import de.intevation.flys.client.client.ui.MultiPeriodPanel;
+
+public class BedMultiPeriodPanel
+extends MultiPeriodPanel
+implements ResizedHandler {
+    protected BedCampaignChart chartContainer1;
+    protected BedloadCampaignChart chartContainer2;
+
+    public BedMultiPeriodPanel() {
+    }
+
+    @Override
+    protected Canvas createHelper() {
+        chartContainer1 = new BedCampaignChart(artifact, this);
+        chartContainer2 = new BedloadCampaignChart(artifact, this);
+        VLayout layout = new VLayout();
+        layout.addMember(chartContainer1);
+        layout.addMember(chartContainer2);
+        return layout;
+    }
+
+    @Override
+    public void onResized(ResizedEvent re) {
+        chartContainer1.update();
+        chartContainer2.update();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/BedloadCampaignChart.java	Wed Sep 12 14:32:17 2012 +0000
@@ -0,0 +1,78 @@
+package de.intevation.flys.client.client.ui.minfo;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.json.client.JSONNumber;
+import com.google.gwt.json.client.JSONObject;
+import com.google.gwt.json.client.JSONString;
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.widgets.Img;
+import com.smartgwt.client.widgets.events.ResizedHandler;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import de.intevation.flys.client.client.Config;
+import de.intevation.flys.client.shared.model.Artifact;
+
+public class BedloadCampaignChart extends VLayout {
+
+    private final Artifact artifact;
+
+    protected Img chartImg;
+
+    public BedloadCampaignChart(Artifact artifact, ResizedHandler resizeHandler) {
+        super();
+
+        this.artifact = artifact;
+        this.chartImg = new Img();
+
+        addResizedHandler(resizeHandler);
+        setAlign(Alignment.CENTER);
+    }
+
+    public void update() {
+        Config config = Config.getInstance();
+        String locale = config.getLocale();
+
+        int hWidth = getWidth() - 12;
+        int hHeight = getHeight() - 12;
+
+        if ((int) (hHeight * 4f / 3) < hWidth) {
+            hWidth = (int) (hHeight * 4f / 3);
+        }
+        else {
+            hHeight = (int) (hWidth * 3f / 4);
+        }
+
+        String river = artifact.getArtifactDescription().getRiver();
+
+        JSONObject jfix = new JSONObject();
+        JSONObject jfilter = new JSONObject();
+        JSONObject jrName = new JSONObject();
+        JSONString jrValue = new JSONString(river);
+        JSONObject jextent = new JSONObject();
+        JSONNumber jwidth = new JSONNumber(hWidth);
+        JSONNumber jheight = new JSONNumber(hHeight);
+
+        jrName.put("name", jrValue);
+        jfilter.put("river", jrName);
+        jextent.put("width", jwidth);
+        jextent.put("height", jheight);
+        jfilter.put("extent", jextent);
+        jfix.put("bedload", jfilter);
+        String filter = jfix.toString();
+
+        String imgUrl = GWT.getModuleBaseURL();
+        imgUrl += "bedload-km-chart";
+        imgUrl += "?locale=" + locale;
+        imgUrl += "&filter=" + filter;
+
+        if (chartImg != null && hasMember(chartImg)) {
+            chartImg.setWidth(hWidth);
+            chartImg.setHeight(hHeight);
+            chartImg.setSrc(imgUrl);
+        }
+        else {
+            chartImg = new Img(imgUrl, hWidth, hHeight);
+            addMember(chartImg);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/BedKMChartServiceImpl.java	Wed Sep 12 14:32:17 2012 +0000
@@ -0,0 +1,106 @@
+package de.intevation.flys.client.server;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
+import de.intevation.artifacts.httpclient.http.HttpClient;
+import de.intevation.artifacts.httpclient.http.HttpClientImpl;
+import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler;
+
+public class BedKMChartServiceImpl extends HttpServlet {
+    private static final Logger log =
+        Logger.getLogger(FixingsKMChartServiceImpl.class);
+
+    public static final String SERVICE_NAME = "bed-km-chart";
+
+    public BedKMChartServiceImpl() {
+    }
+
+    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
+
+        log.info("BedKMChartServiceImpl.doGet");
+
+        String url    = getServletContext().getInitParameter("server-url");
+        String locale = req.getParameter("locale");
+        String filter = req.getParameter("filter");
+
+        if (filter == null || filter.length() == 0) {
+            log.warn("Missing 'filter' parameter.");
+            return;
+        }
+
+        if (locale == null || locale.length() == 0) {
+            locale = "de";
+        }
+
+        Document filterDoc = XMLUtils.jsonToXML(filter);
+
+        if (filterDoc == null) {
+            log.warn("Creating filter document failed.");
+            return;
+        }
+
+        InputStream in;
+
+        try {
+            HttpClient client = new HttpClientImpl(url, locale);
+            in = (InputStream)client.callService(
+                url, // XXX: Why? The URL is passed by construction already.
+                SERVICE_NAME,
+                filterDoc,
+                new StreamResponseHandler());
+        }
+        catch (ConnectionException ce) {
+            log.error(ce);
+            return;
+        }
+
+        resp.setHeader("Content-Type", guessMIMEType(filterDoc));
+
+        try {
+            OutputStream out = resp.getOutputStream();
+
+            byte [] buf = new byte[4096];
+            int i = -1;
+            while ((i = in.read(buf)) >= 0) {
+                out.write(buf, 0, i);
+            }
+            out.flush();
+        }
+        catch (IOException ioe) {
+            log.error(ioe);
+        }
+        finally {
+            try { in.close(); }
+            catch (IOException ioe) { /* ignored */ }
+        }
+    }
+
+    protected static String guessMIMEType(Document document) {
+
+        NodeList formats = document.getElementsByTagName("format");
+
+        String format = "png";
+
+        if (formats.getLength() > 0) {
+            String type = ((Element)formats.item(0)).getAttribute("type");
+            if (type.length() > 0) {
+                format = type;
+            }
+        }
+
+        return "image/" + format;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/BedloadKMChartServiceImpl.java	Wed Sep 12 14:32:17 2012 +0000
@@ -0,0 +1,106 @@
+package de.intevation.flys.client.server;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
+import de.intevation.artifacts.httpclient.http.HttpClient;
+import de.intevation.artifacts.httpclient.http.HttpClientImpl;
+import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler;
+
+public class BedloadKMChartServiceImpl extends HttpServlet {
+   private static final Logger log =
+        Logger.getLogger(FixingsKMChartServiceImpl.class);
+
+    public static final String SERVICE_NAME = "bedload-km-chart";
+
+    public BedloadKMChartServiceImpl() {
+    }
+
+    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
+
+        log.info("BedloadKMChartServiceImpl.doGet");
+
+        String url    = getServletContext().getInitParameter("server-url");
+        String locale = req.getParameter("locale");
+        String filter = req.getParameter("filter");
+
+        if (filter == null || filter.length() == 0) {
+            log.warn("Missing 'filter' parameter.");
+            return;
+        }
+
+        if (locale == null || locale.length() == 0) {
+            locale = "de";
+        }
+
+        Document filterDoc = XMLUtils.jsonToXML(filter);
+
+        if (filterDoc == null) {
+            log.warn("Creating filter document failed.");
+            return;
+        }
+
+        InputStream in;
+
+        try {
+            HttpClient client = new HttpClientImpl(url, locale);
+            in = (InputStream)client.callService(
+                url, // XXX: Why? The URL is passed by construction already.
+                SERVICE_NAME,
+                filterDoc,
+                new StreamResponseHandler());
+        }
+        catch (ConnectionException ce) {
+            log.error(ce);
+            return;
+        }
+
+        resp.setHeader("Content-Type", guessMIMEType(filterDoc));
+
+        try {
+            OutputStream out = resp.getOutputStream();
+
+            byte [] buf = new byte[4096];
+            int i = -1;
+            while ((i = in.read(buf)) >= 0) {
+                out.write(buf, 0, i);
+            }
+            out.flush();
+        }
+        catch (IOException ioe) {
+            log.error(ioe);
+        }
+        finally {
+            try { in.close(); }
+            catch (IOException ioe) { /* ignored */ }
+        }
+    }
+
+    protected static String guessMIMEType(Document document) {
+
+        NodeList formats = document.getElementsByTagName("format");
+
+        String format = "png";
+
+        if (formats.getLength() > 0) {
+            String type = ((Element)formats.item(0)).getAttribute("type");
+            if (type.length() > 0) {
+                format = type;
+            }
+        }
+
+        return "image/" + format;
+    }
+}
--- a/flys-client/src/main/webapp/WEB-INF/web.xml	Wed Sep 12 14:15:25 2012 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/web.xml	Wed Sep 12 14:32:17 2012 +0000
@@ -487,6 +487,26 @@
   </servlet-mapping>
 
   <servlet>
+    <servlet-name>BedKMChart</servlet-name>
+    <servlet-class>de.intevation.flys.client.server.BedKMChartServiceImpl</servlet-class>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>BedKMChart</servlet-name>
+    <url-pattern>/flys/bed-km-chart</url-pattern>
+  </servlet-mapping>
+
+  <servlet>
+    <servlet-name>BedloadKMChart</servlet-name>
+    <servlet-class>de.intevation.flys.client.server.BedloadKMChartServiceImpl</servlet-class>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>BedloadKMChart</servlet-name>
+    <url-pattern>/flys/bedload-km-chart</url-pattern>
+  </servlet-mapping>
+
+  <servlet>
     <servlet-name>login</servlet-name>
     <servlet-class>de.intevation.flys.client.server.LoginServlet</servlet-class>
   </servlet>

http://dive4elements.wald.intevation.org