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:13 UTC

[06/36] isis git commit: ISIS-1529: adds TableColumnOrderService

ISIS-1529: adds TableColumnOrderService


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

Branch: refs/heads/master
Commit: a3d9d9beb8284b462be9c9e36bd7696637209cd2
Parents: fbb0475
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Wed Nov 2 00:03:40 2016 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Wed Jan 18 10:17:29 2017 +0000

----------------------------------------------------------------------
 .../guides/_rgsvc_presentation-layer-spi.adoc   | 13 +++++
 .../_rgsvc_spi_TableColumnOrderService.adoc     | 47 ++++++++++++++++
 .../tablecol/TableColumnOrderService.java       | 59 ++++++++++++++++++++
 .../CollectionContentsAsAjaxTablePanel.java     | 45 +++++++++++++++
 4 files changed, 164 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/a3d9d9be/adocs/documentation/src/main/asciidoc/guides/_rgsvc_presentation-layer-spi.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_presentation-layer-spi.adoc b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_presentation-layer-spi.adoc
index 4c0ac73..c71a074 100644
--- a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_presentation-layer-spi.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_presentation-layer-spi.adoc
@@ -130,6 +130,18 @@ Used by the xref:ugvw.adoc#[Wicket viewer] only.
 
 
 
+|xref:rgsvc.adoc#_rgsvc_spi_TableColumnOrderService[`o.a.i.applib.` +
+`services.tablecol` +
+`TableColumn-` +
+`OrderService`]
+|Allows the columns of a parented or standalone table to be reordered, based upon the parent object, collection id and type of object in the collection..
+|`TableColumn-` +
+`OrderService.Default` +
+``o.a.i.core`` +
+``isis-core-applib``
+|
+
+
 |xref:rgsvc.adoc#_rgsvc_spi_TranslationService[`o.a.i.applib.` +
 `services.i18n` +
 `TranslationService`]
@@ -195,6 +207,7 @@ include::_rgsvc_spi_GridService.adoc[leveloffset=+1]
 include::_rgsvc_spi_HintStore.adoc[leveloffset=+1]
 include::_rgsvc_spi_LocaleProvider.adoc[leveloffset=+1]
 include::_rgsvc_spi_RoutingService.adoc[leveloffset=+1]
+include::_rgsvc_spi_TableColumnOrderService.adoc[leveloffset=+1]
 include::_rgsvc_spi_TranslationService.adoc[leveloffset=+1]
 include::_rgsvc_spi_TranslationsResolver.adoc[leveloffset=+1]
 include::_rgsvc_spi_UrlEncodingService.adoc[leveloffset=+1]

http://git-wip-us.apache.org/repos/asf/isis/blob/a3d9d9be/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
new file mode 100644
index 0000000..197c114
--- /dev/null
+++ b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_spi_TableColumnOrderService.adoc
@@ -0,0 +1,47 @@
+[[_rgsvc_spi_TableColumnOrderService]]
+= `TableColumnOrderService`
+:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
+:_basedir: ../
+:_imagesdir: images/
+
+
+
+The `TableColumnOrderService` (`1.14.0-SNAPSHOT`) provides the ability to reorder (or suppress) columns in both parented- and standalone tables.
+
+
+== SPI
+
+The SPI defined by this service is:
+
+[source,java]
+----
+public interface TableColumnOrderService {
+    Set<String> orderParented(                  // <1>
+            Object parent,
+            String collectionId,
+            Class<?> collectionType,
+            Set<String> propertyIds);
+    Set<String> orderStandalone(                // <3>
+            Class<?> collectionType,
+            Set<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.
+<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.
+
+
+
+== Implementation
+
+The framework provides a fallback implementation of this service, namely `TableColumnOrderService.Default`.
+
+
+== Registering the Services
+
+Assuming that the `configuration-and-annotation` services installer is configured (implicit if using the
+`AppManifest` to xref:rgcms.adoc#_rgcms_classes_AppManifest-bootstrapping[bootstrap the app]), then the
+ default implementation of `TableColumnOrderService` is automatically registered and injected, and no further
+ configuration is required.
+

http://git-wip-us.apache.org/repos/asf/isis/blob/a3d9d9be/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
new file mode 100644
index 0000000..61ed5db
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/tablecol/TableColumnOrderService.java
@@ -0,0 +1,59 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.isis.applib.services.tablecol;
+
+import java.util.Set;
+
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.annotation.Programmatic;
+
+public interface TableColumnOrderService {
+
+    @Programmatic
+    Set<String> orderParented(
+            final Object parent,
+            final String collectionId,
+            final Class<?> collectionType,
+            final Set<String> propertyIds);
+
+    @Programmatic
+    Set<String> orderStandalone(
+            final Class<?> collectionType,
+            final Set<String> propertyIds);
+
+    /**
+     * Used as a fallback.
+     */
+    @DomainService(nature = NatureOfService.DOMAIN)
+    public static class Default implements TableColumnOrderService {
+
+        @Override
+        public Set<String> orderParented(
+                final Object parent,
+                final String collectionId,
+                final Class<?> collectionType,
+                final Set<String> propertyIds) {
+            return propertyIds;
+        }
+
+        @Override
+        public Set<String> orderStandalone(final Class<?> collectionType, final Set<String> propertyIds) {
+            return propertyIds;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/a3d9d9be/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 d37b8e5..650d931 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
@@ -20,8 +20,11 @@
 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;
 
 import org.apache.wicket.Component;
 import org.apache.wicket.ajax.AjaxRequestTarget;
@@ -33,12 +36,14 @@ import org.apache.isis.applib.annotation.Where;
 import org.apache.isis.applib.filter.Filter;
 import org.apache.isis.applib.filter.Filters;
 import org.apache.isis.applib.layout.component.Grid;
+import org.apache.isis.applib.services.tablecol.TableColumnOrderService;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager.ConcurrencyChecking;
 import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException;
 import org.apache.isis.core.metamodel.facets.all.hide.HiddenFacet;
 import org.apache.isis.core.metamodel.facets.all.named.NamedFacet;
 import org.apache.isis.core.metamodel.facets.object.grid.GridFacet;
+import org.apache.isis.core.metamodel.services.ServicesInjector;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.feature.Contributed;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
@@ -183,7 +188,41 @@ public class CollectionContentsAsAjaxTablePanel
                 associationDoesNotReferenceParent(parentSpecIfAny));
         
         final List<? extends ObjectAssociation> propertyList = typeOfSpec.getAssociations(Contributed.INCLUDED, filter);
+        final Map<String, ObjectAssociation> propertyById = Maps.newLinkedHashMap();
         for (final ObjectAssociation property : propertyList) {
+            propertyById.put(property.getId(), property);
+        }
+        Set<String> propertyIds = 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);
+            }
+            if(propertyReorderedIds != null) {
+                propertyIds = propertyReorderedIds;
+                break;
+            }
+        }
+
+        for (final String propertyId : propertyIds) {
+            final ObjectAssociation property = propertyById.get(propertyId);
             final ColumnAbstract<ObjectAdapter> nopc = createObjectAdapterPropertyColumn(property);
             columns.add(nopc);
         }
@@ -241,6 +280,12 @@ public class CollectionContentsAsAjaxTablePanel
         return settings;
     }
 
+
+    protected ServicesInjector getServicesInjector() {
+        return getIsisSessionFactory().getServicesInjector();
+    }
+
+
     //endregion
 
 }