isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1210368 - in /incubator/isis/trunk/framework: core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/hide/ core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/ core/progmodel/src/main/java/org/apach...
Date Mon, 05 Dec 2011 09:11:32 GMT
Author: kevin
Date: Mon Dec  5 09:11:31 2011
New Revision: 1210368

URL: http://svn.apache.org/viewvc?rev=1210368&view=rev
Log:
ISIS-142 and ISIS-143: Provide support for "boolean hidden()" and "String disabled()" methods
for hiding or disabling entire objects at runtime. Partial check-in of "non revolutionary"
code base. Compatible with both solutions, x-ref:
http://www.mail-archive.com/isis-dev@incubator.apache.org/msg02503.html

Added:
    incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/hide/HiddenObjectFacet.java
  (with props)
    incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/HiddenObjectFacetAbstract.java
  (with props)
    incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/method/
    incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/method/HiddenObjectFacetViaHiddenMethod.java
  (with props)
    incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/method/HiddenObjectViaHiddenMethodFacetFactory.java
    incubator/isis/trunk/framework/core/progmodel/src/test/java/org/apache/isis/core/progmodel/facets/object/hidden/
    incubator/isis/trunk/framework/core/progmodel/src/test/java/org/apache/isis/core/progmodel/facets/object/hidden/ObjectHiddenMethodFacetFactoryTest.java
  (with props)
Modified:
    incubator/isis/trunk/framework/progmodels/dflt/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java

Added: incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/hide/HiddenObjectFacet.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/hide/HiddenObjectFacet.java?rev=1210368&view=auto
==============================================================================
--- incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/hide/HiddenObjectFacet.java
(added)
+++ incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/hide/HiddenObjectFacet.java
Mon Dec  5 09:11:31 2011
@@ -0,0 +1,50 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.metamodel.facets.hide;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.interactions.HidingInteractionAdvisor;
+
+/**
+ * Mechanism for determining whether this object is should be hidden.
+ * 
+ * <p>
+ * Even though all the properties of an object may themselves be visible, there could be
reasons to hide the object.
+ * </p>
+ * 
+ * <p>
+ * In the standard Apache Isis Programming Model, typically corresponds to the <tt>hidden</tt>
method.
+ * </p>
+ * 
+ * @see HiddenFacet
+ */
+public interface HiddenObjectFacet extends Facet, HidingInteractionAdvisor {
+
+    /**
+     * The reason the object is hidden.
+     * 
+     * <p>
+     * If the object is actually visible, should return <tt>null</tt>.
+     * </p>
+     */
+    public String hiddenReason(ObjectAdapter target);
+
+}

Propchange: incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/hide/HiddenObjectFacet.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/HiddenObjectFacetAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/HiddenObjectFacetAbstract.java?rev=1210368&view=auto
==============================================================================
--- incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/HiddenObjectFacetAbstract.java
(added)
+++ incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/HiddenObjectFacetAbstract.java
Mon Dec  5 09:11:31 2011
@@ -0,0 +1,49 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.object.hidden;
+
+import org.apache.isis.applib.events.VisibilityEvent;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.hide.HiddenObjectFacet;
+import org.apache.isis.core.metamodel.interactions.VisibilityContext;
+
+public abstract class HiddenObjectFacetAbstract extends FacetAbstract implements HiddenObjectFacet
{
+
+    public static Class<? extends Facet> type() {
+        return HiddenObjectFacet.class;
+    }
+
+    public HiddenObjectFacetAbstract(final FacetHolder holder) {
+        super(type(), holder, false);
+    }
+
+    @Override
+    public String hides(final VisibilityContext<? extends VisibilityEvent> ic) {
+        if (!(ic instanceof VisibilityContext)) {
+            return null;
+        }
+        final ObjectAdapter toValidate = ic.getTarget();
+        return toValidate != null ? hiddenReason(toValidate) : null;
+    }
+
+}

Propchange: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/HiddenObjectFacetAbstract.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/method/HiddenObjectFacetViaHiddenMethod.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/HiddenObjectFacetViaHiddenMethod.java?rev=1210368&view=auto
==============================================================================
--- incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/method/HiddenObjectFacetViaHiddenMethod.java
(added)
+++ incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/method/HiddenObjectFacetViaHiddenMethod.java
Mon Dec  5 09:11:31 2011
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.object.hidden.method;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.applib.events.VisibilityEvent;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.util.AdapterInvokeUtils;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.interactions.VisibilityContext;
+import org.apache.isis.core.progmodel.facets.object.hidden.HiddenObjectFacetAbstract;
+
+public class HiddenObjectFacetViaHiddenMethod extends HiddenObjectFacetAbstract {
+    private final Method method;
+
+    public HiddenObjectFacetViaHiddenMethod(Method method, Class<? extends Facet> facetType,
FacetHolder holder,
+        boolean derived) {
+        super(holder);
+        this.method = method;
+    }
+
+    @Override
+    public String hides(VisibilityContext<? extends VisibilityEvent> ic) {
+        final ObjectAdapter toValidate = ic.getTarget();
+        return toValidate != null ? hiddenReason(toValidate) : null;
+    }
+
+    @Override
+    public String hiddenReason(ObjectAdapter target) {
+        if (target == null) {
+            return null;
+        }
+        final Boolean isHidden = (Boolean) AdapterInvokeUtils.invoke(method, target);
+        return isHidden.booleanValue() ? "Hidden" : null;
+    }
+
+}

Propchange: incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/method/HiddenObjectFacetViaHiddenMethod.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 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=1210368&view=auto
==============================================================================
--- incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/method/HiddenObjectViaHiddenMethodFacetFactory.java
(added)
+++ incubator/isis/trunk/framework/core/progmodel/src/main/java/org/apache/isis/core/progmodel/facets/object/hidden/method/HiddenObjectViaHiddenMethodFacetFactory.java
Mon Dec  5 09:11:31 2011
@@ -0,0 +1,66 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.object.hidden.method;
+
+import java.lang.reflect.Method;
+
+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.progmodel.facets.MethodFinderUtils;
+import org.apache.isis.core.progmodel.facets.MethodPrefixBasedFacetFactoryAbstract;
+
+public class HiddenObjectViaHiddenMethodFacetFactory extends MethodPrefixBasedFacetFactoryAbstract
{
+
+    private static final String VALIDATE_PREFIX = "hidden";
+
+    private static final String[] PREFIXES = { VALIDATE_PREFIX, };
+
+    public HiddenObjectViaHiddenMethodFacetFactory() {
+        super(FeatureType.OBJECTS_ONLY, PREFIXES);
+    }
+
+    @Override
+    public void process(final ProcessClassContext processClassContext) {
+        attachHideFacetIfHideMethodIsFound(processClassContext);
+    }
+
+    public static void attachHideFacetIfHideMethodIsFound(final ProcessClassContext processClassContext)
{
+        final Class<?> cls = processClassContext.getCls();
+        final FacetHolder facetHolder = processClassContext.getFacetHolder();
+
+        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));
+            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));
+            processClassContext.removeMethod(lBooleanMethod);
+        }
+    }
+}

Added: incubator/isis/trunk/framework/core/progmodel/src/test/java/org/apache/isis/core/progmodel/facets/object/hidden/ObjectHiddenMethodFacetFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/progmodel/src/test/java/org/apache/isis/core/progmodel/facets/object/hidden/ObjectHiddenMethodFacetFactoryTest.java?rev=1210368&view=auto
==============================================================================
--- incubator/isis/trunk/framework/core/progmodel/src/test/java/org/apache/isis/core/progmodel/facets/object/hidden/ObjectHiddenMethodFacetFactoryTest.java
(added)
+++ incubator/isis/trunk/framework/core/progmodel/src/test/java/org/apache/isis/core/progmodel/facets/object/hidden/ObjectHiddenMethodFacetFactoryTest.java
Mon Dec  5 09:11:31 2011
@@ -0,0 +1,88 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.progmodel.facets.object.hidden;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facets.FacetFactory.ProcessClassContext;
+import org.apache.isis.core.metamodel.facets.hide.HiddenObjectFacet;
+import org.apache.isis.core.progmodel.facets.AbstractFacetFactoryTest;
+import org.apache.isis.core.progmodel.facets.object.hidden.method.HiddenObjectFacetViaHiddenMethod;
+import org.apache.isis.core.progmodel.facets.object.hidden.method.HiddenObjectViaHiddenMethodFacetFactory;
+
+public class ObjectHiddenMethodFacetFactoryTest extends AbstractFacetFactoryTest {
+
+    private HiddenObjectViaHiddenMethodFacetFactory facetFactory;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        facetFactory = new HiddenObjectViaHiddenMethodFacetFactory();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        facetFactory = null;
+        super.tearDown();
+    }
+
+    public void testDisabledMethodPickedUpAndMethodRemovedBooleanType() {
+        class Customer {
+            @SuppressWarnings("unused")
+            public boolean hidden() {
+                return true;
+            }
+        }
+        final Method hiddenMethod = findMethod(Customer.class, "hidden");
+
+        final ProcessClassContext processClassContext =
+            new ProcessClassContext(Customer.class, methodRemover, facetHolder);
+        facetFactory.process(processClassContext);
+
+        final Facet facet = facetHolder.getFacet(HiddenObjectFacet.class);
+        assertNotNull(facet);
+        assertTrue(facet instanceof HiddenObjectFacetViaHiddenMethod);
+
+        assertTrue(methodRemover.getRemovedMethodMethodCalls().contains(hiddenMethod));
+    }
+
+    public void testDisabledMethodPickedUpAndMethodRemovedBooleanClass() {
+        class Customer {
+            @SuppressWarnings("unused")
+            public Boolean hidden() {
+                return true;
+            }
+        }
+        final Method hiddenMethod = findMethod(Customer.class, "hidden");
+
+        final ProcessClassContext processClassContext =
+            new ProcessClassContext(Customer.class, methodRemover, facetHolder);
+        facetFactory.process(processClassContext);
+
+        final Facet facet = facetHolder.getFacet(HiddenObjectFacet.class);
+        assertNotNull(facet);
+        assertTrue(facet instanceof HiddenObjectFacetViaHiddenMethod);
+
+        assertTrue(methodRemover.getRemovedMethodMethodCalls().contains(hiddenMethod));
+    }
+
+}

Propchange: incubator/isis/trunk/framework/core/progmodel/src/test/java/org/apache/isis/core/progmodel/facets/object/hidden/ObjectHiddenMethodFacetFactoryTest.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/isis/trunk/framework/progmodels/dflt/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/progmodels/dflt/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java?rev=1210368&r1=1210367&r2=1210368&view=diff
==============================================================================
--- incubator/isis/trunk/framework/progmodels/dflt/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
(original)
+++ incubator/isis/trunk/framework/progmodels/dflt/src/main/java/org/apache/isis/progmodels/dflt/ProgrammingModelFacetsJava5.java
Mon Dec  5 09:11:31 2011
@@ -73,6 +73,7 @@ import org.apache.isis.core.progmodel.fa
 import org.apache.isis.core.progmodel.facets.object.encodeable.EncodableAnnotationFacetFactory;
 import org.apache.isis.core.progmodel.facets.object.facets.annotation.FacetsAnnotationFacetFactory;
 import org.apache.isis.core.progmodel.facets.object.hidden.HiddenAnnotationForTypeFacetFactory;
+import org.apache.isis.core.progmodel.facets.object.hidden.method.HiddenObjectViaHiddenMethodFacetFactory;
 import org.apache.isis.core.progmodel.facets.object.icon.method.IconMethodFacetFactory;
 import org.apache.isis.core.progmodel.facets.object.ignore.annotation.RemoveIgnoreAnnotationMethodsFacetFactory;
 import org.apache.isis.core.progmodel.facets.object.ignore.isis.RemoveSetDomainObjectContainerMethodFacetFactory;
@@ -252,7 +253,6 @@ public class ProgrammingModelFacetsJava5
 
         addFactory(DirtyMethodsFacetFactory.class);
         addFactory(ValidateObjectViaValidateMethodFacetFactory.class);
-        addFactory(DisabledObjectViaDisabledMethodFacetFactory.class);
         addFactory(ObjectValidPropertiesFacetFactory.class);
         addFactory(PluralMethodFacetFactory.class);
         addFactory(NamedFacetViaSingularNameStaticMethodFacetFactory.class);
@@ -287,6 +287,10 @@ public class ProgrammingModelFacetsJava5
         addFactory(HiddenAnnotationForTypeFacetFactory.class);
         addFactory(HiddenAnnotationForMemberFacetFactory.class);
 
+        // KAM
+        addFactory(HiddenObjectViaHiddenMethodFacetFactory.class);
+        addFactory(DisabledObjectViaDisabledMethodFacetFactory.class);
+
         addFactory(ImmutableAnnotationFacetFactory.class);
         addFactory(DisabledFacetForPropertyDerivedFromImmutableTypeFacetFactory.class);
         addFactory(DisabledFacetForCollectionDerivedFromImmutableTypeFacetFactory.class);



Mime
View raw message