changeset 2190:2792d2617be9

Introduced an abstract MinMaxState and a concrete class IntRangeState to add min/max value pairs. flys-artifacts/trunk@3800 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 27 Jan 2012 13:23:56 +0000
parents 19518116a49a
children f28844a57fed
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/IntRangeState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MinMaxState.java
diffstat 3 files changed, 106 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Jan 27 13:18:37 2012 +0000
+++ b/flys-artifacts/ChangeLog	Fri Jan 27 13:23:56 2012 +0000
@@ -1,3 +1,11 @@
+2012-01-27  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/states/MinMaxState.java: New
+	  state that eases adding min/max value pairs to describe document.
+
+	* src/main/java/de/intevation/flys/artifacts/states/IntRangeState.java:
+	  New. Subclasses MinMaxState and allows adding min/max integer value pairs.
+
 2012-01-27  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/DefaultState.java: Moved
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/IntRangeState.java	Fri Jan 27 13:23:56 2012 +0000
@@ -0,0 +1,39 @@
+package de.intevation.flys.artifacts.states;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class IntRangeState extends MinMaxState {
+
+    private static final Logger logger = Logger.getLogger(IntRangeState.class);
+
+
+    @Override
+    protected String getUIProvider() {
+        return "timerange";
+    }
+
+
+    @Override
+    protected Object getLower(FLYSArtifact flys) {
+        return 0;
+    }
+
+
+    @Override
+    protected Object getUpper(FLYSArtifact flys) {
+        return 0;
+    }
+
+
+    @Override
+    protected String getType() {
+        return "intrange";
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MinMaxState.java	Fri Jan 27 13:23:56 2012 +0000
@@ -0,0 +1,59 @@
+package de.intevation.flys.artifacts.states;
+
+import org.w3c.dom.Element;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifacts.common.ArtifactNamespaceContext;
+import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
+
+import de.intevation.artifactdatabase.ProtocolUtils;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public abstract class MinMaxState extends DefaultState {
+
+    @Override
+    protected void appendItems(
+        Artifact       artifact,
+        ElementCreator creator,
+        String         name,
+        CallContext    context,
+        Element        select
+    ) {
+        FLYSArtifact flys = (FLYSArtifact) artifact;
+
+        select.setAttributeNS(
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            "art:type",
+            getType());
+
+        Element min = ProtocolUtils.createArtNode(
+            creator,
+            "min",
+            new String[] { "value" },
+            new String[] { String.valueOf(getLower(flys)) });
+
+        Element max = ProtocolUtils.createArtNode(
+            creator,
+            "max",
+            new String[] { "value" },
+            new String[] { String.valueOf(getUpper(flys)) });
+
+        select.appendChild(min);
+        select.appendChild(max);
+    }
+
+
+    protected abstract Object getLower(FLYSArtifact flys);
+
+    protected abstract Object getUpper(FLYSArtifact flys);
+
+    protected abstract String getType();
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org