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 2017/01/20 16:18:14 UTC

[07/36] isis git commit: ISIS-1529: changes TableColumnOrderService to use List rather than Set, as less confusing. Also added additional user guide docs on usage.

ISIS-1529: changes TableColumnOrderService to use List<String> rather than Set<String>, as less confusing.  Also added additional user guide docs on usage.


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

Branch: refs/heads/master
Commit: 12c472685e0cbc72f84658c5da1fa0df8f43116b
Parents: a3d9d9b
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Wed Nov 2 11:16:56 2016 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Wed Jan 18 10:17:37 2017 +0000

----------------------------------------------------------------------
 .gitignore                                      |   1 +
 .../_rgsvc_spi_TableColumnOrderService.adoc     |  14 ++---
 .../src/main/asciidoc/guides/_ugvw_layout.adoc  |  54 ++++++++++++++++++-
 .../wicket-viewer/layouts/customer-order.png    | Bin 0 -> 6640 bytes
 .../tablecol/TableColumnOrderService.java       |  18 ++++---
 .../CollectionContentsAsAjaxTablePanel.java     |  41 +++++++-------
 6 files changed, 94 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/12c47268/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index bb099fc..4ff8c82 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@
 *.class
 bin/
 target/
+.asciidoctor/
 target-ide/
 logs/
 .settings/

http://git-wip-us.apache.org/repos/asf/isis/blob/12c47268/adocs/documentation/src/main/asciidoc/guides/_rgsvc_spi_TableColumnOrderService.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_spi_TableColumnOrderService.adoc b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_spi_TableColumnOrderService.adoc
index 197c114..c7091b3 100644
--- a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_spi_TableColumnOrderService.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_spi_TableColumnOrderService.adoc
@@ -16,20 +16,22 @@ The SPI defined by this service is:
 [source,java]
 ----
 public interface TableColumnOrderService {
-    Set<String> orderParented(                  // <1>
+    List<String> orderParented(                  // <1>
             Object parent,
             String collectionId,
             Class<?> collectionType,
-            Set<String> propertyIds);
-    Set<String> orderStandalone(                // <3>
+            List<String> propertyIds);
+    List<String> orderStandalone(                // <2>
             Class<?> collectionType,
-            Set<String> propertyIds);
+            List<String> propertyIds);
 }
 ----
-<1> for the parent collection owned by the specified parent and collection Id, return the set of property ids in the same or other order, else return `null` if provides no reordering.
+<1> for the parent collection owned by the specified parent and collection Id, return the set of property ids in the same or other order.
 <2> for the standalone collection of the specified type, return the set of property ids in the same or other order, else return `null` if provides no reordering.
 
-There can be multiple implementations of `TableColumnOrderService` registered; the first such service that returns a non-`null` value will be used.  If all provided implementations return `null`, then the framework will fallback to a default implementation.
+There can be multiple implementations of `TableColumnOrderService` registered, ordered as per xref:rgant.adoc#_rgant_DomainServiceLayout_menuOrder[`@DomainServiceLayout#menuOrder()`].
+The ordering provided by the first such service that returns a non-`null` value will be used.
+If all provided implementations return `null`, then the framework will fallback to a default implementation.
 
 
 

http://git-wip-us.apache.org/repos/asf/isis/blob/12c47268/adocs/documentation/src/main/asciidoc/guides/_ugvw_layout.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/guides/_ugvw_layout.adoc b/adocs/documentation/src/main/asciidoc/guides/_ugvw_layout.adoc
index 07ee5ad..aae0eb5 100644
--- a/adocs/documentation/src/main/asciidoc/guides/_ugvw_layout.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/_ugvw_layout.adoc
@@ -6,7 +6,12 @@
 
 
 
-The wicket viewer has full support for the various methods of specifying the xref:ugfun.adoc#_ugfun_object-layout[layout of objects], either statically or dynamically.
+The layout of domain objects can be controlled either through annotations, or through the supplementary `layout.xml` file.
+Of these, the `layout.xml` file is superior; it offers more flexibility, and can be reloaded at runtime, thereby reducing the feedback loop.
+
+In addition, the layout can be fine-tuned using the xref:rgsvc.adoc#_rgsvc_spi_TableColumnOrderService[`TableColumnOrderService`] optional SPI service (`1.14.0-SNAPSHOT`).
+
+== `layout.xml`
 
 For more information, see:
 
@@ -20,3 +25,50 @@ For more information, see:
 
 
 
+== Reordering columns (`1.14.0-SNAPSHOT`)
+
+The optional xref:rgsvc.adoc#_rgsvc_spi_TableColumnOrderService[`TableColumnOrderService`] SPI service can be used to reorder columns in a table, either for a parented collection (owned by parent domain object) or a standalone collection (returned from an action invocation).
+
+For example, suppose there is a `Customer` and an `Order`:
+
+[plantuml, {_imagesdir}/wicket-viewer/layouts/customer-order, png]
+....
+Customer "1" *--> "many" Order : orders
+
+class Order {
+    int num
+    Date placedOn
+    Date shippedOn
+    State state
+}
+....
+
+The order of these properties of `Order`, when rendered in the context of its owning `Customer`, can be controlled using this implementation of `TableColumnOrderService`:
+
+[source,java]
+----
+@DomainService(
+    nature = NatureOfService.DOMAIN,
+    menuOrder = "100"                               // <1>
+)
+public class TableColumnOrderServiceForCustomerOrders
+                 implements TableColumnOrderService {
+    public List<String> orderParented(
+            final Object parent,
+            final String collectionId,
+            final Class<?> collectionType,
+            final List<String> propertyIds) {
+        return parent instanceof Customer && "orders".equals(collectionId)
+             ? Arrays.asList("num", "placedOn", "state", "shippedOn")
+             : null;
+    }
+    public List<String> orderStandalone(
+            final Class<?> collectionType,
+            final List<String> propertyIds) {
+        return null;
+    }
+}
+----
+<1> specifies the order in which the `TableColumnOrderService` implementations are called.
+
+

http://git-wip-us.apache.org/repos/asf/isis/blob/12c47268/adocs/documentation/src/main/asciidoc/guides/images/wicket-viewer/layouts/customer-order.png
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/guides/images/wicket-viewer/layouts/customer-order.png b/adocs/documentation/src/main/asciidoc/guides/images/wicket-viewer/layouts/customer-order.png
new file mode 100644
index 0000000..025dfe0
Binary files /dev/null and b/adocs/documentation/src/main/asciidoc/guides/images/wicket-viewer/layouts/customer-order.png differ

http://git-wip-us.apache.org/repos/asf/isis/blob/12c47268/core/applib/src/main/java/org/apache/isis/applib/services/tablecol/TableColumnOrderService.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/tablecol/TableColumnOrderService.java b/core/applib/src/main/java/org/apache/isis/applib/services/tablecol/TableColumnOrderService.java
index 61ed5db..8aa2b25 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/tablecol/TableColumnOrderService.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/tablecol/TableColumnOrderService.java
@@ -16,7 +16,7 @@
  */
 package org.apache.isis.applib.services.tablecol;
 
-import java.util.Set;
+import java.util.List;
 
 import org.apache.isis.applib.annotation.DomainService;
 import org.apache.isis.applib.annotation.NatureOfService;
@@ -25,16 +25,16 @@ import org.apache.isis.applib.annotation.Programmatic;
 public interface TableColumnOrderService {
 
     @Programmatic
-    Set<String> orderParented(
+    List<String> orderParented(
             final Object parent,
             final String collectionId,
             final Class<?> collectionType,
-            final Set<String> propertyIds);
+            final List<String> propertyIds);
 
     @Programmatic
-    Set<String> orderStandalone(
+    List<String> orderStandalone(
             final Class<?> collectionType,
-            final Set<String> propertyIds);
+            final List<String> propertyIds);
 
     /**
      * Used as a fallback.
@@ -43,16 +43,18 @@ public interface TableColumnOrderService {
     public static class Default implements TableColumnOrderService {
 
         @Override
-        public Set<String> orderParented(
+        public List<String> orderParented(
                 final Object parent,
                 final String collectionId,
                 final Class<?> collectionType,
-                final Set<String> propertyIds) {
+                final List<String> propertyIds) {
             return propertyIds;
         }
 
         @Override
-        public Set<String> orderStandalone(final Class<?> collectionType, final Set<String> propertyIds) {
+        public List<String> orderStandalone(
+                final Class<?> collectionType,
+                final List<String> propertyIds) {
             return propertyIds;
         }
     }

http://git-wip-us.apache.org/repos/asf/isis/blob/12c47268/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java
----------------------------------------------------------------------
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java
index 650d931..c90e9e0 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java
@@ -21,7 +21,6 @@ package org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable
 
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
@@ -192,29 +191,14 @@ public class CollectionContentsAsAjaxTablePanel
         for (final ObjectAssociation property : propertyList) {
             propertyById.put(property.getId(), property);
         }
-        Set<String> propertyIds = propertyById.keySet();
+        List<String> propertyIds = Lists.newArrayList(propertyById.keySet());
 
         // optional SPI to reorder
         final List<TableColumnOrderService> tableColumnOrderServices =
                 getServicesInjector().lookupServices(TableColumnOrderService.class);
 
-        Set<String> propertyReorderedIds = null;
-        for (TableColumnOrderService tableColumnOrderService : tableColumnOrderServices) {
-            final ObjectAdapterMemento parentObjectAdapterMemento = getModel().getParentObjectAdapterMemento();
-
-            final Class<?> collectionType = getModel().getTypeOfSpecification().getCorrespondingClass();
-
-            if(parentObjectAdapterMemento != null) {
-                final ObjectAdapter parentObjectAdapter = parentObjectAdapterMemento
-                        .getObjectAdapter(ConcurrencyChecking.NO_CHECK, getPersistenceSession(), getSpecificationLoader());
-                final Object parent = parentObjectAdapter.getObject();
-                final String collectionId = getModel().getCollectionMemento().getId();
-                propertyReorderedIds =
-                        tableColumnOrderService.orderParented(parent, collectionId, collectionType, propertyIds);
-            } else {
-                propertyReorderedIds =
-                        tableColumnOrderService.orderStandalone(collectionType, propertyIds);
-            }
+        for (final TableColumnOrderService tableColumnOrderService : tableColumnOrderServices) {
+            final List<String> propertyReorderedIds = reordered(tableColumnOrderService, propertyIds);
             if(propertyReorderedIds != null) {
                 propertyIds = propertyReorderedIds;
                 break;
@@ -228,6 +212,25 @@ public class CollectionContentsAsAjaxTablePanel
         }
     }
 
+    private List<String> reordered(
+            final TableColumnOrderService tableColumnOrderService,
+            final List<String> propertyIds) {
+
+        final Class<?> collectionType = getModel().getTypeOfSpecification().getCorrespondingClass();
+
+        final ObjectAdapterMemento parentObjectAdapterMemento = getModel().getParentObjectAdapterMemento();
+        if(parentObjectAdapterMemento != null) {
+            final ObjectAdapter parentObjectAdapter = parentObjectAdapterMemento
+                    .getObjectAdapter(ConcurrencyChecking.NO_CHECK, getPersistenceSession(), getSpecificationLoader());
+            final Object parent = parentObjectAdapter.getObject();
+            final String collectionId = getModel().getCollectionMemento().getId();
+
+            return tableColumnOrderService.orderParented(parent, collectionId, collectionType, propertyIds);
+        } else {
+            return tableColumnOrderService.orderStandalone(collectionType, propertyIds);
+        }
+    }
+
     static Filter<ObjectAssociation> associationDoesNotReferenceParent(final ObjectSpecification parentSpec) {
         if(parentSpec == null) {
             return Filters.any();