ISIS-1239, ISIS-1324, ISIS-1328: multi-select for standalone collections was 
broken, now fixed.

Issue was that earlier work moved entire responsibility for being the 
"UiHintContainer" onto the EntityModel, on the basis that only entities can 
store hints over time.  However, the selector drop-down for standalone 
collections also was storying the hint on the UiHintContainer, which previously 
was also supported by (standalone) EntityCollectionModel.  This meant that the 
hint got lost.  Fix for that is to allow the IsisUiHintEvent to also directly 
hold the hint info.

In addition, the algorithm for selecting the default view was broken for 
standalone collections; should default to "table" if a standalone and there is 
no other metadata available.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/4672aefa
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/4672aefa
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/4672aefa

Branch: refs/heads/master
Commit: 4672aefa73db3b10612c52c8d8c6fd7a117398d2
Parents: 1907cb6b
Author: Dan Haywood <d...@haywood-associates.co.uk>
Authored: Thu Mar 17 11:28:21 2016 +0000
Committer: Dan Haywood <d...@haywood-associates.co.uk>
Committed: Thu Mar 17 11:28:21 2016 +0000

----------------------------------------------------------------------
 .../wicket/model/hints/IsisUiHintEvent.java     | 27 ++++++++
 .../model/models/EntityCollectionModel.java     |  4 +-
 .../selector/CollectionSelectorHelper.java      | 38 +++++++----
 .../selector/CollectionSelectorPanel.java       | 18 +++--
 .../CollectionContentsMultipleViewsPanel.java   | 69 +++++++++++---------
 5 files changed, 107 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/4672aefa/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/hints/IsisUiHintEvent.java
----------------------------------------------------------------------
diff --git 
a/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/hints/IsisUiHintEvent.java
 
b/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/hints/IsisUiHintEvent.java
index a5ddbe7..d472559 100644
--- 
a/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/hints/IsisUiHintEvent.java
+++ 
b/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/hints/IsisUiHintEvent.java
@@ -16,6 +16,7 @@
  */
 package org.apache.isis.viewer.wicket.model.hints;
 
+import org.apache.wicket.Component;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 
 /**
@@ -24,15 +25,41 @@ import org.apache.wicket.ajax.AjaxRequestTarget;
 public class IsisUiHintEvent extends IsisEventLetterAbstract {
     
     private final UiHintContainer uiHintContainer;
+    private final Component component;
+    private final String hintKey;
+    private final String hintValue;
 
     public IsisUiHintEvent(UiHintContainer uiHintContainer, AjaxRequestTarget 
target) {
+        this(uiHintContainer, null, null, null, target);
+    }
+
+    public IsisUiHintEvent(
+            final Component component,
+            final String hintKey,
+            final String hintValue,
+            final AjaxRequestTarget target) {
+        this(null, component, hintKey, hintValue, target);
+    }
+
+    public IsisUiHintEvent(
+            final UiHintContainer uiHintContainer,
+            final Component component,
+            final String hintKey,
+            final String hintValue,
+            final AjaxRequestTarget target) {
         super(target);
         this.uiHintContainer = uiHintContainer;
+        this.component = component;
+        this.hintKey = hintKey;
+        this.hintValue = hintValue;
     }
 
     public UiHintContainer getUiHintContainer() {
         return uiHintContainer;
     }
 
+    public String hintFor(Component component, String hintKey) {
+        return this.component == component && this.hintKey == hintKey ? 
hintValue : null;
+    }
 }
 

http://git-wip-us.apache.org/repos/asf/isis/blob/4672aefa/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java
----------------------------------------------------------------------
diff --git 
a/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java
 
b/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java
index 79b34b3..f09f190 100644
--- 
a/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java
+++ 
b/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java
@@ -376,7 +376,9 @@ public class EntityCollectionModel extends 
ModelAbstract<List<ObjectAdapter>> im
      * Populated only if {@link Type#PARENTED}.
      */
     public CollectionLayoutData getLayoutData() {
-        return (CollectionLayoutData) entityModel.getLayoutMetadata();
+        return entityModel != null
+                ? (CollectionLayoutData) entityModel.getLayoutMetadata()
+                : null;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/isis/blob/4672aefa/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collection/selector/CollectionSelectorHelper.java
----------------------------------------------------------------------
diff --git 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collection/selector/CollectionSelectorHelper.java
 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collection/selector/CollectionSelectorHelper.java
index 7e2d135..a177b82 100644
--- 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collection/selector/CollectionSelectorHelper.java
+++ 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collection/selector/CollectionSelectorHelper.java
@@ -69,10 +69,11 @@ public class CollectionSelectorHelper implements 
Serializable {
         this.model = model;
         this.componentFactories = 
locateComponentFactories(componentFactoryRegistry);
         this.selectedItemSessionAttribute =
-                selectedItemSessionAttribute != null
-                        ? selectedItemSessionAttribute
-                        : ComponentKey.<String>noop();
-        
model.getEntityModel().putSessionAttribute(selectedItemSessionAttribute);
+                selectedItemSessionAttribute != null ? 
selectedItemSessionAttribute : ComponentKey.<String>noop();
+        final EntityModel entityModel = model.getEntityModel();
+        if(entityModel != null) {
+            entityModel.putSessionAttribute(this.selectedItemSessionAttribute);
+        }
     }
 
     private List<ComponentFactory> 
locateComponentFactories(ComponentFactoryRegistry componentFactoryRegistry) {
@@ -146,7 +147,7 @@ public class CollectionSelectorHelper implements 
Serializable {
         }
 
         // else honour @CollectionLayout#renderEagerly
-        return hasRenderEagerlyFacet(model)
+        return hasRenderEagerlyFacet(model) || model.isStandalone()
                 ? CollectionContentsAsAjaxTablePanelFactory.NAME
                 : CollectionContentsHiddenPanelFactory.NAME;
 
@@ -219,17 +220,32 @@ public class CollectionSelectorHelper implements 
Serializable {
     }
 
     public ComponentFactory find(final String selected) {
+        ComponentFactory componentFactory = doFind(selected);
+        if (componentFactory != null) {
+            return componentFactory;
+        }
+
+        final EntityCollectionModel entityCollectionModel = model;
+            final String fallback;
+        fallback = entityCollectionModel.isParented()
+                ? CollectionContentsHiddenPanelFactory.NAME
+                : CollectionContentsAsAjaxTablePanelFactory.NAME;
+        componentFactory = doFind(fallback);
+        if(componentFactory == null) {
+            throw new IllegalStateException(String.format(
+                    "Could not locate '%s' (as the fallback collection panel)",
+                    fallback));
+        }
+        return componentFactory;
+    }
+
+    private ComponentFactory doFind(final String selected) {
         for (ComponentFactory componentFactory : componentFactories) {
             if(selected.equals(componentFactory.getName())) {
                 return componentFactory;
             }
         }
-        if(CollectionContentsHiddenPanelFactory.NAME.equals(selected)) {
-            throw new IllegalStateException(String.format(
-                    "Could not locate '%s' (as the fallback collection panel)",
-                    CollectionContentsHiddenPanelFactory.NAME));
-        }
-        return find(CollectionContentsHiddenPanelFactory.NAME); // fallback
+        return null;
     }
 
     public int lookup(final String view) {

http://git-wip-us.apache.org/repos/asf/isis/blob/4672aefa/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collection/selector/CollectionSelectorPanel.java
----------------------------------------------------------------------
diff --git 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collection/selector/CollectionSelectorPanel.java
 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collection/selector/CollectionSelectorPanel.java
index 2b401fa..ecd1019 100644
--- 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collection/selector/CollectionSelectorPanel.java
+++ 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collection/selector/CollectionSelectorPanel.java
@@ -160,8 +160,8 @@ public class CollectionSelectorPanel extends 
PanelAbstract<EntityCollectionModel
                     Label viewItemIcon = new Label(ID_VIEW_ITEM_ICON, "");
                     link.add(viewItemIcon);
 
-                    boolean isEnabled = componentFactory != 
CollectionSelectorPanel.this.selectedComponentFactory;
-                    if (!isEnabled) {
+                    final boolean selected = componentFactory == 
CollectionSelectorPanel.this.selectedComponentFactory;
+                    if (selected) {
                         viewButtonTitle.setDefaultModel(title);
                         IModel<String> cssClass = 
cssClassFor(componentFactory, viewButtonIcon);
                         viewButtonIcon.add(AttributeModifier.replace("class", 
"ViewLinkItem " + cssClass.getObject()));
@@ -213,12 +213,16 @@ public class CollectionSelectorPanel extends 
PanelAbstract<EntityCollectionModel
 
 
     protected void setViewHintAndBroadcast(String viewName, AjaxRequestTarget 
target) {
-        final UiHintContainer uiHintContainer = 
getUiHintContainer(getModel().isParented()? EntityModel.class: 
EntityCollectionModel.class);
-        if(uiHintContainer == null) {
-            return;
+        final CollectionSelectorPanel component = CollectionSelectorPanel.this;
+        final IsisUiHintEvent hintEvent;
+        if(getModel().isParented()) {
+            final UiHintContainer uiHintContainer = 
getUiHintContainer(EntityModel.class);
+            uiHintContainer.setHint(component, 
CollectionSelectorHelper.UIHINT_EVENT_VIEW_KEY, viewName);
+            hintEvent = new IsisUiHintEvent(uiHintContainer, target);
+        } else {
+            hintEvent = new IsisUiHintEvent(component, 
CollectionSelectorHelper.UIHINT_EVENT_VIEW_KEY, viewName, target);
         }
-        uiHintContainer.setHint(CollectionSelectorPanel.this, 
CollectionSelectorHelper.UIHINT_EVENT_VIEW_KEY, viewName);
-        send(getPage(), Broadcast.EXACT, new IsisUiHintEvent(uiHintContainer, 
target));
+        send(getPage(), Broadcast.EXACT, hintEvent);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/isis/blob/4672aefa/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/multiple/CollectionContentsMultipleViewsPanel.java
----------------------------------------------------------------------
diff --git 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/multiple/CollectionContentsMultipleViewsPanel.java
 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/multiple/CollectionContentsMultipleViewsPanel.java
index a5ef9c5..f22ebe3 100644
--- 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/multiple/CollectionContentsMultipleViewsPanel.java
+++ 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/multiple/CollectionContentsMultipleViewsPanel.java
@@ -94,11 +94,14 @@ public class CollectionContentsMultipleViewsPanel
 
         final List<ComponentFactory> componentFactories = 
selectorHelper.getComponentFactories();
 
-        final CollectionSelectorPanel selectorDropdownPanelIfAny = 
CollectionSelectorProvider.Util.getCollectionSelectorProvider(this);
+        final CollectionSelectorPanel selectorDropdownPanelIfAny =
+                
CollectionSelectorProvider.Util.getCollectionSelectorProvider(this);
         final String selected;
-        selected = selectorDropdownPanelIfAny != null
-                ? 
selectorHelper.honourViewHintElseDefault(selectorDropdownPanelIfAny)
-                : componentFactories.get(0).getName();
+        if (selectorDropdownPanelIfAny != null) {
+            selected = 
selectorHelper.honourViewHintElseDefault(selectorDropdownPanelIfAny);
+        } else {
+            selected = componentFactories.get(0).getName();
+        }
 
         // create all, hide the one not selected
         int i = 0;
@@ -146,42 +149,48 @@ public class CollectionContentsMultipleViewsPanel
         if(uiHintEvent == null) {
             return;
         }
-        final UiHintContainer uiHintContainer = 
uiHintEvent.getUiHintContainer();
-
-        int underlyingViewNum = 0;
         final CollectionSelectorPanel selectorDropdownPanel = 
CollectionSelectorProvider.Util.getCollectionSelectorProvider(this);
         if(selectorDropdownPanel == null) {
             // not expected, because this event shouldn't be called.
             // but no harm in simply returning...
             return;
         }
-        String viewStr = uiHintContainer.getHint(selectorDropdownPanel, 
UIHINT_VIEW);
-
-        if(viewStr != null) {
-            try {
-                underlyingViewNum = selectorHelper.lookup(viewStr);
-
-                final EntityCollectionModel dummyModel = getModel().asDummy();
-                for(int i=0; i<MAX_NUM_UNDERLYING_VIEWS; i++) {
-                    final Component component = underlyingViews[i];
-                    if(component == null) {
-                        continue;
-                    }
-                    final boolean isSelected = i == underlyingViewNum;
-                    applyCssVisibility(component, isSelected);
-                    component.setDefaultModel(isSelected? getModel(): 
dummyModel);
-                }
 
-                this.selectedComponent = underlyingViews[underlyingViewNum];
+        // try to obtain hint directly from hint container (EntityModel)
+        String viewStr = null;
+        final UiHintContainer uiHintContainer = 
uiHintEvent.getUiHintContainer();
+        if(uiHintContainer != null) {
+            viewStr = uiHintContainer.getHint(selectorDropdownPanel, 
UIHINT_VIEW);
+        }
 
-                final AjaxRequestTarget target = uiHintEvent.getTarget();
-                if(target != null) {
-                    target.add(this, selectorDropdownPanel);
-                }
+        // failing that, directly from the UiHintEvent itself (for standalone 
collections, which have no hint container)
+        if(viewStr == null) {
+            viewStr = uiHintEvent.hintFor(selectorDropdownPanel, UIHINT_VIEW);
+        }
+
+        // give up
+        if (viewStr == null) {
+            return;
+        }
 
-            } catch(NumberFormatException ex) {
-                // ignore
+        int underlyingViewNum = selectorHelper.lookup(viewStr);
+
+        final EntityCollectionModel dummyModel = getModel().asDummy();
+        for(int i=0; i<MAX_NUM_UNDERLYING_VIEWS; i++) {
+            final Component component = underlyingViews[i];
+            if(component == null) {
+                continue;
             }
+            final boolean isSelected = i == underlyingViewNum;
+            applyCssVisibility(component, isSelected);
+            component.setDefaultModel(isSelected? getModel(): dummyModel);
+        }
+
+        this.selectedComponent = underlyingViews[underlyingViewNum];
+
+        final AjaxRequestTarget target = uiHintEvent.getTarget();
+        if(target != null) {
+            target.add(this, selectorDropdownPanel);
         }
     }
 

Reply via email to