ISIS-993: working towards factoring out a PropertyGroup component.

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

Branch: refs/heads/ISIS-993
Commit: 205cf8539457f8294daa723301e75b615ca0de89
Parents: cddf255
Author: Dan Haywood <d...@haywood-associates.co.uk>
Authored: Fri Jan 15 08:58:06 2016 +0000
Committer: Dan Haywood <d...@haywood-associates.co.uk>
Committed: Mon Jan 25 15:06:07 2016 +0000

----------------------------------------------------------------------
 .../viewer/wicket/model/models/EntityModel.java |  20 +++
 .../components/entity/column/EntityColumn.html  |  28 +++--
 .../components/entity/column/EntityColumn.java  | 126 ++++++++++++++-----
 .../propsandcolls/EntityPropsAndCollsForm.java  |   9 +-
 .../propsandcolls/EntityPropsAndCollsPanel.html |  10 +-
 .../propsandcolls/EntityPropsAndCollsPanel.java |   6 +-
 6 files changed, 141 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/205cf853/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java
----------------------------------------------------------------------
diff --git 
a/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java
 
b/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java
index 4968208..2e575b8 100644
--- 
a/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java
+++ 
b/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityModel.java
@@ -32,6 +32,7 @@ import 
org.apache.wicket.request.mapper.parameter.PageParameters;
 import org.apache.isis.applib.annotation.BookmarkPolicy;
 import org.apache.isis.applib.layout.v1_0.ColumnMetadata;
 import org.apache.isis.applib.layout.v1_0.ColumnMetadata.Hint;
+import org.apache.isis.applib.layout.v1_0.PropertyGroupMetadata;
 import org.apache.isis.applib.layout.v1_0.TabGroupMetadata;
 import org.apache.isis.applib.layout.v1_0.TabMetadata;
 import org.apache.isis.applib.services.memento.MementoService.Memento;
@@ -722,6 +723,25 @@ public class EntityModel extends 
BookmarkableModel<ObjectAdapter> {
         scopedSessionAttribute.set(value);
     }
 
+
+    private PropertyGroupMetadata propertyGroupMetadata;
+
+    public PropertyGroupMetadata getPropertyGroupMetadata() {
+        return propertyGroupMetadata;
+    }
+
+    /**
+     * Returns a new copy that SHARES the property scalar models (for edit 
form).
+     */
+    public EntityModel cloneWithPropertyGroupMetadata(
+            final PropertyGroupMetadata propertyGroupMetadata) {
+        final EntityModel entityModel = new EntityModel(this.adapterMemento, 
this.propertyScalarModels);
+        entityModel.propertyGroupMetadata = propertyGroupMetadata;
+        return entityModel;
+    }
+
+
+
     // //////////////////////////////////////////////////////////
     // equals, hashCode
     // //////////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/isis/blob/205cf853/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/column/EntityColumn.html
----------------------------------------------------------------------
diff --git 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/column/EntityColumn.html
 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/column/EntityColumn.html
index 43c76da..cab6833 100644
--- 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/column/EntityColumn.html
+++ 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/column/EntityColumn.html
@@ -22,22 +22,24 @@
         <wicket:panel>
             <div class="columnMembers">
                 <div class="inputFormTable properties">
-                    <fieldset wicket:id="memberGroup" class="memberGroup 
myBlockContainer">
-                        <div class="panel panel-default">
-                            <div class="panel-heading">
-                                <span wicket:id="memberGroupName" 
class="panel-title">[group name]</span>
-                                <div class="pull-right additionalLinks">
-                                    <div 
wicket:id="associatedActionLinksPanel"></div>
-                                    <div 
wicket:id="associatedActionLinksPanelDropDown"></div>
+                    <div wicket:id="memberGroup">
+                        <fieldset class="memberGroup myBlockContainer">
+                            <div class="panel panel-default">
+                                <div class="panel-heading">
+                                    <span wicket:id="memberGroupName" 
class="panel-title">[group name]</span>
+                                    <div class="pull-right additionalLinks">
+                                        <div 
wicket:id="associatedActionLinksPanel"></div>
+                                        <div 
wicket:id="associatedActionLinksPanelDropDown"></div>
+                                    </div>
                                 </div>
-                            </div>
-                            <div class="properties panel-body">
-                                <div wicket:id="properties">
-                                    <div wicket:id="property" 
class="property">[property]</div>
+                                <div class="properties panel-body">
+                                    <div wicket:id="properties">
+                                        <div wicket:id="property" 
class="property">[property]</div>
+                                    </div>
                                 </div>
                             </div>
-                        </div>
-                    </fieldset>
+                        </fieldset>
+                    </div>
                 </div>
                 <div wicket:id="collections"></div>
             </div>

http://git-wip-us.apache.org/repos/asf/isis/blob/205cf853/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/column/EntityColumn.java
----------------------------------------------------------------------
diff --git 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/column/EntityColumn.java
 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/column/EntityColumn.java
index 501a5ff..147d276 100644
--- 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/column/EntityColumn.java
+++ 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/column/EntityColumn.java
@@ -18,13 +18,16 @@
  */
 package org.apache.isis.viewer.wicket.ui.components.entity.column;
 
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
+import com.google.common.base.Function;
 import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 
-import org.apache.wicket.Component;
 import org.apache.wicket.MarkupContainer;
 import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.basic.Label;
@@ -33,6 +36,7 @@ import org.apache.wicket.markup.repeater.RepeatingView;
 import org.apache.isis.applib.annotation.ActionLayout;
 import org.apache.isis.applib.layout.v1_0.ColumnMetadata;
 import org.apache.isis.applib.layout.v1_0.PropertyGroupMetadata;
+import org.apache.isis.applib.layout.v1_0.PropertyLayoutMetadata;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import 
org.apache.isis.core.metamodel.facets.object.membergroups.MemberGroupLayoutFacet;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
@@ -113,54 +117,112 @@ public class EntityColumn extends 
PanelAbstract<EntityModel> implements UiHintPa
         final ObjectAdapter adapter = entityModel.getObject();
         final ObjectSpecification objSpec = adapter.getSpecification();
 
-        final Map<String, List<ObjectAssociation>> associationsByGroup = 
PropUtil
-                .propertiesByMemberOrder(adapter);
-        final List<String> groupNames = columnMetaDataIfAny != null
-                ? FluentIterable
-                .from(columnMetaDataIfAny.getPropertyGroups())
-                .transform(PropertyGroupMetadata.Util.nameOf())
-                .toList()
-                : ObjectSpecifications.orderByMemberGroups(objSpec, 
associationsByGroup.keySet(), hint);
+        final Map<String, List<ObjectAssociation>> associationsByGroup = 
PropUtil.propertiesByMemberOrder(adapter);
 
         final RepeatingView memberGroupRv = new RepeatingView(ID_MEMBER_GROUP);
         markupContainer.add(memberGroupRv);
 
+        final ImmutableMap<String, PropertyGroupMetadata> 
propertyGroupMetadataByNameIfAny =
+                columnMetaDataIfAny != null
+                    ? 
Maps.uniqueIndex(columnMetaDataIfAny.getPropertyGroups(), 
PropertyGroupMetadata.Util.nameOf())
+                    : null;
+
+        final Collection<String> groupNames =
+                propertyGroupMetadataByNameIfAny != null
+                    ? propertyGroupMetadataByNameIfAny.keySet()
+                    : ObjectSpecifications.orderByMemberGroups(objSpec, 
associationsByGroup.keySet(), hint);
+
         for(final String groupName: groupNames) {
+
             final List<ObjectAssociation> associationsInGroup = 
associationsByGroup.get(groupName);
             if(associationsInGroup==null) {
                 continue;
             }
 
-            final WebMarkupContainer memberGroupRvContainer = new 
WebMarkupContainer(memberGroupRv.newChildId());
+            final PropertyGroupMetadata propertyGroupMetadata;
+            if (propertyGroupMetadataByNameIfAny != null) {
+                propertyGroupMetadata = 
propertyGroupMetadataByNameIfAny.get(groupName);
+            }
+            else {
+                propertyGroupMetadata = new PropertyGroupMetadata(groupName);
+                propertyGroupMetadata.setProperties(
+                        FluentIterable
+                                .from(associationsInGroup)
+                                .transform(
+                                    new Function<ObjectAssociation, 
PropertyLayoutMetadata>() {
+                                        @Override
+                                        public PropertyLayoutMetadata 
apply(final ObjectAssociation assoc) {
+                                            return new 
PropertyLayoutMetadata(assoc.getId());
+                                        }
+                                    }).toList());
+            }
+
+            if(propertyGroupMetadata.getProperties().isEmpty()) {
+                continue;
+            }
+
+            final String id = memberGroupRv.newChildId();
+
+            final EntityModel entityModelWithHints = 
entityModel.cloneWithPropertyGroupMetadata(propertyGroupMetadata);
+            final WebMarkupContainer memberGroupRvContainer = 
newPropertyGroup(id, entityModelWithHints);
+
             memberGroupRv.add(memberGroupRvContainer);
-            memberGroupRvContainer.add(new Label(ID_MEMBER_GROUP_NAME, 
groupName));
+        }
+    }
 
-            final List<LinkAndLabel> memberGroupActions = Lists.newArrayList();
+    private WebMarkupContainer newPropertyGroup(
+            final String id,
+            final EntityModel entityModel) {
+
+        final PropertyGroupMetadata propertyGroupMetadata = 
entityModel.getPropertyGroupMetadata();
+        String groupName = propertyGroupMetadata.getName();
 
-            final RepeatingView propertyRv = new RepeatingView(ID_PROPERTIES);
-            memberGroupRvContainer.add(propertyRv);
+        final ObjectAdapter adapter = entityModel.getObject();
 
-            @SuppressWarnings("unused")
-            Component component;
-            for (final ObjectAssociation association : associationsInGroup) {
-                final WebMarkupContainer propertyRvContainer = new 
UiHintPathSignificantWebMarkupContainer(propertyRv.newChildId());
-                propertyRv.add(propertyRvContainer);
 
-                addPropertyToForm(entityModel, (OneToOneAssociation) 
association, propertyRvContainer, memberGroupActions);
-            }
+        final WebMarkupContainer memberGroupRvContainer = new 
WebMarkupContainer(id);
+
+        memberGroupRvContainer.add(new Label(ID_MEMBER_GROUP_NAME, groupName));
 
-            final List<LinkAndLabel> actionsPanel = 
LinkAndLabel.positioned(memberGroupActions, ActionLayout.Position.PANEL);
-            final List<LinkAndLabel> actionsPanelDropDown = 
LinkAndLabel.positioned(memberGroupActions, 
ActionLayout.Position.PANEL_DROPDOWN);
-
-            AdditionalLinksPanel.addAdditionalLinks(
-                    memberGroupRvContainer, ID_ASSOCIATED_ACTION_LINKS_PANEL,
-                    actionsPanel,
-                    AdditionalLinksPanel.Style.INLINE_LIST);
-            AdditionalLinksPanel.addAdditionalLinks(
-                    memberGroupRvContainer, 
ID_ASSOCIATED_ACTION_LINKS_PANEL_DROPDOWN,
-                    actionsPanelDropDown,
-                    AdditionalLinksPanel.Style.DROPDOWN);
+        final List<LinkAndLabel> memberGroupActions = Lists.newArrayList();
+
+        final RepeatingView propertyRv = new RepeatingView(ID_PROPERTIES);
+        memberGroupRvContainer.add(propertyRv);
+
+
+        final List<PropertyLayoutMetadata> properties = 
propertyGroupMetadata.getProperties();
+        for (PropertyLayoutMetadata property : properties) {
+            final ObjectAssociation association = 
adapter.getSpecification().getAssociation(property.getId());
+
+            final WebMarkupContainer propertyRvContainer = new 
UiHintPathSignificantWebMarkupContainer(propertyRv.newChildId());
+            propertyRv.add(propertyRvContainer);
+
+            addPropertyToForm(entityModel, (OneToOneAssociation) association, 
propertyRvContainer, memberGroupActions);
         }
+
+// final Map<String, List<ObjectAssociation>> associationsByGroup = 
PropUtil.propertiesByMemberOrder(adapter);
+// final List<ObjectAssociation> associationsInGroup = 
associationsByGroup.get(groupName);
+//        @SuppressWarnings("unused")
+//        Component component;
+//        for (final ObjectAssociation association : associationsInGroup) {
+//            final WebMarkupContainer propertyRvContainer = new 
UiHintPathSignificantWebMarkupContainer(propertyRv.newChildId());
+//            propertyRv.add(propertyRvContainer);
+//
+//            addPropertyToForm(entityModel, (OneToOneAssociation) 
association, propertyRvContainer, memberGroupActions);
+//        }
+
+        final List<LinkAndLabel> actionsPanel = 
LinkAndLabel.positioned(memberGroupActions, ActionLayout.Position.PANEL);
+        final List<LinkAndLabel> actionsPanelDropDown = 
LinkAndLabel.positioned(memberGroupActions, 
ActionLayout.Position.PANEL_DROPDOWN);
+
+        AdditionalLinksPanel.addAdditionalLinks(
+                memberGroupRvContainer, ID_ASSOCIATED_ACTION_LINKS_PANEL,
+                actionsPanel,
+                AdditionalLinksPanel.Style.INLINE_LIST);
+        AdditionalLinksPanel.addAdditionalLinks(
+                memberGroupRvContainer, 
ID_ASSOCIATED_ACTION_LINKS_PANEL_DROPDOWN,
+                actionsPanelDropDown,
+                AdditionalLinksPanel.Style.DROPDOWN);
+        return memberGroupRvContainer;
     }
 
     private void addCollectionsIfRequired(

http://git-wip-us.apache.org/repos/asf/isis/blob/205cf853/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsForm.java
----------------------------------------------------------------------
diff --git 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsForm.java
 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsForm.java
index 22c0cf9..c414a22 100644
--- 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsForm.java
+++ 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsForm.java
@@ -86,7 +86,8 @@ public class EntityPropsAndCollsForm extends 
FormAbstract<ObjectAdapter> impleme
     private static final String ID_LEFT_COLUMN = "leftColumn";
     private static final String ID_MIDDLE_COLUMN = "middleColumn";
     private static final String ID_RIGHT_COLUMN = "rightColumn";
-    
+
+    private static final String ID_ENTITY_COLUMN = "entityColumn";
     private static final String ID_ENTITY_COLLECTIONS = "entityCollections";
     private static final String ID_ENTITY_COLLECTIONS_OVERFLOW = 
"entityCollectionsOverflow";
 
@@ -148,9 +149,7 @@ public class EntityPropsAndCollsForm extends 
FormAbstract<ObjectAdapter> impleme
         add(leftColumn);
 
         if(columnSpans.getLeft() > 0) {
-
             addPropertiesAndCollections(leftColumn, entityModel, 
tabMetaDataIfAny, Hint.LEFT);
-
         } else {
             Components.permanentlyHide(this, ID_LEFT_COLUMN);
         }
@@ -160,7 +159,6 @@ public class EntityPropsAndCollsForm extends 
FormAbstract<ObjectAdapter> impleme
         if(columnSpans.getMiddle() > 0) {
             middleColumn = new WebMarkupContainer(ID_MIDDLE_COLUMN);
             add(middleColumn);
-
             addPropertiesAndCollections(middleColumn, entityModel, 
tabMetaDataIfAny, Hint.MIDDLE);
         } else {
             middleColumn = null;
@@ -172,7 +170,6 @@ public class EntityPropsAndCollsForm extends 
FormAbstract<ObjectAdapter> impleme
         if(columnSpans.getRight() > 0) {
             rightColumn = new WebMarkupContainer(ID_RIGHT_COLUMN);
             add(rightColumn);
-
             addPropertiesAndCollections(rightColumn, entityModel, 
tabMetaDataIfAny, Hint.RIGHT);
         } else {
             rightColumn = null;
@@ -243,7 +240,7 @@ public class EntityPropsAndCollsForm extends 
FormAbstract<ObjectAdapter> impleme
         final EntityModel entityModelWithHints = 
entityModel.cloneWithColumnMetadata(columnMetaDataIfAny, hint);
 
         final EntityColumn columnMembers =
-                new EntityColumn("entityMembers", entityModelWithHints);
+                new EntityColumn(ID_ENTITY_COLUMN, entityModelWithHints);
         markupContainer.add(columnMembers);
     }
 

http://git-wip-us.apache.org/repos/asf/isis/blob/205cf853/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsPanel.html
----------------------------------------------------------------------
diff --git 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsPanel.html
 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsPanel.html
index e204c12..449f18d 100644
--- 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsPanel.html
+++ 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsPanel.html
@@ -21,10 +21,11 @@
     <body>
         <wicket:panel>
             <div class="entityPropertiesPanel entityPropertiesComponentType">
-                <form wicket:id="entityProperties" class="inputForm" 
role="form">
+                <!-- EntityPropsAndCollsForm:start -->
+                <form wicket:id="entityForm" class="inputForm" role="form">
                     <div class="row">
                         <div wicket:id="leftColumn">
-                            <div wicket:id="entityMembers"/>
+                            <div wicket:id="entityColumn"/>
                             <div class="feedbackPanel">
                                 <span wicket:id="feedback"></span>
                             </div>
@@ -35,10 +36,10 @@
                             </div>
                         </div>
                         <div wicket:id="middleColumn">
-                            <div wicket:id="entityMembers"/>
+                            <div wicket:id="entityColumn"/>
                         </div>
                         <div wicket:id="rightColumn">
-                            <div wicket:id="entityMembers"/>
+                            <div wicket:id="entityColumn"/>
                         </div>
                         <div wicket:id="entityCollections"></div>
                     </div>
@@ -46,6 +47,7 @@
                         <div wicket:id="entityCollectionsOverflow"></div>
                     </div>
                 </form>
+                <!-- EntityPropsAndCollsForm:end -->
             </div>
         </wicket:panel>
     </body>

http://git-wip-us.apache.org/repos/asf/isis/blob/205cf853/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsPanel.java
----------------------------------------------------------------------
diff --git 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsPanel.java
 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsPanel.java
index 0ef00d5..a11a234 100644
--- 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsPanel.java
+++ 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/propsandcolls/EntityPropsAndCollsPanel.java
@@ -39,7 +39,7 @@ public class EntityPropsAndCollsPanel extends 
PanelAbstract<EntityModel> {
 
     private static final long serialVersionUID = 1L;
 
-    private static final String ID_ENTITY_PROPERTIES = "entityProperties";
+    private static final String ID_ENTITY_FORM = "entityForm";
 
     private EntityPropsAndCollsForm form;
 
@@ -58,10 +58,10 @@ public class EntityPropsAndCollsPanel extends 
PanelAbstract<EntityModel> {
         final EntityModel model = getModel();
         final ObjectAdapter adapter = model.getObject();
         if (adapter != null) {
-            form = new EntityPropsAndCollsForm(ID_ENTITY_PROPERTIES, model, 
this);
+            form = new EntityPropsAndCollsForm(ID_ENTITY_FORM, model, this);
             addOrReplace(form);
         } else {
-            permanentlyHide(ID_ENTITY_PROPERTIES);
+            permanentlyHide(ID_ENTITY_FORM);
         }
     }
 }

Reply via email to