You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by ah...@apache.org on 2023/10/13 10:12:10 UTC

[causeway] branch master updated: CAUSEWAY-3630: API polishing

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/causeway.git


The following commit(s) were added to refs/heads/master by this push:
     new 1399fee518 CAUSEWAY-3630: API polishing
1399fee518 is described below

commit 1399fee518c46b591480e7640649eeaf86b9e87e
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Oct 13 12:12:05 2023 +0200

    CAUSEWAY-3630: API polishing
---
 .../index/metamodel/tabular/simple/DataColumn.adoc |  3 +--
 .../index/metamodel/tabular/simple/DataTable.adoc  |  5 ++---
 .../tabular}/CollectionContentsExporter.adoc       | 12 +++++------
 core/adoc/modules/_overview/pages/about.adoc       |  4 ++--
 .../tabular/interactive/DataTableInteractive.java  |  3 ++-
 .../core/metamodel/tabular/simple/DataColumn.java  | 13 ++---------
 .../core/metamodel/tabular/simple/DataTable.java   | 25 ++++++----------------
 .../causeway/tabular/applib/DataTableProvider.java | 12 +++++++----
 .../CollectionPresentationSelectorPanel.java       |  1 -
 9 files changed, 29 insertions(+), 49 deletions(-)

diff --git a/antora/components/refguide-index/modules/core/pages/index/metamodel/tabular/simple/DataColumn.adoc b/antora/components/refguide-index/modules/core/pages/index/metamodel/tabular/simple/DataColumn.adoc
index 187e6f107f..66138db8c9 100644
--- a/antora/components/refguide-index/modules/core/pages/index/metamodel/tabular/simple/DataColumn.adoc
+++ b/antora/components/refguide-index/modules/core/pages/index/metamodel/tabular/simple/DataColumn.adoc
@@ -9,8 +9,7 @@ Represents a single association of a domain object type (typically an entity typ
 .DataColumn.java
 ----
 class DataColumn {
-  DataColumn(DataTable parentTable, OneToOneAssociation metamodel)
-  int compareTo(DataColumn o)
+  DataColumn(DataTable parentTable, ObjectAssociation metamodel)
   Comparator<DataColumn> orderByColumnId()     // <.>
 }
 ----
diff --git a/antora/components/refguide-index/modules/core/pages/index/metamodel/tabular/simple/DataTable.adoc b/antora/components/refguide-index/modules/core/pages/index/metamodel/tabular/simple/DataTable.adoc
index 8e974aa2ed..bc444e6e5c 100644
--- a/antora/components/refguide-index/modules/core/pages/index/metamodel/tabular/simple/DataTable.adoc
+++ b/antora/components/refguide-index/modules/core/pages/index/metamodel/tabular/simple/DataTable.adoc
@@ -9,9 +9,8 @@ Represents a collection of domain objects (typically entity instances).
 .DataTable.java
 ----
 class DataTable {
-  DataTable(ObjectSpecification elementType, Comparator<DataColumn> columnOrder)
-  DataTable(ObjectSpecification elementType, String tableFriendlyName, Comparator<DataColumn> columnOrder, Can<ManagedObject> dataElements)
-  DataTable withDataElements(Can<ManagedObject> dataElements)
+  DataTable(ObjectSpecification elementType, Can<? extends ObjectAssociation> dataColumns)
+  DataTable(ObjectSpecification elementType, String tableFriendlyName, Can<? extends ObjectAssociation> dataColumns, Can<ManagedObject> dataElements)
   void setDataElements(Can<ManagedObject> dataElements)
   String getLogicalName()     // <.>
   int getElementCount()     // <.>
diff --git a/antora/components/refguide-index/modules/viewer/pages/index/commons/applib/tabular/export/CollectionContentsExporter.adoc b/antora/components/refguide-index/modules/viewer/pages/index/commons/applib/services/tabular/CollectionContentsExporter.adoc
similarity index 83%
rename from antora/components/refguide-index/modules/viewer/pages/index/commons/applib/tabular/export/CollectionContentsExporter.adoc
rename to antora/components/refguide-index/modules/viewer/pages/index/commons/applib/services/tabular/CollectionContentsExporter.adoc
index 3e932657f8..d0d9ff6581 100644
--- a/antora/components/refguide-index/modules/viewer/pages/index/commons/applib/tabular/export/CollectionContentsExporter.adoc
+++ b/antora/components/refguide-index/modules/viewer/pages/index/commons/applib/services/tabular/CollectionContentsExporter.adoc
@@ -14,7 +14,7 @@ interface CollectionContentsExporter {
   String getTitleLabel()     // <.>
   String getCssClass()     // <.>
   int orderOfAppearanceInUiDropdown()     // <.>
-  boolean appliesTo(Class<?> domainObjectType)     // <.>
+  boolean appliesTo(ObjectSpecification objectType)     // <.>
   boolean isPageReloadRequiredOnTableViewActivation()     // <.>
 }
 ----
@@ -26,10 +26,10 @@ interface CollectionContentsExporter {
 --
 An ordinal, that governs the order of appearance in the UI dropdown.
 --
-<.> xref:#appliesTo_Class[appliesTo(Class)]
+<.> xref:#appliesTo_ObjectSpecification[appliesTo(ObjectSpecification)]
 +
 --
-Whether this exporter applies to given _domainObjectType_ . If `false` this exporter is not provided to the end user.
+Whether this exporter applies to given _objectType_ . If `false` , this exporter is not provided to the end user.
 --
 <.> xref:#isPageReloadRequiredOnTableViewActivation_[isPageReloadRequiredOnTableViewActivation()]
 +
@@ -55,10 +55,10 @@ An ordinal, that governs the order of appearance in the UI dropdown.
 
 Lowest comes first.
 
-[#appliesTo_Class]
-=== appliesTo(Class)
+[#appliesTo_ObjectSpecification]
+=== appliesTo(ObjectSpecification)
 
-Whether this exporter applies to given _domainObjectType_ . If `false` this exporter is not provided to the end user.
+Whether this exporter applies to given _objectType_ . If `false` , this exporter is not provided to the end user.
 
 [#isPageReloadRequiredOnTableViewActivation_]
 === isPageReloadRequiredOnTableViewActivation()
diff --git a/core/adoc/modules/_overview/pages/about.adoc b/core/adoc/modules/_overview/pages/about.adoc
index d89af5d261..47eed73aec 100644
--- a/core/adoc/modules/_overview/pages/about.adoc
+++ b/core/adoc/modules/_overview/pages/about.adoc
@@ -2400,7 +2400,7 @@ org.apache.causeway.core:causeway-core-metamodel:jar:<managed> +
 
 .Document Index Entries
 ****
-xref:refguide:viewer:index/commons/applib/mixins/Object_impersonate.adoc[Object_impersonate], xref:refguide:viewer:index/commons/applib/mixins/Object_impersonateWithRoles.adoc[Object_impersonateWithRoles], xref:refguide:viewer:index/commons/applib/services/branding/BrandingUiService.adoc[BrandingUiService], xref:refguide:viewer:index/commons/applib/services/header/HeaderUiService.adoc[HeaderUiService], xref:refguide:viewer:index/commons/applib/services/menu/MenuUiService.adoc[MenuUiServi [...]
+xref:refguide:viewer:index/commons/applib/mixins/Object_impersonate.adoc[Object_impersonate], xref:refguide:viewer:index/commons/applib/mixins/Object_impersonateWithRoles.adoc[Object_impersonateWithRoles], xref:refguide:viewer:index/commons/applib/services/branding/BrandingUiService.adoc[BrandingUiService], xref:refguide:viewer:index/commons/applib/services/header/HeaderUiService.adoc[HeaderUiService], xref:refguide:viewer:index/commons/applib/services/menu/MenuUiService.adoc[MenuUiServi [...]
 ****
 
 |Apache Causeway Viewer - Commons Model
@@ -4924,7 +4924,7 @@ Artifact: causeway-extensions-tabular
 Type: pom
 Directory: /extensions/vw/tabular
 ----
-|Basis for viewers to provide alternative representations of collections for download.
+|Tabular Data Extensions such as download of representations of collections.
 
 |Apache Causeway Ext - Tabular (Applib)
 [source,yaml]
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/interactive/DataTableInteractive.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/interactive/DataTableInteractive.java
index 21077145c6..9572f3d2b7 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/interactive/DataTableInteractive.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/interactive/DataTableInteractive.java
@@ -263,7 +263,8 @@ implements MultiselectChoices {
     public DataTable export() {
         return new DataTable(getElementType(),
                 getTitle().getValue(),
-                org.apache.causeway.core.metamodel.tabular.simple.DataColumn.orderByColumnId(),
+                getDataColumns().getValue()
+                    .map(DataColumn::getAssociationMetaModel),
                 getDataRowsFiltered().getValue()
                     .stream()
                     .map(dr->dr.getRowElement())
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/simple/DataColumn.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/simple/DataColumn.java
index c5840307ad..7c752e1969 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/simple/DataColumn.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/simple/DataColumn.java
@@ -23,7 +23,6 @@ import java.util.Optional;
 
 import org.apache.causeway.commons.internal.base._Strings;
 import org.apache.causeway.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.causeway.core.metamodel.spec.feature.OneToOneAssociation;
 
 import lombok.Getter;
 import lombok.NonNull;
@@ -31,12 +30,9 @@ import lombok.NonNull;
 /**
  * Represents a single association of a domain object type (typically an entity type).
  *
- * @apiNote implements {@link Comparable} such that
- *      column ordering is delegated to the parent's
- *      {@link DataTable#getColumnOrder()}.
  * @since 2.0 {@index}
  */
-public class DataColumn implements Comparable<DataColumn> {
+public class DataColumn {
 
     @Getter private final @NonNull DataTable parentTable;
     @Getter private final @NonNull ObjectAssociation metamodel;
@@ -45,7 +41,7 @@ public class DataColumn implements Comparable<DataColumn> {
     @Getter private final @NonNull Optional<String> columnDescription;
     @Getter private final boolean isMultivalued;
 
-    public DataColumn(final DataTable parentTable, final OneToOneAssociation metamodel) {
+    public DataColumn(final DataTable parentTable, final ObjectAssociation metamodel) {
         this.parentTable = parentTable;
         this.metamodel = metamodel;
         this.columnId = metamodel.getId();
@@ -54,11 +50,6 @@ public class DataColumn implements Comparable<DataColumn> {
         this.isMultivalued = metamodel.isCollection();
     }
 
-    @Override
-    public final int compareTo(final DataColumn o) {
-        return parentTable.getColumnOrder().compare(this, o);
-    }
-
     // -- UTILITY
 
     /**
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/simple/DataTable.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/simple/DataTable.java
index 85e38a72ed..0fb246826b 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/simple/DataTable.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/simple/DataTable.java
@@ -18,7 +18,6 @@
  */
 package org.apache.causeway.core.metamodel.tabular.simple;
 
-import java.util.Comparator;
 import java.util.stream.Stream;
 
 import org.springframework.lang.Nullable;
@@ -27,7 +26,7 @@ import org.apache.causeway.commons.collections.Can;
 import org.apache.causeway.commons.internal.base._Strings;
 import org.apache.causeway.core.metamodel.object.ManagedObject;
 import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
-import org.apache.causeway.core.metamodel.spec.feature.MixedIn;
+import org.apache.causeway.core.metamodel.spec.feature.ObjectAssociation;
 
 import lombok.Getter;
 import lombok.NonNull;
@@ -44,45 +43,33 @@ public class DataTable {
     @Getter private final @NonNull String tableFriendlyName;
     @Getter private final @NonNull ObjectSpecification elementType;
     @Getter private final @NonNull Can<DataColumn> dataColumns;
-    @Getter private final @NonNull Comparator<DataColumn> columnOrder;
     @Getter private @NonNull Can<DataRow> dataRows;
 
     public DataTable(
             final @NonNull ObjectSpecification elementType,
-            final @NonNull Comparator<DataColumn> columnOrder) {
-        this(elementType, elementType.getSingularName(), columnOrder, Can.empty());
+            final @NonNull Can<? extends ObjectAssociation> dataColumns) {
+        this(elementType, elementType.getSingularName(), dataColumns, Can.empty());
     }
 
     public DataTable(
             final @NonNull ObjectSpecification elementType,
             final @Nullable String tableFriendlyName,
-            final @NonNull Comparator<DataColumn> columnOrder,
+            final @NonNull Can<? extends ObjectAssociation> dataColumns,
             final @NonNull Can<ManagedObject> dataElements) {
 
         this.tableFriendlyName = _Strings.nonEmpty(tableFriendlyName)
                 .orElse("Collection"); // fallback to a generic name
 
         this.elementType = elementType;
-        this.columnOrder = columnOrder;
 
-        //TODO externalize filtering
-        this.dataColumns = elementType
-                .streamProperties(MixedIn.EXCLUDED)
-                .filter(prop->prop.isIncludedWithSnapshots())
-                .map(property->new DataColumn(this, property))
-                //.sorted() // don't sort, use meta-model's order, to preserve order from schema
-                .collect(Can.toCan());
+        this.dataColumns = dataColumns
+                .map(assoc->new DataColumn(this, assoc));
 
         setDataElements(dataElements);
     }
 
     // -- POPULATE
 
-    public DataTable withDataElements(final Can<ManagedObject> dataElements) {
-        return new DataTable(elementType, tableFriendlyName, columnOrder, dataElements);
-    }
-
-    //XXX perhaps remove this mutability
     public void setDataElements(final Can<ManagedObject> dataElements) {
         this.dataRows = dataElements
                 .map(domainObject->new DataRow(this, domainObject));
diff --git a/extensions/vw/tabular/applib/src/main/java/org/apache/causeway/tabular/applib/DataTableProvider.java b/extensions/vw/tabular/applib/src/main/java/org/apache/causeway/tabular/applib/DataTableProvider.java
index 2deff3a399..982f394a51 100644
--- a/extensions/vw/tabular/applib/src/main/java/org/apache/causeway/tabular/applib/DataTableProvider.java
+++ b/extensions/vw/tabular/applib/src/main/java/org/apache/causeway/tabular/applib/DataTableProvider.java
@@ -25,8 +25,8 @@ import javax.inject.Inject;
 import org.apache.causeway.commons.collections.Can;
 import org.apache.causeway.core.config.beans.CausewayBeanTypeRegistry;
 import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
+import org.apache.causeway.core.metamodel.spec.feature.MixedIn;
 import org.apache.causeway.core.metamodel.specloader.SpecificationLoader;
-import org.apache.causeway.core.metamodel.tabular.simple.DataColumn;
 import org.apache.causeway.core.metamodel.tabular.simple.DataTable;
 
 import lombok.val;
@@ -41,11 +41,15 @@ public abstract class DataTableProvider {
 
     /**
      * Returns an empty {@link DataTable} for given domain object type.
-     * It can be populated later on using {@link DataTable#withDataElements(Can)}.
+     * It can be populated later on using {@link DataTable#setDataElements(Can)}.
      */
     public DataTable getDataTable(final Class<?> domainType) {
-        val typeSpec = specLoader.specForTypeElseFail(domainType);
-        return new DataTable(typeSpec, DataColumn.orderByColumnId());
+        val elementType = specLoader.specForTypeElseFail(domainType);
+        var dataColumns = elementType
+                .streamProperties(MixedIn.EXCLUDED)
+                .filter(prop->prop.isIncludedWithSnapshots())
+                .collect(Can.toCan());
+        return new DataTable(elementType, dataColumns);
     }
 
     public Stream<DataTable> streamDataTables() {
diff --git a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/collection/selector/CollectionPresentationSelectorPanel.java b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/collection/selector/CollectionPresentationSelectorPanel.java
index 982b2f894c..2cc6790131 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/collection/selector/CollectionPresentationSelectorPanel.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/collection/selector/CollectionPresentationSelectorPanel.java
@@ -107,7 +107,6 @@ extends PanelAbstract<DataTableInteractive, EntityCollectionModel> {
 
     private void addDropdown() {
         final Can<ComponentFactoryKey> componentFactories = selectorHelper.getComponentFactories();
-                //.map(key->key.resolve(this::getServiceRegistry));
         final String selected = selectorHelper.honourViewHintElseDefault(this);
 
         // selector