You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2015/10/14 09:43:52 UTC

[02/14] isis git commit: ISIS-1213: add in parameters for mix-in actions.

ISIS-1213: add in parameters for mix-in actions.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/3fc01b54
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/3fc01b54
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/3fc01b54

Branch: refs/heads/master
Commit: 3fc01b5494391a1aea3010506412d15b0617484d
Parents: 643b394
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Mon Oct 12 23:41:03 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Mon Oct 12 23:41:03 2015 +0100

----------------------------------------------------------------------
 .../specimpl/ObjectActionMixedIn.java           | 34 ++++++++++-
 .../specimpl/ObjectActionParameterMixedIn.java  | 23 ++++++++
 .../ObjectActionParameterParseableMixedIn.java  | 59 ++++++++++++++++++++
 .../OneToOneActionParameterMixedIn.java         | 59 ++++++++++++++++++++
 4 files changed, 173 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/3fc01b54/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectActionMixedIn.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectActionMixedIn.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectActionMixedIn.java
index 42abd39..8e113a5 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectActionMixedIn.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectActionMixedIn.java
@@ -19,6 +19,8 @@ package org.apache.isis.core.metamodel.specloader.specimpl;
 import java.util.Collections;
 import java.util.List;
 
+import com.google.common.collect.Lists;
+
 import org.apache.isis.applib.Identifier;
 import org.apache.isis.applib.annotation.Bulk;
 import org.apache.isis.applib.annotation.InvokedOn;
@@ -29,6 +31,7 @@ import org.apache.isis.applib.services.bookmark.Bookmark;
 import org.apache.isis.applib.services.command.Command;
 import org.apache.isis.applib.services.command.Command.Executor;
 import org.apache.isis.applib.services.command.CommandContext;
+import org.apache.isis.core.commons.lang.ObjectExtensions;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.consent.Consent;
 import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
@@ -69,6 +72,11 @@ public class ObjectActionMixedIn extends ObjectActionImpl implements MixedInMemb
      */
     private final FacetHolder facetHolder = new FacetHolderImpl();
 
+    /**
+     * Lazily initialized by {@link #getParameters()} (so don't use directly!)
+     */
+    private List<ObjectActionParameterMixedIn> parameters;
+
     private final Identifier identifier;
 
     public ObjectActionMixedIn(
@@ -102,7 +110,29 @@ public class ObjectActionMixedIn extends ObjectActionImpl implements MixedInMemb
     }
 
     public synchronized List<ObjectActionParameter> getParameters() {
-        return mixinAction.getParameters();
+        //return mixinAction.getParameters();
+
+        if (this.parameters == null) {
+            final List<ObjectActionParameter> mixinActionParameters = mixinAction.getParameters();
+            final List<ObjectActionParameterMixedIn> mixedInParameters = Lists.newArrayList();
+
+            for (int paramNum = 0; paramNum < mixinActionParameters.size(); paramNum++ ) {
+
+                final ObjectActionParameterAbstract mixinParameter =
+                        (ObjectActionParameterAbstract) mixinActionParameters.get(paramNum);
+                final ObjectActionParameterMixedIn mixedInParameter;
+                if(mixinParameter instanceof ObjectActionParameterParseable) {
+                    mixedInParameter = new ObjectActionParameterParseableMixedIn(mixinParameter, this);
+                } else if(mixinParameter instanceof OneToOneActionParameterImpl) {
+                    mixedInParameter = new OneToOneActionParameterMixedIn(mixinParameter, this);
+                } else {
+                    throw new RuntimeException("Unknown implementation of ObjectActionParameter; " + mixinParameter.getClass().getName());
+                }
+                mixedInParameters.add(mixedInParameter);
+            }
+            this.parameters = mixedInParameters;
+        }
+        return ObjectExtensions.asListT(parameters, ObjectActionParameter.class);
     }
 
     @Override
@@ -258,7 +288,7 @@ public class ObjectActionMixedIn extends ObjectActionImpl implements MixedInMemb
     
     // //////////////////////////////////////
 
-    private ObjectAdapter mixinAdapterFor(final ObjectAdapter mixedInAdapter) {
+    ObjectAdapter mixinAdapterFor(final ObjectAdapter mixedInAdapter) {
         final ObjectSpecification objectSpecification = getSpecificationLoader().loadSpecification(mixinType);
         final MixinFacet mixinFacet = objectSpecification.getFacet(MixinFacet.class);
         final Object mixinPojo = mixinFacet.instantiate(mixedInAdapter.getObject());

http://git-wip-us.apache.org/repos/asf/isis/blob/3fc01b54/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectActionParameterMixedIn.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectActionParameterMixedIn.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectActionParameterMixedIn.java
new file mode 100644
index 0000000..905c075
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectActionParameterMixedIn.java
@@ -0,0 +1,23 @@
+/**
+ *  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.specloader.specimpl;
+
+import org.apache.isis.core.metamodel.spec.feature.ObjectActionParameter;
+
+public interface ObjectActionParameterMixedIn extends ObjectActionParameter {
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/3fc01b54/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectActionParameterParseableMixedIn.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectActionParameterParseableMixedIn.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectActionParameterParseableMixedIn.java
new file mode 100644
index 0000000..333487a
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectActionParameterParseableMixedIn.java
@@ -0,0 +1,59 @@
+/**
+ *  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.specloader.specimpl;
+
+import java.util.List;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
+
+/**
+ * REVIEW: this is a bit hacky having 'Contributed' subtypes of both {@link ObjectActionParameterParseable} and also
+ * {@link OneToOneActionParameterImpl}.  However, the {@link ObjectActionParameterParseable parseable} version
+ * only seems to be used by the DnD viewer; Scimpi, Wicket and RO do not.  So, we could hopefully simplify the
+ * hierarchy at some point.
+ */
+public class ObjectActionParameterParseableMixedIn extends ObjectActionParameterParseable implements ObjectActionParameterMixedIn {
+
+    private final ObjectActionParameterAbstract mixinParameter;
+    private final ObjectActionMixedIn objectActionMixedIn;
+
+    public ObjectActionParameterParseableMixedIn(
+            final ObjectActionParameterAbstract mixinParameter,
+            final ObjectActionMixedIn objectActionMixedIn) {
+        super(mixinParameter.getNumber(), objectActionMixedIn, mixinParameter.getPeer());
+        this.mixinParameter = mixinParameter;
+        this.objectActionMixedIn = objectActionMixedIn;
+    }
+
+    @Override
+    public ObjectAdapter[] getAutoComplete(
+            final ObjectAdapter mixedInAdapter,
+            final String searchArg,
+            final InteractionInitiatedBy interactionInitiatedBy) {
+        return mixinParameter.getAutoComplete(objectActionMixedIn.mixinAdapterFor(mixedInAdapter), searchArg, interactionInitiatedBy);
+    }
+
+    protected ObjectAdapter targetForDefaultOrChoices(
+            final ObjectAdapter mixedInAdapter,
+            final List<ObjectAdapter> argumentsIfAvailable) {
+        return objectActionMixedIn.mixinAdapterFor(mixedInAdapter);
+    }
+
+
+    
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/3fc01b54/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/OneToOneActionParameterMixedIn.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/OneToOneActionParameterMixedIn.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/OneToOneActionParameterMixedIn.java
new file mode 100644
index 0000000..f8e12a0
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/OneToOneActionParameterMixedIn.java
@@ -0,0 +1,59 @@
+/**
+ *  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.specloader.specimpl;
+
+import java.util.List;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
+import org.apache.isis.core.metamodel.spec.feature.ObjectActionParameter;
+
+public class OneToOneActionParameterMixedIn extends OneToOneActionParameterImpl implements ObjectActionParameterMixedIn {
+
+    private final ObjectActionParameter mixinActionParameter;
+    private final ObjectActionMixedIn mixedInAction;
+
+    public OneToOneActionParameterMixedIn(
+            final ObjectActionParameterAbstract mixinActionParameter,
+            final ObjectActionMixedIn mixedInAction) {
+        super(mixinActionParameter.getNumber(), mixedInAction, mixinActionParameter.getPeer());
+        this.mixinActionParameter = mixinActionParameter;
+        this.mixedInAction = mixedInAction;
+    }
+
+    @Override
+    public ObjectAdapter[] getAutoComplete(
+            final ObjectAdapter mixedInAdapter,
+            final String searchArg,
+            final InteractionInitiatedBy interactionInitiatedBy) {
+        return mixinActionParameter.getAutoComplete(
+                mixinAdapterFor(mixedInAdapter), searchArg,
+                interactionInitiatedBy);
+    }
+
+    protected ObjectAdapter targetForDefaultOrChoices(
+            final ObjectAdapter mixedInAdapter,
+            final List<ObjectAdapter> argumentsIfAvailable) {
+        return mixinAdapterFor(mixedInAdapter);
+    }
+
+    private ObjectAdapter mixinAdapterFor(final ObjectAdapter mixedInAdapter) {
+        return mixedInAction.mixinAdapterFor(mixedInAdapter);
+    }
+
+
+}