changeset 822:ffb98b228b3c

Add code to extract data to load from datacage tree. flys-client/trunk@2493 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 12 Aug 2011 15:51:51 +0000
parents 56069d236afa
children 407de0f4b66a
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java flys-client/src/main/java/de/intevation/flys/client/server/meta/Converter.java flys-client/src/main/java/de/intevation/flys/client/shared/model/AttrList.java flys-client/src/main/java/de/intevation/flys/client/shared/model/ToLoad.java
diffstat 5 files changed, 209 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Aug 09 13:37:40 2011 +0000
+++ b/flys-client/ChangeLog	Fri Aug 12 15:51:51 2011 +0000
@@ -1,3 +1,24 @@
+2011-08-12	Sascha L. Teichmann	<sascha.teichmann@intevation.de> 
+
+	Extract selected data from datacage panel
+
+	* src/main/java/de/intevation/flys/client/server/meta/Converter.java:
+	  Removed some debugging.
+
+	* src/main/java/de/intevation/flys/client/shared/model/ToLoad.java: New.
+	  Contains artifact id, db ids, factory name and facet number. Should
+	  be enough to identify the data to load.
+	* src/main/java/de/intevation/flys/client/shared/model/AttrList.java:
+	  Fixed indexing bug.
+
+	* src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java:
+	  Added a toLoad() method which returns a list of ToLoad data to load via
+	  the corresponding factories.
+	  If you double click on a tree node all data below this filled into this list
+	  and the window is disposed.
+	  You can do multipl selects on the and press the '+' button to do
+	  a multiselect loading.
+
 2011-08-09	Sascha L. Teichmann	<sascha.teichmann@intevation.de> 
 
 	* src/main/java/de/intevation/flys/client/server/meta/Converter.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java	Tue Aug 09 13:37:40 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java	Fri Aug 12 15:51:51 2011 +0000
@@ -7,6 +7,7 @@
 import com.smartgwt.client.util.SC;
 
 import com.smartgwt.client.widgets.Window;
+import com.smartgwt.client.widgets.Button;
 
 import com.smartgwt.client.widgets.tree.Tree;
 import com.smartgwt.client.widgets.tree.TreeGrid;
@@ -17,8 +18,13 @@
 import com.smartgwt.client.widgets.layout.Layout;
 import com.smartgwt.client.widgets.layout.VLayout;
 
-import com.smartgwt.client.widgets.tree.events.LeafClickEvent;
-import com.smartgwt.client.widgets.tree.events.LeafClickHandler;
+import com.smartgwt.client.widgets.events.ClickHandler;
+import com.smartgwt.client.widgets.events.ClickEvent;
+
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+
+import com.smartgwt.client.widgets.grid.events.RecordDoubleClickEvent;
+import com.smartgwt.client.widgets.grid.events.RecordDoubleClickHandler;
 
 import de.intevation.flys.client.shared.model.Artifact;
 import de.intevation.flys.client.shared.model.ArtifactDescription;
@@ -26,6 +32,7 @@
 import de.intevation.flys.client.shared.model.DataList;
 import de.intevation.flys.client.shared.model.DataItem;
 import de.intevation.flys.client.shared.model.User;
+import de.intevation.flys.client.shared.model.ToLoad;
 
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.Config;
@@ -39,6 +46,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Stack;
 
 public class DatacageWindow
 extends      Window
@@ -58,13 +66,15 @@
 
     protected Layout layout;
 
+    protected List<ToLoad> toLoad;
+
 
     public DatacageWindow(Artifact artifact, User user) {
         this.artifact = artifact;
         this.user     = user;
 
-        setWidth(250);
-        setHeight(400);
+        setWidth(300);
+        setHeight(500);
 
         layout = new VLayout();
         layout.setWidth100();
@@ -83,15 +93,26 @@
         treeGrid.setHeight100();
         treeGrid.setShowRoot(false);
 
-        treeGrid.addLeafClickHandler(new LeafClickHandler() {
+        treeGrid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {
             @Override
-            public void onLeafClick(LeafClickEvent lce) {
-                GWT.log("I was here");
+            public void onRecordDoubleClick(RecordDoubleClickEvent event) {
+                doubleClickedOnTree(event);
             }
         });
 
         layout.addMember(treeGrid);
 
+        // TODO: i18n + icon
+        Button plusBtn = new Button("+");
+        plusBtn.addClickHandler(new ClickHandler() {
+            @Override
+            public void onClick(ClickEvent event) {
+                plusClicked();
+            }
+        });
+
+        layout.addMember(plusBtn);
+
         String river =  findRiver();
         // TODO: i18n
         setTitle("Datenkorb: " + river);
@@ -102,9 +123,73 @@
 
         centerInPage();
 
+        toLoad = new ArrayList<ToLoad>();
+
         triggerTreeBuilding();
     }
 
+    public List<ToLoad> toLoad() {
+        return toLoad;
+    }
+
+    public void plusClicked() {
+        if (treeGrid == null) {
+            return;
+        }
+
+        ListGridRecord [] selection = treeGrid.getSelection();
+
+        if (selection != null) {
+            for (ListGridRecord record: selection) {
+                if (record instanceof TreeNode) {
+                    collectToLoads((TreeNode)record);
+                }
+            }
+        }
+
+        GWT.log(toLoad.toString());
+
+        if (!toLoad.isEmpty()) {
+            destroy();
+        }
+    }
+
+    protected void doubleClickedOnTree(RecordDoubleClickEvent event) {
+
+        TreeNode node = (TreeNode)event.getRecord();
+        collectToLoads(node);
+        GWT.log(toLoad.toString());
+        destroy();
+    }
+
+    protected void collectToLoads(TreeNode node) {
+        Stack<TreeNode> stack = new Stack<TreeNode>();
+
+        stack.push(node);
+
+        while (!stack.isEmpty()) {
+            node = stack.pop();
+            String factory = node.getAttribute("factory");
+            if (factory != null) { // we need at least a factory
+                String ids        = node.getAttribute("ids");
+                String artifactId = node.getAttribute("artifact-id");
+                String num        = node.getAttribute("num");
+
+                ToLoad tl = new ToLoad(factory, artifactId, ids, num);
+                if (!toLoad.contains(tl)) {
+                    toLoad.add(tl);
+                }
+            }
+            TreeNode [] children = tree.getChildren(node);
+            if (children != null) {
+                for (TreeNode child: children) {
+                    stack.push(child);
+                }
+            }
+        }
+    }
+
+
     protected void triggerTreeBuilding() {
         Config config = Config.getInstance();
         String url    = config.getServerUrl();
--- a/flys-client/src/main/java/de/intevation/flys/client/server/meta/Converter.java	Tue Aug 09 13:37:40 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/meta/Converter.java	Fri Aug 12 15:51:51 2011 +0000
@@ -28,7 +28,7 @@
 
     public static class NameConverter implements NodeConverter {
         public DataCageNode convert(Element node, Converter converter) {
-            System.err.println("NameConverter called");
+            //System.err.println("NameConverter called");
             DataCageNode out = new DataCageNode(
                 node.getAttribute("name"),
                 toAttrList(node.getAttributes()));
@@ -39,11 +39,12 @@
 
     public static class I18NConverter implements NodeConverter {
         public DataCageNode convert(Element node, Converter converter) {
-            System.err.println("I18NConverter called");
+            //System.err.println("I18NConverter called");
+            String name = node.hasAttribute("description")
+                ? node.getAttribute("description")
+                : "${" + node.getLocalName() + "}";
             DataCageNode out =
-                new DataCageNode(
-                    "${" + node.getLocalName() + "}",
-                    toAttrList(node.getAttributes()));
+                new DataCageNode(name, toAttrList(node.getAttributes()));
             converter.convertChildren(out, node);
             return out;
         }
@@ -52,7 +53,7 @@
     protected Map<String, NodeConverter> converters;
 
     protected void convertChildren(DataCageNode parent, Element sub) {
-        System.err.println("convertChildren called");
+        //System.err.println("convertChildren called");
         NodeList children = sub.getChildNodes();
         for (int i = 0, N = children.getLength(); i < N; ++i) {
             Node child = children.item(i);
@@ -122,7 +123,7 @@
         for (int i = 0; i < N; ++i) {
             Node node = nodeMap.item(i);
             if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
-                Attr   attr   = (Attr)node;
+                Attr   attr  = (Attr)node;
                 String key   = attr.getName();
                 String value = attr.getValue();
                 result.add(key, value);
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/AttrList.java	Tue Aug 09 13:37:40 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/AttrList.java	Fri Aug 12 15:51:51 2011 +0000
@@ -22,11 +22,11 @@
     }
 
     public String getKey(int index) {
-        return keyValues.get(index/2);
+        return keyValues.get(index*2);
     }
 
     public String getValue(int index) {
-        return keyValues.get(index/2 + 1);
+        return keyValues.get(index*2 + 1);
     }
 
     public void add(String key, String value) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/ToLoad.java	Fri Aug 12 15:51:51 2011 +0000
@@ -0,0 +1,86 @@
+package de.intevation.flys.client.shared.model;
+
+import java.io.Serializable;
+
+public class ToLoad implements Serializable
+{
+    protected String artifactId;
+    protected String ids;
+    protected String factory;
+    protected String num;
+
+    public ToLoad() {
+    }
+
+    public ToLoad(
+        String factory,
+        String artifactId, 
+        String ids, 
+        String num
+    ) {
+        this.factory    = factory;
+        this.artifactId = artifactId;
+        this.ids        = ids;
+        this.num        = num;
+    }
+
+    public String getArtifactId() {
+        return artifactId;
+    }
+
+    public void setArtifactId(String artifactId) {
+        this.artifactId = artifactId;
+    }
+
+    public String getIds() {
+        return ids;
+    }
+
+    public void setIds(String ids) {
+        this.ids = ids;
+    }
+
+    public String getFactory() {
+        return factory;
+    }
+
+    public void setFactory(String factory) {
+        this.factory = factory;
+    }
+
+    public String getNum() {
+        return num;
+    }
+
+    public void setNum(String num) {
+        this.num = num;
+    }
+
+    private static final boolean equals(String a, String b) {
+        if ((a == null && b != null) || (a != null && b == null)) {
+            return false;
+        }
+        return (a == null && b == null) || a.equals(b);
+    }
+
+    @Override
+    public boolean equals(Object other) {
+        if (!(other instanceof ToLoad)) {
+            return false;
+        }
+        ToLoad o = (ToLoad)other;
+        return equals(factory,    o.factory)
+            && equals(artifactId, o.artifactId)
+            && equals(ids,        o.ids)
+            && equals(num,        o.num);
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder("[")
+          .append("factory='").append(factory).append("', artifactId='")
+          .append(artifactId).append("', ids='").append(ids)
+          .append("', num='").append(num).append("']");
+        return sb.toString();
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org