changeset 1709:f643ea084213

Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering). flys-artifacts/trunk@2969 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 14 Oct 2011 08:52:44 +0000
parents e99b4bd32cd5
children 055f32a5388a
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WaterlevelArtifact.java flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
diffstat 5 files changed, 95 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Oct 13 12:42:31 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Oct 14 08:52:44 2011 +0000
@@ -1,6 +1,30 @@
+2011-10-14	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Add possibility of programmatic configuration of initial "activity"
+	state (active or inactive) of (Managed)Facets by introducing
+	FLYSArtifact.getInitialFacetActivity. This method shall be overriden
+	by subclasses where Facets are wanted to come to live inactive.
+	Artifacts will be asked only once how the MangedFacet should come to live,
+	namely when AttributeWriter finds a genuinely new Facet.
+
+	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WaterlevelArtifact.java
+	  (getInitialFacetActivity):
+	  New function to let Artifact decide whether a ManagedFacet shall
+	  initially be set to active or inactive.
+
+	 * src/main/java/de/intevation/flys/collections/AttributeWriter.java:
+	   Accept database in constructor. For genuinely new Facets, spawn its
+	   mother artifact and ask whether the (Managed)Facet shall be active
+	   or inactive (initially).
+
+	 * src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
+	   (buildOutAttributes): Pass database to AttributeWrite (which needs it
+	   to spawn artifacts), rename items parameter to reflect content.
+
 2011-10-13	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
-	Cosemtics, removed obsolete imports.
+	Cosmetics, removed obsolete imports.
 
 	* src/main/java/de/intevation/flys/artifacts/WaterlevelArtifact.java,
 	  src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Thu Oct 13 12:42:31 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Fri Oct 14 08:52:44 2011 +0000
@@ -982,5 +982,21 @@
 
         destroyStates(ids, context);
     }
+    
+    
+    /**
+     * Determines Facets initial disposition regarding activity (think of
+     * selection in Client ThemeList GUI). This will be checked one time
+     * when the facet enters a collections describe document.
+     *
+     * @param facetName name of the facet.
+     * @param index     index of the facet.
+     *
+     * @return 1 if wished to be initally active, 0 if not. FLYSArtifact
+     *         defaults to "1".
+     */
+    public int getInitialFacetActivity(String facetName, int index) {
+        return 1;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WaterlevelArtifact.java	Thu Oct 13 12:42:31 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WaterlevelArtifact.java	Fri Oct 14 08:52:44 2011 +0000
@@ -91,5 +91,21 @@
     public String getName() {
         return ARTIFACT_NAME;
     }
+
+    /**
+     * Determines Facets initial disposition regarding activity (think of
+     * selection in Client ThemeList GUI).
+     * WaterlevelArtifact Facets should come to live "inactive" (always
+     * return 0).
+     *
+     * @param facetName name of the facet.
+     * @param index     index of the facet.
+     *
+     * @return Always 0 to have Facets initial predisposition to "inactive".
+     */
+    @Override
+    public int getInitialFacetActivity(String facetName, int index) {
+        return 0;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java	Thu Oct 13 12:42:31 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java	Fri Oct 14 08:52:44 2011 +0000
@@ -10,6 +10,8 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
+import de.intevation.artifacts.ArtifactDatabase;
+import de.intevation.artifacts.ArtifactDatabaseException;
 import de.intevation.artifacts.ArtifactNamespaceContext;
 
 import de.intevation.artifactdatabase.state.Facet;
@@ -18,6 +20,7 @@
 import de.intevation.artifacts.common.utils.XMLUtils;
 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
 
+import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.model.ManagedFacet;
 
 /**
@@ -27,7 +30,11 @@
  */
 public class AttributeWriter {
 
+    /** ArtifactDatabase used to fetch Artifacts. */
+    protected ArtifactDatabase db = null;
+
     protected Map<String, Output> oldAttr;
+
     protected Map<String, Output> newAttr;
 
     private static Logger logger = Logger.getLogger(AttributeWriter.class);
@@ -36,14 +43,17 @@
     /**
      * Create a AttributeWriter.
      * Attributes not present in newAttr will not be included in the document.
+     * @param db      Database to fetch artifacts.
      * @param oldAttr "Old" (possibly user-changed) outputs.
      * @param newAttr "New" (eventually re-read in its original, unchagnged
      *                form) outputs.
      */
     public AttributeWriter(
+        ArtifactDatabase    db,
         Map<String, Output> oldAttr,
         Map<String, Output> newAttr)
     {
+        this.db      = db;
         this.oldAttr = oldAttr;
         this.newAttr = newAttr;
     }
@@ -109,7 +119,13 @@
             facetsB = b.getFacets();
         }
 
-        writeFacets(doc, cr, output, facetsA, facetsB);
+
+        try {
+            writeFacets(doc, cr, output, facetsA, facetsB);
+        }
+        catch (ArtifactDatabaseException ade) {
+            logger.error(ade, ade);
+        }
     }
 
 
@@ -125,6 +141,7 @@
         Element        output,
         List<Facet>    newFacets,
         List<Facet>    oldFacets)
+    throws ArtifactDatabaseException
     {
         int num = newFacets.size();
 
@@ -144,6 +161,15 @@
             }
         }
 
+        // With each genuinely new Facet, ask Artifact whether it comes to live
+        // in/activate.
+        for (ManagedFacet newMF: genuinelyNewFacets) {
+            FLYSArtifact flys = (FLYSArtifact) db.getRawArtifact(newMF.getArtifact());
+            newMF.setActive(flys.getInitialFacetActivity(
+                newMF.getName(),
+                newMF.getIndex()));
+        }
+        
         // For each genuinely new Facet check positional conflicts.
         for (ManagedFacet newMF: genuinelyNewFacets) {
             boolean conflicts = true;
@@ -184,7 +210,8 @@
      * @return facet if genuinely new, matching old facet otherwise.
      */
     protected ManagedFacet pickFacet(ManagedFacet facet,
-         List<Facet> oldFacets) {
+        List<Facet> oldFacets)
+    {
         if (oldFacets == null) {
             logger.debug("No old facets to compare a new to found.");
             return facet;
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Thu Oct 13 12:42:31 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Oct 14 08:52:44 2011 +0000
@@ -46,7 +46,6 @@
     /** The logger used in this class. */
     private static Logger log = Logger.getLogger(FLYSArtifactCollection.class);
 
-
     /** Constant XPath that points to the outputmodes of an artifact. */
     public static final String XPATH_ARTIFACT_OUTPUTMODES =
         "/art:result/art:outputmodes";
@@ -128,6 +127,7 @@
     /**
      * Merge the current art:outputs nodes with the the outputs provided by the
      * artifacts in the Collection.
+     * @param uuids Artifact uuids.
      */
     protected Node mergeAttributes(
         ArtifactDatabase db,
@@ -302,13 +302,13 @@
 
     /**
      * Return merged output document.
-     * @param items List of artifact uuids.
+     * @param uuids List of artifact uuids.
      */
     protected Document buildOutAttributes(
         ArtifactDatabase db,
         CallContext      context,
         Document         oldAttr,
-        String[]         items)
+        String[]         uuids)
     {
         Document doc = XMLUtils.newDocument();
 
@@ -320,8 +320,8 @@
         AttributeParser aParser = new AttributeParser();
         OutputParser    oParser = new OutputParser(db, context);
 
-        if (items != null) {
-            for (String uuid: items) {
+        if (uuids != null) {
+            for (String uuid: uuids) {
                 try {
                     oParser.parse(uuid);
                 }
@@ -333,7 +333,10 @@
 
         aParser.parse(oldAttr);
 
-        return new AttributeWriter(aParser.getOuts(), oParser.getOuts()).write();
+        return new AttributeWriter(
+            db,
+            aParser.getOuts(),
+            oParser.getOuts()).write();
     }
 
 

http://dive4elements.wald.intevation.org