changeset 826:2f65c742803f

Datacage: Aggregate items to load for easier filtering facets flys-client/trunk@2523 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 22 Aug 2011 14:29:49 +0000
parents 1b9b7e9ab219
children bd56dc762e7f
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/ToLoad.java
diffstat 3 files changed, 116 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Aug 22 13:29:55 2011 +0000
+++ b/flys-client/ChangeLog	Mon Aug 22 14:29:49 2011 +0000
@@ -1,3 +1,11 @@
+2011-08-22	Sascha L. Teichmann	<sascha.teichmann@intevation.de> 
+
+	* src/main/java/de/intevation/flys/client/shared/model/ToLoad.java,
+	  src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java:
+	  Aggregate the items to load by artifact id and factories. Makes
+	  it easier to build filter views on new created artifacts to be
+	  added to the current collection.
+
 2011-08-22  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/CollectionView.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java	Mon Aug 22 13:29:55 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java	Mon Aug 22 14:29:49 2011 +0000
@@ -45,6 +45,8 @@
 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;
 
@@ -66,7 +68,7 @@
 
     protected Layout layout;
 
-    protected List<ToLoad> toLoad;
+    protected Map<String, ToLoad> toLoad;
 
 
     public DatacageWindow(Artifact artifact, User user) {
@@ -123,12 +125,12 @@
 
         centerInPage();
 
-        toLoad = new ArrayList<ToLoad>();
+        toLoad = new HashMap<String, ToLoad>();
 
         triggerTreeBuilding();
     }
 
-    public List<ToLoad> toLoad() {
+    public Map<String, ToLoad> toLoad() {
         return toLoad;
     }
 
@@ -175,10 +177,12 @@
                 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);
+                ToLoad tl = toLoad.get(artifactId);
+                if (tl == null) {
+                    tl = new ToLoad(artifactId);
                 }
+
+                tl.add(factory, ids, num);
             }
             TreeNode [] children = tree.getChildren(node);
             if (children != null) {
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ToLoad.java	Mon Aug 22 13:29:55 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/ToLoad.java	Mon Aug 22 14:29:49 2011 +0000
@@ -1,27 +1,85 @@
 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
 {
-    protected String artifactId;
-    protected String ids;
-    protected String factory;
-    protected String num;
+    public static class Tuple {
 
-    public ToLoad() {
+        protected String ids;
+        protected String num;
+
+        public Tuple() {
+        }
+
+        public Tuple(String ids, String num) {
+            this.ids = ids;
+            this.num = num;
+        }
+
+        @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(
-        String factory,
-        String artifactId, 
-        String ids, 
-        String num
-    ) {
-        this.factory    = factory;
+    public static class Factory {
+
+        protected String      name;
+        protected List<Tuple> tuples;
+
+        public Factory() {
+            tuples = new ArrayList<Tuple>();
+        }
+
+        public Factory(String name) {
+            this();
+            this.name = name;
+        }
+
+        void add(String ids, String num) {
+            Tuple t = new Tuple(ids, num);
+            if (!tuples.contains(t)) {
+                tuples.add(t);
+            }
+        }
+
+        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(", ");
+                }
+            }
+        }
+    }
+
+    protected String artifactId;
+
+    protected Map<String, Factory> factories;
+
+    public ToLoad() {
+        factories = new HashMap<String, Factory>();
+    }
+
+    public ToLoad(String artifactId) {
         this.artifactId = artifactId;
-        this.ids        = ids;
-        this.num        = num;
     }
 
     public String getArtifactId() {
@@ -32,31 +90,15 @@
         this.artifactId = artifactId;
     }
 
-    public String getIds() {
-        return ids;
-    }
-
-    public void setIds(String ids) {
-        this.ids = ids;
-    }
-
-    public String getFactory() {
-        return factory;
+    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);
     }
 
-    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) {
+    protected static final boolean equals(String a, String b) {
         if ((a == null && b != null) || (a != null && b == null)) {
             return false;
         }
@@ -64,23 +106,28 @@
     }
 
     @Override
-    public boolean equals(Object other) {
-        if (!(other instanceof ToLoad)) {
-            return false;
+    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(", ");
+            }
         }
-        ToLoad o = (ToLoad)other;
-        return equals(factory,    o.factory)
-            && equals(artifactId, o.artifactId)
-            && equals(ids,        o.ids)
-            && equals(num,        o.num);
+        return sb.append("]]").toString();
     }
 
-    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();
+    public boolean isEmpty() {
+        return factories.isEmpty();
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org