changeset 804:374712890b94

Facets read from Collection's DESCRIBE document keep all their attributes after the Collection's attribute has been modified. flys-client/trunk@2362 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 19 Jul 2011 16:32:52 +0000 (2011-07-19)
parents 653ae84533e7
children f43d06d6a4a2
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java flys-client/src/main/java/de/intevation/flys/client/server/DescribeCollectionServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/AttributedTheme.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultTheme.java flys-client/src/main/java/de/intevation/flys/client/shared/model/FacetRecord.java flys-client/src/main/java/de/intevation/flys/client/shared/model/Theme.java
diffstat 8 files changed, 222 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Jul 18 09:52:16 2011 +0000
+++ b/flys-client/ChangeLog	Tue Jul 19 16:32:52 2011 +0000
@@ -1,3 +1,25 @@
+2011-07-19  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/AttributedTheme.java:
+	  New. This theme stores all its attributes in a map. The intent of this
+	  theme is to save all the facet's values contained in the DESCRIBE of the
+	  Collection to be able to write an equivalent attribute part as the
+	  incoming DESCRIBE has -> no loss of attributes like WMS URL or
+	  layernames in a map theme!
+
+	* src/main/java/de/intevation/flys/client/server/DescribeCollectionServiceImpl.java:
+	  Instantiate new AttributedThemes to save all information of a facet.
+
+	* src/main/java/de/intevation/flys/client/server/CollectionHelper.java:
+	  Write all attributes of an AttributedTheme into a facet's element.
+
+	* src/main/java/de/intevation/flys/client/shared/model/Theme.java,
+	  src/main/java/de/intevation/flys/client/shared/model/DefaultTheme.java,
+	  src/main/java/de/intevation/flys/client/shared/model/FacetRecord.java,
+	  src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java:
+	  The 'active' member variable is an integer value now as it is in the
+	  Collection's DESCRIBE document, too.
+
 2011-07-18  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java	Mon Jul 18 09:52:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java	Tue Jul 19 16:32:52 2011 +0000
@@ -236,7 +236,7 @@
         FacetRecord rec = (FacetRecord) list.getRecord(row);
 
         Theme theme = rec.getTheme();
-        theme.setActive(rec.getActive());
+        theme.setActive(rec.getActive() ? 1 : 0);
 
         updateCollection();
     }
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java	Mon Jul 18 09:52:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java	Tue Jul 19 16:32:52 2011 +0000
@@ -2,6 +2,7 @@
 
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -10,6 +11,7 @@
 import de.intevation.artifacts.common.utils.XMLUtils;
 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
 
+import de.intevation.flys.client.shared.model.AttributedTheme;
 import de.intevation.flys.client.shared.model.Collection;
 import de.intevation.flys.client.shared.model.OutputMode;
 import de.intevation.flys.client.shared.model.Theme;
@@ -143,14 +145,24 @@
             return null;
         }
 
-        Element t = cr.create("theme");
+        Element t = cr.create("facet");
 
-        cr.addAttr(t, "active", theme.isActive() ? "1" : "0", true);
-        cr.addAttr(t, "artifact", theme.getArtifact(), true);
-        cr.addAttr(t, "facet", theme.getFacet(), true);
-        cr.addAttr(t, "pos", Integer.toString(theme.getPosition()), true);
-        cr.addAttr(t, "index", Integer.toString(theme.getIndex()), true);
-        cr.addAttr(t, "description", theme.getDescription(), true);
+        if (theme instanceof AttributedTheme) {
+            AttributedTheme at = (AttributedTheme) theme;
+            Set<String>   keys = at.getKeys();
+
+            for (String key: keys) {
+                cr.addAttr(t, key, at.getAttr(key), true);
+            }
+        }
+        else {
+            cr.addAttr(t, "active", Integer.toString(theme.getActive()), true);
+            cr.addAttr(t, "artifact", theme.getArtifact(), true);
+            cr.addAttr(t, "facet", theme.getFacet(), true);
+            cr.addAttr(t, "pos", Integer.toString(theme.getPosition()), true);
+            cr.addAttr(t, "index", Integer.toString(theme.getIndex()), true);
+            cr.addAttr(t, "description", theme.getDescription(), true);
+        }
 
         return t;
     }
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DescribeCollectionServiceImpl.java	Mon Jul 18 09:52:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/DescribeCollectionServiceImpl.java	Tue Jul 19 16:32:52 2011 +0000
@@ -9,6 +9,8 @@
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
@@ -23,6 +25,7 @@
 import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler;
 
 import de.intevation.flys.client.shared.exceptions.ServerException;
+import de.intevation.flys.client.shared.model.AttributedTheme;
 import de.intevation.flys.client.shared.model.Collection;
 import de.intevation.flys.client.shared.model.CollectionItem;
 import de.intevation.flys.client.shared.model.DefaultCollection;
@@ -206,7 +209,7 @@
 
         NodeList themes = node.getElementsByTagNameNS(
             ArtifactNamespaceContext.NAMESPACE_URI,
-            "theme");
+            "facet");
 
         int num = themes != null ? themes.getLength() : 0;
 
@@ -229,29 +232,22 @@
 
         String uri = ArtifactNamespaceContext.NAMESPACE_URI;
 
-        String strAct = ele.getAttributeNS(uri, "active");
-        String art    = ele.getAttributeNS(uri, "artifact");
-        String fac    = ele.getAttributeNS(uri, "facet");
-        String strPos = ele.getAttributeNS(uri, "pos");
-        String desc   = ele.getAttributeNS(uri, "description");
-        String strIdx = ele.getAttributeNS(uri, "index");
+        NamedNodeMap attrMap = ele.getAttributes();
+        int          attrNum = attrMap != null ? attrMap.getLength() : 0;
 
-        if (strAct.length() > 0 && art.length() > 0 && fac.length() > 0
-         && strPos.length() > 0 && strIdx.length() > 0)
-        {
-            try {
-                int pos    = Integer.valueOf(strPos);
-                int active = Integer.valueOf(strAct);
-                int idx    = Integer.valueOf(strIdx);
+        AttributedTheme t = new AttributedTheme();
 
-                return new DefaultTheme(pos, idx, active > 0, art, fac, desc);
-            }
-            catch (NumberFormatException nfe) {
-                nfe.printStackTrace();
-            }
+        for (int i = 0; i < attrNum; i++) {
+            Node attr = attrMap.item(i);
+
+            String prefix = attr.getPrefix();
+            String name   = attr.getNodeName().replace(prefix + ":", "");
+            String value  = attr.getNodeValue();
+
+            t.addAttr(name, value);
         }
 
-        return null;
+        return t;
     }
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/AttributedTheme.java	Tue Jul 19 16:32:52 2011 +0000
@@ -0,0 +1,157 @@
+package de.intevation.flys.client.shared.model;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class AttributedTheme implements Theme {
+
+    protected Map<String, String> attributes;
+
+
+    public AttributedTheme() {
+        this.attributes = new HashMap<String, String>();
+    }
+
+
+    public Set<String> getKeys() {
+        return attributes.keySet();
+    }
+
+
+    public void addAttr(String name, String value) {
+        if (name != null && value != null) {
+            attributes.put(name, value);
+        }
+    }
+
+
+    public String getAttr(String name) {
+        return attributes.get(name);
+    }
+
+
+    public Integer getAttrAsInt(String name) {
+        String attr = getAttr(name);
+
+        if (attr != null && attr.length() > 0) {
+            try {
+                return Integer.parseInt(attr);
+            }
+            catch (NumberFormatException nfe) {
+            }
+        }
+
+        return null;
+    }
+
+
+    public boolean getAttrAsBoolean(String name) {
+        String attr = getAttr(name);
+
+        if (attr != null) {
+            try {
+                int num = Integer.valueOf(attr);
+                return num > 0;
+            }
+            catch (NumberFormatException nfe) {
+                // do nothing
+            }
+        }
+
+        return Boolean.valueOf(attr);
+    }
+
+
+    @Override
+    public int getPosition() {
+        Integer pos = getAttrAsInt("pos");
+
+        return pos != null ? pos.intValue() : -1;
+    }
+
+
+    @Override
+    public void setPosition(int pos) {
+        addAttr("pos", String.valueOf(pos));
+    }
+
+
+    @Override
+    public int getIndex() {
+        Integer idx = getAttrAsInt("index");
+
+        return idx != null ? idx.intValue() : -1;
+    }
+
+
+    @Override
+    public int getActive() {
+        return getAttrAsInt("active");
+    }
+
+
+    @Override
+    public void setActive(int active) {
+        addAttr("active", String.valueOf(active));
+    }
+
+
+    @Override
+    public String getArtifact() {
+        return getAttr("artifact");
+    }
+
+
+    @Override
+    public String getFacet() {
+        return getAttr("facet");
+    }
+
+
+    @Override
+    public String getDescription() {
+        return getAttr("description");
+    }
+
+
+    @Override
+    public boolean equals(Object o) {
+        if (!(o instanceof AttributedTheme)) {
+            return false;
+        }
+
+        AttributedTheme other = (AttributedTheme) o;
+
+        if (other.getPosition() != getPosition()) {
+            return false;
+        }
+
+        if (!other.getArtifact().equals(getArtifact())) {
+            return false;
+        }
+
+        if (other.getActive() != getActive()) {
+            return false;
+        }
+
+        if (!other.getFacet().equals(getFacet())) {
+            return false;
+        }
+
+        if (!other.getDescription().equals(getDescription())) {
+            return false;
+        }
+
+        if (other.getIndex() != getIndex()) {
+            return false;
+        }
+
+        return true;
+    }
+}
+// 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/DefaultTheme.java	Mon Jul 18 09:52:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultTheme.java	Tue Jul 19 16:32:52 2011 +0000
@@ -10,7 +10,7 @@
 
     protected int index;
 
-    protected boolean active;
+    protected int active;
 
     protected String artifact;
 
@@ -26,7 +26,7 @@
     public DefaultTheme(
         int     pos,
         int     index,
-        boolean active,
+        int     active,
         String  art,
         String  facet,
         String  description)
@@ -55,12 +55,12 @@
     }
 
 
-    public boolean isActive() {
+    public int getActive() {
         return active;
     }
 
 
-    public void setActive(boolean active) {
+    public void setActive(int active) {
         this.active = active;
     }
 
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/FacetRecord.java	Mon Jul 18 09:52:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/FacetRecord.java	Tue Jul 19 16:32:52 2011 +0000
@@ -10,15 +10,13 @@
  */
 public class FacetRecord extends ListGridRecord {
 
-    protected boolean active;
-
     protected Theme   theme;
 
 
     public FacetRecord(Theme theme) {
         this.theme = theme;
 
-        setActive(theme.isActive());
+        setActive(theme.getActive() == 1);
         setName(theme.getDescription());
     }
 
@@ -46,7 +44,6 @@
 
 
     public void setActive(boolean active) {
-        this.active = active;
         setAttribute("active", active);
     }
 }
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Theme.java	Mon Jul 18 09:52:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Theme.java	Tue Jul 19 16:32:52 2011 +0000
@@ -14,9 +14,9 @@
 
     int getIndex();
 
-    boolean isActive();
+    int getActive();
 
-    void setActive(boolean active);
+    void setActive(int active);
 
     String getArtifact();
 

http://dive4elements.wald.intevation.org