changeset 3559:f9f266504f1d

S/Q relation: Initially activate/deactivate facets. flys-artifacts/trunk@5156 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 29 Jul 2012 12:30:25 +0000
parents c3cd414982fe
children 6b1e228959a6
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SQRelation.java
diffstat 1 files changed, 80 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SQRelation.java	Sun Jul 29 11:39:39 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SQRelation.java	Sun Jul 29 12:30:25 2012 +0000
@@ -1,10 +1,14 @@
 package de.intevation.flys.artifacts.states;
 
 import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.artifactdatabase.state.FacetActivity;
 
+import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.CallContext;
 import de.intevation.artifacts.CallMeta;
 
+import de.intevation.artifacts.common.utils.StringUtils;
+
 import de.intevation.flys.artifacts.FLYSArtifact;
 
 import de.intevation.flys.artifacts.access.SQRelationAccess;
@@ -52,6 +56,66 @@
     public static final String I18N_FACET_OUTLIER_MEASUREMENT =
         "facet.sq_relation.outlier.measurement";
 
+    public static final int CURVE_INDEX               = 0;
+    public static final int MEASURREMENT_INDEX        = 1;
+    public static final int OUTLIER_INDEX             = 2;
+    public static final int OUTLIER_CURVE_INDEX       = 3;
+    public static final int OUTLIER_MEASUREMENT_INDEX = 4;
+
+    public static final String [][] FACET_NAMES = {
+        { SQ_A_CURVE, SQ_B_CURVE, SQ_C_CURVE,
+          SQ_D_CURVE, SQ_E_CURVE, SQ_F_CURVE
+        },
+        { SQ_A_MEASUREMENT, SQ_B_MEASUREMENT, SQ_C_MEASUREMENT,
+          SQ_D_MEASUREMENT, SQ_E_MEASUREMENT, SQ_F_MEASUREMENT
+        },
+        { SQ_A_OUTLIER, SQ_B_OUTLIER, SQ_C_OUTLIER,
+          SQ_D_OUTLIER, SQ_E_OUTLIER, SQ_F_OUTLIER
+        },
+        { SQ_A_OUTLIER_CURVE, SQ_B_OUTLIER_CURVE, SQ_C_OUTLIER_CURVE,
+          SQ_D_OUTLIER_CURVE, SQ_E_OUTLIER_CURVE, SQ_F_OUTLIER_CURVE
+        },
+        { SQ_A_OUTLIER_MEASUREMENT, SQ_B_OUTLIER_MEASUREMENT,
+          SQ_C_OUTLIER_MEASUREMENT, SQ_D_OUTLIER_MEASUREMENT,
+          SQ_E_OUTLIER_MEASUREMENT, SQ_F_OUTLIER_MEASUREMENT
+        }
+    };
+
+
+    static {
+        // Active/deactivate facets.
+        FacetActivity.Registry.getInstance().register(
+            "minfo",
+            new FacetActivity() {
+                @Override
+                public Boolean isInitialActive(
+                    Artifact artifact,
+                    Facet    facet,
+                    String   output
+                ) {
+                    String name = facet.getName();
+
+                    if (StringUtils.contains(name, FACET_NAMES[CURVE_INDEX])
+                    ||  StringUtils.contains(
+                        name, FACET_NAMES[OUTLIER_MEASUREMENT_INDEX])
+                    ) {
+                        // TODO: Only the last should be active.
+                        return Boolean.TRUE;
+                    }
+
+                    if (StringUtils.contains(
+                        name, FACET_NAMES[MEASURREMENT_INDEX])
+                    || StringUtils.contains(
+                        name, FACET_NAMES[OUTLIER_INDEX])
+                    ) {
+                        return Boolean.FALSE;
+                    }
+
+                    return null;
+                }
+            });
+    }
+
     public SQRelation() {
     }
 
@@ -107,17 +171,17 @@
         String   stateId = getID();
         for (int i = 0; i < 6; i++) {
             container.add(new SQOverviewFacet(
-                    i,
-                    i,
-                    "sq_chart_overview",
-                    Resources.getMsg(
-                        context.getMeta(),
-                        I18N_FACET_CURVE,
-                        I18N_FACET_CURVE
-                    ),
-                    hash,
-                    getID()
-                ));
+                i,
+                i,
+                "sq_chart_overview",
+                Resources.getMsg(
+                    meta,
+                    I18N_FACET_CURVE,
+                    I18N_FACET_CURVE
+                ),
+                hash,
+                getID()
+            ));
         }
         for (int res = 0, n = sqr.length; res < n; res++) {
 
@@ -132,7 +196,7 @@
                 container.add(new SQCurveFacet(
                     res,
                     i,
-                    getFractionFacetname(0, i),
+                    getFractionFacetname(CURVE_INDEX, i),
                     Resources.getMsg(
                         meta,
                         I18N_FACET_CURVE,
@@ -160,7 +224,7 @@
                     container.add(new SQOutlierFacet(
                         index,
                         i,
-                        getFractionFacetname(2, i),
+                        getFractionFacetname(OUTLIER_INDEX, i),
                         Resources.getMsg(
                             meta,
                             I18N_FACET_OUTLIERS,
@@ -174,7 +238,7 @@
                     container.add(new SQOutlierCurveFacet(
                         index,
                         i,
-                        getFractionFacetname(3, i),
+                        getFractionFacetname(OUTLIER_CURVE_INDEX, i),
                         Resources.getMsg(
                             meta,
                             I18N_FACET_OUTLIER_CURVE,
@@ -188,7 +252,7 @@
                     container.add(new SQOutlierMeasurementFacet(
                         index,
                         i,
-                        getFractionFacetname(4, i),
+                        getFractionFacetname(OUTLIER_MEASUREMENT_INDEX, i),
                         Resources.getMsg(
                             meta,
                             I18N_FACET_OUTLIER_MEASUREMENT,
@@ -203,7 +267,7 @@
                 container.add(new SQMeasurementFacet(
                     res,
                     i,
-                    getFractionFacetname(1, i),
+                    getFractionFacetname(MEASURREMENT_INDEX, i),
                     Resources.getMsg(
                         meta,
                         I18N_FACET_MEASUREMENTS,
@@ -216,26 +280,6 @@
         } // for all results
     }
 
-    public static final String [][] FACET_NAMES = {
-        { SQ_A_CURVE, SQ_B_CURVE, SQ_C_CURVE,
-          SQ_D_CURVE, SQ_E_CURVE, SQ_F_CURVE
-        },
-        { SQ_A_MEASUREMENT, SQ_B_MEASUREMENT, SQ_C_MEASUREMENT,
-          SQ_D_MEASUREMENT, SQ_E_MEASUREMENT, SQ_F_MEASUREMENT
-        },
-        { SQ_A_OUTLIER, SQ_B_OUTLIER, SQ_C_OUTLIER,
-          SQ_D_OUTLIER, SQ_E_OUTLIER, SQ_F_OUTLIER
-        },
-        { SQ_A_OUTLIER_CURVE, SQ_B_OUTLIER_CURVE, SQ_C_OUTLIER_CURVE,
-          SQ_D_OUTLIER_CURVE, SQ_E_OUTLIER_CURVE, SQ_F_OUTLIER_CURVE
-        },
-        { SQ_A_OUTLIER_MEASUREMENT, SQ_B_OUTLIER_MEASUREMENT,
-          SQ_C_OUTLIER_MEASUREMENT, SQ_D_OUTLIER_MEASUREMENT,
-          SQ_E_OUTLIER_MEASUREMENT, SQ_F_OUTLIER_MEASUREMENT
-        }
-    };
-
-
     protected static String getFractionFacetname(int type, int idx) {
         if (log.isDebugEnabled()) {
             log.debug("getFractionFacetname(): " + type + " | " + idx);

http://dive4elements.wald.intevation.org