changeset 1412:659a488243da

Added code to trigger loading selected WMS layers from ExternalWMSWindow. Note: no code for loading/adding layers to the current map existing yet. flys-client/trunk@3299 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 22 Nov 2011 13:04:46 +0000 (2011-11-22)
parents 63be3137abac
children 0d3bbe4240b1
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/MapOutputTab.java flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java flys-client/src/main/java/de/intevation/flys/client/client/ui/map/WMSLayersTree.java
diffstat 5 files changed, 102 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Nov 21 21:00:03 2011 +0000
+++ b/flys-client/ChangeLog	Tue Nov 22 13:04:46 2011 +0000
@@ -1,3 +1,24 @@
+2011-11-22  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java:
+	  Defined an internal interface LayerLoader to load selected WMSLayers of
+	  the tree. The constructor of ExternalWMSWindow now requires an instance
+	  of LayerLoader. The "go on" button in the layer panel will finally
+	  trigger the LayerLoader.load() method.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java:
+	  Implements the ExternalWMSWindow.LayerLoader interface to add the
+	  selected WMS layers to the map. TODO: implement code to load/add layers.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/WMSLayersTree.java:
+	  Added an inner class WMSLayerNode that extends TreeNode with the
+	  addition to save a WMSLayer object. The reason here: we want to have all
+	  information of the selected WMS layers for loading mechanisms.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java:
+	  Modified the constructor call of ExternalWMSWindow. The MapOutputTab is
+	  used as ExternalWMSWindow.LayerLoader.
+
 2011-11-21  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/shared/model/WMSLayer.java: New.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java	Mon Nov 21 21:00:03 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java	Tue Nov 22 13:04:46 2011 +0000
@@ -1,5 +1,8 @@
 package de.intevation.flys.client.client.ui.map;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.user.client.ui.TextBox;
@@ -10,11 +13,13 @@
 import com.smartgwt.client.widgets.Window;
 import com.smartgwt.client.widgets.events.ClickEvent;
 import com.smartgwt.client.widgets.events.ClickHandler;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
 import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.layout.Layout;
 import com.smartgwt.client.widgets.layout.VLayout;
 
 import de.intevation.flys.client.shared.model.Capabilities;
+import de.intevation.flys.client.shared.model.WMSLayer;
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.services.GCService;
 import de.intevation.flys.client.client.services.GCServiceAsync;
@@ -22,6 +27,11 @@
 
 public class ExternalWMSWindow extends Window {
 
+    public interface LayerLoader {
+        void load(List<WMSLayer> toLoad);
+    } // end of interface WMSLayerLoader
+
+
     protected GCServiceAsync gcService = GWT.create(GCService.class);
     protected FLYSConstants  MSG       = GWT.create(FLYSConstants.class);
 
@@ -33,9 +43,12 @@
 
     protected String url;
 
+    protected LayerLoader loader;
 
-    public ExternalWMSWindow() {
+
+    public ExternalWMSWindow(LayerLoader loader) {
         super();
+        this.loader = loader;
     }
 
 
@@ -212,6 +225,8 @@
     protected Layout createLayersPanel() {
         setTitle(MSG.addwmsLayerTitle());
 
+        final WMSLayersTree tree = new WMSLayersTree(capabilites);
+
         ClickHandler backHandler = new ClickHandler() {
             @Override
             public void onClick(ClickEvent e) {
@@ -222,7 +237,21 @@
         ClickHandler goHandler = new ClickHandler() {
             @Override
             public void onClick(ClickEvent e) {
-                goToLayersPanel();
+                ListGridRecord[] selection = tree.getSelectedRecords();
+
+                if (selection == null || selection.length == 0) {
+                    return;
+                }
+
+                List<WMSLayer> toLoad = new ArrayList<WMSLayer>();
+
+                for (ListGridRecord record: selection) {
+                    toLoad.add(
+                        ((WMSLayersTree.WMSLayerNode) record).getWMSLayer());
+
+                }
+
+                finish(toLoad);
             }
         };
 
@@ -233,8 +262,7 @@
             }
         };
 
-        VLayout       root = new VLayout();
-        WMSLayersTree tree = new WMSLayersTree(capabilites);
+        VLayout root = new VLayout();
 
         root.setLayoutMargin(10);
         tree.setHeight(420);
@@ -301,6 +329,13 @@
     }
 
 
+    protected void finish(List<WMSLayer> toLoad) {
+        loader.load(toLoad);
+
+        quit();
+    }
+
+
     protected void quit() {
         destroy();
     }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java	Mon Nov 21 21:00:03 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java	Tue Nov 22 13:04:46 2011 +0000
@@ -40,6 +40,7 @@
 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.StepForwardService;
@@ -53,7 +54,9 @@
 import de.intevation.flys.client.client.ui.ThemePanel;
 
 
-public class MapOutputTab extends OutputTab implements RedrawRequestHandler {
+public class MapOutputTab
+extends      OutputTab
+implements   RedrawRequestHandler, ExternalWMSWindow.LayerLoader {
 
     public static final String DEFAULT_SRID = "4326";
 
@@ -239,6 +242,13 @@
     }
 
 
+    @Override
+    public void load(List<WMSLayer> toLoad) {
+        GWT.log("The user wants to add " + toLoad.size() + " new WMS layers.");
+        // TODO
+    }
+
+
     protected void setFloodmap(FloodMap floodMap) {
         this.floodMap = floodMap;
     }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Mon Nov 21 21:00:03 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Tue Nov 22 13:04:46 2011 +0000
@@ -524,8 +524,8 @@
     protected ImgButton createWMSControl() {
         ImgButton add = createButton(MSG.addWMS(), new ClickHandler() {
             public void onClick(ClickEvent event) {
-                // TODO
-                new ExternalWMSWindow().start();
+                MapOutputTab ot = (MapOutputTab) getOutputTab();
+                new ExternalWMSWindow(ot).start();
             }
         });
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/WMSLayersTree.java	Mon Nov 21 21:00:03 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/WMSLayersTree.java	Tue Nov 22 13:04:46 2011 +0000
@@ -14,6 +14,28 @@
 
 public class WMSLayersTree extends TreeGrid {
 
+    /**
+     * An internal TreeNode that stores besides some string attribute a WMSLayer
+     * object.
+     */
+    public static class WMSLayerNode extends TreeNode {
+
+        protected WMSLayer wms;
+
+        public WMSLayerNode(WMSLayer wms) {
+            super();
+            this.wms = wms;
+
+            setAttribute("name", wms.getName());
+            setAttribute("title", wms.getTitle());
+        }
+
+        public WMSLayer getWMSLayer() {
+            return wms;
+        }
+    } // end of class WMSLayerNode
+
+
     protected Capabilities capabilites;
 
     public WMSLayersTree(Capabilities capabilites) {
@@ -57,11 +79,8 @@
         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());
+            WMSLayerNode tn = buildTreeNode(layer);
+            TreeNode[] tns  = buildTree(layer.getLayers());
 
             if (tns != null && tns.length > 0) {
                 tn.setAttribute("children-nodes", tns);
@@ -72,4 +91,9 @@
 
         return (TreeNode[]) layerNodes.toArray(new TreeNode[layerNodes.size()]);
     }
+
+
+    protected static WMSLayerNode buildTreeNode(WMSLayer wms) {
+        return new WMSLayerNode(wms);
+    }
 }

http://dive4elements.wald.intevation.org