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/26 19:43:57 UTC
[isis] branch master updated: ISIS-2369: proposed fix: have
EntityIconAndTitlePanelFactory also
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 45192c1 ISIS-2369: proposed fix: have EntityIconAndTitlePanelFactory also
45192c1 is described below
commit 45192c1938fe9dc81d038aa0bc11a55554c16865
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue May 26 21:43:46 2020 +0200
ISIS-2369: proposed fix: have EntityIconAndTitlePanelFactory also
handle IModels of type ScalarModel which do no longer implement
ObjectAdapterModel; we do this by use of the adapter idiom:
EntityModelForReference acts as an adapter from ScalarModel to
ObjectAdapterModel
---
.../icontitle/EntityIconAndTitlePanelFactory.java | 65 +++++++++++++++++-----
.../scalars/reference/ReferencePanel.java | 21 +++----
2 files changed, 58 insertions(+), 28 deletions(-)
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/icontitle/EntityIconAndTitlePanelFactory.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/icontitle/EntityIconAndTitlePanelFactory.java
index f61e8bb..eafcb61 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/icontitle/EntityIconAndTitlePanelFactory.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/icontitle/EntityIconAndTitlePanelFactory.java
@@ -22,15 +22,26 @@ package org.apache.isis.viewer.wicket.ui.components.entity.icontitle;
import org.apache.wicket.Component;
import org.apache.wicket.model.IModel;
+import org.apache.isis.core.commons.internal.exceptions._Exceptions;
import org.apache.isis.core.metamodel.facets.object.value.ValueFacet;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.viewer.wicket.model.models.EntityModelForReference;
import org.apache.isis.viewer.wicket.model.models.ObjectAdapterModel;
+import org.apache.isis.viewer.wicket.model.models.ScalarModel;
import org.apache.isis.viewer.wicket.ui.ComponentFactory;
import org.apache.isis.viewer.wicket.ui.ComponentFactoryAbstract;
import org.apache.isis.viewer.wicket.ui.ComponentType;
+import lombok.val;
+
/**
* {@link ComponentFactory} for {@link EntityIconAndTitlePanel}.
+ *
+ * @implNote Knows how to deal with {@link ObjectAdapterModel}. And for
+ * {@link ScalarModel} we have an adapter {@link EntityModelForReference}
+ * that implements {@link ObjectAdapterModel}, such that it can also deal
+ * with {@link ScalarModel}.
+ *
*/
public class EntityIconAndTitlePanelFactory extends ComponentFactoryAbstract {
@@ -57,24 +68,50 @@ public class EntityIconAndTitlePanelFactory extends ComponentFactoryAbstract {
@Override
protected ApplicationAdvice appliesTo(final IModel<?> model) {
- if (!(model instanceof ObjectAdapterModel)) {
- return ApplicationAdvice.DOES_NOT_APPLY;
- }
- final ObjectAdapterModel entityModel = (ObjectAdapterModel) model;
- final ObjectSpecification specification = entityModel.getTypeOfSpecification();
- final boolean isObject = specification.isNotCollection();
- final boolean isValue = specification.containsFacet(ValueFacet.class);
- boolean b = isObject && !isValue;
- if (!b) {
- return ApplicationAdvice.DOES_NOT_APPLY;
+
+ final ObjectSpecification spec;
+
+ if (model instanceof ObjectAdapterModel) {
+ spec = ((ObjectAdapterModel) model).getTypeOfSpecification();
+ } else if (model instanceof ScalarModel) {
+ spec = ((ScalarModel) model).getTypeOfSpecification();
+ } else {
+ return ApplicationAdvice.DOES_NOT_APPLY;
}
-
- return ApplicationAdvice.APPLIES;
+
+ return isScalarAndNotAValue(spec)
+ ? ApplicationAdvice.APPLIES
+ : ApplicationAdvice.DOES_NOT_APPLY;
}
@Override
public Component createComponent(final String id, final IModel<?> model) {
- final ObjectAdapterModel entityModel = (ObjectAdapterModel) model;
- return new EntityIconAndTitlePanel(id, entityModel);
+
+ final ObjectAdapterModel objectAdapterModel;
+
+ if (model instanceof ObjectAdapterModel) {
+ objectAdapterModel = (ObjectAdapterModel) model;
+ } else if (model instanceof ScalarModel) {
+ val scalarModel = (ScalarModel) model;
+
+ // effectively acts as an adapter from ScalarModel to ObjectAdapterModel
+ objectAdapterModel = new EntityModelForReference(scalarModel);
+ objectAdapterModel.setRenderingHint(scalarModel.getRenderingHint());
+ } else {
+ throw _Exceptions.unexpectedCodeReach();
+ }
+
+ return new EntityIconAndTitlePanel(id, objectAdapterModel);
+ }
+
+ // -- HELPER
+
+ private boolean isScalarAndNotAValue(ObjectSpecification spec) {
+ val isObject = spec.isNotCollection();
+ val isValue = spec.containsFacet(ValueFacet.class);
+ return isObject && !isValue;
}
+
+
+
}
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/reference/ReferencePanel.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/reference/ReferencePanel.java
index 2d761ff..d409952 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/reference/ReferencePanel.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/reference/ReferencePanel.java
@@ -37,9 +37,7 @@ import org.apache.isis.core.metamodel.facets.object.autocomplete.AutoCompleteFac
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.core.webapp.context.memento.ObjectMemento;
import org.apache.isis.viewer.common.model.object.ObjectUiModel.HasRenderingHints;
-import org.apache.isis.viewer.wicket.model.models.EntityModelForReference;
import org.apache.isis.viewer.wicket.model.models.ScalarModel;
-import org.apache.isis.viewer.wicket.ui.ComponentFactory;
import org.apache.isis.viewer.wicket.ui.ComponentType;
import org.apache.isis.viewer.wicket.ui.components.scalars.ScalarPanelAbstract2;
import org.apache.isis.viewer.wicket.ui.components.scalars.ScalarPanelSelect2Abstract;
@@ -251,18 +249,13 @@ public class ReferencePanel extends ScalarPanelSelect2Abstract {
if(componentForRegular != null) {
- final EntityModelForReference entityModelForLink = new EntityModelForReference(getModel());
-
- //XXX assuming, that scalar models don't have a context adapter
- //entityModelForLink.setContextAdapterIfAny(model.getContextAdapterIfAny());
- entityModelForLink.setRenderingHint(getModel().getRenderingHint());
-
- final ComponentFactory componentFactory =
- getComponentFactoryRegistry()
- .findComponentFactory(ComponentType.ENTITY_ICON_AND_TITLE, entityModelForLink);
- final Component component = componentFactory
- .createComponent(ComponentType.ENTITY_ICON_AND_TITLE.getWicketId(), entityModelForLink);
-
+ val scalarModel = getModel();
+
+ val componentFactory = getComponentFactoryRegistry()
+ .findComponentFactory(ComponentType.ENTITY_ICON_AND_TITLE, scalarModel);
+ val component = componentFactory
+ .createComponent(ComponentType.ENTITY_ICON_AND_TITLE.getWicketId(), scalarModel);
+
componentForRegular.addOrReplace(component);
boolean inlinePrompt = scalarModel.isInlinePrompt();