[PATCH 4 of 8] Add the new difference facet and set facets active/inactive

Wald Commits scm-commit at wald.intevation.org
Thu Mar 6 15:22:29 CET 2014


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1394111244 -3600
# Branch minfo-opt
# Node ID 6451970e0562a4ed6f0f4b0ead3bc95584402ef1
# Parent  8b95f9c4f341a8397b4986879920001e870ec9be
Add the new difference facet and set facets active/inactive.

diff -r 8b95f9c4f341 -r 6451970e0562 artifacts/src/main/java/org/dive4elements/river/artifacts/states/WDifferencesState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WDifferencesState.java	Thu Mar 06 14:04:46 2014 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WDifferencesState.java	Thu Mar 06 14:07:24 2014 +0100
@@ -14,6 +14,7 @@
 import org.apache.log4j.Logger;
 
 import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifactdatabase.state.FacetActivity;
 import org.dive4elements.artifactdatabase.data.StateData;
 
 import org.dive4elements.artifacts.CallContext;
@@ -30,12 +31,14 @@
 import org.dive4elements.river.artifacts.model.CalculationResult;
 import org.dive4elements.river.artifacts.model.DataFacet;
 import org.dive4elements.river.artifacts.model.DifferenceCurveFacet;
+import org.dive4elements.river.artifacts.model.DifferenceCurveFilterFacet;
 import org.dive4elements.river.artifacts.model.EmptyFacet;
 import org.dive4elements.river.artifacts.model.FacetTypes;
 import org.dive4elements.river.artifacts.model.WKms;
 import org.dive4elements.river.artifacts.model.WQKms;
 
 import org.dive4elements.river.artifacts.model.fixings.FixRealizingResult;
+import org.dive4elements.river.artifacts.resources.Resources;
 
 import org.dive4elements.river.utils.RiverUtils;
 import org.dive4elements.river.utils.StringUtil;
@@ -48,6 +51,31 @@
     /** The logger that is used in this state. */
     private static Logger logger = Logger.getLogger(WDifferencesState.class);
 
+    private static final String I18N_DIFFERENCES_FACET_NAME =
+        "facet.w_differences";
+    private static final String I18N_DIFFERENCES_FACET_NAME_RAW =
+        "facet.w_differences.raw";
+
+    static {
+        // Active/deactivate facets.
+        FacetActivity.Registry.getInstance().register(
+            "winfo",
+            new FacetActivity() {
+                @Override
+                public Boolean isInitialActive(
+                    Artifact artifact,
+                    Facet    facet,
+                    String   output
+                ) {
+                    String name = facet.getName();
+
+                    if (name.equals(FacetTypes.W_DIFFERENCES)) {
+                        return Boolean.FALSE;
+                    }
+                    return Boolean.TRUE;
+                }
+            });
+    }
 
     /** Specify to display nothing (this is kind of a "final" state). */
     @Override
@@ -190,10 +218,13 @@
                 context);
 
             String facetName = "diff ()";
+            String minName = "min";
+            String subName = "sub";
 
             if (minuendWKms != null && subtrahendWKms != null) {
-                facetName = StringUtil.wWrap(minuendWKms.getName())
-                    + " - " + StringUtil.wWrap(subtrahendWKms.getName());
+                minName = StringUtil.wWrap(minuendWKms.getName());
+                subName = StringUtil.wWrap(subtrahendWKms.getName());
+                facetName = minName + " - " + subName;
                 WKms wkms = WKmsOperation.SUBTRACTION.operate(minuendWKms,
                      subtrahendWKms);
                 wkms.setName(facetName);
@@ -201,8 +232,27 @@
                 logger.debug("WKMSSubtraction happened");
             }
             if (facets != null) {
-                facets.add(new DifferenceCurveFacet(i/2, W_DIFFERENCES, facetName,
-                    ComputeType.ADVANCE, id, hash));
+                facets.add(new DifferenceCurveFacet(
+                    i/2,
+                    W_DIFFERENCES,
+                    Resources.getMsg(
+                        context.getMeta(),
+                        I18N_DIFFERENCES_FACET_NAME_RAW,
+                        facetName,
+                        new Object[] { minName, subName }),
+                    ComputeType.ADVANCE,
+                    id,
+                    hash));
+                facets.add(new DifferenceCurveFilterFacet(i/2,
+                    W_DIFFERENCES_FILTERED,
+                    Resources.getMsg(
+                        context.getMeta(),
+                        I18N_DIFFERENCES_FACET_NAME,
+                        facetName,
+                        new Object[] { minName, subName }),
+                    ComputeType.ADVANCE,
+                    id,
+                    hash));
             }
         }
 


More information about the Dive4elements-commits mailing list