You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2018/01/24 15:16:37 UTC

[isis] 01/20: ISIS-1825: uses thread local to pass rendering context up to the scalar panel so that it, in turn, can correctly report on where it is being rendered.

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch ISIS-1569-replay-commands
in repository https://gitbox.apache.org/repos/asf/isis.git

commit d7d7cde2d44249b7a92cd14bbdc4ec7ddd2b79a1
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Jan 17 12:42:39 2018 +0000

    ISIS-1825: uses thread local to pass rendering context up to the scalar panel so that it, in turn, can correctly report on where it is being rendered.
---
 .../ajaxtable/IsisAjaxFallbackDataTable.java       | 15 +++++++++++++-
 .../components/scalars/ScalarPanelAbstract2.java   | 24 ++++++++++++++++------
 2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxFallbackDataTable.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxFallbackDataTable.java
index 39de90f..9838d8b 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxFallbackDataTable.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxFallbackDataTable.java
@@ -39,6 +39,7 @@ import org.apache.wicket.util.lang.Generics;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.viewer.wicket.model.hints.UiHintContainer;
+import org.apache.isis.viewer.wicket.model.models.EntityCollectionModel;
 import org.apache.isis.viewer.wicket.model.models.EntityModel;
 import org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable.columns.ObjectAdapterToggleboxColumn;
 import org.apache.isis.viewer.wicket.ui.util.CssClassAppender;
@@ -86,6 +87,13 @@ public class IsisAjaxFallbackDataTable<T, S> extends DataTable<T, S> {
         addBottomToolbar(new NoRecordsToolbar(this));
     }
 
+    private final static ThreadLocal<EntityCollectionModel> entityCollectionModel = new ThreadLocal<>();
+
+    public static Boolean isParented() {
+        EntityCollectionModel entityCollectionModel = IsisAjaxFallbackDataTable.entityCollectionModel.get();
+        return entityCollectionModel != null ? entityCollectionModel.isParented() : null;
+    }
+
     @Override
     protected void onConfigure() {
         super.onConfigure();
@@ -93,7 +101,12 @@ public class IsisAjaxFallbackDataTable<T, S> extends DataTable<T, S> {
 
     @Override
     protected void onBeforeRender() {
-        super.onBeforeRender();
+        try {
+            entityCollectionModel.set(dataProvider.getEntityCollectionModel());
+            super.onBeforeRender();
+        } finally {
+            entityCollectionModel.set(null);
+        }
     }
 
     @Override
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/ScalarPanelAbstract2.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/ScalarPanelAbstract2.java
index 3f16905..695f971 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/ScalarPanelAbstract2.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/ScalarPanelAbstract2.java
@@ -59,6 +59,7 @@ import org.apache.isis.viewer.wicket.model.models.ScalarModel;
 import org.apache.isis.viewer.wicket.ui.ComponentType;
 import org.apache.isis.viewer.wicket.ui.components.actionmenu.entityactions.AdditionalLinksPanel;
 import org.apache.isis.viewer.wicket.ui.components.actionmenu.entityactions.LinkAndLabelUtil;
+import org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable.IsisAjaxFallbackDataTable;
 import org.apache.isis.viewer.wicket.ui.components.property.PropertyEditFormPanel;
 import org.apache.isis.viewer.wicket.ui.components.property.PropertyEditPanel;
 import org.apache.isis.viewer.wicket.ui.components.propertyheader.PropertyEditPromptHeaderPanel;
@@ -536,17 +537,28 @@ public abstract class ScalarPanelAbstract2 extends PanelAbstract<ScalarModel> im
 		case STANDALONE_TITLE_COLUMN:
 			return Where.STANDALONE_TABLES;
 		case PROPERTY_COLUMN:
-			final ObjectAdapter parentAdapter =
-			 	scalarModel.getParentEntityModel().load(AdapterManager.ConcurrencyChecking.NO_CHECK);
-			final boolean parented = parentAdapter.isParentedCollection();
-			return parented ? Where.PARENTED_TABLES : Where.STANDALONE_TABLES;
-		case REGULAR:
+            // this is pretty hacky, but can't (for the moment) think of another way to
+            // pass through the context other than a thread-local
+            Boolean parented = IsisAjaxFallbackDataTable.isParented();
+            if(parented == null) {
+                // this code is wrong (but kept in because it's what we had before) ...
+                // the parentEntityModel *isn't* the "parented" collection (eg Parent#child, a java.util.List),
+                // rather it is the parent of this field (the Child object itself).
+                EntityModel parentEntityModel = scalarModel.getParentEntityModel();
+                final ObjectAdapter parentAdapter =
+                     parentEntityModel.load(AdapterManager.ConcurrencyChecking.NO_CHECK);
+                parented = parentAdapter.isParentedCollection();
+            }
+            // this bit is correct, I think; earlier in the stack trace is the IsisAjaxFallbackDataTable which
+            // tells us whether it's being used to render a parented collection or a standalone collection.
+            return parented ? Where.PARENTED_TABLES : Where.STANDALONE_TABLES;
+
+        case REGULAR:
 			return Where.OBJECT_FORMS;
 		default:
 			throw new RuntimeException("unmatched case "+scalarModel.getRenderingHint());
 		}
     }
-    
 
     // ///////////////////////////////////////////////////////////////////
 

-- 
To stop receiving notification emails like this one, please contact
danhaywood@apache.org.