changeset 1414:3484cbfaf369

Create new Artifacts for selected WMS layers of the ExternalWMSWindow. flys-client/trunk@3304 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 22 Nov 2011 20:13:16 +0000
parents 0d3bbe4240b1
children dfa2d4753fc0
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/WMSLayer.java
diffstat 4 files changed, 88 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Nov 22 20:08:41 2011 +0000
+++ b/flys-client/ChangeLog	Tue Nov 22 20:13:16 2011 +0000
@@ -1,3 +1,16 @@
+2011-11-22  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/WMSLayer.java: Added
+	  the URL of the WMS server to the constructor parameterlist, because this
+	  information is absolutely required for a WMS layer.
+
+	* src/main/java/de/intevation/flys/client/server/GCServiceImpl.java:
+	  Modified the constructor call of WMSLayer.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java:
+	  Add WMS layers by using LoadArtifactService.loadMany() which creates a new
+	  Artifact for each WMS layer. TODO: Trigger reload of MapThemePanel.
+
 2011-11-22  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/server/LoadArtifactServiceImpl.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java	Tue Nov 22 20:08:41 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java	Tue Nov 22 20:13:16 2011 +0000
@@ -7,6 +7,7 @@
 import com.google.gwt.user.client.ui.HorizontalPanel;
 import com.google.gwt.user.client.ui.Widget;
 
+import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.events.ResizedEvent;
 import com.smartgwt.client.widgets.events.ResizedHandler;
@@ -37,12 +38,15 @@
 import de.intevation.flys.client.shared.model.DefaultData;
 import de.intevation.flys.client.shared.model.DefaultDataItem;
 import de.intevation.flys.client.shared.model.MapConfig;
+import de.intevation.flys.client.shared.model.Recommendation;
 import de.intevation.flys.client.shared.model.Theme;
 import de.intevation.flys.client.shared.model.ThemeList;
 import de.intevation.flys.client.shared.model.OutputMode;
 import de.intevation.flys.client.shared.model.WMSLayer;
 
 import de.intevation.flys.client.client.Config;
+import de.intevation.flys.client.client.services.LoadArtifactService;
+import de.intevation.flys.client.client.services.LoadArtifactServiceAsync;
 import de.intevation.flys.client.client.services.StepForwardService;
 import de.intevation.flys.client.client.services.StepForwardServiceAsync;
 import de.intevation.flys.client.client.services.MapOutputService;
@@ -64,6 +68,8 @@
 
     public static final String WSPLGEN_FACET = "floodmap.wsplgen";
 
+    public static final String EXTERNAL_WMS_FACTORY = "externalwmsfactory";
+
 
     protected StepForwardServiceAsync feedService =
         GWT.create(StepForwardService.class);
@@ -71,6 +77,10 @@
     protected MapOutputServiceAsync mapService =
         GWT.create(MapOutputService.class);
 
+    /** Service handle to clone and add artifacts to collection. */
+    protected LoadArtifactServiceAsync loadArtifactService =
+        GWT.create(LoadArtifactService.class);
+
     protected MapToolbar controlPanel;
     protected ThemePanel themePanel;
     protected Widget     mapPanel;
@@ -245,7 +255,37 @@
     @Override
     public void load(List<WMSLayer> toLoad) {
         GWT.log("The user wants to add " + toLoad.size() + " new WMS layers.");
-        // TODO
+
+        int len = toLoad.size();
+
+        Recommendation[] recom = new Recommendation[len];
+
+        for (int i = 0; i < len; i++) {
+            WMSLayer w = toLoad.get(i);
+
+            String ids = w.getServer() + ";" + w.getName() + ";" + w.getTitle();
+            recom[i] = new Recommendation(EXTERNAL_WMS_FACTORY, ids);
+        }
+
+        Collection c = getCollection();
+
+        Config config = Config.getInstance();
+        String locale = config.getLocale();
+
+        loadArtifactService.loadMany(c, recom, EXTERNAL_WMS_FACTORY, locale,
+            new AsyncCallback<Artifact[]>() {
+
+                @Override
+                public void onFailure(Throwable throwable) {
+                    SC.warn(throwable.getMessage());
+                }
+
+                @Override
+                public void onSuccess(Artifact[] newArtifacts) {
+                    SC.warn("SUCCESS!");
+                }
+            }
+        );
     }
 
 
--- a/flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java	Tue Nov 22 20:08:41 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java	Tue Nov 22 20:13:16 2011 +0000
@@ -161,7 +161,7 @@
             XPATH_LAYERS,
             XPathConstants.NODESET);
 
-        List<WMSLayer> layers = parseLayers(layerNodes);
+        List<WMSLayer> layers = parseLayers(layerNodes, onlineResource);
 
         return new Capabilities(
             title,
@@ -222,7 +222,16 @@
     }
 
 
-    protected List<WMSLayer> parseLayers(NodeList layersNode) {
+    /**
+     * @param layersNode
+     * @param onlineResource
+     *
+     * @return
+     */
+    protected List<WMSLayer> parseLayers(
+        NodeList layersNode,
+        String   onlineResource
+    ) {
         int len = layersNode != null ? layersNode.getLength() : 0;
 
         logger.debug("Node has " + len + " layers.");
@@ -230,14 +239,14 @@
         List<WMSLayer> layers = new ArrayList<WMSLayer>(len);
 
         for (int i = 0; i < len; i++) {
-            layers.add(parseLayer(layersNode.item(i)));
+            layers.add(parseLayer(layersNode.item(i), onlineResource));
         }
 
         return layers;
     }
 
 
-    protected WMSLayer parseLayer(Node layerNode) {
+    protected WMSLayer parseLayer(Node layerNode, String onlineResource) {
         String title = (String) XMLUtils.xpath(
             layerNode,
             "Title/text()",
@@ -255,9 +264,9 @@
             "Layer",
             XPathConstants.NODESET);
 
-        List<WMSLayer> layers = parseLayers(layersNodes);
+        List<WMSLayer> layers = parseLayers(layersNodes, onlineResource);
 
-        return new WMSLayer(title, name, layers);
+        return new WMSLayer(onlineResource, 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/WMSLayer.java	Tue Nov 22 20:08:41 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/WMSLayer.java	Tue Nov 22 20:13:16 2011 +0000
@@ -7,6 +7,7 @@
 
 public class WMSLayer implements Serializable {
 
+    protected String server;
     protected String name;
     protected String title;
 
@@ -18,13 +19,30 @@
     }
 
 
-    public WMSLayer(String title, String name, List<WMSLayer> layers) {
+    /**
+     * @param server
+     * @param title
+     * @param name
+     * @param layers
+     */
+    public WMSLayer(
+        String         server,
+        String         title,
+        String         name,
+        List<WMSLayer> layers
+    ) {
+        this.server = server;
         this.title  = title;
         this.name   = name;
         this.layers = layers;
     }
 
 
+    public String getServer() {
+        return server;
+    }
+
+
     public String getName() {
         return name;
     }

http://dive4elements.wald.intevation.org