changeset 1411:63be3137abac

Parse and display WMS layers supported by a user specified WMS service. flys-client/trunk@3298 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 21 Nov 2011 21:00:03 +0000
parents 6bb2c1ffab2b
children 659a488243da
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java flys-client/src/main/java/de/intevation/flys/client/client/ui/map/WMSLayersTree.java flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/Capabilities.java flys-client/src/main/java/de/intevation/flys/client/shared/model/WMSLayer.java
diffstat 6 files changed, 199 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Nov 21 19:38:26 2011 +0000
+++ b/flys-client/ChangeLog	Mon Nov 21 21:00:03 2011 +0000
@@ -1,3 +1,23 @@
+2011-11-21  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/WMSLayer.java: New.
+	  This class stores layer information provided by capabilities document.
+	  Note, that a WMSLayer can have further sublayers.
+
+	* src/main/java/de/intevation/flys/client/server/GCServiceImpl.java: Parse
+	  layers from capabilities document.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/WMSLayersTree.java:
+	  New. This tree displays WMSLayers.
+
+	* src/main/java/de/intevation/flys/client/shared/model/Capabilities.java:
+	  Now, the list of layers is from type List<WMSLayer> instead of
+	  List<String>.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java:
+	  Use the WMSLayersTree to display the layers provided by the given WMS
+	  service.
+
 2011-11-21  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java	Mon Nov 21 19:38:26 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java	Mon Nov 21 21:00:03 2011 +0000
@@ -7,7 +7,6 @@
 import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.Button;
 import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.Window;
 import com.smartgwt.client.widgets.events.ClickEvent;
 import com.smartgwt.client.widgets.events.ClickHandler;
@@ -234,12 +233,13 @@
             }
         };
 
-        VLayout root = new VLayout();
+        VLayout       root = new VLayout();
+        WMSLayersTree tree = new WMSLayersTree(capabilites);
 
-        root.addMember(new Label("STEP 3"));
+        root.setLayoutMargin(10);
+        tree.setHeight(420);
 
-        // TODO IMPLEMENT ME
-
+        root.addMember(tree);
         root.addMember(createButtonPanel(backHandler, goHandler, cancelHandler));
 
         return root;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/WMSLayersTree.java	Mon Nov 21 21:00:03 2011 +0000
@@ -0,0 +1,75 @@
+package de.intevation.flys.client.client.ui.map;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.smartgwt.client.types.TreeModelType;
+import com.smartgwt.client.widgets.tree.Tree;
+import com.smartgwt.client.widgets.tree.TreeGrid;
+import com.smartgwt.client.widgets.tree.TreeNode;
+
+import de.intevation.flys.client.shared.model.Capabilities;
+import de.intevation.flys.client.shared.model.WMSLayer;
+
+
+public class WMSLayersTree extends TreeGrid {
+
+    protected Capabilities capabilites;
+
+    public WMSLayersTree(Capabilities capabilites) {
+        super();
+        this.capabilites = capabilites;
+
+        initTree();
+    }
+
+
+    protected void initTree() {
+        setLoadDataOnDemand(false);
+        setWidth100();
+        setHeight100();
+        setShowRoot(false);
+        setShowConnectors(true);
+        setNodeIcon("[SKIN]/images/blank.gif");
+
+        Tree tree = new Tree();
+        tree.setChildrenProperty("children-nodes");
+        tree.setNameProperty("title");
+        tree.setIdField("title");
+        tree.setModelType(TreeModelType.CHILDREN);
+        tree.setShowRoot(false);
+
+        TreeNode     root = new TreeNode("Root");
+        TreeNode[] layers = buildTree(capabilites.getLayers());
+
+        root.setAttribute("children-nodes", layers);
+        tree.setRoot(root);
+
+        setData(tree);
+
+        if (layers != null && layers.length == 1) {
+            tree.openFolder(layers[0]);
+        }
+    }
+
+
+    protected TreeNode[] buildTree(List<WMSLayer> layers) {
+        List<TreeNode> layerNodes = new ArrayList<TreeNode>();
+
+        for (WMSLayer layer: layers) {
+            TreeNode tn  = new TreeNode();
+            tn.setAttribute("name", layer.getName());
+            tn.setAttribute("title", layer.getTitle());
+
+            TreeNode[] tns = buildTree(layer.getLayers());
+
+            if (tns != null && tns.length > 0) {
+                tn.setAttribute("children-nodes", tns);
+            }
+
+            layerNodes.add(tn);
+        }
+
+        return (TreeNode[]) layerNodes.toArray(new TreeNode[layerNodes.size()]);
+    }
+}
--- a/flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java	Mon Nov 21 19:38:26 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java	Mon Nov 21 21:00:03 2011 +0000
@@ -5,6 +5,8 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.xml.xpath.XPathConstants;
 
@@ -12,6 +14,7 @@
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 import org.apache.log4j.Logger;
 
@@ -20,6 +23,7 @@
 import de.intevation.flys.client.shared.exceptions.ServerException;
 import de.intevation.flys.client.shared.model.Capabilities;
 import de.intevation.flys.client.shared.model.ContactInformation;
+import de.intevation.flys.client.shared.model.WMSLayer;
 import de.intevation.flys.client.client.services.GCService;
 
 
@@ -75,6 +79,9 @@
     public static final String XPATH_ACCESS_CONSTRAINTS =
         "/WMS_Capabilities/Service/AccessConstraints/text()";
 
+    public static final String XPATH_LAYERS =
+        "/WMS_Capabilities/Capability/Layer";
+
 
     private Logger logger = Logger.getLogger(GCServiceImpl.class);
 
@@ -149,7 +156,12 @@
         logger.debug("Found fees: " + fees);
         logger.debug("Found access constraints: " + accessConstraints);
 
-        // TODO PARSE LAYERS
+        NodeList layerNodes = (NodeList) XMLUtils.xpath(
+            doc,
+            XPATH_LAYERS,
+            XPathConstants.NODESET);
+
+        List<WMSLayer> layers = parseLayers(layerNodes);
 
         return new Capabilities(
             title,
@@ -157,7 +169,7 @@
             ci,
             fees,
             accessConstraints,
-            null);
+            layers);
     }
 
 
@@ -208,5 +220,44 @@
 
         return ci;
     }
+
+
+    protected List<WMSLayer> parseLayers(NodeList layersNode) {
+        int len = layersNode != null ? layersNode.getLength() : 0;
+
+        logger.debug("Node has " + len + " layers.");
+
+        List<WMSLayer> layers = new ArrayList<WMSLayer>(len);
+
+        for (int i = 0; i < len; i++) {
+            layers.add(parseLayer(layersNode.item(i)));
+        }
+
+        return layers;
+    }
+
+
+    protected WMSLayer parseLayer(Node layerNode) {
+        String title = (String) XMLUtils.xpath(
+            layerNode,
+            "Title/text()",
+            XPathConstants.STRING);
+
+        String name = (String) XMLUtils.xpath(
+            layerNode,
+            "Name/text()",
+            XPathConstants.STRING);
+
+        logger.debug("Found layers: " + title + "(" + name + ")");
+
+        NodeList layersNodes = (NodeList) XMLUtils.xpath(
+            layerNode,
+            "Layer",
+            XPathConstants.NODESET);
+
+        List<WMSLayer> layers = parseLayers(layersNodes);
+
+        return new WMSLayer(title, name, layers);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Capabilities.java	Mon Nov 21 19:38:26 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Capabilities.java	Mon Nov 21 21:00:03 2011 +0000
@@ -14,11 +14,11 @@
 
     protected ContactInformation contactInformation;
 
-    protected List<String> layers;
+    protected List<WMSLayer> layers;
 
 
     public Capabilities() {
-        layers = new ArrayList<String>();
+        layers = new ArrayList<WMSLayer>();
     }
 
 
@@ -33,7 +33,7 @@
         ContactInformation contactInformation,
         String             fees,
         String             accessConstraints,
-        List<String>       layers
+        List<WMSLayer>     layers
     ) {
         this.title              = title;
         this.onlineResource     = onlineResource;
@@ -69,7 +69,7 @@
     }
 
 
-    public List<String> getLayers() {
+    public List<WMSLayer> getLayers() {
         return layers;
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/WMSLayer.java	Mon Nov 21 21:00:03 2011 +0000
@@ -0,0 +1,42 @@
+package de.intevation.flys.client.shared.model;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class WMSLayer implements Serializable {
+
+    protected String name;
+    protected String title;
+
+    protected List<WMSLayer> layers;
+
+
+    public WMSLayer() {
+        layers = new ArrayList<WMSLayer>();
+    }
+
+
+    public WMSLayer(String title, String name, List<WMSLayer> layers) {
+        this.title  = title;
+        this.name   = name;
+        this.layers = layers;
+    }
+
+
+    public String getName() {
+        return name;
+    }
+
+
+    public String getTitle() {
+        return title;
+    }
+
+
+    public List<WMSLayer> getLayers() {
+        return layers;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org