http://git-wip-us.apache.org/repos/asf/isis/blob/d84c6609/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java ---------------------------------------------------------------------- diff --git a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java deleted file mode 100644 index 9c5bf1d..0000000 --- a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java +++ /dev/null @@ -1,453 +0,0 @@ -/* - * 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.viewer.wicket.model.models; - -import java.io.Serializable; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import com.google.common.base.Function; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import org.apache.isis.core.commons.factory.InstanceUtil; -import org.apache.isis.core.commons.lang.ClassUtil; -import org.apache.isis.core.commons.lang.Closure; -import org.apache.isis.core.commons.lang.IterableExtensions; -import org.apache.isis.core.metamodel.adapter.ObjectAdapter; -import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager; -import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager.ConcurrencyChecking; -import org.apache.isis.core.metamodel.facets.collections.sortedby.SortedByFacet; -import org.apache.isis.core.metamodel.facets.object.paged.PagedFacet; -import org.apache.isis.core.metamodel.facets.object.plural.PluralFacet; -import org.apache.isis.core.metamodel.services.ServicesInjectorSpi; -import org.apache.isis.core.metamodel.spec.ObjectSpecification; -import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi; -import org.apache.isis.core.metamodel.spec.feature.ObjectAction; -import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation; -import org.apache.isis.core.runtime.system.context.IsisContext; -import org.apache.isis.core.runtime.system.persistence.PersistenceSession; -import org.apache.isis.viewer.wicket.model.links.LinkAndLabel; -import org.apache.isis.viewer.wicket.model.links.LinksProvider; -import org.apache.isis.viewer.wicket.model.mementos.CollectionMemento; -import org.apache.isis.viewer.wicket.model.mementos.ObjectAdapterMemento; - -/** - * 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. - */ -public class EntityCollectionModel extends ModelAbstract<List<ObjectAdapter>> implements LinksProvider { - - private static final long serialVersionUID = 1L; - - private static final int PAGE_SIZE_DEFAULT_FOR_PARENTED = 12; - private static final int PAGE_SIZE_DEFAULT_FOR_STANDALONE = 25; - - 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, ObjectAdapterMemento.Functions.fromMemento(ConcurrencyChecking.NO_CHECK)); - } - - @Override - void setObject(final EntityCollectionModel entityCollectionModel, final List<ObjectAdapter> list) { - entityCollectionModel.mementoList = Lists.newArrayList(Lists.transform(list, ObjectAdapterMemento.Functions.toMemento())); - } - - @Override - public String getName(final EntityCollectionModel model) { - PluralFacet facet = model.getTypeOfSpecification().getFacet(PluralFacet.class); - return facet.value(); - } - - @Override - public int getCount(final EntityCollectionModel model) { - return model.mementoList.size(); - } - - }, - /** - * A collection of an entity (eg Order/OrderDetail). - */ - PARENTED { - @Override - List<ObjectAdapter> load(final EntityCollectionModel entityCollectionModel) { - final ObjectAdapter adapter = entityCollectionModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.NO_CHECK); - final OneToManyAssociation collection = entityCollectionModel.collectionMemento.getCollection(); - final ObjectAdapter collectionAsAdapter = collection.get(adapter); - - final List<Object> objectList = asIterable(collectionAsAdapter); - - final Class<? extends Comparator<?>> sortedBy = entityCollectionModel.sortedBy; - if(sortedBy != null) { - @SuppressWarnings("unchecked") - final Comparator<Object> comparator = (Comparator<Object>) InstanceUtil.createInstance(sortedBy); - getServicesInjector().injectServicesInto(comparator); - Collections.sort(objectList, comparator); - } - - final Iterable<ObjectAdapter> adapterIterable = Iterables.transform(objectList, ObjectAdapter.Functions.adapterForUsing(getAdapterManagerStatic())); - final List<ObjectAdapter> adapterList = Lists.newArrayList(adapterIterable); - - return adapterList; - } - - @SuppressWarnings("unchecked") - private List<Object> asIterable(final ObjectAdapter collectionAsAdapter) { - final Iterable<Object> objects = (Iterable<Object>) collectionAsAdapter.getObject(); - return Lists.newArrayList(objects); - } - - @Override - void setObject(EntityCollectionModel entityCollectionModel, List<ObjectAdapter> list) { - // no-op - throw new UnsupportedOperationException(); - } - - @Override - public String getName(EntityCollectionModel model) { - return model.getCollectionMemento().getName(); - } - - @Override - public int getCount(EntityCollectionModel model) { - return load(model).size(); - } - }; - - abstract List<ObjectAdapter> load(EntityCollectionModel entityCollectionModel); - - abstract void setObject(EntityCollectionModel entityCollectionModel, List<ObjectAdapter> list); - - public abstract String getName(EntityCollectionModel entityCollectionModel); - - public abstract int getCount(EntityCollectionModel entityCollectionModel); - } - - static class LowestCommonSuperclassClosure implements Closure<Class<?>>{ - private Class<?> common; - @Override - public Class<?> execute(final Class<?> value) { - if(common == null) { - common = value; - } else { - Class<?> current = common; - while(!current.isAssignableFrom(value)) { - current = current.getSuperclass(); - } - common = current; - } - return common; - } - Class<?> getLowestCommonSuperclass() { - return common; - } - } - - /** - * Factory. - */ - public static EntityCollectionModel createStandalone(final ObjectAdapter collectionAsAdapter) { - final Iterable<Object> pojos = EntityCollectionModel.asIterable(collectionAsAdapter); - - final List<ObjectAdapterMemento> mementoList = - Lists.newArrayList(Iterables.transform(pojos, ObjectAdapterMemento.Functions.fromPojo(getAdapterManagerStatic()))); - - - final ObjectSpecification elementSpec; - if(!Iterables.isEmpty(pojos)) { - // dynamically determine the spec of the elements - // (ie so a List<Object> can be rendered according to the runtime type of its elements, - // rather than the compile-time type - final LowestCommonSuperclassClosure closure = new LowestCommonSuperclassClosure(); - Function<Object, Class<?>> function = new Function<Object, Class<?>>(){ - @Override - public Class<?> apply(Object obj) { - return obj.getClass(); - } - }; - IterableExtensions.fold(Iterables.transform(pojos, function), closure); - elementSpec = getSpecificationLoaderStatic().loadSpecification(closure.getLowestCommonSuperclass()); - } else { - elementSpec = collectionAsAdapter.getElementSpecification(); - } - - final Class<?> elementType; - int pageSize = PAGE_SIZE_DEFAULT_FOR_STANDALONE; - if (elementSpec != null) { - elementType = elementSpec.getCorrespondingClass(); - pageSize = pageSize(elementSpec.getFacet(PagedFacet.class), PAGE_SIZE_DEFAULT_FOR_STANDALONE); - } else { - elementType = Object.class; - } - - return new EntityCollectionModel(elementType, mementoList, pageSize); - } - - /** - * The {@link ActionModel model} of the {@link ObjectAction action} - * that generated this {@link EntityCollectionModel}. - * - * <p> - * Populated only for {@link Type#STANDALONE standalone} collections. - * - * @see #setActionHint(ActionModel) - */ - public ActionModel getActionModelHint() { - return actionModelHint; - } - /** - * Called only for {@link Type#STANDALONE standalone} collections. - * - * @see #getActionModelHint() - */ - public void setActionHint(ActionModel actionModelHint) { - this.actionModelHint = actionModelHint; - } - - /** - * 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#STANDALONE}. - */ - private List<ObjectAdapterMemento> toggledMementosList; - - /** - * Populated only if {@link Type#PARENTED}. - */ - private ObjectAdapterMemento parentObjectAdapterMemento; - - /** - * Populated only if {@link Type#PARENTED}. - */ - private CollectionMemento collectionMemento; - - private final int pageSize; - - /** - * Additional links to render (if any) - */ - private List<LinkAndLabel> entityActions = Lists.newArrayList(); - - /** - * Optionally populated only if {@link Type#PARENTED}. - */ - private Class<? extends Comparator<?>> sortedBy; - - /** - * Optionally populated, only if {@link Type#STANDALONE} (ie called from an action). - */ - private ActionModel actionModelHint; - - private EntityCollectionModel(final Class<?> typeOf, final List<ObjectAdapterMemento> mementoList, final int pageSize) { - this.type = Type.STANDALONE; - this.typeOf = typeOf; - this.mementoList = mementoList; - this.pageSize = pageSize; - this.toggledMementosList = Lists.newArrayList(); - } - - 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 = forName(collection.getSpecification()); - this.parentObjectAdapterMemento = parentAdapterMemento; - this.collectionMemento = new CollectionMemento(collection); - this.pageSize = pageSize(collection.getFacet(PagedFacet.class), PAGE_SIZE_DEFAULT_FOR_PARENTED); - final SortedByFacet sortedByFacet = collection.getFacet(SortedByFacet.class); - this.sortedBy = sortedByFacet != null?sortedByFacet.value(): null; - } - - private static Class<?> forName(final ObjectSpecification objectSpec) { - final String fullName = objectSpec.getFullIdentifier(); - return ClassUtil.forName(fullName); - } - - - private static int pageSize(final PagedFacet pagedFacet, final int defaultPageSize) { - return pagedFacet != null ? pagedFacet.value(): defaultPageSize; - } - - public boolean isParented() { - return type == Type.PARENTED; - } - - public boolean isStandalone() { - return type == Type.STANDALONE; - } - - public int getPageSize() { - return pageSize; - } - - /** - * The name of the collection (if has an entity, ie, if - * {@link #isParented() is parented}.) - * - * <p> - * If {@link #isStandalone()}, returns the {@link PluralFacet} of the {@link #getTypeOfSpecification() specification} - * (eg 'Customers'). - */ - public String getName() { - return type.getName(this); - } - - public int getCount() { - return this.type.getCount(this); - } - - - @Override - protected List<ObjectAdapter> load() { - return type.load(this); - } - - public ObjectSpecification getTypeOfSpecification() { - if (typeOfSpec == null) { - typeOfSpec = getSpecificationLoaderStatic().loadSpecification(typeOf); - } - return typeOfSpec; - } - - @Override - public void setObject(List<ObjectAdapter> list) { - super.setObject(list); - type.setObject(this, list); - } - - /** - * Not API, but to refresh the model list. - */ - public void setObjectList(ObjectAdapter resultAdapter) { - final Iterable<Object> pojos = EntityCollectionModel.asIterable(resultAdapter); - this.mementoList = Lists.newArrayList( - Iterables.transform(pojos, ObjectAdapterMemento.Functions.fromPojo(getAdapterManagerStatic()))); - } - - /** - * Populated only if {@link Type#PARENTED}. - */ - public ObjectAdapterMemento getParentObjectAdapterMemento() { - return parentObjectAdapterMemento; - } - - /** - * Populated only if {@link Type#PARENTED}. - */ - public CollectionMemento getCollectionMemento() { - return collectionMemento; - } - - @SuppressWarnings("unchecked") - private static Iterable<Object> asIterable(final ObjectAdapter resultAdapter) { - return (Iterable<Object>) resultAdapter.getObject(); - } - - - public void toggleSelectionOn(ObjectAdapter selectedAdapter) { - ObjectAdapterMemento selectedAsMemento = ObjectAdapterMemento.createOrNull(selectedAdapter); - - // try to remove; if couldn't, then mustn't have been in there, in which case add. - boolean removed = toggledMementosList.remove(selectedAsMemento); - if(!removed) { - toggledMementosList.add(selectedAsMemento); - } - } - - public List<ObjectAdapterMemento> getToggleMementosList() { - return Collections.unmodifiableList(this.toggledMementosList); - } - - public void clearToggleMementosList() { - this.toggledMementosList.clear(); - } - - public void addEntityActions(List<LinkAndLabel> entityActions) { - this.entityActions.addAll(entityActions); - } - - @Override - public List<LinkAndLabel> getLinks() { - return Collections.unmodifiableList(entityActions); - } - - public EntityCollectionModel asDummy() { - return new EntityCollectionModel(typeOf, Collections.<ObjectAdapterMemento>emptyList(), pageSize); - } - - // ////////////////////////////////////// - - private static AdapterManager getAdapterManagerStatic() { - return getPersistenceSessionStatic().getAdapterManager(); - } - - private static ServicesInjectorSpi getServicesInjector() { - return getPersistenceSessionStatic().getServicesInjector(); - } - - private static PersistenceSession getPersistenceSessionStatic() { - return IsisContext.getPersistenceSession(); - } - - private static SpecificationLoaderSpi getSpecificationLoaderStatic() { - return IsisContext.getSpecificationLoader(); - } - -}
http://git-wip-us.apache.org/repos/asf/isis/blob/d84c6609/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java ---------------------------------------------------------------------- diff --git a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java deleted file mode 100644 index 2b88467..0000000 --- a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java +++ /dev/null @@ -1,689 +0,0 @@ -/* - * 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.viewer.wicket.model.models; - -import java.io.Serializable; -import java.util.Map; -import java.util.Set; -import com.google.common.collect.Maps; -import org.apache.wicket.model.Model; -import org.apache.wicket.request.mapper.parameter.PageParameters; -import org.apache.isis.applib.annotation.BookmarkPolicy; -import org.apache.isis.applib.services.memento.MementoService.Memento; -import org.apache.isis.core.metamodel.adapter.ObjectAdapter; -import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager.ConcurrencyChecking; -import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller; -import org.apache.isis.core.metamodel.adapter.oid.RootOid; -import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException; -import org.apache.isis.core.metamodel.consent.Consent; -import org.apache.isis.core.metamodel.facets.members.disabled.DisabledFacet; -import org.apache.isis.core.metamodel.facets.object.bookmarkpolicy.BookmarkPolicyFacet; -import org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet; -import org.apache.isis.core.metamodel.spec.ObjectSpecId; -import org.apache.isis.core.metamodel.spec.ObjectSpecification; -import org.apache.isis.core.metamodel.spec.ObjectSpecifications.MemberGroupLayoutHint; -import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi; -import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation; -import org.apache.isis.core.runtime.services.memento.MementoServiceDefault; -import org.apache.isis.core.runtime.system.context.IsisContext; -import org.apache.isis.viewer.wicket.model.common.PageParametersUtils; -import org.apache.isis.viewer.wicket.model.mementos.ObjectAdapterMemento; -import org.apache.isis.viewer.wicket.model.mementos.PageParameterNames; -import org.apache.isis.viewer.wicket.model.mementos.PropertyMemento; - -/** - * Backing model to represent a {@link ObjectAdapter}. - * - * <p> - * So that the model is {@link Serializable}, the {@link ObjectAdapter} is - * stored as a {@link ObjectAdapterMemento}. - */ -public class EntityModel extends BookmarkableModel<ObjectAdapter> { - - 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 PageParameters pageParameters = PageParametersUtils.newPageParameters(); - - final Boolean persistent = adapter != null && adapter.representsPersistent(); - - if (persistent) { - final String oidStr = adapter.getOid().enStringNoVersion(getOidMarshaller()); - - PageParameterNames.OBJECT_OID.addStringTo(pageParameters, oidStr); - } 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 RenderingHint { - REGULAR, - PROPERTY_COLUMN, - PARENTED_TITLE_COLUMN, - STANDALONE_TITLE_COLUMN; - - public boolean isRegular() { - return this == REGULAR; - } - - public boolean isInTablePropertyColumn() { - return this == PROPERTY_COLUMN; - } - - public boolean isInTable() { - return isInTablePropertyColumn() || isInTableTitleColumn(); - } - - public boolean isInTableTitleColumn() { - return isInParentedTableTitleColumn() || isInStandaloneTableTitleColumn(); - } - - public boolean isInParentedTableTitleColumn() { - return this == PARENTED_TITLE_COLUMN; - } - - public boolean isInStandaloneTableTitleColumn() { - return this == STANDALONE_TITLE_COLUMN; - } - } - - public enum Mode { - VIEW, EDIT; - } - - private ObjectAdapterMemento adapterMemento; - private Mode mode = Mode.VIEW; - private RenderingHint renderingHint = RenderingHint.REGULAR; - private final Map<PropertyMemento, ScalarModel> propertyScalarModels = Maps.newHashMap(); - private MemberGroupLayoutHint memberGroupLayoutHint; - - /** - * Toggled by 'entityDetailsButton'. - */ - private boolean entityDetailsVisible; - - /** - * {@link ConcurrencyException}, if any, that might have occurred previously - */ - private ConcurrencyException concurrencyException; - - private final HintPageParameterSerializer hintPageParameterSerializer = new HintPageParameterSerializerDirect(); - - // ////////////////////////////////////////////////////////// - // constructors - // ////////////////////////////////////////////////////////// - - public EntityModel() { - pendingModel = new PendingModel(this); - } - - public EntityModel(final PageParameters pageParameters) { - this(ObjectAdapterMemento.createPersistent(rootOidFrom(pageParameters))); - hintPageParameterSerializer.pageParametersToHints(pageParameters, getHints()); - } - public EntityModel(final ObjectAdapter adapter) { - this(ObjectAdapterMemento.createOrNull(adapter)); - setObject(adapter); - } - - public EntityModel(final ObjectAdapterMemento adapterMemento) { - this.adapterMemento = adapterMemento; - this.pendingModel = new PendingModel(this); - } - - private static String oidStr(final PageParameters pageParameters) { - return PageParameterNames.OBJECT_OID.getStringFrom(pageParameters); - } - - private static RootOid rootOidFrom(final PageParameters pageParameters) { - return getOidMarshaller().unmarshal(oidStr(pageParameters), RootOid.class); - } - - - ////////////////////////////////////////////////// - // BookmarkableModel - ////////////////////////////////////////////////// - - - @Override - public PageParameters getPageParameters() { - PageParameters pageParameters = createPageParameters(getObject()); - hintPageParameterSerializer.hintsToPageParameters(getHints(), pageParameters); - return pageParameters; - } - - @Deprecated - public PageParameters asPageParameters() { - return getPageParameters(); - } - - public PageParameters getPageParametersWithoutUiHints() { - return createPageParameters(getObject()); - } - - - static interface HintPageParameterSerializer { - public void hintsToPageParameters(Map<String,String> hints, PageParameters pageParameters); - public void pageParametersToHints(final PageParameters pageParameters, Map<String,String> hints); - } - - static class HintPageParameterSerializerDirect implements HintPageParameterSerializer, Serializable { - - private static final long serialVersionUID = 1L; - - public void hintsToPageParameters(Map<String,String> hints, PageParameters pageParameters) { - Set<String> hintKeys = hints.keySet(); - for (String key : hintKeys) { - String value = hints.get(key); - pageParameters.add("hint-" + key, value); - } - } - - @Override - public void pageParametersToHints(final PageParameters pageParameters, Map<String,String> hints) { - Set<String> namedKeys = pageParameters.getNamedKeys(); - for (String namedKey : namedKeys) { - if(namedKey.startsWith("hint-")) { - String value = pageParameters.get(namedKey).toString(null); - String key = namedKey.substring(5); - hints.put(key, value); // may replace - } - } - } - } - - static class HintPageParameterSerializerUsingViewModelSupport implements HintPageParameterSerializer, Serializable { - private static final long serialVersionUID = 1L; - - public void hintsToPageParameters(Map<String,String> hints, PageParameters pageParameters) { - if(hints.isEmpty()) { - return; - } - MementoServiceDefault vms = new MementoServiceDefault(); - Memento memento = vms.create(); - Set<String> hintKeys = hints.keySet(); - for (String key : hintKeys) { - String safeKey = key.replace(':', '_'); - Serializable value = hints.get(key); - memento.set(safeKey, value); - } - String serializedHints = memento.asString(); - PageParameterNames.ANCHOR.addStringTo(pageParameters, serializedHints); - } - - public void pageParametersToHints(final PageParameters pageParameters, Map<String,String> hints) { - String hintsStr = PageParameterNames.ANCHOR.getStringFrom(pageParameters); - if(hintsStr != null) { - try { - Memento memento = new MementoServiceDefault().parse(hintsStr); - Set<String> keys = memento.keySet(); - for (String safeKey : keys) { - String value = memento.get(safeKey, String.class); - String key = safeKey.replace('_', ':'); - hints.put(key, value); - } - } catch(RuntimeException ex) { - // fail gracefully, ie ignore. - System.err.println(ex); - } - } - } - } - - - - - @Override - public String getTitle() { - return getObject().titleString(null); - } - - public boolean hasAsRootPolicy() { - return hasBookmarkPolicy(BookmarkPolicy.AS_ROOT); - } - - public boolean hasAsChildPolicy() { - return hasBookmarkPolicy(BookmarkPolicy.AS_CHILD); - } - - private boolean hasBookmarkPolicy(final BookmarkPolicy policy) { - final BookmarkPolicyFacet facet = getBookmarkPolicyFacetIfAny(); - return facet != null && facet.value() == policy; - } - - private BookmarkPolicyFacet getBookmarkPolicyFacetIfAny() { - final ObjectSpecId specId = getObjectAdapterMemento().getObjectSpecId(); - final ObjectSpecification objectSpec = getSpecificationLoader().lookupBySpecId(specId); - return objectSpec.getFacet(BookmarkPolicyFacet.class); - } - - - - // ////////////////////////////////////////////////////////// - // ObjectAdapterMemento, typeOfSpecification - // ////////////////////////////////////////////////////////// - - public ObjectAdapterMemento getObjectAdapterMemento() { - return adapterMemento; - } - - /** - * Overridable for submodels (eg {@link ScalarModel}) that know the type of - * the adapter without there being one. - */ - public ObjectSpecification getTypeOfSpecification() { - if (adapterMemento == null) { - return null; - } - return getSpecificationFor(adapterMemento.getObjectSpecId()); - } - - private ObjectSpecification getSpecificationFor(ObjectSpecId objectSpecId) { - return getSpecificationLoader().lookupBySpecId(objectSpecId); - } - - // ////////////////////////////////////////////////////////// - // loadObject, load, setObject - // ////////////////////////////////////////////////////////// - - /** - * Not Wicket API, but used by <tt>EntityPage</tt> to do eager loading - * when rendering after post-and-redirect. - * @return - */ - public ObjectAdapter load(ConcurrencyChecking concurrencyChecking) { - if (adapterMemento == null) { - return null; - } - - final ObjectAdapter objectAdapter = adapterMemento.getObjectAdapter(concurrencyChecking); - return objectAdapter; - } - - - /** - * Callback from {@link #getObject()}, defaults to loading the object - * using {@link ConcurrencyChecking#CHECK strict} checking. - * - * <p> - * If non-strict checking is required, then just call {@link #load(ConcurrencyChecking)} with an - * argument of {@link ConcurrencyChecking#NO_CHECK} first. - */ - @Override - public ObjectAdapter load() { - return load(ConcurrencyChecking.CHECK); - } - - - @Override - public void setObject(final ObjectAdapter adapter) { - super.setObject(adapter); - adapterMemento = ObjectAdapterMemento.createOrNull(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() { - adapterMemento.resetVersion(); - for (final PropertyMemento pm : propertyScalarModels.keySet()) { - final ScalarModel scalarModel = propertyScalarModels.get(pm); - final ObjectAdapter associatedAdapter = pm.getProperty().get(getObject()); - scalarModel.setObject(associatedAdapter); - } - } - - // ////////////////////////////////////////////////////////// - // RenderingHint, Mode, entityDetailsVisible - // ////////////////////////////////////////////////////////// - - - public RenderingHint getRenderingHint() { - return renderingHint; - } - public void setRenderingHint(RenderingHint renderingHint) { - this.renderingHint = renderingHint; - } - - public ObjectAdapterMemento getContextAdapterIfAny() { - return contextAdapterIfAny; - } - - /** - * Used as a hint when the {@link #getRenderingHint()} is {@link RenderingHint#PARENTED_TITLE_COLUMN}, - * provides a context adapter to obtain the title. - */ - public void setContextAdapterIfAny(ObjectAdapterMemento contextAdapterIfAny) { - this.contextAdapterIfAny = contextAdapterIfAny; - } - - public Mode getMode() { - return mode; - } - - 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 (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; - } - - public MemberGroupLayoutHint getMemberGroupLayoutHint() { - return memberGroupLayoutHint; - } - public void setMemberGroupLayoutHint(MemberGroupLayoutHint memberGroupLayoutHint) { - this.memberGroupLayoutHint = memberGroupLayoutHint; - } - - - - - - // ////////////////////////////////////////////////////////// - // concurrency exceptions - // ////////////////////////////////////////////////////////// - - public void setException(ConcurrencyException ex) { - this.concurrencyException = ex; - } - - public String getAndClearConcurrencyExceptionIfAny() { - if(concurrencyException == null) { - return null; - } - final String message = concurrencyException.getMessage(); - concurrencyException = null; - return message; - } - - // ////////////////////////////////////////////////////////// - // validation & apply - // ////////////////////////////////////////////////////////// - - public String getReasonInvalidIfAny() { - final ObjectAdapter adapter = getObjectAdapterMemento().getObjectAdapter(ConcurrencyChecking.CHECK); - final Consent validity = adapter.getSpecification().isValid(adapter); - return validity.isAllowed() ? null : validity.getReason(); - } - - /** - * Apply changes to the underlying adapter (possibly returning a new adapter). - * - * @return adapter, which may be different from the original (if a {@link org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet#isCloneable(Object) cloneable} view model, for example. - */ - public ObjectAdapter apply() { - ObjectAdapter adapter = getObjectAdapterMemento().getObjectAdapter(ConcurrencyChecking.CHECK); - for (final ScalarModel scalarModel : propertyScalarModels.values()) { - final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty(); - - // - // previously there was a guard here to only apply changes provided: - // - // property.containsDoOpFacet(NotPersistedFacet.class) == null - // - // however, that logic is wrong; although a property may not be directly - // persisted so far as JDO is concerned, it may be indirectly persisted - // as the result of business logic in the setter. - // - // for example, see ExampleTaggableEntity (in isisaddons-module-tags). - // - - // - // on the other hand, we mustn't attempt to apply changes for disabled properties... - // even if the property is persisted (it might be written to by an action), it is never updated by - // an edit. - // - // Fundamentally, then, any non-disabled property (whether persisted or not) should be updated in the - // Isis runtime. - // - - if(property.containsDoOpFacet(DisabledFacet.class)) { - // skip, as per comments above - continue; - } - - final ObjectAdapter associate = scalarModel.getObject(); - property.set(adapter, associate); - } - - final ViewModelFacet recreatableObjectFacet = adapter.getSpecification().getFacet(ViewModelFacet.class); - if(recreatableObjectFacet != null) { - final Object viewModel = adapter.getObject(); - final boolean cloneable = recreatableObjectFacet.isCloneable(viewModel); - if(cloneable) { - final Object newViewModel = recreatableObjectFacet.clone(viewModel); - adapter = getAdapterManager().adapterFor(newViewModel); - } - } - - getObjectAdapterMemento().setAdapter(adapter); - toViewMode(); - - return adapter; - } - - - // ////////////////////////////////////////////////////////// - // Pending - // ////////////////////////////////////////////////////////// - - private static final class PendingModel extends Model<ObjectAdapterMemento> { - private static final long serialVersionUID = 1L; - - private final EntityModel entityModel; - - /** - * Whether pending has been set (could have been set to null) - */ - private boolean hasPending; - /** - * The new value (could be set to null; hasPending is used to distinguish). - */ - private ObjectAdapterMemento pending; - - - public PendingModel(EntityModel entityModel) { - this.entityModel = entityModel; - } - - @Override - public ObjectAdapterMemento getObject() { - if (hasPending) { - return pending; - } - final ObjectAdapter adapter = entityModel.getObject(); - return ObjectAdapterMemento.createOrNull(adapter); - } - - @Override - public void setObject(final ObjectAdapterMemento adapterMemento) { - pending = adapterMemento; - hasPending = true; - } - - public void clearPending() { - this.hasPending = false; - this.pending = null; - } - - private ObjectAdapter getPendingAdapter() { - final ObjectAdapterMemento memento = getObject(); - return memento != null ? memento.getObjectAdapter(ConcurrencyChecking.NO_CHECK) : null; - } - - public ObjectAdapter getPendingElseCurrentAdapter() { - return hasPending ? getPendingAdapter() : entityModel.getObject(); - } - - public ObjectAdapterMemento getPending() { - return pending; - } - - public void setPending(ObjectAdapterMemento selectedAdapterMemento) { - this.pending = selectedAdapterMemento; - hasPending=true; - } - } - - private final PendingModel pendingModel; - private ObjectAdapterMemento contextAdapterIfAny; - - public ObjectAdapter getPendingElseCurrentAdapter() { - return pendingModel.getPendingElseCurrentAdapter(); - } - - public ObjectAdapter getPendingAdapter() { - return pendingModel.getPendingAdapter(); - } - - public ObjectAdapterMemento getPending() { - return pendingModel.getPending(); - } - - public void setPending(ObjectAdapterMemento selectedAdapterMemento) { - pendingModel.setPending(selectedAdapterMemento); - } - - public void clearPending() { - pendingModel.clearPending(); - } - - - // ////////////////////////////////////////////////////////// - // equals, hashCode - // ////////////////////////////////////////////////////////// - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((adapterMemento == null) ? 0 : adapterMemento.hashCode()); - return result; - } - - /** - * In order that <tt>IsisAjaxFallbackDataTable</tt> can use a - * <tt>ReuseIfModelsEqualStrategy</tt> to preserve any concurrency exception - * information in original model. - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - EntityModel other = (EntityModel) obj; - if (adapterMemento == null) { - if (other.adapterMemento != null) - return false; - } else if (!adapterMemento.equals(other.adapterMemento)) - return false; - return true; - - } - - - // ////////////////////////////////////////////////////////// - // Dependencies (from context) - // ////////////////////////////////////////////////////////// - - protected static OidMarshaller getOidMarshaller() { - return IsisContext.getOidMarshaller(); - } - - protected SpecificationLoaderSpi getSpecificationLoader() { - return IsisContext.getSpecificationLoader(); - } - - - - - -} http://git-wip-us.apache.org/repos/asf/isis/blob/d84c6609/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ImageResourceCache.java ---------------------------------------------------------------------- diff --git a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ImageResourceCache.java b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ImageResourceCache.java deleted file mode 100644 index b0828df..0000000 --- a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ImageResourceCache.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.viewer.wicket.model.models; - -import java.io.Serializable; - -import org.apache.wicket.request.resource.ResourceReference; - -import org.apache.isis.core.metamodel.adapter.ObjectAdapter; -import org.apache.isis.core.metamodel.spec.ObjectSpecification; - -/** - * Ideally I'd like to move this to the <tt>org.apache.isis.viewer.wicket.model.isis</tt> - * package, however to do so would break existing API (gmap3 has a dependency on this, for example). - */ -public interface ImageResourceCache extends Serializable { - - ResourceReference resourceReferenceFor(ObjectAdapter adapter); - - ResourceReference resourceReferenceForSpec(ObjectSpecification objectSpecification); - -} http://git-wip-us.apache.org/repos/asf/isis/blob/d84c6609/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ModelAbstract.java ---------------------------------------------------------------------- diff --git a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ModelAbstract.java b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ModelAbstract.java deleted file mode 100644 index ce17a7c..0000000 --- a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ModelAbstract.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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.viewer.wicket.model.models; - -import java.util.Map; -import com.google.common.collect.Maps; -import org.apache.wicket.Component; -import org.apache.wicket.model.LoadableDetachableModel; -import org.apache.wicket.util.string.PrependingStringBuffer; -import org.apache.wicket.util.string.Strings; -import org.apache.isis.core.commons.authentication.AuthenticationSession; -import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager; -import org.apache.isis.core.runtime.system.context.IsisContext; -import org.apache.isis.core.runtime.system.persistence.PersistenceSession; -import org.apache.isis.viewer.wicket.model.hints.UiHintContainer; -import org.apache.isis.viewer.wicket.model.hints.UiHintPathSignificant; - -/** - * Adapter for {@link LoadableDetachableModel}s, providing access to some of the - * Isis' dependencies. - */ -public abstract class ModelAbstract<T> extends LoadableDetachableModel<T> implements UiHintContainer { - - private static final long serialVersionUID = 1L; - - public ModelAbstract() { - } - - public ModelAbstract(final T t) { - super(t); - } - - - // ////////////////////////////////////////////////////////// - // Hint support - // ////////////////////////////////////////////////////////// - - private final Map<String, String> hints = Maps.newTreeMap(); - - public String getHint(final Component component, final String key) { - if(component == null) { - return null; - } - String hintKey = hintKey(component, key); - return hints.get(hintKey); - } - - @Override - public void setHint(Component component, String key, String value) { - if(component == null) { - return; - } - String hintKey = hintKey(component, key); - if(value != null) { - hints.put(hintKey, value); - } else { - hints.remove(hintKey); - } - } - - @Override - public void clearHint(Component component, String key) { - setHint(component, key, null); - } - - - private static String hintKey(Component component, String key) { - return hintPathFor(component) + "-" + key; - } - - private static String hintPathFor(Component component) - { - return Strings.afterFirstPathComponent(fullHintPathFor(component), Component.PATH_SEPARATOR); - } - - private static String fullHintPathFor(Component component) - { - final PrependingStringBuffer buffer = new PrependingStringBuffer(32); - for (Component c = component; c != null; c = c.getParent()) - { - if(c instanceof UiHintPathSignificant) { - if (buffer.length() > 0) - { - buffer.prepend(Component.PATH_SEPARATOR); - } - buffer.prepend(c.getId()); - } - } - return buffer.toString(); - } - - protected Map<String, String> getHints() { - return hints; - } - - // ////////////////////////////////////////////////////////////// - // Dependencies - // ////////////////////////////////////////////////////////////// - - protected AuthenticationSession getAuthenticationSession() { - return IsisContext.getAuthenticationSession(); - } - - protected PersistenceSession getPersistenceSession() { - return IsisContext.getPersistenceSession(); - } - - protected AdapterManager getAdapterManager() { - return getPersistenceSession().getAdapterManager(); - } - -} http://git-wip-us.apache.org/repos/asf/isis/blob/d84c6609/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/PageType.java ---------------------------------------------------------------------- diff --git a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/PageType.java b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/PageType.java deleted file mode 100644 index f23b506..0000000 --- a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/PageType.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.viewer.wicket.model.models; - - - -/** - * Enumerates the different types of pages that can be rendered. - * - * <p> - * Is used by {@link PageClassRegistry} to lookup the concrete page to render - * different types of pages. This allows the large-scale structure of page - * layout (eg headers, footers) to be altered. - */ -public enum PageType { - SIGN_IN, - SIGN_UP, - SIGN_UP_VERIFY, - PASSWORD_RESET, - HOME, - ABOUT, - ENTITY, - ACTION_PROMPT, - STANDALONE_COLLECTION, - VALUE, - VOID_RETURN; -} http://git-wip-us.apache.org/repos/asf/isis/blob/d84c6609/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java ---------------------------------------------------------------------- diff --git a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java deleted file mode 100644 index f3d3310..0000000 --- a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java +++ /dev/null @@ -1,727 +0,0 @@ -/* - * 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.viewer.wicket.model.models; - -import java.math.BigDecimal; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import com.google.common.collect.Lists; - -import org.apache.wicket.Session; - -import org.apache.isis.applib.annotation.Where; -import org.apache.isis.applib.profiles.Localization; -import org.apache.isis.core.commons.authentication.AuthenticationSession; -import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider; -import org.apache.isis.core.metamodel.adapter.ObjectAdapter; -import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager.ConcurrencyChecking; -import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException; -import org.apache.isis.core.metamodel.consent.Consent; -import org.apache.isis.core.metamodel.facetapi.Facet; -import org.apache.isis.core.metamodel.facetapi.FacetHolder; -import org.apache.isis.core.metamodel.facets.objectvalue.mandatory.MandatoryFacet; -import org.apache.isis.core.metamodel.facets.object.parseable.ParseableFacet; -import org.apache.isis.core.metamodel.facets.objectvalue.typicallen.TypicalLengthFacet; -import org.apache.isis.core.metamodel.spec.ObjectSpecId; -import org.apache.isis.core.metamodel.spec.ObjectSpecification; -import org.apache.isis.core.metamodel.spec.feature.ObjectActionParameter; -import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation; -import org.apache.isis.core.metamodel.facets.value.bigdecimal.BigDecimalValueFacet; -import org.apache.isis.core.metamodel.facets.value.string.StringValueSemanticsProvider; -import org.apache.isis.core.runtime.system.context.IsisContext; -import org.apache.isis.viewer.wicket.model.links.LinkAndLabel; -import org.apache.isis.viewer.wicket.model.links.LinksProvider; -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.mementos.SpecUtils; - -/** - * 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). - */ -public class ScalarModel extends EntityModel implements LinksProvider { - - 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) { - ObjectSpecId type = scalarModel.getPropertyMemento().getType(); - return SpecUtils.getSpecificationFor(type); - } - - @Override - public String getIdentifier(final ScalarModel scalarModel) { - return scalarModel.getPropertyMemento().getIdentifier(); - } - - @Override - public String getLongName(final ScalarModel scalarModel) { - ObjectSpecId objectSpecId = scalarModel.parentObjectAdapterMemento.getObjectSpecId(); - final String specShortName = SpecUtils.getSpecificationFor(objectSpecId).getShortIdentifier(); - return specShortName + "-" + scalarModel.getPropertyMemento().getProperty().getId(); - } - - @Override - public String disable(final ScalarModel scalarModel, final Where where) { - final ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK); - final OneToOneAssociation property = scalarModel.getPropertyMemento().getProperty(); - try { - final AuthenticationSession session = scalarModel.getAuthenticationSession(); - final Consent usable = property.isUsable(session, parentAdapter, where); - return usable.isAllowed() ? null : usable.getReason(); - } catch (final Exception ex) { - return ex.getLocalizedMessage(); - } - } - - @Override - 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(ConcurrencyChecking.CHECK); - final ObjectAdapter currentValue = property.get(parentAdapter); - Localization localization = IsisContext.getLocalization(); - final ObjectAdapter proposedAdapter = parseableFacet.parseTextEntry(currentValue, proposedPojoAsStr, localization); - final Consent valid = property.isAssociationValid(parentAdapter, proposedAdapter); - return valid.isAllowed() ? null : valid.getReason(); - } catch (final ConcurrencyException ex) { - // disregard concurrency exceptions because will pick up at the IFormValidator level rather - // than each individual property. - return null; - } catch (final Exception ex) { - return ex.getLocalizedMessage(); - } - } - - @Override - public String validate(final ScalarModel scalarModel, final ObjectAdapter proposedAdapter) { - final ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK); - 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 boolean hasChoices(final ScalarModel scalarModel) { - final PropertyMemento propertyMemento = scalarModel.getPropertyMemento(); - final OneToOneAssociation property = propertyMemento.getProperty(); - return property.hasChoices(); - } - - @Override - public List<ObjectAdapter> getChoices(final ScalarModel scalarModel, final ObjectAdapter[] argumentsIfAvailable) { - final PropertyMemento propertyMemento = scalarModel.getPropertyMemento(); - final OneToOneAssociation property = propertyMemento.getProperty(); - final ObjectAdapter[] choices = property.getChoices(scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.NO_CHECK)); - return choicesAsList(choices); - } - - @Override - public boolean hasAutoComplete(final ScalarModel scalarModel) { - final PropertyMemento propertyMemento = scalarModel.getPropertyMemento(); - final OneToOneAssociation property = propertyMemento.getProperty(); - return property.hasAutoComplete(); - } - - @Override - public List<ObjectAdapter> getAutoComplete(final ScalarModel scalarModel, String searchArg) { - final PropertyMemento propertyMemento = scalarModel.getPropertyMemento(); - final OneToOneAssociation property = propertyMemento.getProperty(); - final ObjectAdapter[] choices = property.getAutoComplete(scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.NO_CHECK), searchArg); - return choicesAsList(choices); - } - - @Override - public int getAutoCompleteOrChoicesMinLength(ScalarModel scalarModel) { - - if (scalarModel.hasAutoComplete()) { - final PropertyMemento propertyMemento = scalarModel.getPropertyMemento(); - final OneToOneAssociation property = propertyMemento.getProperty(); - return property.getAutoCompleteMinLength(); - } else { - return 0; - } - } - - - @Override - public void resetVersion(ScalarModel scalarModel) { - scalarModel.parentObjectAdapterMemento.resetVersion(); - } - - @Override - public String getDescribedAs(final ScalarModel scalarModel) { - final PropertyMemento propertyMemento = scalarModel.getPropertyMemento(); - final OneToOneAssociation property = propertyMemento.getProperty(); - return property.getDescription(); - } - - @Override - public Integer getLength(ScalarModel scalarModel) { - final PropertyMemento propertyMemento = scalarModel.getPropertyMemento(); - final OneToOneAssociation property = propertyMemento.getProperty(); - final BigDecimalValueFacet facet = property.getFacet(BigDecimalValueFacet.class); - return facet != null? facet.getLength(): null; - } - - @Override - public Integer getScale(ScalarModel scalarModel) { - final PropertyMemento propertyMemento = scalarModel.getPropertyMemento(); - final OneToOneAssociation property = propertyMemento.getProperty(); - final BigDecimalValueFacet facet = property.getFacet(BigDecimalValueFacet.class); - return facet != null? facet.getScale(): null; - } - - @Override - public int getTypicalLength(ScalarModel scalarModel) { - final PropertyMemento propertyMemento = scalarModel.getPropertyMemento(); - final OneToOneAssociation property = propertyMemento.getProperty(); - final TypicalLengthFacet facet = property.getFacet(TypicalLengthFacet.class); - return facet != null? facet.value() : StringValueSemanticsProvider.TYPICAL_LENGTH; - } - - @Override - public void reset(ScalarModel scalarModel) { - final OneToOneAssociation property = scalarModel.propertyMemento.getProperty(); - final ObjectAdapter associatedAdapter = property.get(scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK)); - - scalarModel.setObject(associatedAdapter); - } - }, - PARAMETER { - @Override - public String getName(final ScalarModel scalarModel) { - return scalarModel.getParameterMemento().getActionParameter().getName(); - } - - @Override - 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; - } - ObjectSpecId objectSpecId = adapterMemento.getObjectSpecId(); - final String specShortName = SpecUtils.getSpecificationFor(objectSpecId).getShortIdentifier(); - final String parmId = scalarModel.getParameterMemento().getActionParameter().getIdentifier().toNameIdentityString(); - return specShortName + "-" + parmId + "-" + scalarModel.getParameterMemento().getNumber(); - } - - @Override - public String disable(final ScalarModel scalarModel, Where where) { - // always enabled - return null; - } - - @Override - public String parseAndValidate(final ScalarModel scalarModel, final String proposedPojoAsStr) { - final ObjectActionParameter parameter = scalarModel.getParameterMemento().getActionParameter(); - try { - final ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK); - Localization localization = IsisContext.getLocalization(); - final String invalidReasonIfAny = parameter.isValid(parentAdapter, proposedPojoAsStr, localization); - return invalidReasonIfAny; - } catch (final Exception ex) { - return ex.getLocalizedMessage(); - } - } - - @Override - public String validate(final ScalarModel scalarModel, final ObjectAdapter proposedAdapter) { - final ObjectActionParameter parameter = scalarModel.getParameterMemento().getActionParameter(); - try { - final ObjectAdapter parentAdapter = scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK); - Localization localization = IsisContext.getLocalization(); - final String invalidReasonIfAny = parameter.isValid(parentAdapter, proposedAdapter.getObject(), localization); - return invalidReasonIfAny; - } catch (final Exception ex) { - return ex.getLocalizedMessage(); - } - } - - @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 boolean hasChoices(final ScalarModel scalarModel) { - final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento(); - final ObjectActionParameter actionParameter = parameterMemento.getActionParameter(); - return actionParameter.hasChoices(); - } - @Override - public List<ObjectAdapter> getChoices(final ScalarModel scalarModel, final ObjectAdapter[] argumentsIfAvailable) { - final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento(); - final ObjectActionParameter actionParameter = parameterMemento.getActionParameter(); - final ObjectAdapter[] choices = actionParameter.getChoices(scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK), argumentsIfAvailable); - return choicesAsList(choices); - } - - @Override - public boolean hasAutoComplete(final ScalarModel scalarModel) { - final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento(); - final ObjectActionParameter actionParameter = parameterMemento.getActionParameter(); - return actionParameter.hasAutoComplete(); - } - @Override - public List<ObjectAdapter> getAutoComplete(final ScalarModel scalarModel, final String searchArg) { - final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento(); - final ObjectActionParameter actionParameter = parameterMemento.getActionParameter(); - final ObjectAdapter[] choices = actionParameter.getAutoComplete(scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.NO_CHECK), searchArg); - return choicesAsList(choices); - } - - @Override - public int getAutoCompleteOrChoicesMinLength(ScalarModel scalarModel) { - if (scalarModel.hasAutoComplete()) { - final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento(); - final ObjectActionParameter actionParameter = parameterMemento.getActionParameter(); - return actionParameter.getAutoCompleteMinLength(); - } else { - return 0; - } - } - - @Override - public void resetVersion(ScalarModel scalarModel) { - // no-op? - } - @Override - public String getDescribedAs(final ScalarModel scalarModel) { - final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento(); - final ObjectActionParameter actionParameter = parameterMemento.getActionParameter(); - return actionParameter.getDescription(); - } - - @Override - public Integer getLength(ScalarModel scalarModel) { - final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento(); - final ObjectActionParameter actionParameter = parameterMemento.getActionParameter(); - final BigDecimalValueFacet facet = actionParameter.getFacet(BigDecimalValueFacet.class); - return facet != null? facet.getLength(): null; - } - - @Override - public Integer getScale(ScalarModel scalarModel) { - final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento(); - final ObjectActionParameter actionParameter = parameterMemento.getActionParameter(); - final BigDecimalValueFacet facet = actionParameter.getFacet(BigDecimalValueFacet.class); - return facet != null? facet.getScale(): null; - } - - @Override - public int getTypicalLength(ScalarModel scalarModel) { - final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento(); - final ObjectActionParameter actionParameter = parameterMemento.getActionParameter(); - final TypicalLengthFacet facet = actionParameter.getFacet(TypicalLengthFacet.class); - return facet != null? facet.value() : StringValueSemanticsProvider.TYPICAL_LENGTH; - } - - @Override - public void reset(ScalarModel scalarModel) { - final ObjectActionParameter actionParameter = scalarModel.parameterMemento.getActionParameter(); - final ObjectAdapter defaultAdapter = actionParameter.getDefault(scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.NO_CHECK)); - scalarModel.setObject(defaultAdapter); - } - }; - - 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 ObjectSpecification getScalarTypeSpec(ScalarModel scalarModel); - - public abstract String getIdentifier(ScalarModel scalarModel); - - public abstract String disable(ScalarModel scalarModel, Where where); - - public abstract String parseAndValidate(ScalarModel scalarModel, String proposedPojoAsStr); - - public abstract String validate(ScalarModel scalarModel, ObjectAdapter proposedAdapter); - - public abstract String getLongName(ScalarModel scalarModel); - - public abstract boolean isRequired(ScalarModel scalarModel); - - public abstract <T extends Facet> T getFacet(ScalarModel scalarModel, Class<T> facetType); - - static boolean isRequired(final FacetHolder facetHolder) { - final MandatoryFacet mandatoryFacet = facetHolder.getFacet(MandatoryFacet.class); - final boolean required = mandatoryFacet != null && !mandatoryFacet.isInvertedSemantics(); - return required; - } - - public abstract boolean hasChoices(ScalarModel scalarModel); - public abstract List<ObjectAdapter> getChoices(ScalarModel scalarModel, final ObjectAdapter[] argumentsIfAvailable); - - public abstract boolean hasAutoComplete(ScalarModel scalarModel); - public abstract List<ObjectAdapter> getAutoComplete(ScalarModel scalarModel, String searchArg); - public abstract int getAutoCompleteOrChoicesMinLength(ScalarModel scalarModel); - - public abstract void resetVersion(ScalarModel scalarModel); - - public abstract String getDescribedAs(ScalarModel scalarModel); - - - public abstract Integer getLength(ScalarModel scalarModel); - public abstract Integer getScale(ScalarModel scalarModel); - - public abstract int getTypicalLength(ScalarModel scalarModel); - - public abstract void reset(ScalarModel scalarModel); - - - } - - 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#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. - */ - public ScalarModel(final ObjectAdapterMemento parentObjectAdapterMemento, final ActionParameterMemento apm) { - this.kind = Kind.PARAMETER; - this.parentObjectAdapterMemento = parentObjectAdapterMemento; - this.parameterMemento = apm; - - reset(); - 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; - - reset(); - setObject(parentObjectAdapterMemento); - setMode(Mode.VIEW); - } - - public void reset() { - kind.reset(this); - } - - public ObjectAdapterMemento getParentObjectAdapterMemento() { - return parentObjectAdapterMemento; - } - - protected void setObject(final ObjectAdapterMemento parentObjectAdapterMemento) { - final OneToOneAssociation property = propertyMemento.getProperty(); - final ObjectAdapter associatedAdapter = property.get(parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK)); - - setObject(associatedAdapter); - } - - /** - * 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 String getObjectAsString() { - final ObjectAdapter adapter = getObject(); - if (adapter == null) { - return null; - } - return adapter.titleString(null); - } - - @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()); - } - Localization localization = IsisContext.getLocalization(); - final ObjectAdapter adapter = parseableFacet.parseTextEntry(getObject(), enteredText, localization); - - setObject(adapter); - } - - public String disable(Where where) { - return kind.disable(this, where); - } - - 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 ((AuthenticationSessionProvider) 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 void resetVersion() { - kind.resetVersion(this); - } - - public String getDescribedAs() { - return kind.getDescribedAs(this); - } - - public boolean hasChoices() { - return kind.hasChoices(this); - } - - public List<ObjectAdapter> getChoices(final ObjectAdapter[] argumentsIfAvailable) { - return kind.getChoices(this, argumentsIfAvailable); - } - - public boolean hasAutoComplete() { - return kind.hasAutoComplete(this); - } - - public List<ObjectAdapter> getAutoComplete(String searchTerm) { - return kind.getAutoComplete(this, searchTerm); - } - - /** - * for {@link BigDecimal}s only. - * - * @see #getScale() - */ - public int getLength() { - return kind.getLength(this); - } - - /** - * for {@link BigDecimal}s only. - * - * @see #getLength() - */ - public Integer getScale() { - return kind.getScale(this); - } - - public int getTypicalLength() { - return kind.getTypicalLength(this); - } - - /** - * Additional links to render (if any) - */ - private List<LinkAndLabel> entityActions = Lists.newArrayList(); - - - public void addEntityActions(List<LinkAndLabel> entityActions) { - this.entityActions.addAll(entityActions); - } - - @Override - public List<LinkAndLabel> getLinks() { - return Collections.unmodifiableList(entityActions); - } - - /** - * @return - */ - public int getAutoCompleteMinLength() { - return kind.getAutoCompleteOrChoicesMinLength(this); - } - - /** - * @return - */ - public ScalarModelWithPending asScalarModelWithPending() { - return new ScalarModelWithPending(){ - - private static final long serialVersionUID = 1L; - - @Override - public ObjectAdapterMemento getPending() { - return ScalarModel.this.getPending(); - } - - @Override - public void setPending(ObjectAdapterMemento pending) { - ScalarModel.this.setPending(pending); - } - - @Override - public ScalarModel getScalarModel() { - return ScalarModel.this; - } - }; - } - - - // ////////////////////////////////////// - - /** - * transient because only temporary hint. - */ - private transient ObjectAdapter[] actionArgsHint; - - public void setActionArgsHint(ObjectAdapter[] actionArgsHint) { - this.actionArgsHint = actionArgsHint; - } - - /** - * The initial call of choicesXxx() for any given scalar argument needs the current values - * of all args (possibly as initialized through a defaultNXxx(). - */ - public ObjectAdapter[] getActionArgsHint() { - return actionArgsHint; - } - - -} http://git-wip-us.apache.org/repos/asf/isis/blob/d84c6609/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModelWithPending.java ---------------------------------------------------------------------- diff --git a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModelWithPending.java b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModelWithPending.java deleted file mode 100644 index d153f08..0000000 --- a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModelWithPending.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * 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.viewer.wicket.model.models; - -import java.io.Serializable; - -import org.apache.wicket.model.Model; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.isis.core.metamodel.adapter.ObjectAdapter; -import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager.ConcurrencyChecking; -import org.apache.isis.viewer.wicket.model.mementos.ObjectAdapterMemento; - -/** - * For widgets that use a <tt>com.vaynberg.wicket.select2.Select2Choice</tt>; - * synchronizes the {@link Model} of the <tt>Select2Choice</tt> - * with the parent {@link ScalarModel}, allowing also for pending values. - */ -public interface ScalarModelWithPending extends Serializable { - - public ObjectAdapterMemento getPending(); - public void setPending(ObjectAdapterMemento pending); - - public ScalarModel getScalarModel(); - - static class Util { - - private static final Logger LOG = LoggerFactory.getLogger(ScalarModelWithPending.Util.class); - - public static Model<ObjectAdapterMemento> createModel(final ScalarModelWithPending owner) { - return new Model<ObjectAdapterMemento>() { - - private static final long serialVersionUID = 1L; - - @Override - public ObjectAdapterMemento getObject() { - if (owner.getPending() != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("pending not null: " + owner.getPending().toString()); - } - return owner.getPending(); - } - if (LOG.isDebugEnabled()) { - LOG.debug("pending is null"); - } - - final ObjectAdapterMemento objectAdapterMemento = owner.getScalarModel().getObjectAdapterMemento(); - owner.setPending(objectAdapterMemento); - - return objectAdapterMemento; - } - - @Override - public void setObject(final ObjectAdapterMemento adapterMemento) { - if (LOG.isDebugEnabled()) { - LOG.debug("setting to: " + adapterMemento!=null?adapterMemento.toString():null); - } - owner.setPending(adapterMemento); - if (owner.getScalarModel() != null) { - if(adapterMemento == null) { - owner.getScalarModel().setObject((ObjectAdapter)null); - } else { - if (owner.getPending() != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("setting to pending: " + owner.getPending().toString()); - } - owner.getScalarModel().setObject(owner.getPending().getObjectAdapter(ConcurrencyChecking.NO_CHECK)); - } - } - } - } - }; - } - } -} \ No newline at end of file