You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/05/14 12:26:30 UTC
[isis] branch master updated: ISIS-2340: moving more logic to
common UI Model and meta-model (4)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 8adbdf1 ISIS-2340: moving more logic to common UI Model and meta-model (4)
8adbdf1 is described below
commit 8adbdf1029f8188ad9c5188cba9bdd56c69c4217
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu May 14 14:26:17 2020 +0200
ISIS-2340: moving more logic to common UI Model and meta-model (4)
---
.../interactions/managed/ManagedProperty.java | 14 ++++++++---
.../common/model/binding/UiComponentFactory.java | 3 ++-
.../viewer/wicket/model/models/ScalarModel.java | 23 -----------------
.../wicket/model/models/ScalarPropertyModel.java | 29 ++++++++++------------
4 files changed, 26 insertions(+), 43 deletions(-)
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/interactions/managed/ManagedProperty.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/interactions/managed/ManagedProperty.java
index b86c12f..c94507c 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/interactions/managed/ManagedProperty.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/interactions/managed/ManagedProperty.java
@@ -22,6 +22,7 @@ import java.util.Optional;
import javax.annotation.Nullable;
+import org.apache.isis.applib.annotation.Where;
import org.apache.isis.core.commons.collections.Can;
import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
import org.apache.isis.core.metamodel.consent.Veto;
@@ -114,11 +115,18 @@ public final class ManagedProperty extends ManagedMember {
return Optional.empty();
}
- public ManagedObject getPropertyValue() {
+ /**
+ * If visibility is vetoed, returns an empty but specified ManagedObject.
+ * @return the property value as to be used by the UI for representation
+ */
+ public ManagedObject getPropertyValue(@NonNull Where where) {
val property = getProperty();
+ val owner = getOwner();
- return Optional.ofNullable(property.get(getOwner()))
- .orElse(ManagedObject.of(property.getSpecification(), null));
+ return property.isVisible(owner, InteractionInitiatedBy.FRAMEWORK, where).isAllowed()
+ && property.isVisible(owner, InteractionInitiatedBy.USER, where).isAllowed()
+ ? property.get(owner, InteractionInitiatedBy.USER)
+ : ManagedObject.of(property.getSpecification(), null);
}
diff --git a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/UiComponentFactory.java b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/UiComponentFactory.java
index 55beade..6510071 100644
--- a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/UiComponentFactory.java
+++ b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/UiComponentFactory.java
@@ -111,9 +111,10 @@ public interface UiComponentFactory<T> {
}
public <T> Optional<T> getFeatureValue(@Nullable Class<T> type) {
+ val managedProperty = (ManagedProperty)getObjectFeature();
//TODO do a type check before the cast, so we can throw a more detailed exception
// that is, given type must be assignable from the actual pojo type
- return Optional.ofNullable(((ManagedProperty)getObjectFeature()).getPropertyValue().getPojo())
+ return Optional.ofNullable(managedProperty.getPropertyValue(where).getPojo())
.map(type::cast);
}
diff --git a/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java b/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java
index 7d15091..f3d9475 100644
--- a/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java
+++ b/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarModel.java
@@ -28,7 +28,6 @@ import org.apache.isis.core.commons.collections.Can;
import org.apache.isis.core.commons.internal.base._Casts;
import org.apache.isis.core.commons.internal.base._NullSafe;
import org.apache.isis.core.commons.internal.collections._Lists;
-import org.apache.isis.core.metamodel.consent.Consent;
import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
import org.apache.isis.core.metamodel.facetapi.Facet;
import org.apache.isis.core.metamodel.facets.object.parseable.ParseableFacet;
@@ -37,7 +36,6 @@ import org.apache.isis.core.metamodel.spec.ManagedObject;
import org.apache.isis.core.metamodel.spec.ObjectSpecId;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
-import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
import org.apache.isis.core.webapp.context.memento.ObjectMemento;
import org.apache.isis.viewer.common.model.feature.ScalarUiModel;
import org.apache.isis.viewer.wicket.model.links.LinkAndLabel;
@@ -131,27 +129,6 @@ implements ScalarUiModel, LinksProvider, FormExecutorContext {
return owner;
}
-
- protected static void setObjectFromPropertyIfVisible(
- final ScalarModel scalarModel,
- final OneToOneAssociation property,
- final ManagedObject parentAdapter) {
-
- final Where where = scalarModel.getRenderingHint().asWhere();
-
- final Consent visibility =
- property.isVisible(parentAdapter, InteractionInitiatedBy.FRAMEWORK, where);
-
- final ManagedObject associatedAdapter;
- if (visibility.isAllowed()) {
- associatedAdapter = property.get(parentAdapter, InteractionInitiatedBy.USER);
- } else {
- associatedAdapter = null;
- }
-
- scalarModel.setObject(associatedAdapter);
- }
-
/**
* Whether the scalar represents a {@link Kind#PROPERTY property} or a
* {@link Kind#PARAMETER}.
diff --git a/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarPropertyModel.java b/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarPropertyModel.java
index f970c58..7186f5b 100644
--- a/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarPropertyModel.java
+++ b/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ScalarPropertyModel.java
@@ -49,14 +49,14 @@ implements PropertyUiModel {
*/
public ScalarPropertyModel(
EntityModel parentEntityModel,
- PropertyMemento pm,
+ PropertyMemento propertyMemento,
EntityModel.Mode mode,
EntityModel.RenderingHint renderingHint) {
- super(parentEntityModel, pm, mode, renderingHint);
- this.propertyMemento = pm;
+ super(parentEntityModel, propertyMemento, mode, renderingHint);
+ this.propertyMemento = propertyMemento;
reset();
- getAndStore(parentEntityModel);
+ //getAndStore(parentEntityModel);
}
public ScalarPropertyModel copyHaving(
@@ -128,9 +128,16 @@ implements PropertyUiModel {
}
public void reset() {
- val parentAdapter = getParentUiModel().load();
- setObjectFromPropertyIfVisible(this, getMetaModel(), parentAdapter);
+ val where = this.getRenderingHint().asWhere();
+ val propertyValue = getManagedProperty().getPropertyValue(where);
+
+ val presentationValue = ManagedObject.isNullOrUnspecifiedOrEmpty(propertyValue)
+ ? null
+ : propertyValue;
+
+ this.setObject(presentationValue);
}
+
@Override
public ManagedObject load() {
@@ -172,15 +179,5 @@ implements PropertyUiModel {
protected Can<ObjectAction> calcAssociatedActions() {
return getManagedProperty().getAssociatedActions();
}
-
- // -- HELPER
-
- private void getAndStore(final EntityModel parentEntityModel) {
- val parentAdapterMemento = parentEntityModel.getObjectAdapterMemento();
- val parentAdapter = super.getCommonContext().reconstructObject(parentAdapterMemento);
- val property = propertyMemento.getProperty(getSpecificationLoader());
- setObjectFromPropertyIfVisible(ScalarPropertyModel.this, property, parentAdapter);
- }
-
}