changeset 782:4a7ece57f44c

#159 The tables in the WQ panel for calculation 4 are now filled with data. flys-client/trunk@2273 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 01 Jul 2011 08:44:24 +0000
parents 6653cf54b45d
children 8ebaad41285b
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/DistancePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/range/DistanceInfoDataSource.java flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoXML.java flys-client/src/main/webapp/WEB-INF/web.xml
diffstat 5 files changed, 204 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Thu Jun 30 11:59:02 2011 +0000
+++ b/flys-client/ChangeLog	Fri Jul 01 08:44:24 2011 +0000
@@ -1,3 +1,21 @@
+2011-07-01  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/server/DistanceInfoXML.java:
+	  New. This service - which is no GWT RPC Service - returns the distance
+	  info document as XML. The content of the document is not modified,
+	  parsed but only copied through.
+
+	* src/main/java/de/intevation/flys/client/client/ui/range/DistanceInfoDataSource.java:
+	  New. This data source is used to fill the LocationsTable and RangeTable.
+	  It uses the DistanceInfoXML service to query the required data
+	  automatically using a "locations" or "distances" filter to reduce the
+	  size of the data document.
+
+	* src/main/java/de/intevation/flys/client/client/ui/DistancePanel.java:
+	  Use the DistanceInfoDataSource to fill the locations and distances tables.
+
+	* src/main/webapp/WEB-INF/web.xml: Registered the new service.
+
 2011-06-30  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/range/LocationsTable.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DistancePanel.java	Thu Jun 30 11:59:02 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DistancePanel.java	Fri Jul 01 08:44:24 2011 +0000
@@ -15,13 +15,16 @@
 import com.smartgwt.client.widgets.tab.TabSet;
 import com.smartgwt.client.widgets.tab.Tab;
 
+import de.intevation.flys.client.shared.model.ArtifactDescription;
 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.DefaultData;
 import de.intevation.flys.client.shared.model.DefaultDataItem;
 
+import de.intevation.flys.client.client.Config;
 import de.intevation.flys.client.client.FLYSConstants;
+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;
 
@@ -296,6 +299,17 @@
 
 
     protected void initHelperPanel() {
+        Config config = Config.getInstance();
+        String url    = config.getServerUrl();
+        String river  = getRiverName();
+
+        distancesTable.setAutoFetchData(true);
+        locationsTable.setAutoFetchData(true);
+        distancesTable.setDataSource(new DistanceInfoDataSource(
+            url, river, "distances"));
+        locationsTable.setDataSource(new DistanceInfoDataSource(
+            url, river, "locations"));
+
         tabs = new TabSet();
         tabs.setWidth100();
         tabs.setHeight100();
@@ -311,5 +325,30 @@
 
         helperContainer.addChild(tabs);
     }
+
+
+    protected String getRiverName() {
+        ArtifactDescription adescr = artifact.getArtifactDescription();
+        DataList[] data = adescr.getOldData();
+
+        if (data != null && data.length > 0) {
+            for (int i = 0; i < data.length; i++) {
+                DataList dl = data[i];
+
+                if (dl.getState().equals("state.winfo.river")) {
+                    for (int j = 0; j < dl.size(); j++) {
+                        Data d = dl.get(j);
+                        DataItem[] di = d.getItems();
+
+                        if (di != null && di.length == 1) {
+                           return d.getItems()[0].getStringValue();
+                        }
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/range/DistanceInfoDataSource.java	Fri Jul 01 08:44:24 2011 +0000
@@ -0,0 +1,53 @@
+package de.intevation.flys.client.client.ui.range;
+
+import com.google.gwt.core.client.GWT;
+
+import com.smartgwt.client.data.DataSource;
+import com.smartgwt.client.data.DataSourceField;
+import com.smartgwt.client.types.DSDataFormat;
+import com.smartgwt.client.types.FieldType;
+
+
+public class DistanceInfoDataSource extends DataSource {
+
+    public static final String XPATH_DISTANCE_DEFAULT = "/distances/distance";
+
+
+    public DistanceInfoDataSource(String url, String river, String filter) {
+        setDataFormat(DSDataFormat.XML);
+        setRecordXPath(XPATH_DISTANCE_DEFAULT);
+
+        DataSourceField desc = new DataSourceField(
+            "description", FieldType.TEXT, "description");
+
+        DataSourceField from = new DataSourceField(
+            "from", FieldType.TEXT, "from");
+
+        DataSourceField to = new DataSourceField(
+            "to", FieldType.TEXT, "to");
+
+        DataSourceField side = new DataSourceField(
+            "riverside", FieldType.TEXT, "riverside");
+
+        DataSourceField top = new DataSourceField(
+            "top", FieldType.TEXT, "top");
+
+        DataSourceField bottom = new DataSourceField(
+            "bottom", FieldType.TEXT, "bottom");
+
+        setFields(desc, from, to, side, top, bottom);
+        setDataURL(getServiceURL(url, river, filter));
+    }
+
+
+    protected String getServiceURL(String server, String river, String filter) {
+        String url = GWT.getModuleBaseURL();
+        url += "distanceinfoxml";
+        url += "?server=" + server;
+        url += "&river=" + river;
+        url += "&filter=" + filter;
+
+        return url;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoXML.java	Fri Jul 01 08:44:24 2011 +0000
@@ -0,0 +1,84 @@
+package de.intevation.flys.client.server;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import de.intevation.artifacts.common.ArtifactNamespaceContext;
+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;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class DistanceInfoXML
+extends      HttpServlet
+{
+    public static final String ERROR_NO_DISTANCEINFO_FOUND =
+        "error_no_distanceinfo_found";
+
+
+    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
+        System.out.println("DistanceInfoXML.doGet");
+
+        String river  = req.getParameter("river");
+        String url    = req.getParameter("server");
+        String filter = req.getParameter("filter");
+
+        Document doc = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+            doc,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element riverEl = ec.create("river");
+        riverEl.setTextContent(river);
+
+        doc.appendChild(riverEl);
+
+        if (filter != null && filter.length() > 0) {
+            Element typeEl = ec.create("filter");
+            typeEl.setTextContent(filter);
+
+            riverEl.appendChild(typeEl);
+        }
+
+        HttpClient client = new HttpClientImpl(url);
+
+        try {
+            InputStream in = (InputStream) client.callService(
+                url, "distanceinfo", doc, new StreamResponseHandler());
+
+            OutputStream out = resp.getOutputStream();
+
+            byte[] b = new byte[4096];
+            int i;
+            while ((i = in.read(b)) >= 0) {
+                out.write(b, 0, i);
+            }
+
+            out.flush();
+            out.close();
+        }
+        catch (ConnectionException ce) {
+            System.err.println(ce.getLocalizedMessage());
+        }
+        catch (IOException ioe) {
+            System.err.println(ioe.getLocalizedMessage());
+        }
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml	Thu Jun 30 11:59:02 2011 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/web.xml	Fri Jul 01 08:44:24 2011 +0000
@@ -158,6 +158,16 @@
   </servlet-mapping>
 
   <servlet>
+    <servlet-name>DistanceInfoXML</servlet-name>
+    <servlet-class>de.intevation.flys.client.server.DistanceInfoXML</servlet-class>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>DistanceInfoXML</servlet-name>
+    <url-pattern>/flys/distanceinfoxml</url-pattern>
+  </servlet-mapping>
+
+  <servlet>
     <servlet-name>ExportService</servlet-name>
     <servlet-class>de.intevation.flys.client.server.ExportServiceImpl</servlet-class>
   </servlet>

http://dive4elements.wald.intevation.org