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 2015/11/06 08:16:32 UTC
[04/11] isis git commit: ISIS-1151: a default view can now be set
ISIS-1151: a default view can now be set
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/6839d188
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/6839d188
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/6839d188
Branch: refs/heads/master
Commit: 6839d1887c6c8d459415836acd0246ea22ecc045
Parents: 9aaeed0
Author: Sander Ginn <sa...@Sanders-MacBook-Pro.local>
Authored: Wed Nov 4 16:24:04 2015 +0100
Committer: Sander Ginn <sa...@Sanders-MacBook-Pro.local>
Committed: Wed Nov 4 16:24:04 2015 +0100
----------------------------------------------------------------------
.../selector/CollectionSelectorHelper.java | 73 ++++++++++++++------
1 file changed, 53 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/6839d188/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 a600923..6380e6b 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
@@ -21,12 +21,16 @@ package org.apache.isis.viewer.wicket.ui.components.collection.selector;
import java.io.Serializable;
import java.util.List;
+
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
+
import org.apache.wicket.Component;
import org.apache.wicket.model.IModel;
+
import org.apache.isis.applib.annotation.Render;
+import org.apache.isis.core.metamodel.facets.collections.collection.defaultview.DefaultViewFacet;
import org.apache.isis.core.metamodel.facets.members.render.RenderFacet;
import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
import org.apache.isis.viewer.wicket.model.hints.UiHintContainer;
@@ -73,15 +77,15 @@ public class CollectionSelectorHelper implements Serializable {
public int honourViewHintElseDefault(final Component component) {
// honour hints ...
final UiHintContainer hintContainer = getUiHintContainer(component);
- if(hintContainer != null) {
+ if (hintContainer != null) {
String viewStr = hintContainer.getHint(component, UIHINT_EVENT_VIEW_KEY);
- if(viewStr != null) {
+ if (viewStr != null) {
try {
int view = Integer.parseInt(viewStr);
- if(view >= 0 && view < componentFactories.size()) {
+ if (view >= 0 && view < componentFactories.size()) {
return view;
}
- } catch(NumberFormatException ex) {
+ } catch (NumberFormatException ex) {
// ignore
}
}
@@ -89,8 +93,8 @@ public class CollectionSelectorHelper implements Serializable {
// ... else default
int initialFactory = determineInitialFactory();
- if(hintContainer != null) {
- hintContainer.setHint(component, UIHINT_EVENT_VIEW_KEY, ""+initialFactory);
+ if (hintContainer != null) {
+ hintContainer.setHint(component, UIHINT_EVENT_VIEW_KEY, "" + initialFactory);
// don't broadcast (no AjaxRequestTarget, still configuring initial setup)
}
return initialFactory;
@@ -104,15 +108,24 @@ public class CollectionSelectorHelper implements Serializable {
* otherwise first factory.
*/
private int determineInitialFactory() {
- if(!hasRenderEagerlyFacet(model)) {
- for(int i=0; i<componentFactories.size(); i++) {
- if(componentFactories.get(i) instanceof CollectionContentsAsUnresolvedPanelFactory) {
+ if (!hasRenderEagerlyFacet(model)) {
+ for (int i = 0; i < componentFactories.size(); i++) {
+ if (componentFactories.get(i) instanceof CollectionContentsAsUnresolvedPanelFactory) {
+ return i;
+ }
+ }
+ }
+ if (hasDefaultViewFacet(model)) {
+ DefaultViewFacet defaultViewFacet = model.getCollectionMemento().getCollection().getFacet(DefaultViewFacet.class);
+ for (int i = 0; i < componentFactories.size(); i++) {
+ if (componentFactories.get(i).getName().equals(defaultViewFacet.value())) {
return i;
}
}
}
+
int ajaxTableIdx = findAjaxTable(componentFactories);
- if(ajaxTableIdx>=0) {
+ if (ajaxTableIdx >= 0) {
return ajaxTableIdx;
}
return 0;
@@ -124,7 +137,7 @@ public class CollectionSelectorHelper implements Serializable {
static List<ComponentFactory> orderAjaxTableToEnd(List<ComponentFactory> componentFactories) {
int ajaxTableIdx = findAjaxTable(componentFactories);
- if(ajaxTableIdx>=0) {
+ if (ajaxTableIdx >= 0) {
List<ComponentFactory> orderedFactories = Lists.newArrayList(componentFactories);
ComponentFactory ajaxTableFactory = orderedFactories.remove(ajaxTableIdx);
orderedFactories.add(ajaxTableFactory);
@@ -135,26 +148,21 @@ public class CollectionSelectorHelper implements Serializable {
}
private static int findAjaxTable(List<ComponentFactory> componentFactories) {
- for(int i=0; i<componentFactories.size(); i++) {
- if(componentFactories.get(i) instanceof CollectionContentsAsAjaxTablePanelFactory) {
+ for (int i = 0; i < componentFactories.size(); i++) {
+ if (componentFactories.get(i) instanceof CollectionContentsAsAjaxTablePanelFactory) {
return i;
}
}
return -1;
}
-
private static UiHintContainer getUiHintContainer(final Component component) {
return UiHintContainer.Util.hintContainerOf(component, EntityModel.class);
}
-
private static boolean hasRenderEagerlyFacet(IModel<?> model) {
- if(!(model instanceof EntityCollectionModel)) {
- return false;
- }
- final EntityCollectionModel entityCollectionModel = (EntityCollectionModel) model;
- if(!entityCollectionModel.isParented()) {
+ final EntityCollectionModel entityCollectionModel = toEntityCollectionModel(model);
+ if (entityCollectionModel == null) {
return false;
}
@@ -164,6 +172,31 @@ public class CollectionSelectorHelper implements Serializable {
return renderFacet != null && renderFacet.value() == Render.Type.EAGERLY;
}
+ private static boolean hasDefaultViewFacet(IModel<?> model) {
+ final EntityCollectionModel entityCollectionModel = toEntityCollectionModel(model);
+ if (entityCollectionModel == null) {
+ return false;
+ }
+
+ final OneToManyAssociation collection =
+ entityCollectionModel.getCollectionMemento().getCollection();
+ DefaultViewFacet defaultViewFacet = collection.getFacet(DefaultViewFacet.class);
+ return defaultViewFacet != null;
+ }
+
+ private static EntityCollectionModel toEntityCollectionModel(IModel<?> model) {
+ if (!(model instanceof EntityCollectionModel)) {
+ return null;
+ }
+
+ final EntityCollectionModel entityCollectionModel = (EntityCollectionModel) model;
+ if (!entityCollectionModel.isParented()) {
+ return null;
+ }
+
+ return entityCollectionModel;
+ }
+
//endregion
}