changeset 278:f33af25b7490

Datacage: transport rpc result to ui. flys-client/trunk@1905 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 11 May 2011 16:38:54 +0000
parents 50b88b641be6
children e763d8efd42f
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/services/MetaDataService.java flys-client/src/main/java/de/intevation/flys/client/client/services/MetaDataServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java flys-client/src/main/java/de/intevation/flys/client/server/MetaDataServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DataCageNode.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DataCageTree.java
diffstat 7 files changed, 204 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed May 11 15:33:54 2011 +0000
+++ b/flys-client/ChangeLog	Wed May 11 16:38:54 2011 +0000
@@ -1,3 +1,23 @@
+2011-05-11	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/DataCageNode.java,
+	  src/main/java/de/intevation/flys/client/shared/model/DataCageTree.java:
+	  New. Server -> Client transport model. Ugly because it re-invents XML
+	  documents. XML is received by the RPC service from the artifact server,
+	  transformed into this transport representation and this is transformed
+	  in ui elements on the client side.
+
+	* src/main/java/de/intevation/flys/client/server/MetaDataServiceImpl.java:
+	  Transform the incoming XML to transport representation. TODO:
+	  Do not simply copy the XML.
+
+	* src/main/java/de/intevation/flys/client/client/services/MetaDataServiceAsync.java,
+	  src/main/java/de/intevation/flys/client/client/services/MetaDataService.java:
+	  Changed signature tio transport the tree.
+
+	* src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java:
+	  Transform the transport tree into ui elements.
+
 2011-05-11  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/ExportPanel.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/MetaDataService.java	Wed May 11 15:33:54 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/MetaDataService.java	Wed May 11 16:38:54 2011 +0000
@@ -5,12 +5,12 @@
 
 import de.intevation.flys.client.shared.exceptions.ServerException;
 
-import java.util.List;
+import de.intevation.flys.client.shared.model.DataCageTree;
 
 @RemoteServiceRelativePath("meta-data")
 public interface MetaDataService extends RemoteService
 {
-    List getMetaData(String serverUrl, String locale, String name)
+    DataCageTree getMetaData(String serverUrl, String locale, String name)
         throws ServerException;
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/MetaDataServiceAsync.java	Wed May 11 15:33:54 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/MetaDataServiceAsync.java	Wed May 11 16:38:54 2011 +0000
@@ -2,14 +2,14 @@
 
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
-import java.util.List;
+import de.intevation.flys.client.shared.model.DataCageTree;
 
 public interface MetaDataServiceAsync {
     void getMetaData(
         String              serverUrl,
         String              locale,
         String              name, 
-        AsyncCallback<List> cb);
+        AsyncCallback<DataCageTree> cb);
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java	Wed May 11 15:33:54 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java	Wed May 11 16:38:54 2011 +0000
@@ -1,6 +1,7 @@
 package de.intevation.flys.client.client.ui;
 
 import java.util.List;
+import java.util.ArrayList;
 
 import com.google.gwt.core.client.GWT;
 
@@ -10,6 +11,12 @@
 
 import com.smartgwt.client.widgets.Window;
 
+import com.smartgwt.client.widgets.tree.Tree;
+import com.smartgwt.client.widgets.tree.TreeNode;
+import com.smartgwt.client.widgets.tree.TreeGrid;
+
+import com.smartgwt.client.widgets.layout.Layout;
+import com.smartgwt.client.widgets.layout.VLayout;
 
 import de.intevation.flys.client.shared.model.Artifact;
 import de.intevation.flys.client.shared.model.ArtifactDescription;
@@ -23,6 +30,8 @@
 import de.intevation.flys.client.client.services.MetaDataService;
 import de.intevation.flys.client.client.services.MetaDataServiceAsync;
 
+import de.intevation.flys.client.shared.model.DataCageTree;
+import de.intevation.flys.client.shared.model.DataCageNode;
 
 public class DatacageWindow
 extends      Window
@@ -36,14 +45,36 @@
 
     protected Artifact artifact;
 
+    protected TreeGrid treeGrid;
+
+    protected Layout layout;
+
+
     public DatacageWindow(Artifact artifact) {
         this.artifact = artifact;
-        setHeight(115);  
+
+        setWidth(200);
+        setHeight(300);
+
+        layout = new VLayout();
+        layout.setWidth100();
+
+        addItem(layout);
+
+        treeGrid = new TreeGrid();  
+        treeGrid.setLoadDataOnDemand(false);          
+        treeGrid.setWidth100();  
+        treeGrid.setHeight100();
+
+        layout.addMember(treeGrid);
+
         String river =  findRiver();
         setTitle("Datenkorb: " + river);  
         setShowMinimizeButton(false);  
         setIsModal(true);  
         setShowModalMask(true);  
+        setCanDragResize(true);
+
         centerInPage();
 
         triggerTreeBuilding(river);
@@ -56,18 +87,73 @@
 
         metaDataService.getMetaData(
             url, locale, river,
-            new AsyncCallback<List>() {
+            new AsyncCallback<DataCageTree>() {
                 public void onFailure(Throwable caught) {
                     GWT.log("Could not load meta data.");
                     SC.warn(messages.getString(caught.getMessage()));
                 }
 
-                public void onSuccess(List list) {
-                    GWT.log("Successfully created a new collection.");
+                public void onSuccess(DataCageTree tree) {
+                    GWT.log("Successfully loaded meta data.");
+                    buildTree(tree);
                 }
             });
     }
 
+    protected void buildTree(DataCageTree tree) {
+        treeGrid.setData(convert(tree));
+    }
+
+    protected static TreeNode convert(DataCageNode node) {
+        List<DataCageNode> children = node.getChildren();
+
+        TreeNode [] cs;
+
+        if (children != null) {
+            ArrayList<TreeNode> nc = new ArrayList<TreeNode>(children.size());
+
+            for (DataCageNode dcn: children) {
+                nc.add(convert(dcn));
+            }
+
+            cs = nc.toArray(new TreeNode[nc.size()]);
+        }
+        else {
+            cs = new TreeNode[0];
+        }
+
+        return new TreeNode(node.getName(), cs);
+    }
+
+    protected static Tree convert(DataCageTree tree) {
+        DataCageNode root = tree.getRoot();
+
+        List<DataCageNode> children = root.getChildren();
+
+        TreeNode [] cs;
+
+        if (children != null) {
+            ArrayList<TreeNode> nc = new ArrayList<TreeNode>(children.size());
+
+            if (nc != null) {
+                for (DataCageNode dcn: children) {
+                    nc.add(convert(dcn));
+                }
+            }
+            cs = nc.toArray(new TreeNode[nc.size()]);
+        }
+        else {
+            cs = new TreeNode[0];
+        }
+
+        TreeNode rn = new TreeNode(root.getName(), cs);
+
+        Tree r = new Tree();
+        r.setRoot(rn);
+
+        return r;
+    }
+
     protected String findRiver() {
 
         ArtifactDescription adescr = artifact.getArtifactDescription();
--- a/flys-client/src/main/java/de/intevation/flys/client/server/MetaDataServiceImpl.java	Wed May 11 15:33:54 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/MetaDataServiceImpl.java	Wed May 11 16:38:54 2011 +0000
@@ -23,6 +23,9 @@
 import de.intevation.artifacts.httpclient.http.HttpClient;
 import de.intevation.artifacts.httpclient.http.HttpClientImpl;
 
+import de.intevation.flys.client.shared.model.DataCageTree;
+import de.intevation.flys.client.shared.model.DataCageNode;
+
 public class MetaDataServiceImpl
 extends      RemoteServiceServlet
 implements   MetaDataService
@@ -30,7 +33,7 @@
     public static final String ERROR_NO_META_DATA_FOUND =
         "error_no_meta_data_found";
 
-    public List getMetaData(String url, String locale, String river) 
+    public DataCageTree getMetaData(String url, String locale, String river) 
     throws ServerException
     {
         System.out.println("MetaDataService.getDistanceInfo");
@@ -51,9 +54,7 @@
         HttpClient client = new HttpClientImpl(url, locale);
 
         try {
-            Document result = client.callService(url, "metadata", doc);
-
-            return new ArrayList();
+            return convert(client.callService(url, "metadata", doc));
         }
         catch (ConnectionException ce) {
             System.err.println(ce.getLocalizedMessage());
@@ -61,5 +62,27 @@
 
         throw new ServerException(ERROR_NO_META_DATA_FOUND);
     }
+
+    protected static DataCageNode convert(Node node) {
+        String name = node.getLocalName();
+        DataCageNode dvn = new DataCageNode(name);
+        NodeList children = node.getChildNodes();
+        for (int i = 0, N = children.getLength(); i < N; ++i) {
+            dvn.addChild(convert(children.item(i)));
+        }
+        return dvn;
+    }
+
+    protected static DataCageTree convert(Document document) {
+        ArrayList<DataCageNode> roots = new ArrayList<DataCageNode>();
+        NodeList nodes = document.getChildNodes();
+        for (int i = 0, N = nodes.getLength(); i < N; ++i) {
+            Node node = nodes.item(i);
+            if (node.getNodeType() == Node.ELEMENT_NODE) {
+                roots.add(convert(nodes.item(i)));
+            }
+        }
+        return new DataCageTree(roots.get(0));
+    }
 }
 // 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/shared/model/DataCageNode.java	Wed May 11 16:38:54 2011 +0000
@@ -0,0 +1,39 @@
+package de.intevation.flys.client.shared.model;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import java.io.Serializable;
+
+public class DataCageNode implements Serializable
+{
+    protected String             name;
+    protected List<DataCageNode> children;
+
+    public DataCageNode() {
+    }
+
+    public DataCageNode(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void addChild(DataCageNode child) {
+        if (children == null) {
+            children = new ArrayList<DataCageNode>();
+        }
+        children.add(child);
+    }
+
+    public List<DataCageNode> getChildren() {
+        return children;
+    }
+}
+// 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/shared/model/DataCageTree.java	Wed May 11 16:38:54 2011 +0000
@@ -0,0 +1,24 @@
+package de.intevation.flys.client.shared.model;
+
+import java.io.Serializable;
+
+public class DataCageTree implements Serializable
+{
+    protected DataCageNode root;
+
+    public DataCageTree() {
+    }
+
+    public DataCageTree(DataCageNode root) {
+        this.root = root;
+    }
+
+    public void setRoot(DataCageNode root) {
+        this.root = root;
+    }
+
+    public DataCageNode getRoot() {
+        return root;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org