changeset 831:9101b4d64666

Datacage: Re-written ToLoad to feature the new filter models. flys-client/trunk@2539 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 23 Aug 2011 16:58:07 +0000
parents 3dde14f0bd98
children 303a923d232b
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/shared/model/FacetFilter.java flys-client/src/main/java/de/intevation/flys/client/shared/model/ToLoad.java
diffstat 4 files changed, 49 insertions(+), 127 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Aug 23 16:30:22 2011 +0000
+++ b/flys-client/ChangeLog	Tue Aug 23 16:58:07 2011 +0000
@@ -1,3 +1,14 @@
+2011-08-23	Sascha L. Teichmann	<sascha.teichmann@intevation.de> 
+
+	* src/main/java/de/intevation/flys/client/shared/model/ToLoad.java:
+	  Re-written to feature the new models.
+
+	* src/main/java/de/intevation/flys/client/shared/model/FacetFilter.java:
+	  Be aware of null values for num and name.
+
+	* src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java:
+	  Adjusted calls for new toLoad semantics.
+
 2011-08-23	Sascha L. Teichmann	<sascha.teichmann@intevation.de> 
 
 	* src/main/java/de/intevation/flys/client/shared/model/ArtifactFilter.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java	Tue Aug 23 16:30:22 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java	Tue Aug 23 16:58:07 2011 +0000
@@ -45,8 +45,6 @@
 import de.intevation.flys.client.shared.model.AttrList;
 
 import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Stack;
 
@@ -69,7 +67,7 @@
 
     protected Layout layout;
 
-    protected Map<String, ToLoad> toLoad;
+    protected ToLoad toLoad;
 
 
     public DatacageWindow(Artifact artifact, User user) {
@@ -131,12 +129,12 @@
 
         centerInPage();
 
-        toLoad = new HashMap<String, ToLoad>();
+        toLoad = new ToLoad();
 
         triggerTreeBuilding();
     }
 
-    public Map<String, ToLoad> toLoad() {
+    public ToLoad getToLoad() {
         return toLoad;
     }
 
@@ -155,8 +153,6 @@
             }
         }
 
-        GWT.log(toLoad.toString());
-
         if (!toLoad.isEmpty()) {
             destroy();
         }
@@ -166,7 +162,6 @@
 
         TreeNode node = (TreeNode)event.getRecord();
         collectToLoads(node);
-        GWT.log(toLoad.toString());
         destroy();
     }
 
@@ -179,16 +174,12 @@
             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");
+                String artifact = node.getAttribute("artifact-id");
+                String out      = node.getAttribute("out");
+                String name     = node.getName();
+                String num      = node.getAttribute("num");
 
-                ToLoad tl = toLoad.get(artifactId);
-                if (tl == null) {
-                    tl = new ToLoad(artifactId);
-                }
-
-                tl.add(factory, ids, num);
+                toLoad.add(artifact, factory, out, name, num);
             }
             TreeNode [] children = tree.getChildren(node);
             if (children != null) {
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/FacetFilter.java	Tue Aug 23 16:30:22 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/FacetFilter.java	Tue Aug 23 16:58:07 2011 +0000
@@ -32,12 +32,19 @@
         this.num = num;
     }
 
+    protected static boolean equals(String a, String b) {
+        if (a == null && b == null) return true;
+        if (a == null && b != null) return false;
+        if (a != null && b == null) return false;
+        return a.equals(b);
+    }
+
     public boolean equals(Object other) {
         if (!(other instanceof FacetFilter)) {
             return false;
         }
         FacetFilter o = (FacetFilter)other;
-        return o.name.equals(name) && o.num.equals(num);
+        return equals(o.name, name) && equals(o.num, num);
     }
 }
 // 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/ToLoad.java	Tue Aug 23 16:30:22 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/ToLoad.java	Tue Aug 23 16:58:07 2011 +0000
@@ -1,133 +1,46 @@
 package de.intevation.flys.client.shared.model;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Map;
 import java.util.HashMap;
-import java.util.Iterator;
 
 import java.io.Serializable;
 
 public class ToLoad implements Serializable
 {
-    public static class Tuple {
-
-        protected String ids;
-        protected String num;
-
-        public Tuple() {
-        }
-
-        public Tuple(String ids, String num) {
-            this.ids = ids;
-            this.num = num;
-        }
+    protected Map<String, Map<String, ArtifactFilter>> artifacts;
 
-        @Override
-        public boolean equals(Object other) {
-            if (!(other instanceof Tuple)) {
-                return false;
-            }
-            Tuple o = (Tuple)other;
-            return ToLoad.equals(o.ids, ids) && ToLoad.equals(o.num, num);
-        }
-
-        public void toString(StringBuilder sb) {
-            sb.append("[ids='").append(ids)
-              .append("', num='").append(num).append("']");
-        }
+    public ToLoad() {
+        artifacts = new HashMap<String, Map<String, ArtifactFilter>>();
     }
 
-    public static class Factory {
-
-        protected String      name;
-        protected List<Tuple> tuples;
-
-        public Factory() {
-            tuples = new ArrayList<Tuple>();
-        }
+    public void add(
+        String artifactName,
+        String factory,
+        String out,
+        String name,
+        String num
+    ) {
+        if (artifactName == null) artifactName = "";
+        if (out          == null) out          = "";
 
-        public Factory(String name) {
-            this();
-            this.name = name;
-        }
+        Map<String, ArtifactFilter> artifact = artifacts.get(artifactName);
 
-        void add(String ids, String num) {
-            Tuple t = new Tuple(ids, num);
-            if (!tuples.contains(t)) {
-                tuples.add(t);
-            }
+        if (artifact == null) {
+            artifact = new HashMap<String, ArtifactFilter>();
+            artifacts.put(artifactName, artifact);
         }
 
-        public void toString(StringBuilder sb) {
-            for (Iterator<Tuple> iter = tuples.iterator(); iter.hasNext();) {
-                Tuple t = iter.next();
-                t.toString(sb);
-                if (iter.hasNext()) {
-                    sb.append(", ");
-                }
-            }
+        ArtifactFilter filter = artifact.get(factory);
+        if (filter == null) {
+            filter = new ArtifactFilter(factory);
+            artifact.put(factory, filter);
         }
-    }
-
-    protected String artifactId;
-
-    protected Map<String, Factory> factories;
-
-    public ToLoad() {
-        factories = new HashMap<String, Factory>();
-    }
-
-    public ToLoad(String artifactId) {
-        this.artifactId = artifactId;
-    }
-
-    public String getArtifactId() {
-        return artifactId;
-    }
-
-    public void setArtifactId(String artifactId) {
-        this.artifactId = artifactId;
-    }
 
-    public void add(String factoryName, String ids, String num) {
-        Factory factory = factories.get(factoryName);
-        if (factory == null) {
-            factory = new Factory(factoryName);
-        }
-        factory.add(ids, num);
-    }
-
-    protected 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 String toString() {
-        StringBuilder sb = new StringBuilder("[")
-          .append("artifactId='").append(artifactId).append("', factories=[");
-
-        for (Iterator<Map.Entry<String, Factory>> 
-            iter = factories.entrySet().iterator(); iter.hasNext();) {
-            Map.Entry<String, Factory> entry = iter.next();
-            String  name    = entry.getKey();
-            Factory factory = entry.getValue();
-
-            sb.append("[name='").append(name).append("', factory=[");
-            factory.toString(sb);
-            sb.append(']');
-            if (iter.hasNext()) {
-                sb.append(", ");
-            }
-        }
-        return sb.append("]]").toString();
+        filter.add(out, name, num);
     }
 
     public boolean isEmpty() {
-        return factories.isEmpty();
+        return artifacts.isEmpty();
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org