incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1098948 [7/16] - in /incubator/isis/trunk/viewer: restful/applib/src/main/java/org/apache/isis/viewer/restful/applib/ restful/applib/src/main/java/org/apache/isis/viewer/restful/applib/providers/ restful/applib/src/main/java/org/apache/isi...
Date Tue, 03 May 2011 07:44:50 GMT
Modified: incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java?rev=1098948&r1=1098947&r2=1098948&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java (original)
+++ incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java Tue May  3 07:44:41 2011
@@ -17,7 +17,6 @@
  *  under the License.
  */
 
-
 package org.apache.isis.viewer.wicket.model.models;
 
 import java.util.Map;
@@ -25,12 +24,6 @@ import java.util.Map.Entry;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.wicket.Component;
-import org.apache.wicket.PageParameters;
-import org.apache.wicket.markup.html.link.BookmarkablePageLink;
-
-import com.google.common.collect.Maps;
-
 import org.apache.isis.applib.Identifier;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.oid.Oid;
@@ -48,19 +41,22 @@ import org.apache.isis.viewer.wicket.mod
 import org.apache.isis.viewer.wicket.model.mementos.PageParameterNames;
 import org.apache.isis.viewer.wicket.model.mementos.SpecMemento;
 import org.apache.isis.viewer.wicket.model.util.ActionParams;
+import org.apache.wicket.Component;
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+
+import com.google.common.collect.Maps;
 
 /**
- * Models an action invocation, either the gathering of arguments for the
- * action's {@link Mode#PARAMETERS parameters}, or the handling of the
- * {@link Mode#RESULTS results} once invoked.
+ * Models an action invocation, either the gathering of arguments for the action's {@link Mode#PARAMETERS parameters},
+ * or the handling of the {@link Mode#RESULTS results} once invoked.
  */
 public class ActionModel extends ModelAbstract<ObjectAdapter> {
 
     private static final long serialVersionUID = 1L;
 
     /**
-     * Whether we are obtaining arguments (eg in a dialog), or displaying the
-     * results
+     * Whether we are obtaining arguments (eg in a dialog), or displaying the results
      */
     public enum Mode {
         PARAMETERS, RESULTS
@@ -91,16 +87,16 @@ public class ActionModel extends ModelAb
     /**
      * Factory; for use directly.
      */
-    public static ActionModel create(ObjectAdapterMemento targetAdapter,
-            ActionMemento action, Mode mode, SingleResultsMode singleResultsMode) {
+    public static ActionModel create(final ObjectAdapterMemento targetAdapter, final ActionMemento action,
+        final Mode mode, final SingleResultsMode singleResultsMode) {
         return new ActionModel(targetAdapter, action, mode, singleResultsMode);
     }
 
     /**
      * Factory; for use by {@link BookmarkablePageLink}s.
      */
-    public static ActionModel createForPersistent(
-            PageParameters pageParameters, OidStringifier oidStringifier) {
+    public static ActionModel createForPersistent(final PageParameters pageParameters,
+        final OidStringifier oidStringifier) {
         return new ActionModel(pageParameters, oidStringifier);
     }
 
@@ -109,37 +105,30 @@ public class ActionModel extends ModelAb
      * 
      * see {@link #ActionModel(PageParameters)}
      */
-    public static PageParameters createPageParameters(
-            final ObjectAdapter adapter, final ObjectAction noAction,
-            OidStringifier oidStringifier, ObjectAdapter contextAdapter,
-            SingleResultsMode singleResultsMode) {
-        PageParameters pageParameters = EntityModel.createPageParameters(
-                adapter, oidStringifier);
+    public static PageParameters createPageParameters(final ObjectAdapter adapter, final ObjectAction noAction,
+        final OidStringifier oidStringifier, final ObjectAdapter contextAdapter,
+        final SingleResultsMode singleResultsMode) {
+        final PageParameters pageParameters = EntityModel.createPageParameters(adapter, oidStringifier);
 
-        String actionType = noAction.getType().name();
-        String actionNameParmsId = determineActionId(noAction);
+        final String actionType = noAction.getType().name();
+        final String actionNameParmsId = determineActionId(noAction);
 
-        Mode actionMode = determineActionMode(noAction, contextAdapter);
+        final Mode actionMode = determineActionMode(noAction, contextAdapter);
 
         PageParameterNames.ACTION_TYPE.addTo(pageParameters, actionType);
-        ObjectSpecification actionOnTypeSpec = noAction.getOnType();
+        final ObjectSpecification actionOnTypeSpec = noAction.getOnType();
         if (actionOnTypeSpec != null) {
-            PageParameterNames.ACTION_OWNING_SPEC.addTo(pageParameters,
-                    actionOnTypeSpec.getFullIdentifier());
+            PageParameterNames.ACTION_OWNING_SPEC.addTo(pageParameters, actionOnTypeSpec.getFullIdentifier());
         }
-        PageParameterNames.ACTION_NAME_PARMS.addTo(pageParameters,
-                actionNameParmsId);
+        PageParameterNames.ACTION_NAME_PARMS.addTo(pageParameters, actionNameParmsId);
         PageParameterNames.ACTION_MODE.addTo(pageParameters, actionMode.name());
-        PageParameterNames.ACTION_SINGLE_RESULTS_MODE.addTo(pageParameters,
-                singleResultsMode.name());
+        PageParameterNames.ACTION_SINGLE_RESULTS_MODE.addTo(pageParameters, singleResultsMode.name());
 
-        addActionParamContextIfPossible(noAction, oidStringifier,
-                contextAdapter, pageParameters);
+        addActionParamContextIfPossible(noAction, oidStringifier, contextAdapter, pageParameters);
         return pageParameters;
     }
 
-    private static Mode determineActionMode(final ObjectAction noAction,
-    		ObjectAdapter contextAdapter) {
+    private static Mode determineActionMode(final ObjectAction noAction, final ObjectAdapter contextAdapter) {
         final int parameterCount = noAction.getParameterCount();
         if (parameterCount == 0) {
             return Mode.RESULTS;
@@ -149,25 +138,21 @@ public class ActionModel extends ModelAb
         }
         // no need to prompt for contributed actions (ie if have a context
         // adapter)
-        ObjectActionParameter actionParam = noAction.getParameters().get(0);
-        return ActionParams.compatibleWith(contextAdapter, actionParam) ? Mode.RESULTS
-                : Mode.PARAMETERS;
+        final ObjectActionParameter actionParam = noAction.getParameters().get(0);
+        return ActionParams.compatibleWith(contextAdapter, actionParam) ? Mode.RESULTS : Mode.PARAMETERS;
     }
 
-    private static void addActionParamContextIfPossible(
-            final ObjectAction noAction, OidStringifier oidStringifier,
-            ObjectAdapter contextAdapter, PageParameters pageParameters) {
+    private static void addActionParamContextIfPossible(final ObjectAction noAction,
+        final OidStringifier oidStringifier, final ObjectAdapter contextAdapter, final PageParameters pageParameters) {
         if (contextAdapter == null) {
             return;
         }
         int i = 0;
-        for (ObjectActionParameter actionParam : noAction.getParameters()) {
+        for (final ObjectActionParameter actionParam : noAction.getParameters()) {
             if (ActionParams.compatibleWith(contextAdapter, actionParam)) {
-                final String oidStr = oidStringifier.enString(contextAdapter
-                        .getOid());
+                final String oidStr = oidStringifier.enString(contextAdapter.getOid());
                 final String oidKeyValue = "" + i + "=" + oidStr;
-                PageParameterNames.ACTION_PARAM_CONTEXT.addTo(pageParameters,
-                        oidKeyValue);
+                PageParameterNames.ACTION_PARAM_CONTEXT.addTo(pageParameters, oidKeyValue);
                 return;
             }
             i++;
@@ -175,7 +160,7 @@ public class ActionModel extends ModelAb
     }
 
     private static String determineActionId(final ObjectAction noAction) {
-        Identifier identifier = noAction.getIdentifier();
+        final Identifier identifier = noAction.getIdentifier();
         if (identifier != null) {
             return identifier.toNameParmsIdentityString();
         }
@@ -187,10 +172,10 @@ public class ActionModel extends ModelAb
         return action.getParameterCount() > 0 ? Mode.PARAMETERS : Mode.RESULTS;
     }
 
-    private ObjectAdapterMemento targetAdapterMemento;
-    private ActionMemento actionMemento;
+    private final ObjectAdapterMemento targetAdapterMemento;
+    private final ActionMemento actionMemento;
     private Mode actionMode;
-    private SingleResultsMode singleResultsMode;
+    private final SingleResultsMode singleResultsMode;
 
     private SelectionHandler selectionHandler;
     private NoResultsHandler noResultsHandler;
@@ -198,15 +183,12 @@ public class ActionModel extends ModelAb
     /**
      * Lazily populated in {@link #getArgumentModel(ActionParameterMemento)}
      */
-    private Map<Integer, ScalarModel> arguments = Maps.newHashMap();
+    private final Map<Integer, ScalarModel> arguments = Maps.newHashMap();
     private ActionExecutor executor;
 
-    private ActionModel(PageParameters pageParameters,
-            OidStringifier oidStringifier) {
-        this(newObjectAdapterMementoFrom(pageParameters, oidStringifier),
-                newActionMementoFrom(pageParameters),
-                actionModeFor(pageParameters),
-                singleResultsModeFor(pageParameters));
+    private ActionModel(final PageParameters pageParameters, final OidStringifier oidStringifier) {
+        this(newObjectAdapterMementoFrom(pageParameters, oidStringifier), newActionMementoFrom(pageParameters),
+            actionModeFor(pageParameters), singleResultsModeFor(pageParameters));
 
         setContextArgumentIfPossible(pageParameters, oidStringifier);
 
@@ -216,113 +198,99 @@ public class ActionModel extends ModelAb
             private static final long serialVersionUID = 1L;
 
             @Override
-            public void onNoResults(Component context) {
+            public void onNoResults(final Component context) {
                 reset();
                 context.setResponsePage(context.getPage());
             }
         });
     }
 
-    private static ActionMemento newActionMementoFrom(
-            PageParameters pageParameters) {
-        return new ActionMemento(actionOwningSpecFor(pageParameters),
-                actionTypeFor(pageParameters),
-                actionNameParmsFor(pageParameters));
+    private static ActionMemento newActionMementoFrom(final PageParameters pageParameters) {
+        return new ActionMemento(actionOwningSpecFor(pageParameters), actionTypeFor(pageParameters),
+            actionNameParmsFor(pageParameters));
     }
 
-    private static SingleResultsMode singleResultsModeFor(
-            PageParameters pageParameters) {
-        return SingleResultsMode
-                .valueOf(PageParameterNames.ACTION_SINGLE_RESULTS_MODE
-                        .getFrom(pageParameters));
+    private static SingleResultsMode singleResultsModeFor(final PageParameters pageParameters) {
+        return SingleResultsMode.valueOf(PageParameterNames.ACTION_SINGLE_RESULTS_MODE.getFrom(pageParameters));
     }
 
-    private static Mode actionModeFor(PageParameters pageParameters) {
-        return Mode.valueOf(PageParameterNames.ACTION_MODE
-                .getFrom(pageParameters));
+    private static Mode actionModeFor(final PageParameters pageParameters) {
+        return Mode.valueOf(PageParameterNames.ACTION_MODE.getFrom(pageParameters));
     }
 
-    private static String actionNameParmsFor(PageParameters pageParameters) {
+    private static String actionNameParmsFor(final PageParameters pageParameters) {
         return PageParameterNames.ACTION_NAME_PARMS.getFrom(pageParameters);
     }
 
-    private static ActionType actionTypeFor(
-            PageParameters pageParameters) {
-        return ActionType.valueOf(PageParameterNames.ACTION_TYPE
-                .getFrom(pageParameters));
+    private static ActionType actionTypeFor(final PageParameters pageParameters) {
+        return ActionType.valueOf(PageParameterNames.ACTION_TYPE.getFrom(pageParameters));
     }
 
-    private static SpecMemento actionOwningSpecFor(PageParameters pageParameters) {
-        return SpecMemento.representing(PageParameterNames.ACTION_OWNING_SPEC
-                .getFrom(pageParameters));
+    private static SpecMemento actionOwningSpecFor(final PageParameters pageParameters) {
+        return SpecMemento.representing(PageParameterNames.ACTION_OWNING_SPEC.getFrom(pageParameters));
     }
 
-    private static ObjectAdapterMemento newObjectAdapterMementoFrom(
-            PageParameters pageParameters, OidStringifier oidStringifier) {
-        return ObjectAdapterMemento.createPersistent(oidFor(pageParameters,
-                oidStringifier), objectSpecFor(pageParameters));
+    private static ObjectAdapterMemento newObjectAdapterMementoFrom(final PageParameters pageParameters,
+        final OidStringifier oidStringifier) {
+        return ObjectAdapterMemento.createPersistent(oidFor(pageParameters, oidStringifier),
+            objectSpecFor(pageParameters));
     }
 
-    private static SpecMemento objectSpecFor(PageParameters pageParameters) {
-        return SpecMemento.representing(PageParameterNames.OBJECT_SPEC
-                .getFrom(pageParameters));
+    private static SpecMemento objectSpecFor(final PageParameters pageParameters) {
+        return SpecMemento.representing(PageParameterNames.OBJECT_SPEC.getFrom(pageParameters));
     }
 
-    private static Oid oidFor(PageParameters pageParameters,
-            OidStringifier oidStringifier) {
-        return oidStringifier.deString(PageParameterNames.OBJECT_OID
-                .getFrom(pageParameters));
+    private static Oid oidFor(final PageParameters pageParameters, final OidStringifier oidStringifier) {
+        return oidStringifier.deString(PageParameterNames.OBJECT_OID.getFrom(pageParameters));
     }
 
-    private ActionModel(final ObjectAdapterMemento adapterMemento,
-            final ActionMemento actionMemento, final Mode actionMode,
-            final SingleResultsMode singleResultsMode) {
+    private ActionModel(final ObjectAdapterMemento adapterMemento, final ActionMemento actionMemento,
+        final Mode actionMode, final SingleResultsMode singleResultsMode) {
         this.targetAdapterMemento = adapterMemento;
         this.actionMemento = actionMemento;
         this.actionMode = actionMode;
         this.singleResultsMode = singleResultsMode;
     }
 
-    private boolean setContextArgumentIfPossible(PageParameters pageParameters,
-            OidStringifier oidStringifier) {
-        String paramContext = PageParameterNames.ACTION_PARAM_CONTEXT
-                .getFrom(pageParameters);
+    private boolean setContextArgumentIfPossible(final PageParameters pageParameters,
+        final OidStringifier oidStringifier) {
+        final String paramContext = PageParameterNames.ACTION_PARAM_CONTEXT.getFrom(pageParameters);
         if (paramContext == null) {
             return false;
         }
-        ObjectAction action = actionMemento.getAction();
-        int parameterCount = action.getParameterCount();
+        final ObjectAction action = actionMemento.getAction();
+        final int parameterCount = action.getParameterCount();
 
-        Map.Entry<Integer, String> mapEntry = parse(paramContext);
+        final Map.Entry<Integer, String> mapEntry = parse(paramContext);
 
         Oid oid;
-        int paramNum = mapEntry.getKey();
+        final int paramNum = mapEntry.getKey();
         if (paramNum >= parameterCount) {
             return false;
         }
 
         try {
             oid = oidStringifier.deString(mapEntry.getValue());
-        } catch (Exception e) {
+        } catch (final Exception e) {
             return false;
         }
 
-        ObjectAdapter argumentAdapter = getAdapterManager().getAdapterFor(oid);
+        final ObjectAdapter argumentAdapter = getAdapterManager().getAdapterFor(oid);
         if (argumentAdapter == null) {
             return false;
         }
 
-        ObjectActionParameter actionParam = action.getParameters().get(paramNum);
-        ActionParameterMemento apm = new ActionParameterMemento(actionParam);
-        ScalarModel argumentModel = getArgumentModel(apm);
+        final ObjectActionParameter actionParam = action.getParameters().get(paramNum);
+        final ActionParameterMemento apm = new ActionParameterMemento(actionParam);
+        final ScalarModel argumentModel = getArgumentModel(apm);
         argumentModel.setObject(argumentAdapter);
 
         return true;
     }
 
-    public static Entry<Integer, String> parse(String paramContext) {
-        Pattern compile = Pattern.compile("([^=]+)=(.+)");
-        Matcher matcher = compile.matcher(paramContext);
+    public static Entry<Integer, String> parse(final String paramContext) {
+        final Pattern compile = Pattern.compile("([^=]+)=(.+)");
+        final Matcher matcher = compile.matcher(paramContext);
         if (!matcher.matches()) {
             return null;
         }
@@ -330,7 +298,7 @@ public class ActionModel extends ModelAb
         final int paramNum;
         try {
             paramNum = Integer.parseInt(matcher.group(1));
-        } catch (Exception e) {
+        } catch (final Exception e) {
             // ignore
             return null;
         }
@@ -338,7 +306,7 @@ public class ActionModel extends ModelAb
         final String oidStr;
         try {
             oidStr = matcher.group(2);
-        } catch (Exception e) {
+        } catch (final Exception e) {
             return null;
         }
 
@@ -355,17 +323,17 @@ public class ActionModel extends ModelAb
             }
 
             @Override
-            public String setValue(String value) {
+            public String setValue(final String value) {
                 return null;
             }
         };
     }
 
-    public ScalarModel getArgumentModel(ActionParameterMemento apm) {
+    public ScalarModel getArgumentModel(final ActionParameterMemento apm) {
         ScalarModel scalarModel = arguments.get(apm.getNumber());
         if (scalarModel == null) {
             scalarModel = new ScalarModel(targetAdapterMemento, apm);
-            int number = scalarModel.getParameterMemento().getNumber();
+            final int number = scalarModel.getParameterMemento().getNumber();
             arguments.put(number, scalarModel);
         }
         return scalarModel;
@@ -386,47 +354,44 @@ public class ActionModel extends ModelAb
     @Override
     public ObjectAdapter getObject() {
         detach(); // force re-execute
-        ObjectAdapter result = super.getObject();
+        final ObjectAdapter result = super.getObject();
         arguments.clear();
         return result;
     }
 
     @Override
     protected ObjectAdapter load() {
-    	ObjectAdapter results = executeAction();
+        final ObjectAdapter results = executeAction();
         this.actionMode = Mode.RESULTS;
         return results;
     }
 
     private ObjectAdapter executeAction() {
-    	ObjectAdapter targetAdapter = getTargetAdapter();
-    	ObjectAdapter[] arguments = getArgumentsAsArray();
-        ObjectAction action = getActionMemento().getAction();
-        ObjectAdapter results = action.execute(targetAdapter, arguments);
+        final ObjectAdapter targetAdapter = getTargetAdapter();
+        final ObjectAdapter[] arguments = getArgumentsAsArray();
+        final ObjectAction action = getActionMemento().getAction();
+        final ObjectAdapter results = action.execute(targetAdapter, arguments);
         return results;
     }
 
     public String getReasonInvalidIfAny() {
-    	ObjectAdapter targetAdapter = getTargetAdapter();
-    	ObjectAdapter[] proposedArguments = getArgumentsAsArray();
-        ObjectAction objectAction = getActionMemento().getAction();
-        Consent validity = objectAction.isProposedArgumentSetValid(
-                targetAdapter, proposedArguments);
+        final ObjectAdapter targetAdapter = getTargetAdapter();
+        final ObjectAdapter[] proposedArguments = getArgumentsAsArray();
+        final ObjectAction objectAction = getActionMemento().getAction();
+        final Consent validity = objectAction.isProposedArgumentSetValid(targetAdapter, proposedArguments);
         return validity.isAllowed() ? null : validity.getReason();
     }
 
     @Override
-    public void setObject(ObjectAdapter object) {
-        throw new UnsupportedOperationException(
-                "target adapter for ActionModel cannot be changed");
+    public void setObject(final ObjectAdapter object) {
+        throw new UnsupportedOperationException("target adapter for ActionModel cannot be changed");
     }
 
     public ObjectAdapter[] getArgumentsAsArray() {
-        ObjectAction objectAction = getActionMemento().getAction();
-        ObjectAdapter[] arguments = new ObjectAdapter[objectAction
-                .getParameterCount()];
+        final ObjectAction objectAction = getActionMemento().getAction();
+        final ObjectAdapter[] arguments = new ObjectAdapter[objectAction.getParameterCount()];
         for (int i = 0; i < arguments.length; i++) {
-            ScalarModel scalarModel = this.arguments.get(i);
+            final ScalarModel scalarModel = this.arguments.get(i);
             arguments[i] = scalarModel.getObject();
         }
         return arguments;
@@ -436,16 +401,14 @@ public class ActionModel extends ModelAb
      * The {@link SelectionHandler}, if any.
      * 
      * <p>
-     * If specified, then
-     * {@link EntityCollectionModel#setSelectionHandler(SelectionHandler)
-     * propogated} if the results is a {@link EntityCollectionModel collection},
-     * or used directly if the results is an {@link EntityModel}.
+     * If specified, then {@link EntityCollectionModel#setSelectionHandler(SelectionHandler) propogated} if the results
+     * is a {@link EntityCollectionModel collection}, or used directly if the results is an {@link EntityModel}.
      */
     public SelectionHandler getSelectionHandler() {
         return selectionHandler;
     }
 
-    public void setSelectionHandler(SelectionHandler selectionHandler) {
+    public void setSelectionHandler(final SelectionHandler selectionHandler) {
         this.selectionHandler = selectionHandler;
     }
 
@@ -456,7 +419,7 @@ public class ActionModel extends ModelAb
         return noResultsHandler;
     }
 
-    public void setNoResultsHandler(NoResultsHandler noResultsHandler) {
+    public void setNoResultsHandler(final NoResultsHandler noResultsHandler) {
         this.noResultsHandler = noResultsHandler;
     }
 
@@ -464,7 +427,7 @@ public class ActionModel extends ModelAb
         return executor;
     }
 
-    public void setExecutor(ActionExecutor executor) {
+    public void setExecutor(final ActionExecutor executor) {
         this.executor = executor;
     }
 

Modified: incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ApplicationActionsModel.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ApplicationActionsModel.java?rev=1098948&r1=1098947&r2=1098948&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ApplicationActionsModel.java (original)
+++ incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ApplicationActionsModel.java Tue May  3 07:44:41 2011
@@ -17,7 +17,6 @@
  *  under the License.
  */
 
-
 package org.apache.isis.viewer.wicket.model.models;
 
 import java.util.List;
@@ -25,16 +24,16 @@ import java.util.List;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 
 /**
- * Backing model for actions of application services menu bar (typically, as displayed
- * along the top or side of the page).
+ * Backing model for actions of application services menu bar (typically, as displayed along the top or side of the
+ * page).
  */
 public class ApplicationActionsModel extends ModelAbstract<List<ObjectAdapter>> {
 
-	private static final long serialVersionUID = 1L;
-	
-	@Override
-	protected List<ObjectAdapter> load() {
-		return getPersistenceSession().getServices();
-	}
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    protected List<ObjectAdapter> load() {
+        return getPersistenceSession().getServices();
+    }
 
 }

Modified: incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java?rev=1098948&r1=1098947&r2=1098948&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java (original)
+++ incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java Tue May  3 07:44:41 2011
@@ -17,17 +17,11 @@
  *  under the License.
  */
 
-
 package org.apache.isis.viewer.wicket.model.models;
 
 import java.io.Serializable;
 import java.util.List;
 
-import org.apache.wicket.Component;
-
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
@@ -38,147 +32,135 @@ import org.apache.isis.viewer.wicket.mod
 import org.apache.isis.viewer.wicket.model.util.ClassLoaders;
 import org.apache.isis.viewer.wicket.model.util.Mementos;
 import org.apache.isis.viewer.wicket.model.util.ObjectAdapters;
+import org.apache.wicket.Component;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
 
 /**
- * Model representing a collection of entities, either {@link Type#STANDALONE
- * standalone} (eg result of invoking an action) or {@link Type#PARENTED
- * parented} (contents of the collection of an entity).
+ * Model representing a collection of entities, either {@link Type#STANDALONE standalone} (eg result of invoking an
+ * action) or {@link Type#PARENTED parented} (contents of the collection of an entity).
  * 
  * <p>
- * So that the model is {@link Serializable}, the {@link ObjectAdapter}s within the 
- * collection are stored as {@link ObjectAdapterMemento}s.
+ * So that the model is {@link Serializable}, the {@link ObjectAdapter}s within the collection are stored as
+ * {@link ObjectAdapterMemento}s.
  */
 public class EntityCollectionModel extends ModelAbstract<List<ObjectAdapter>> {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
+
+    public enum Type {
+        /**
+         * A simple list of object mementos, eg the result of invoking an action
+         * 
+         * <p>
+         * This deals with both persisted and transient objects.
+         */
+        STANDALONE {
+            @Override
+            List<ObjectAdapter> load(final EntityCollectionModel entityCollectionModel) {
+                return Lists.transform(entityCollectionModel.mementoList, ObjectAdapters.fromMemento());
+            }
+        },
+        /**
+         * A collection of an entity (eg Order/OrderDetail).
+         */
+        PARENTED {
+            @Override
+            List<ObjectAdapter> load(final EntityCollectionModel entityCollectionModel) {
+                final ObjectAdapter adapter = entityCollectionModel.parentObjectAdapterMemento.getObjectAdapter();
+                final OneToManyAssociation collection = entityCollectionModel.collectionMemento.getCollection();
+                final ObjectAdapter collectionAsAdapter = collection.get(adapter);
+
+                final Iterable<Object> objectList = asIterable(collectionAsAdapter);
+
+                final Iterable<ObjectAdapter> adapterIterable =
+                    Iterables.transform(objectList, ObjectAdapters.fromPojo());
+                final List<ObjectAdapter> adapterList = Lists.newArrayList(adapterIterable);
+
+                return adapterList;
+            }
+
+            @SuppressWarnings("unchecked")
+            private Iterable<Object> asIterable(final ObjectAdapter collectionAsAdapter) {
+                return (Iterable<Object>) collectionAsAdapter.getObject();
+            }
+        };
+
+        abstract List<ObjectAdapter> load(EntityCollectionModel entityCollectionModel);
+    }
+
+    /**
+     * Factory.
+     */
+    public static EntityCollectionModel createStandalone(final ObjectAdapter collectionAsAdapter) {
+        final Iterable<Object> iterable = EntityCollectionModel.asIterable(collectionAsAdapter);
+
+        final Iterable<ObjectAdapterMemento> oidIterable = Iterables.transform(iterable, Mementos.fromPojo());
+        final List<ObjectAdapterMemento> mementoList = Lists.newArrayList(oidIterable);
+
+        final ObjectSpecification elementSpec = collectionAsAdapter.getElementSpecification();
+        final Class<?> elementType = elementSpec.getCorrespondingClass();
+        return new EntityCollectionModel(elementType, mementoList);
+    }
+
+    /**
+     * Factory.
+     */
+    public static EntityCollectionModel createParented(final EntityModel model, final OneToManyAssociation collection) {
+        return new EntityCollectionModel(model, collection);
+    }
+
+    /**
+     * Factory.
+     */
+    public static EntityCollectionModel createParented(final ObjectAdapter adapter,
+        final OneToManyAssociation collection) {
+        return new EntityCollectionModel(adapter, collection);
+    }
+
+    private final Type type;
+
+    private final Class<?> typeOf;
+    private transient ObjectSpecification typeOfSpec;
+
+    /**
+     * Populated only if {@link Type#STANDALONE}.
+     */
+    private List<ObjectAdapterMemento> mementoList;
+
+    /**
+     * Populated only if {@link Type#PARENTED}.
+     */
+    private ObjectAdapterMemento parentObjectAdapterMemento;
+
+    /**
+     * Populated only if {@link Type#PARENTED}.
+     */
+    private CollectionMemento collectionMemento;
 
-	public enum Type {
-		/**
-		 * A simple list of object mementos, eg the result of invoking an action
-		 * 
-		 * <p>
-		 * This deals with both persisted and transient objects.
-		 */
-		STANDALONE {
-			@Override
-			List<ObjectAdapter> load(
-					EntityCollectionModel entityCollectionModel) {
-				return Lists.transform(entityCollectionModel.mementoList,
-						ObjectAdapters.fromMemento());
-			}
-		},
-		/**
-		 * A collection of an entity (eg Order/OrderDetail).
-		 */
-		PARENTED {
-			@Override
-			List<ObjectAdapter> load(
-					EntityCollectionModel entityCollectionModel) {
-				ObjectAdapter adapter = entityCollectionModel.parentObjectAdapterMemento
-						.getObjectAdapter();
-				OneToManyAssociation collection = entityCollectionModel.collectionMemento
-						.getCollection();
-				ObjectAdapter collectionAsAdapter = collection.get(adapter);
-
-				Iterable<Object> objectList = asIterable(collectionAsAdapter);
-
-				Iterable<ObjectAdapter> adapterIterable = Iterables.transform(
-						objectList, ObjectAdapters.fromPojo());
-				List<ObjectAdapter> adapterList = Lists
-						.newArrayList(adapterIterable);
-
-				return adapterList;
-			}
-
-			@SuppressWarnings("unchecked")
-			private Iterable<Object> asIterable(ObjectAdapter collectionAsAdapter) {
-				return (Iterable<Object>) collectionAsAdapter.getObject();
-			}
-		};
-
-		abstract List<ObjectAdapter> load(
-				EntityCollectionModel entityCollectionModel);
-	}
-
-	/**
-	 * Factory.
-	 */
-	public static EntityCollectionModel createStandalone(
-			ObjectAdapter collectionAsAdapter) {
-		Iterable<Object> iterable = EntityCollectionModel
-				.asIterable(collectionAsAdapter);
-
-		Iterable<ObjectAdapterMemento> oidIterable = Iterables.transform(
-				iterable, Mementos.fromPojo());
-		List<ObjectAdapterMemento> mementoList = Lists.newArrayList(oidIterable);
-		
-		final ObjectSpecification elementSpec = collectionAsAdapter.getElementSpecification();
-		final Class<?> elementType = elementSpec.getCorrespondingClass();
-		return new EntityCollectionModel(elementType, mementoList);
-	}
-
-	/**
-	 * Factory.
-	 */
-	public static EntityCollectionModel createParented(EntityModel model,
-			OneToManyAssociation collection) {
-		return new EntityCollectionModel(model, collection);
-	}
-
-	/**
-	 * Factory.
-	 */
-	public static EntityCollectionModel createParented(ObjectAdapter adapter,
-			OneToManyAssociation collection) {
-		return new EntityCollectionModel(adapter, collection);
-	}
-
-	private final Type type;
-
-	private Class<?> typeOf;
-	private transient ObjectSpecification typeOfSpec;
-
-	/**
-	 * Populated only if {@link Type#STANDALONE}.
-	 */
-	private List<ObjectAdapterMemento> mementoList;
-
-	/**
-	 * Populated only if {@link Type#PARENTED}.
-	 */
-	private ObjectAdapterMemento parentObjectAdapterMemento;
-
-	/**
-	 * Populated only if {@link Type#PARENTED}.
-	 */
-	private CollectionMemento collectionMemento;
-
-	private SelectionHandler selectionHandler;
-
-	private EntityCollectionModel(Class<?> typeOf,
-			List<ObjectAdapterMemento> mementoList) {
-		this.type = Type.STANDALONE;
-		this.typeOf = typeOf;
-		this.mementoList = mementoList;
-	}
-
-	private EntityCollectionModel(ObjectAdapter adapter,
-			OneToManyAssociation collection) {
-		this(ObjectAdapterMemento.createOrNull(adapter), collection);
-	}
-
-	private EntityCollectionModel(EntityModel model,
-			OneToManyAssociation collection) {
-		this(model.getObjectAdapterMemento(), collection);
-	}
-
-	private EntityCollectionModel(ObjectAdapterMemento parentAdapterMemento,
-			OneToManyAssociation collection) {
-		this.type = Type.PARENTED;
-		this.typeOf = ClassLoaders.forName(collection.getSpecification());
-		this.parentObjectAdapterMemento = parentAdapterMemento;
-		this.collectionMemento = new CollectionMemento(collection);
-	}
+    private SelectionHandler selectionHandler;
+
+    private EntityCollectionModel(final Class<?> typeOf, final List<ObjectAdapterMemento> mementoList) {
+        this.type = Type.STANDALONE;
+        this.typeOf = typeOf;
+        this.mementoList = mementoList;
+    }
+
+    private EntityCollectionModel(final ObjectAdapter adapter, final OneToManyAssociation collection) {
+        this(ObjectAdapterMemento.createOrNull(adapter), collection);
+    }
+
+    private EntityCollectionModel(final EntityModel model, final OneToManyAssociation collection) {
+        this(model.getObjectAdapterMemento(), collection);
+    }
+
+    private EntityCollectionModel(final ObjectAdapterMemento parentAdapterMemento, final OneToManyAssociation collection) {
+        this.type = Type.PARENTED;
+        this.typeOf = ClassLoaders.forName(collection.getSpecification());
+        this.parentObjectAdapterMemento = parentAdapterMemento;
+        this.collectionMemento = new CollectionMemento(collection);
+    }
 
     public boolean isParented() {
         return type == Type.PARENTED;
@@ -198,56 +180,53 @@ public class EntityCollectionModel exten
         return getCollectionMemento().getName();
     }
 
-	@Override
-	protected List<ObjectAdapter> load() {
-		return type.load(this);
-	}
-
-	public ObjectSpecification getTypeOfSpecification() {
-		if (typeOfSpec == null) {
-			typeOfSpec = IsisContext.getSpecificationLoader()
-					.loadSpecification(typeOf);
-		}
-		return typeOfSpec;
-	}
-
-	/**
-	 * Populated only if {@link Type#PARENTED}.
-	 */
-	public ObjectAdapterMemento getParentObjectAdapterMemento() {
-		return parentObjectAdapterMemento;
-	}
-
-	/**
-	 * Populated only if {@link Type#PARENTED}.
-	 */
-	public CollectionMemento getCollectionMemento() {
-		return collectionMemento;
-	}
-
-	/**
-	 * The {@link SelectionHandler}, if any.
-	 * 
-	 * <p>
-	 * If specified, then view {@link Component}s are expected to render the
-	 * collection so that one of the entities can be selected.
-	 */
-	public SelectionHandler getSelectionHandler() {
-		return selectionHandler;
-	}
-
-	public void setSelectionHandler(SelectionHandler selectionHandler) {
-		this.selectionHandler = selectionHandler;
-	}
-
-	public boolean hasSelectionHandler() {
-		return getSelectionHandler() != null;
-	}
+    @Override
+    protected List<ObjectAdapter> load() {
+        return type.load(this);
+    }
 
+    public ObjectSpecification getTypeOfSpecification() {
+        if (typeOfSpec == null) {
+            typeOfSpec = IsisContext.getSpecificationLoader().loadSpecification(typeOf);
+        }
+        return typeOfSpec;
+    }
 
+    /**
+     * Populated only if {@link Type#PARENTED}.
+     */
+    public ObjectAdapterMemento getParentObjectAdapterMemento() {
+        return parentObjectAdapterMemento;
+    }
+
+    /**
+     * Populated only if {@link Type#PARENTED}.
+     */
+    public CollectionMemento getCollectionMemento() {
+        return collectionMemento;
+    }
+
+    /**
+     * The {@link SelectionHandler}, if any.
+     * 
+     * <p>
+     * If specified, then view {@link Component}s are expected to render the collection so that one of the entities can
+     * be selected.
+     */
+    public SelectionHandler getSelectionHandler() {
+        return selectionHandler;
+    }
+
+    public void setSelectionHandler(final SelectionHandler selectionHandler) {
+        this.selectionHandler = selectionHandler;
+    }
+
+    public boolean hasSelectionHandler() {
+        return getSelectionHandler() != null;
+    }
 
-	@SuppressWarnings("unchecked")
-	public static Iterable<Object> asIterable(ObjectAdapter resultAdapter) {
-		return (Iterable<Object>) resultAdapter.getObject();
-	}
+    @SuppressWarnings("unchecked")
+    public static Iterable<Object> asIterable(final ObjectAdapter resultAdapter) {
+        return (Iterable<Object>) resultAdapter.getObject();
+    }
 }

Modified: incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java?rev=1098948&r1=1098947&r2=1098948&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java (original)
+++ incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java Tue May  3 07:44:41 2011
@@ -17,7 +17,6 @@
  *  under the License.
  */
 
-
 package org.apache.isis.viewer.wicket.model.models;
 
 import java.io.Serializable;
@@ -40,98 +39,86 @@ import com.google.common.collect.Maps;
  * Backing model to represent a {@link ObjectAdapter}.
  * 
  * <p>
- * So that the model is {@link Serializable}, the {@link ObjectAdapter} is stored
- * as a {@link ObjectAdapterMemento}.
+ * So that the model is {@link Serializable}, the {@link ObjectAdapter} is stored as a {@link ObjectAdapterMemento}.
  */
 public class EntityModel extends ModelAbstract<ObjectAdapter> {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-    ////////////////////////////////////////////////////////////
+    // //////////////////////////////////////////////////////////
     // factory methods for PageParameters
-    ////////////////////////////////////////////////////////////
+    // //////////////////////////////////////////////////////////
+
+    /**
+     * Factory method for creating {@link PageParameters} to represent an entity.
+     */
+    public static PageParameters createPageParameters(final ObjectAdapter adapter, final OidStringifier oidStringifier) {
+
+        final PageParameters pageParameters = new PageParameters();
+
+        final Boolean persistent = adapter.isPersistent();
+        PageParameterNames.OBJECT_PERSISTENT.addTo(pageParameters, persistent.toString());
+
+        if (persistent) {
+            final String oidStr = oidStringifier.enString(adapter.getOid());
+            final ObjectSpecification noSpec = adapter.getSpecification();
+
+            PageParameterNames.OBJECT_OID.addTo(pageParameters, oidStr);
+            PageParameterNames.OBJECT_SPEC.addTo(pageParameters, noSpec.getFullIdentifier());
+        } else {
+            // don't do anything; instead the page should be redirected back to
+            // an EntityPage so that the underlying EntityModel that contains the
+            // memento for the transient ObjectAdapter can be accessed.
+        }
 
-	/**
-	 * Factory method for creating {@link PageParameters} to represent
-	 * an entity.
-	 */
-	public static PageParameters createPageParameters(
-			final ObjectAdapter adapter, OidStringifier oidStringifier) {
-
-		PageParameters pageParameters = new PageParameters();
-
-		Boolean persistent = adapter.isPersistent();
-		PageParameterNames.OBJECT_PERSISTENT.addTo(pageParameters, persistent
-				.toString());
-
-		if (persistent) {
-			String oidStr = oidStringifier.enString(adapter.getOid());
-			ObjectSpecification noSpec = adapter.getSpecification();
-
-			PageParameterNames.OBJECT_OID.addTo(pageParameters, oidStr);
-			PageParameterNames.OBJECT_SPEC.addTo(pageParameters, noSpec
-					.getFullIdentifier());
-		} else {
-			// don't do anything; instead the page should be redirected back to
-			// an EntityPage so that the underlying EntityModel that contains the
-			// memento for the transient ObjectAdapter can be accessed.
-		}
-
-		return pageParameters;
-	}
-
-	public enum Mode {
-		VIEW, EDIT;
-	}
-
-	private ObjectAdapterMemento adapterMemento;
-	private Mode mode = Mode.VIEW;
-	private Map<PropertyMemento, ScalarModel> propertyScalarModels = Maps
-			.newHashMap();
+        return pageParameters;
+    }
+
+    public enum Mode {
+        VIEW, EDIT;
+    }
+
+    private ObjectAdapterMemento adapterMemento;
+    private Mode mode = Mode.VIEW;
+    private final Map<PropertyMemento, ScalarModel> propertyScalarModels = Maps.newHashMap();
 
     /**
      * Toggled by 'entityDetailsButton'.
      */
     private boolean entityDetailsVisible;
 
-    
-    ////////////////////////////////////////////////////////////
+    // //////////////////////////////////////////////////////////
     // constructors
-    ////////////////////////////////////////////////////////////
-    
-	public EntityModel() {
-	}
-
-	public EntityModel(PageParameters pageParameters,
-			OidStringifier oidStringifier) {
-		this(ObjectAdapterMemento.createPersistent(
-				oidStringifier.deString(PageParameterNames.OBJECT_OID
-						.getFrom(pageParameters)), SpecMemento
-						.representing(PageParameterNames.OBJECT_SPEC
-								.getFrom(pageParameters))));
-	}
-
-	public EntityModel(ObjectAdapter adapter) {
-		this(ObjectAdapterMemento.createOrNull(adapter));
-		setObject(adapter);
-	}
-
-	public EntityModel(ObjectAdapterMemento adapterMemento) {
-		this.adapterMemento = adapterMemento;
-	}
+    // //////////////////////////////////////////////////////////
+
+    public EntityModel() {
+    }
+
+    public EntityModel(final PageParameters pageParameters, final OidStringifier oidStringifier) {
+        this(ObjectAdapterMemento.createPersistent(
+            oidStringifier.deString(PageParameterNames.OBJECT_OID.getFrom(pageParameters)),
+            SpecMemento.representing(PageParameterNames.OBJECT_SPEC.getFrom(pageParameters))));
+    }
 
-	
-    ////////////////////////////////////////////////////////////
+    public EntityModel(final ObjectAdapter adapter) {
+        this(ObjectAdapterMemento.createOrNull(adapter));
+        setObject(adapter);
+    }
+
+    public EntityModel(final ObjectAdapterMemento adapterMemento) {
+        this.adapterMemento = adapterMemento;
+    }
+
+    // //////////////////////////////////////////////////////////
     // ObjectAdapterMemento, typeOfSpecification
-    ////////////////////////////////////////////////////////////
+    // //////////////////////////////////////////////////////////
 
-	public ObjectAdapterMemento getObjectAdapterMemento() {
-		return adapterMemento;
-	}
+    public ObjectAdapterMemento getObjectAdapterMemento() {
+        return adapterMemento;
+    }
 
     /**
-     * Overridable for submodels (eg {@link ScalarModel}) that know the type of
-     * the adapter without there being one.
+     * Overridable for submodels (eg {@link ScalarModel}) that know the type of the adapter without there being one.
      */
     public ObjectSpecification getTypeOfSpecification() {
         if (adapterMemento == null) {
@@ -140,179 +127,171 @@ public class EntityModel extends ModelAb
         return adapterMemento.getSpecMemento().getSpecification();
     }
 
-    ////////////////////////////////////////////////////////////
+    // //////////////////////////////////////////////////////////
     // load, setObject
-    ////////////////////////////////////////////////////////////
+    // //////////////////////////////////////////////////////////
+
+    @Override
+    protected ObjectAdapter load() {
+        if (adapterMemento == null) {
+            return null;
+        }
+        return adapterMemento.getObjectAdapter();
+    }
+
+    @Override
+    public void setObject(final ObjectAdapter adapter) {
+        super.setObject(adapter);
+        adapterMemento = ObjectAdapterMemento.createOrNull(adapter);
+    }
+
+    @Override
+    public void detach() {
+        if (isAttached()) {
+            if (adapterMemento != null) {
+                adapterMemento.captureTitleHintIfPossible(adapterMemento.getObjectAdapter());
+            }
+        }
+        super.detach();
+    }
 
-	@Override
-	protected ObjectAdapter load() {
-		if (adapterMemento == null) {
-			return null;
-		}
-		return adapterMemento.getObjectAdapter();
-	}
-
-	@Override
-	public void setObject(ObjectAdapter adapter) {
-		super.setObject(adapter);
-		adapterMemento = ObjectAdapterMemento.createOrNull(adapter);
-	}
-
-	@Override
-	public void detach() {
-		if (isAttached()) {
-			if (adapterMemento != null) {
-				adapterMemento
-						.captureTitleHintIfPossible(adapterMemento
-								.getObjectAdapter());
-			}
-		}
-		super.detach();
-	}
-
-
-	// hmmm... doesn't seem to be used; get rid of if come back.
-	// I'm guessing the property models stuff below superceded this.
-	
-//    ////////////////////////////////////////////////////////////
-//    // child (property) model objects;
-//    ////////////////////////////////////////////////////////////
-//	
-//	public void setChildModelObject(String propertyIdentifier,
-//			ObjectAdapter associatedAdapter) {
-//		ObjectAdapter adapter = getObject();
-//		if (adapter == null) {
-//			// let's fail fast, because this presumably ought not to happen
-//			throw new IllegalStateException(
-//					"no adapter set for the EntityModel");
-//		}
-//		ObjectSpecification noSpec = adapter.getSpecification();
-//		ObjectAssociation association = noSpec.getAssociation(propertyIdentifier);
-//		if (association == null) {
-//			throw new IllegalArgumentException(String.format(
-//					"Id '%s' does not represent an association in spec '%s'",
-//					propertyIdentifier, noSpec.getFullName()));
-//		}
-//		if (association.isOneToManyAssociation()) {
-//			throw new IllegalArgumentException(String.format(
-//					"Association '%s' is not a property in spec '%s'",
-//					propertyIdentifier, noSpec.getFullName()));
-//		}
-//		OneToOneAssociation property = (OneToOneAssociation) association;
-//
-//		// TODO: need to add in validation here.
-//		// Also, not sure if should be copying into a pending value rather than
-//		// apply directly.
-//
-//		if (associatedAdapter != null) {
-//			property.set(adapter, associatedAdapter);
-//		} else {
-//			property.clearAssociation(adapter);
-//		}
-//	}
+    // hmmm... doesn't seem to be used; get rid of if come back.
+    // I'm guessing the property models stuff below superceded this.
 
-	
-    ////////////////////////////////////////////////////////////
+    // ////////////////////////////////////////////////////////////
+    // // child (property) model objects;
+    // ////////////////////////////////////////////////////////////
+    //
+    // public void setChildModelObject(String propertyIdentifier,
+    // ObjectAdapter associatedAdapter) {
+    // ObjectAdapter adapter = getObject();
+    // if (adapter == null) {
+    // // let's fail fast, because this presumably ought not to happen
+    // throw new IllegalStateException(
+    // "no adapter set for the EntityModel");
+    // }
+    // ObjectSpecification noSpec = adapter.getSpecification();
+    // ObjectAssociation association = noSpec.getAssociation(propertyIdentifier);
+    // if (association == null) {
+    // throw new IllegalArgumentException(String.format(
+    // "Id '%s' does not represent an association in spec '%s'",
+    // propertyIdentifier, noSpec.getFullName()));
+    // }
+    // if (association.isOneToManyAssociation()) {
+    // throw new IllegalArgumentException(String.format(
+    // "Association '%s' is not a property in spec '%s'",
+    // propertyIdentifier, noSpec.getFullName()));
+    // }
+    // OneToOneAssociation property = (OneToOneAssociation) association;
+    //
+    // // TODO: need to add in validation here.
+    // // Also, not sure if should be copying into a pending value rather than
+    // // apply directly.
+    //
+    // if (associatedAdapter != null) {
+    // property.set(adapter, associatedAdapter);
+    // } else {
+    // property.clearAssociation(adapter);
+    // }
+    // }
+
+    // //////////////////////////////////////////////////////////
     // PropertyModels
-    ////////////////////////////////////////////////////////////
+    // //////////////////////////////////////////////////////////
+
+    /**
+     * Lazily populates with the current value of each property.
+     */
+    public ScalarModel getPropertyModel(final PropertyMemento pm) {
+        ScalarModel scalarModel = propertyScalarModels.get(pm);
+        if (scalarModel == null) {
+            scalarModel = new ScalarModel(getObjectAdapterMemento(), pm);
+            if (isViewMode()) {
+                scalarModel.toViewMode();
+            } else {
+                scalarModel.toEditMode();
+            }
+            propertyScalarModels.put(pm, scalarModel);
+        }
+        return scalarModel;
+
+    }
+
+    /**
+     * Resets the {@link #propertyScalarModels hash} of {@link ScalarModel}s for each {@link PropertyMemento property}
+     * to the value held in the underlying {@link #getObject() entity}.
+     */
+    public void resetPropertyModels() {
+        for (final PropertyMemento pm : propertyScalarModels.keySet()) {
+            final ScalarModel scalarModel = propertyScalarModels.get(pm);
+            final ObjectAdapter associatedAdapter = pm.getProperty().get(getObject());
+            scalarModel.setObject(associatedAdapter);
+        }
+    }
+
+    // //////////////////////////////////////////////////////////
+    // Mode, entityDetailsVisible
+    // //////////////////////////////////////////////////////////
+
+    public Mode getMode() {
+        return mode;
+    }
 
-	/**
-	 * Lazily populates with the current value of each property.
-	 */
-	public ScalarModel getPropertyModel(PropertyMemento pm) {
-		ScalarModel scalarModel = propertyScalarModels.get(pm);
-		if (scalarModel == null) {
-			scalarModel = new ScalarModel(getObjectAdapterMemento(), pm);
-			if (isViewMode()) {
-				scalarModel.toViewMode();
-			} else {
-				scalarModel.toEditMode();
-			}
-			propertyScalarModels.put(pm, scalarModel);
-		}
-		return scalarModel;
-		
-	}
-
-	/**
-	 * Resets the {@link #propertyScalarModels hash} of {@link ScalarModel}s for
-	 * each {@link PropertyMemento property} to the value held in the underlying
-	 * {@link #getObject() entity}.
-	 */
-	public void resetPropertyModels() {
-		for (PropertyMemento pm : propertyScalarModels.keySet()) {
-			ScalarModel scalarModel = propertyScalarModels.get(pm);
-			ObjectAdapter associatedAdapter = pm.getProperty().get(getObject());
-			scalarModel.setObject(associatedAdapter);
-		}
-	}
-
-	
-	////////////////////////////////////////////////////////////
-	// Mode, entityDetailsVisible
-    ////////////////////////////////////////////////////////////
-	
-	public Mode getMode() {
-		return mode;
-	}
-
-	protected void setMode(Mode mode) {
-		this.mode = mode;
-	}
-
-	public boolean isViewMode() {
-		return mode == Mode.VIEW;
-	}
+    protected void setMode(final Mode mode) {
+        this.mode = mode;
+    }
+
+    public boolean isViewMode() {
+        return mode == Mode.VIEW;
+    }
 
     public boolean isEditMode() {
         return mode == Mode.EDIT;
     }
 
-	public EntityModel toEditMode() {
-		setMode(Mode.EDIT);
-		for (ScalarModel scalarModel : propertyScalarModels.values()) {
-			scalarModel.toEditMode();
-		}
-		return this;
-	}
-
-	public EntityModel toViewMode() {
-		setMode(Mode.VIEW);
-		for (ScalarModel scalarModel : propertyScalarModels.values()) {
-			scalarModel.toViewMode();
-		}
-		return this;
-	}
+    public EntityModel toEditMode() {
+        setMode(Mode.EDIT);
+        for (final ScalarModel scalarModel : propertyScalarModels.values()) {
+            scalarModel.toEditMode();
+        }
+        return this;
+    }
+
+    public EntityModel toViewMode() {
+        setMode(Mode.VIEW);
+        for (final ScalarModel scalarModel : propertyScalarModels.values()) {
+            scalarModel.toViewMode();
+        }
+        return this;
+    }
 
     public boolean isEntityDetailsVisible() {
         return entityDetailsVisible;
     }
-    
+
     public void toggleDetails() {
         entityDetailsVisible = !entityDetailsVisible;
     }
 
-
-    ////////////////////////////////////////////////////////////
+    // //////////////////////////////////////////////////////////
     // Mode
-    ////////////////////////////////////////////////////////////
-	
-	public String getReasonInvalidIfAny() {
-		ObjectAdapter adapter = getObjectAdapterMemento().getObjectAdapter();
-		Consent validity = adapter.getSpecification().isValid(adapter);
-		return validity.isAllowed() ? null : validity.getReason();
-	}
-
-	public void apply() {
-		ObjectAdapter adapter = getObjectAdapterMemento().getObjectAdapter();
-		for (ScalarModel scalarModel : propertyScalarModels.values()) {
-			OneToOneAssociation property = scalarModel.getPropertyMemento()
-					.getProperty();
-			ObjectAdapter associate = scalarModel.getObject();
-			property.set(adapter, associate);
-		}
-		getObjectAdapterMemento().setAdapter(adapter);
-		toViewMode();
-	}
+    // //////////////////////////////////////////////////////////
+
+    public String getReasonInvalidIfAny() {
+        final ObjectAdapter adapter = getObjectAdapterMemento().getObjectAdapter();
+        final Consent validity = adapter.getSpecification().isValid(adapter);
+        return validity.isAllowed() ? null : validity.getReason();
+    }
+
+    public void apply() {
+        final ObjectAdapter adapter = getObjectAdapterMemento().getObjectAdapter();
+        for (final ScalarModel scalarModel : propertyScalarModels.values()) {
+            final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty();
+            final ObjectAdapter associate = scalarModel.getObject();
+            property.set(adapter, associate);
+        }
+        getObjectAdapterMemento().setAdapter(adapter);
+        toViewMode();
+    }
 
 }

Modified: incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ModelAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ModelAbstract.java?rev=1098948&r1=1098947&r2=1098948&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ModelAbstract.java (original)
+++ incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ModelAbstract.java Tue May  3 07:44:41 2011
@@ -17,7 +17,6 @@
  *  under the License.
  */
 
-
 package org.apache.isis.viewer.wicket.model.models;
 
 import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
@@ -26,31 +25,29 @@ import org.apache.isis.runtimes.dflt.run
 import org.apache.wicket.model.LoadableDetachableModel;
 
 /**
- * Adapter for {@link LoadableDetachableModel}s, providing access to some
- * of the Isis' dependencies.
+ * Adapter for {@link LoadableDetachableModel}s, providing access to some of the Isis' dependencies.
  */
 public abstract class ModelAbstract<T> extends LoadableDetachableModel<T> {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
+
+    public ModelAbstract() {
+    }
 
-	public ModelAbstract() {
-	}
-	
-	public ModelAbstract(T t) {
-		super(t);
-	}
-
-	
-	////////////////////////////////////////////////////////////////
-	// Dependencies
-	////////////////////////////////////////////////////////////////
-	
-	protected PersistenceSession getPersistenceSession() {
-		return IsisContext.getPersistenceSession();
-	}
-
-	protected AdapterManager getAdapterManager() {
-		return getPersistenceSession().getAdapterManager();
-	}
+    public ModelAbstract(final T t) {
+        super(t);
+    }
+
+    // //////////////////////////////////////////////////////////////
+    // Dependencies
+    // //////////////////////////////////////////////////////////////
+
+    protected PersistenceSession getPersistenceSession() {
+        return IsisContext.getPersistenceSession();
+    }
+
+    protected AdapterManager getAdapterManager() {
+        return getPersistenceSession().getAdapterManager();
+    }
 
 }
\ No newline at end of file

Modified: incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java?rev=1098948&r1=1098947&r2=1098948&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java (original)
+++ incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java Tue May  3 07:44:41 2011
@@ -17,7 +17,6 @@
  *  under the License.
  */
 
-
 package org.apache.isis.viewer.wicket.model.models;
 
 import java.util.Arrays;
@@ -37,407 +36,371 @@ import org.apache.isis.core.metamodel.sp
 import org.apache.isis.viewer.wicket.model.mementos.ActionParameterMemento;
 import org.apache.isis.viewer.wicket.model.mementos.ObjectAdapterMemento;
 import org.apache.isis.viewer.wicket.model.mementos.PropertyMemento;
-import org.apache.isis.viewer.wicket.model.models.ScalarModel.Kind;
 import org.apache.isis.viewer.wicket.model.nof.AuthenticationSessionAccessor;
 import org.apache.isis.viewer.wicket.model.util.ClassLoaders;
 import org.apache.wicket.Session;
 
 /**
- * Represents a scalar of an entity, either a {@link Kind#PROPERTY property} or a
- * {@link Kind#PARAMETER parameter}.
+ * Represents a scalar of an entity, either a {@link Kind#PROPERTY property} or a {@link Kind#PARAMETER parameter}.
  * 
  * <p>
- * Is the backing model to each of the fields that appear in forms (for entities or
- * action dialogs).
+ * Is the backing model to each of the fields that appear in forms (for entities or action dialogs).
  */
 public class ScalarModel extends EntityModel {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
+
+    public enum Kind {
+        PROPERTY {
+            @Override
+            public String getName(final ScalarModel scalarModel) {
+                return scalarModel.getPropertyMemento().getProperty().getName();
+            }
+
+            @Override
+            public ObjectSpecification getScalarTypeSpec(final ScalarModel scalarModel) {
+                return scalarModel.getPropertyMemento().getType().getSpecification();
+            }
 
-	public enum Kind {
-		PROPERTY {
-			@Override
-			public String getName(ScalarModel scalarModel) {
-				return scalarModel.getPropertyMemento().getProperty().getName();
-			}
-
-			@Override
-			public ObjectSpecification getScalarTypeSpec(
-					ScalarModel scalarModel) {
-				return scalarModel.getPropertyMemento().getType()
-						.getSpecification();
-			}
-
-			@Override
-			public String getIdentifier(ScalarModel scalarModel) {
-				return scalarModel.getPropertyMemento().getIdentifier();
-			}
-
-			@Override
-			public String getLongName(ScalarModel scalarModel) {
-				final String specShortName = scalarModel.parentObjectAdapterMemento.getSpecMemento().getSpecification().getShortIdentifier();
-				return specShortName + "-" + scalarModel.getPropertyMemento().getProperty().getId();
-			}
-
-			@Override
-			public String disable(ScalarModel scalarModel) {
-				ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento
-						.getObjectAdapter();
-				OneToOneAssociation property = scalarModel.getPropertyMemento()
-						.getProperty();
-				try {
-					AuthenticationSession session = scalarModel
-							.getAuthenticationSession();
-					Consent usable = property.isUsable(session, parentAdapter);
-					return usable.isAllowed() ? null : usable.getReason();
-				} catch (Exception ex) {
-					return ex.getLocalizedMessage();
-				}
-			}
-
-			@Override
-			public String parseAndValidate(ScalarModel scalarModel,
-					String proposedPojoAsStr) {
-				OneToOneAssociation property = scalarModel.getPropertyMemento()
-						.getProperty();
-				ParseableFacet parseableFacet = property
-						.getFacet(ParseableFacet.class);
-				if (parseableFacet == null) {
-					parseableFacet = property.getSpecification().getFacet(
-							ParseableFacet.class);
-				}
-				try {
-					ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento
-							.getObjectAdapter();
-					final ObjectAdapter currentValue = property.get(parentAdapter);
-					ObjectAdapter proposedAdapter = parseableFacet
-							.parseTextEntry(currentValue, proposedPojoAsStr);
-					Consent valid = property.isAssociationValid(parentAdapter,
-							proposedAdapter);
-					return valid.isAllowed() ? null : valid.getReason();
-				} catch (Exception ex) {
-					return ex.getLocalizedMessage();
-				}
-			}
-
-			@Override
-			public String validate(ScalarModel scalarModel,
-					ObjectAdapter proposedAdapter) {
-				ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento
-						.getObjectAdapter();
-				OneToOneAssociation property = scalarModel.getPropertyMemento()
-						.getProperty();
-				try {
-					Consent valid = property.isAssociationValid(parentAdapter,
-							proposedAdapter);
-					return valid.isAllowed() ? null : valid.getReason();
-				} catch (Exception ex) {
-					return ex.getLocalizedMessage();
-				}
-			}
-
-			@Override
-			public boolean isRequired(ScalarModel scalarModel) {
-				FacetHolder facetHolder = scalarModel.getPropertyMemento().getProperty();
-				return isRequired(facetHolder);
-			}
-
-			@Override
-			public <T extends Facet> T getFacet(ScalarModel scalarModel, Class<T> facetType) {
-				FacetHolder facetHolder = scalarModel.getPropertyMemento().getProperty();
-				return facetHolder.getFacet(facetType);
-			}
+            @Override
+            public String getIdentifier(final ScalarModel scalarModel) {
+                return scalarModel.getPropertyMemento().getIdentifier();
+            }
+
+            @Override
+            public String getLongName(final ScalarModel scalarModel) {
+                final String specShortName =
+                    scalarModel.parentObjectAdapterMemento.getSpecMemento().getSpecification().getShortIdentifier();
+                return specShortName + "-" + scalarModel.getPropertyMemento().getProperty().getId();
+            }
+
+            @Override
+            public String disable(final ScalarModel scalarModel) {
+                final ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento.getObjectAdapter();
+                final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty();
+                try {
+                    final AuthenticationSession session = scalarModel.getAuthenticationSession();
+                    final Consent usable = property.isUsable(session, parentAdapter);
+                    return usable.isAllowed() ? null : usable.getReason();
+                } catch (final Exception ex) {
+                    return ex.getLocalizedMessage();
+                }
+            }
 
             @Override
-            public List<ObjectAdapter> getChoices(ScalarModel scalarModel) {
+            public String parseAndValidate(final ScalarModel scalarModel, final String proposedPojoAsStr) {
+                final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty();
+                ParseableFacet parseableFacet = property.getFacet(ParseableFacet.class);
+                if (parseableFacet == null) {
+                    parseableFacet = property.getSpecification().getFacet(ParseableFacet.class);
+                }
+                try {
+                    final ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento.getObjectAdapter();
+                    final ObjectAdapter currentValue = property.get(parentAdapter);
+                    final ObjectAdapter proposedAdapter =
+                        parseableFacet.parseTextEntry(currentValue, proposedPojoAsStr);
+                    final Consent valid = property.isAssociationValid(parentAdapter, proposedAdapter);
+                    return valid.isAllowed() ? null : valid.getReason();
+                } catch (final Exception ex) {
+                    return ex.getLocalizedMessage();
+                }
+            }
+
+            @Override
+            public String validate(final ScalarModel scalarModel, final ObjectAdapter proposedAdapter) {
+                final ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento.getObjectAdapter();
+                final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty();
+                try {
+                    final Consent valid = property.isAssociationValid(parentAdapter, proposedAdapter);
+                    return valid.isAllowed() ? null : valid.getReason();
+                } catch (final Exception ex) {
+                    return ex.getLocalizedMessage();
+                }
+            }
+
+            @Override
+            public boolean isRequired(final ScalarModel scalarModel) {
+                final FacetHolder facetHolder = scalarModel.getPropertyMemento().getProperty();
+                return isRequired(facetHolder);
+            }
+
+            @Override
+            public <T extends Facet> T getFacet(final ScalarModel scalarModel, final Class<T> facetType) {
+                final FacetHolder facetHolder = scalarModel.getPropertyMemento().getProperty();
+                return facetHolder.getFacet(facetType);
+            }
+
+            @Override
+            public List<ObjectAdapter> getChoices(final ScalarModel scalarModel) {
                 final PropertyMemento propertyMemento = scalarModel.getPropertyMemento();
                 final OneToOneAssociation property = propertyMemento.getProperty();
-                final ObjectAdapter[] choices = property.getChoices(scalarModel.parentObjectAdapterMemento.getObjectAdapter());
+                final ObjectAdapter[] choices =
+                    property.getChoices(scalarModel.parentObjectAdapterMemento.getObjectAdapter());
                 return choicesAsList(choices);
             }
-		},
-		PARAMETER {
-			@Override
-			public String getName(ScalarModel scalarModel) {
-				return scalarModel.getParameterMemento()
-						.getActionParameter().getName();
-			}
-
-			@Override
-			public ObjectSpecification getScalarTypeSpec(
-					ScalarModel scalarModel) {
-				return scalarModel.getParameterMemento()
-						.getSpecification();
-			}
-
-			@Override
-			public String getIdentifier(ScalarModel scalarModel) {
-				return "" + scalarModel.getParameterMemento().getNumber();
-			}
-
-			@Override
-			public String getLongName(ScalarModel scalarModel) {
-				final ObjectAdapterMemento adapterMemento = scalarModel.getObjectAdapterMemento();
-				if (adapterMemento == null) {
-					// shouldn't happen
-					return null;
-				}
-				final String specShortName = adapterMemento.getSpecMemento().getSpecification().getShortIdentifier();
-				final String parmId = scalarModel.getParameterMemento().getActionParameter().getIdentifier().toNameIdentityString();
-				return specShortName + "-" + parmId + "-" + scalarModel.getParameterMemento().getNumber();
-			}
-
-			@Override
-			public String disable(ScalarModel scalarModel) {
-				// always enabled
-				return null;
-			}
-
-			@Override
-			public String parseAndValidate(ScalarModel scalarModel,
-					String proposedPojoAsStr) {
-				ObjectActionParameter parameter = scalarModel.getParameterMemento().getActionParameter();
-				ParseableFacet parseableFacet = parameter
-						.getFacet(ParseableFacet.class);
-				if (parseableFacet == null) {
-					parseableFacet = parameter.getSpecification().getFacet(
-							ParseableFacet.class);
-				}
-				try {
-					ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento
-							.getObjectAdapter();
-					String invalidReasonIfAny = parameter.isValid(parentAdapter,
-							proposedPojoAsStr);
-					return invalidReasonIfAny;
-				} catch (Exception ex) {
-					return ex.getLocalizedMessage();
-				}
-			}
-
-			@Override
-			public String validate(ScalarModel scalarModel,
-					ObjectAdapter proposedAdapter) {
-				// TODO - not supported in NOF 4.0.0
-				return null;
-			}
-
-			@Override
-			public boolean isRequired(ScalarModel scalarModel) {
-				FacetHolder facetHolder = scalarModel.getParameterMemento().getActionParameter();
-				return isRequired(facetHolder);
-			}
-			
-
-			@Override
-			public <T extends Facet> T getFacet(ScalarModel scalarModel, Class<T> facetType) {
-				FacetHolder facetHolder = scalarModel.getParameterMemento().getActionParameter();
-				return facetHolder.getFacet(facetType);
-			}
+        },
+        PARAMETER {
+            @Override
+            public String getName(final ScalarModel scalarModel) {
+                return scalarModel.getParameterMemento().getActionParameter().getName();
+            }
 
             @Override
-            public List<ObjectAdapter> getChoices(ScalarModel scalarModel) {
+            public ObjectSpecification getScalarTypeSpec(final ScalarModel scalarModel) {
+                return scalarModel.getParameterMemento().getSpecification();
+            }
+
+            @Override
+            public String getIdentifier(final ScalarModel scalarModel) {
+                return "" + scalarModel.getParameterMemento().getNumber();
+            }
+
+            @Override
+            public String getLongName(final ScalarModel scalarModel) {
+                final ObjectAdapterMemento adapterMemento = scalarModel.getObjectAdapterMemento();
+                if (adapterMemento == null) {
+                    // shouldn't happen
+                    return null;
+                }
+                final String specShortName = adapterMemento.getSpecMemento().getSpecification().getShortIdentifier();
+                final String parmId =
+                    scalarModel.getParameterMemento().getActionParameter().getIdentifier().toNameIdentityString();
+                return specShortName + "-" + parmId + "-" + scalarModel.getParameterMemento().getNumber();
+            }
+
+            @Override
+            public String disable(final ScalarModel scalarModel) {
+                // always enabled
+                return null;
+            }
+
+            @Override
+            public String parseAndValidate(final ScalarModel scalarModel, final String proposedPojoAsStr) {
+                final ObjectActionParameter parameter = scalarModel.getParameterMemento().getActionParameter();
+                ParseableFacet parseableFacet = parameter.getFacet(ParseableFacet.class);
+                if (parseableFacet == null) {
+                    parseableFacet = parameter.getSpecification().getFacet(ParseableFacet.class);
+                }
+                try {
+                    final ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento.getObjectAdapter();
+                    final String invalidReasonIfAny = parameter.isValid(parentAdapter, proposedPojoAsStr);
+                    return invalidReasonIfAny;
+                } catch (final Exception ex) {
+                    return ex.getLocalizedMessage();
+                }
+            }
+
+            @Override
+            public String validate(final ScalarModel scalarModel, final ObjectAdapter proposedAdapter) {
+                // TODO - not supported in NOF 4.0.0
+                return null;
+            }
+
+            @Override
+            public boolean isRequired(final ScalarModel scalarModel) {
+                final FacetHolder facetHolder = scalarModel.getParameterMemento().getActionParameter();
+                return isRequired(facetHolder);
+            }
+
+            @Override
+            public <T extends Facet> T getFacet(final ScalarModel scalarModel, final Class<T> facetType) {
+                final FacetHolder facetHolder = scalarModel.getParameterMemento().getActionParameter();
+                return facetHolder.getFacet(facetType);
+            }
+
+            @Override
+            public List<ObjectAdapter> getChoices(final ScalarModel scalarModel) {
                 final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
                 final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
-                final ObjectAdapter[] choices = actionParameter.getChoices(scalarModel.parentObjectAdapterMemento.getObjectAdapter());
+                final ObjectAdapter[] choices =
+                    actionParameter.getChoices(scalarModel.parentObjectAdapterMemento.getObjectAdapter());
                 return choicesAsList(choices);
             }
-		};
-		
-		private static List<ObjectAdapter> choicesAsList(ObjectAdapter[] choices) {
+        };
+
+        private static List<ObjectAdapter> choicesAsList(final ObjectAdapter[] choices) {
             if (choices != null && choices.length > 0) {
                 return Arrays.asList(choices);
             }
             return Collections.emptyList();
-		}
+        }
 
-		public abstract String getName(ScalarModel scalarModel);
+        public abstract String getName(ScalarModel scalarModel);
 
-		public abstract ObjectSpecification getScalarTypeSpec(
-				ScalarModel scalarModel);
+        public abstract ObjectSpecification getScalarTypeSpec(ScalarModel scalarModel);
 
-		public abstract String getIdentifier(ScalarModel scalarModel);
+        public abstract String getIdentifier(ScalarModel scalarModel);
 
-		public abstract String disable(ScalarModel scalarModel);
+        public abstract String disable(ScalarModel scalarModel);
 
-		public abstract String parseAndValidate(
-				ScalarModel scalarModel, String proposedPojoAsStr);
+        public abstract String parseAndValidate(ScalarModel scalarModel, String proposedPojoAsStr);
 
-		public abstract String validate(ScalarModel scalarModel,
-				ObjectAdapter proposedAdapter);
+        public abstract String validate(ScalarModel scalarModel, ObjectAdapter proposedAdapter);
 
-		public abstract String getLongName(ScalarModel scalarModel);
+        public abstract String getLongName(ScalarModel scalarModel);
 
-		public abstract boolean isRequired(ScalarModel scalarModel);
+        public abstract boolean isRequired(ScalarModel scalarModel);
 
-		public abstract <T extends Facet> T getFacet(ScalarModel scalarModel, Class<T> facetType);
+        public abstract <T extends Facet> T getFacet(ScalarModel scalarModel, Class<T> facetType);
 
-		static boolean isRequired(FacetHolder facetHolder) {
-			MandatoryFacet mandatoryFacet = facetHolder.getFacet(MandatoryFacet.class);
-			boolean required = mandatoryFacet != null && !mandatoryFacet.isInvertedSemantics();
-			return required;
-		}
+        static boolean isRequired(final FacetHolder facetHolder) {
+            final MandatoryFacet mandatoryFacet = facetHolder.getFacet(MandatoryFacet.class);
+            final boolean required = mandatoryFacet != null && !mandatoryFacet.isInvertedSemantics();
+            return required;
+        }
 
         public abstract List<ObjectAdapter> getChoices(ScalarModel scalarModel);
-		
-	}
 
-	private final Kind kind;
-	private final ObjectAdapterMemento parentObjectAdapterMemento;
+    }
+
+    private final Kind kind;
+    private final ObjectAdapterMemento parentObjectAdapterMemento;
+
+    /**
+     * Populated only if {@link #getKind()} is {@link Kind#PARAMETER}
+     */
+    private ActionParameterMemento parameterMemento;
 
-	/**
-	 * Populated only if {@link #getKind()} is {@link Kind#PARAMETER}
-	 */
-	private ActionParameterMemento parameterMemento;
-
-	/**
-	 * Populated only if {@link #getKind()} is {@link Kind#PROPERTY}
-	 */
-	private PropertyMemento propertyMemento;
+    /**
+     * Populated only if {@link #getKind()} is {@link Kind#PROPERTY}
+     */
+    private PropertyMemento propertyMemento;
 
     /**
-     * Creates a model representing an action parameter of an action of a parent object, with the 
-     * {@link #getObject() value of this model} to be default value (if any) of that action parameter.
+     * Creates a model representing an action parameter of an action of a parent object, with the {@link #getObject()
+     * value of this model} to be default value (if any) of that action parameter.
      */
-	public ScalarModel(ObjectAdapterMemento parentObjectAdapterMemento, ActionParameterMemento apm) {
-		this.kind = Kind.PARAMETER;
-		this.parentObjectAdapterMemento = parentObjectAdapterMemento;
-		this.parameterMemento = apm;
-
-		final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
-		final ObjectAdapter defaultAdapter = 
-		    actionParameter.getDefault(parentObjectAdapterMemento.getObjectAdapter());
-		setObject(defaultAdapter);
-		
-		setMode(Mode.EDIT);
-	}
-
-	/**
-	 * Creates a model representing a property of a parent object, with the 
-	 * {@link #getObject() value of this model} to be current value of the property.
-	 */
-	public ScalarModel(ObjectAdapterMemento parentObjectAdapterMemento,
-			PropertyMemento pm) {
-		this.kind = Kind.PROPERTY;
-		this.parentObjectAdapterMemento = parentObjectAdapterMemento;
-		this.propertyMemento = pm;
-		
+    public ScalarModel(final ObjectAdapterMemento parentObjectAdapterMemento, final ActionParameterMemento apm) {
+        this.kind = Kind.PARAMETER;
+        this.parentObjectAdapterMemento = parentObjectAdapterMemento;
+        this.parameterMemento = apm;
+
+        final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
+        final ObjectAdapter defaultAdapter = actionParameter.getDefault(parentObjectAdapterMemento.getObjectAdapter());
+        setObject(defaultAdapter);
+
+        setMode(Mode.EDIT);
+    }
+
+    /**
+     * Creates a model representing a property of a parent object, with the {@link #getObject() value of this model} to
+     * be current value of the property.
+     */
+    public ScalarModel(final ObjectAdapterMemento parentObjectAdapterMemento, final PropertyMemento pm) {
+        this.kind = Kind.PROPERTY;
+        this.parentObjectAdapterMemento = parentObjectAdapterMemento;
+        this.propertyMemento = pm;
+
         final OneToOneAssociation property = propertyMemento.getProperty();
-        ObjectAdapter associatedAdapter = property.get(parentObjectAdapterMemento.getObjectAdapter());
+        final ObjectAdapter associatedAdapter = property.get(parentObjectAdapterMemento.getObjectAdapter());
+
+        setObject(associatedAdapter);
+        setMode(Mode.VIEW);
+    }
 
-		setObject(associatedAdapter);
-		setMode(Mode.VIEW);
-	}
-
-	/**
-	 * Whether the scalar represents a {@link Kind#PROPERTY property} or a
-	 * {@link Kind#PARAMETER}.
-	 */
-	public Kind getKind() {
-		return kind;
-	}
-
-	public String getName() {
-		return kind.getName(this);
-	}
-
-	/**
-	 * Populated only if {@link #getKind()} is {@link Kind#PROPERTY}
-	 */
-	public PropertyMemento getPropertyMemento() {
-		return propertyMemento;
-	}
-
-	/**
-	 * Populated only if {@link #getKind()} is {@link Kind#PARAMETER}
-	 */
-	public ActionParameterMemento getParameterMemento() {
-		return parameterMemento;
-	}
-
-	/**
-	 * Overrides superclass' implementation, because a {@link ScalarModel} can
-	 * know the {@link ObjectSpecification of} the {@link ObjectAdapter 
-	 * adapter} without there necessarily being any adapter being
-	 * {@link #setObject(ObjectAdapter) set}.
-	 */
-	@Override
-	public ObjectSpecification getTypeOfSpecification() {
-		return kind.getScalarTypeSpec(this);
-	}
-
-	public boolean isScalarTypeAnyOf(Class<?>... requiredClass) {
-		String fullName = getTypeOfSpecification().getFullIdentifier();
-		for (Class<?> requiredCls : requiredClass) {
-			if (fullName.equals(requiredCls.getName())) {
-				return true;
-			}
-		}
-		return false;
-	}
-
-	public Class<?> getScalarType() {
-		return ClassLoaders.forName(getTypeOfSpecification());
-	}
-
-	public String getObjectAsString() {
-		ObjectAdapter adapter = getObject();
-		if (adapter == null) {
-			return null;
-		}
-		return adapter.titleString();
-	}
-
-	@Override
-	public void setObject(ObjectAdapter adapter) {
-		super.setObject(adapter); // associated value
-	}
-
-	public void setObjectAsString(String enteredText) {
-		// parse text to get adapter
-		ParseableFacet parseableFacet = getTypeOfSpecification().getFacet(
-				ParseableFacet.class);
-		if (parseableFacet == null) {
-			throw new RuntimeException("unable to parse string for "
-					+ getTypeOfSpecification().getFullIdentifier());
-		}
-		ObjectAdapter adapter = parseableFacet.parseTextEntry(getObject(),
-				enteredText);
-
-		setObject(adapter);
-	}
-
-	public String disable() {
-		return kind.disable(this);
-	}
-
-	public String parseAndValidate(String proposedPojoAsStr) {
-		return kind.parseAndValidate(this, proposedPojoAsStr);
-	}
-
-	public String validate(ObjectAdapter proposedAdapter) {
-		return kind.validate(this, proposedAdapter);
-	}
-
-	/**
-	 * Default implementation looks up from singleton, but can be overridden for
-	 * testing.
-	 */
-	protected AuthenticationSession getAuthenticationSession() {
-		return ((AuthenticationSessionAccessor) Session.get())
-				.getAuthenticationSession();
-	}
-
-	public boolean isRequired() {
-		return kind.isRequired(this);
-	}
-
-	public String getLongName() {
-		return kind.getLongName(this);
-	}
-
-	public <T extends Facet> T getFacet(Class<T> facetType) {
-		return kind.getFacet(this, facetType);
-	}
+    /**
+     * Whether the scalar represents a {@link Kind#PROPERTY property} or a {@link Kind#PARAMETER}.
+     */
+    public Kind getKind() {
+        return kind;
+    }
+
+    public String getName() {
+        return kind.getName(this);
+    }
+
+    /**
+     * Populated only if {@link #getKind()} is {@link Kind#PROPERTY}
+     */
+    public PropertyMemento getPropertyMemento() {
+        return propertyMemento;
+    }
+
+    /**
+     * Populated only if {@link #getKind()} is {@link Kind#PARAMETER}
+     */
+    public ActionParameterMemento getParameterMemento() {
+        return parameterMemento;
+    }
+
+    /**
+     * Overrides superclass' implementation, because a {@link ScalarModel} can know the {@link ObjectSpecification of}
+     * the {@link ObjectAdapter adapter} without there necessarily being any adapter being
+     * {@link #setObject(ObjectAdapter) set}.
+     */
+    @Override
+    public ObjectSpecification getTypeOfSpecification() {
+        return kind.getScalarTypeSpec(this);
+    }
+
+    public boolean isScalarTypeAnyOf(final Class<?>... requiredClass) {
+        final String fullName = getTypeOfSpecification().getFullIdentifier();
+        for (final Class<?> requiredCls : requiredClass) {
+            if (fullName.equals(requiredCls.getName())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public Class<?> getScalarType() {
+        return ClassLoaders.forName(getTypeOfSpecification());
+    }
+
+    public String getObjectAsString() {
+        final ObjectAdapter adapter = getObject();
+        if (adapter == null) {
+            return null;
+        }
+        return adapter.titleString();
+    }
+
+    @Override
+    public void setObject(final ObjectAdapter adapter) {
+        super.setObject(adapter); // associated value
+    }
+
+    public void setObjectAsString(final String enteredText) {
+        // parse text to get adapter
+        final ParseableFacet parseableFacet = getTypeOfSpecification().getFacet(ParseableFacet.class);
+        if (parseableFacet == null) {
+            throw new RuntimeException("unable to parse string for " + getTypeOfSpecification().getFullIdentifier());
+        }
+        final ObjectAdapter adapter = parseableFacet.parseTextEntry(getObject(), enteredText);
+
+        setObject(adapter);
+    }
+
+    public String disable() {
+        return kind.disable(this);
+    }
+
+    public String parseAndValidate(final String proposedPojoAsStr) {
+        return kind.parseAndValidate(this, proposedPojoAsStr);
+    }
+
+    public String validate(final ObjectAdapter proposedAdapter) {
+        return kind.validate(this, proposedAdapter);
+    }
+
+    /**
+     * Default implementation looks up from singleton, but can be overridden for testing.
+     */
+    protected AuthenticationSession getAuthenticationSession() {
+        return ((AuthenticationSessionAccessor) Session.get()).getAuthenticationSession();
+    }
+
+    public boolean isRequired() {
+        return kind.isRequired(this);
+    }
+
+    public String getLongName() {
+        return kind.getLongName(this);
+    }
+
+    public <T extends Facet> T getFacet(final Class<T> facetType) {
+        return kind.getFacet(this, facetType);
+    }
 
     public List<ObjectAdapter> getChoices() {
         return kind.getChoices(this);

Modified: incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ValueModel.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ValueModel.java?rev=1098948&r1=1098947&r2=1098948&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ValueModel.java (original)
+++ incubator/isis/trunk/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ValueModel.java Tue May  3 07:44:41 2011
@@ -17,7 +17,6 @@
  *  under the License.
  */
 
-
 package org.apache.isis.viewer.wicket.model.models;
 
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
@@ -28,16 +27,17 @@ import org.apache.isis.viewer.wicket.mod
  */
 public class ValueModel extends ModelAbstract<ObjectAdapter> {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
+
+    private final ObjectAdapterMemento adapterMemento;
 
-	private ObjectAdapterMemento adapterMemento;
-	public ValueModel(ObjectAdapter adapter) {
-		adapterMemento = ObjectAdapterMemento.createOrNull(adapter);
-	}
-
-	@Override
-	protected ObjectAdapter load() {
-		return adapterMemento.getObjectAdapter();
-	}
+    public ValueModel(final ObjectAdapter adapter) {
+        adapterMemento = ObjectAdapterMemento.createOrNull(adapter);
+    }
+
+    @Override
+    protected ObjectAdapter load() {
+        return adapterMemento.getObjectAdapter();
+    }
 
 }



Mime
View raw message