incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1210483 - in /incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object: disabled/method/ hidden/method/
Date Mon, 05 Dec 2011 14:51:00 GMT
Author: kevin
Date: Mon Dec  5 14:51:00 2011
New Revision: 1210483

URL: http://svn.apache.org/viewvc?rev=1210483&view=rev
Log:
ISIS-142 and ISIS-143: Attempt at implementing Dan's suggested solution
http://www.mail-archive.com/isis-dev@incubator.apache.org/msg02498.html
http://www.mail-archive.com/isis-dev@incubator.apache.org/msg02516.html

Modified:
    incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectViaDisabledMethodFacetFactory.java
    incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/method/HiddenObjectViaHiddenMethodFacetFactory.java

Modified: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectViaDisabledMethodFacetFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectViaDisabledMethodFacetFactory.java?rev=1210483&r1=1210482&r2=1210483&view=diff
==============================================================================
--- incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectViaDisabledMethodFacetFactory.java
(original)
+++ incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/disabled/method/DisabledObjectViaDisabledMethodFacetFactory.java
Mon Dec  5 14:51:00 2011
@@ -20,13 +20,18 @@
 package org.apache.isis.core.progmodel.facets.object.disabled.method;
 
 import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.List;
 
 import org.apache.isis.core.metamodel.facetapi.FacetHolder;
 import org.apache.isis.core.metamodel.facetapi.FacetUtil;
 import org.apache.isis.core.metamodel.facetapi.FeatureType;
 import org.apache.isis.core.metamodel.methodutils.MethodScope;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
 import org.apache.isis.core.progmodel.facets.MethodFinderUtils;
 import org.apache.isis.core.progmodel.facets.MethodPrefixBasedFacetFactoryAbstract;
+import org.apache.isis.core.progmodel.facets.members.disable.method.DisableForContextFacetViaMethod;
 
 public class DisabledObjectViaDisabledMethodFacetFactory extends MethodPrefixBasedFacetFactoryAbstract
{
 
@@ -46,8 +51,57 @@ public class DisabledObjectViaDisabledMe
         final Method method =
             MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, DISABLED_PREFIX, String.class,
NO_PARAMETERS_TYPES);
         if (method != null) {
+
             FacetUtil.addFacet(new DisabledObjectFacetViaDisabledMethod(method, facetHolder));
+
+            // DNW
+            ObjectSpecification spec = getSpecificationLookup().loadSpecification(cls);
+            List<ObjectAssociation> members = spec.getAssociations();
+            for (ObjectAssociation member : members) {
+                FacetUtil.addFacet(new DisableForContextFacetViaMethod(method, member));
+            }
+
+            // Method methods[] = cls.getMethods();
+            // addFacetToFacetHolder(methods, facetHolder, method);
             processClassContext.removeMethod(method);
         }
     }
+
+    protected void addFacetToFacetHolder(final Method methods[], final FacetHolder facetHolder,
final Method facetMethod) {
+        // Original
+        FacetUtil.addFacet(new DisabledObjectFacetViaDisabledMethod(facetMethod, facetHolder));
+
+        // Dan's suggestion
+        // for (ObjectMember member : objectSpec.getMembers()) {
+        // FacetUtil.addFacet(new DisabledObjectFacetViaDisabledMethod(method, member));
+        // }
+
+        // Try 3?
+        for (Method method : methods) {
+            if (!anIsisMethod(method.getName())) {
+                // DNW
+                // FacetUtil.addFacet(new DisableForContextFacetViaMethod(method, facetHolder));
+            }
+        }
+
+    }
+
+    /**
+     * Check if method name starts with any of the Isis prefixes...
+     * 
+     * @param name
+     * @return
+     */
+    private boolean anIsisMethod(String name) {
+        List<String> names =
+            Arrays.asList("choices", "clear", "created", "default", "hide", "validate", "disable",
"iconName",
+                "modify", "set");
+
+        for (String prefix : names) {
+            if (name.startsWith(prefix)) {
+                return true;
+            }
+        }
+        return false;
+    }
 }

Modified: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/method/HiddenObjectViaHiddenMethodFacetFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/method/HiddenObjectViaHiddenMethodFacetFactory.java?rev=1210483&r1=1210482&r2=1210483&view=diff
==============================================================================
--- incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/method/HiddenObjectViaHiddenMethodFacetFactory.java
(original)
+++ incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/method/HiddenObjectViaHiddenMethodFacetFactory.java
Mon Dec  5 14:51:00 2011
@@ -20,6 +20,8 @@
 package org.apache.isis.core.progmodel.facets.object.hidden.method;
 
 import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.List;
 
 import org.apache.isis.core.metamodel.facetapi.FacetHolder;
 import org.apache.isis.core.metamodel.facetapi.FacetUtil;
@@ -43,24 +45,71 @@ public class HiddenObjectViaHiddenMethod
         attachHideFacetIfHideMethodIsFound(processClassContext);
     }
 
-    public static void attachHideFacetIfHideMethodIsFound(final ProcessClassContext processClassContext)
{
+    public void attachHideFacetIfHideMethodIsFound(final ProcessClassContext processClassContext)
{
         final Class<?> cls = processClassContext.getCls();
         final FacetHolder facetHolder = processClassContext.getFacetHolder();
 
+        final Method methods[] = cls.getMethods();
+
         final Method uBooleanMethod =
             MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, VALIDATE_PREFIX, Boolean.class,
NO_PARAMETERS_TYPES);
         if (uBooleanMethod != null) {
-            FacetUtil.addFacet(new HiddenObjectFacetViaHiddenMethod(uBooleanMethod,
-                HiddenObjectFacetViaHiddenMethod.class, facetHolder, false));
+            addFacetToFacetHolder(methods, facetHolder, uBooleanMethod);
             processClassContext.removeMethod(uBooleanMethod);
             return;
         }
         final Method lBooleanMethod =
             MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, VALIDATE_PREFIX, boolean.class,
NO_PARAMETERS_TYPES);
         if (lBooleanMethod != null) {
-            FacetUtil.addFacet(new HiddenObjectFacetViaHiddenMethod(lBooleanMethod,
-                HiddenObjectFacetViaHiddenMethod.class, facetHolder, false));
+            addFacetToFacetHolder(methods, facetHolder, lBooleanMethod);
             processClassContext.removeMethod(lBooleanMethod);
         }
     }
+
+    protected void addFacetToFacetHolder(final Method methods[], final FacetHolder facetHolder,
final Method facetMethod) {
+        // Original
+        FacetUtil.addFacet(new HiddenObjectFacetViaHiddenMethod(facetMethod, HiddenObjectFacetViaHiddenMethod.class,
+            facetHolder, false));
+
+        // Dan's suggestion
+        // for (ObjectMember member : objectSpec.getMembers()) {
+        // FacetUtil.addFacet(new DisabledObjectFacetViaDisabledMethod(method, member));
+        // }
+
+        // Try 3?
+        for (Method method : methods) {
+            if (!anIsisMethod(method.getName())) {
+                // FacetUtil.addFacet(new HideForSessionFacetViaMethod(method, facetHolder));
+
+                // DNW
+                // FacetUtil.addFacet(new HideForContextFacetViaMethod(method, facetHolder));
+
+                // DNW
+                // FacetUtil.addFacet(new HiddenObjectFacetViaHiddenMethod(method,
+                // HiddenObjectFacetViaHiddenMethod.class,
+                // facetHolder, false));
+            }
+        }
+
+    }
+
+    /**
+     * Check if method name starts with any of the Isis prefixes...
+     * 
+     * @param name
+     * @return
+     */
+    private boolean anIsisMethod(String name) {
+        List<String> names =
+            Arrays.asList("choices", "clear", "created", "default", "hide", "validate", "disable",
"iconName",
+                "modify", "hidden", "set");
+
+        for (String prefix : names) {
+            if (name.startsWith(prefix)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
 }



Mime
View raw message