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 2024/12/13 11:51:18 UTC
(causeway) branch v3 updated: CAUSEWAY-2297: work on simplified tree model (part 10)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v3
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/v3 by this push:
new ac09a3cbe55 CAUSEWAY-2297: work on simplified tree model (part 10)
ac09a3cbe55 is described below
commit ac09a3cbe553e4e481b46a5c49bf277df7179851
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Dec 13 12:51:12 2024 +0100
CAUSEWAY-2297: work on simplified tree model (part 10)
- new programming model to hint parent/child relations (uses
CollectionLayout#navigableSubtree)
---
.../causeway/applib/annotation/Collection.java | 4 +--
.../applib/annotation/CollectionLayout.java | 13 +++++--
.../causeway/applib/annotation/Navigable.java | 3 ++
.../causeway/applib/annotation/Property.java | 10 +++---
.../causeway/applib/annotation/PropertyLayout.java | 7 +++-
.../causeway/applib/graph/tree/TreeNode.java | 42 +++++++++++-----------
.../apache/causeway/applib/graph/tree/Trees.adoc | 36 +++++++++++++++----
.../core/metamodel/facets/FacetFactory.java | 6 ++--
8 files changed, 80 insertions(+), 41 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/annotation/Collection.java b/api/applib/src/main/java/org/apache/causeway/applib/annotation/Collection.java
index 5f8837dcb66..ba11a1cd6e1 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/annotation/Collection.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/annotation/Collection.java
@@ -40,9 +40,9 @@ import org.apache.causeway.applib.events.domain.CollectionDomainEvent;
@Target({
ElementType.METHOD,
ElementType.FIELD,
+ ElementType.RECORD_COMPONENT,
ElementType.TYPE,
- ElementType.ANNOTATION_TYPE
-})
+ ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@DomainObject(nature=Nature.MIXIN, mixinMethod = "coll") // meta annotation, only applies at class level
@Domain.Include // meta annotation, in support of meta-model validation
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/annotation/CollectionLayout.java b/api/applib/src/main/java/org/apache/causeway/applib/annotation/CollectionLayout.java
index 891ec29f0ec..b89b9d7b550 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/annotation/CollectionLayout.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/annotation/CollectionLayout.java
@@ -39,9 +39,9 @@ import java.util.Comparator;
@Target({
ElementType.METHOD,
ElementType.FIELD,
+ ElementType.RECORD_COMPONENT,
ElementType.TYPE,
- ElementType.ANNOTATION_TYPE
-})
+ ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@DomainObject(nature=Nature.MIXIN, mixinMethod = "coll") // meta annotation, only applies at class level
@Domain.Include // meta annotation, in support of meta-model validation
@@ -110,6 +110,15 @@ public @interface CollectionLayout {
String named()
default "";
+ /**
+ * When set, identifies logical children, that are navigable via the UI.
+ * <p>
+ * The order of appearance of this tree branch in the UI relative to other branches of the same tree node,
+ * is given in <i>Dewey-decimal</i> notation.
+ */
+ String navigableSubtree()
+ default "";
+
/**
* The page size for instances of this class when rendered within
* a table.
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/annotation/Navigable.java b/api/applib/src/main/java/org/apache/causeway/applib/annotation/Navigable.java
index 658f60c7975..abb296ce04b 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/annotation/Navigable.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/annotation/Navigable.java
@@ -27,6 +27,9 @@ package org.apache.causeway.applib.annotation;
public enum Navigable {
NOT_SPECIFIED,
IGNORE,
+ /**
+ * When used via {@link PropertyLayout}, identifies a logical parent, that is navigable via the UI.
+ */
PARENT;
public boolean isParent() { return this == PARENT; }
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/annotation/Property.java b/api/applib/src/main/java/org/apache/causeway/applib/annotation/Property.java
index 3fe24c68afc..c815a5dca74 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/annotation/Property.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/annotation/Property.java
@@ -18,9 +18,6 @@
*/
package org.apache.causeway.applib.annotation;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
@@ -41,6 +38,9 @@ import org.apache.causeway.applib.spec.Specification;
import org.apache.causeway.applib.value.Blob;
import org.apache.causeway.applib.value.Clob;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
/**
* Collects together all the domain semantics for the property of a domain
* object.
@@ -56,9 +56,9 @@ import org.apache.causeway.applib.value.Clob;
@Target({
ElementType.METHOD,
ElementType.FIELD,
+ ElementType.RECORD_COMPONENT,
ElementType.TYPE,
- ElementType.ANNOTATION_TYPE
-})
+ ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@DomainObject(nature=Nature.MIXIN, mixinMethod = "prop") // meta annotation, only applies at class level
@Domain.Include // meta annotation, in support of meta-model validation
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/annotation/PropertyLayout.java b/api/applib/src/main/java/org/apache/causeway/applib/annotation/PropertyLayout.java
index 065c79a5cd3..b2734b6aa87 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/annotation/PropertyLayout.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/annotation/PropertyLayout.java
@@ -36,7 +36,12 @@ import java.lang.annotation.Target;
* @see org.apache.causeway.applib.annotation.ParameterLayout
*/
@Inherited
-@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.ANNOTATION_TYPE })
+@Target({
+ ElementType.METHOD,
+ ElementType.FIELD,
+ ElementType.RECORD_COMPONENT,
+ ElementType.TYPE,
+ ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@DomainObject(nature=Nature.MIXIN, mixinMethod = "prop") // meta annotation, only applies at class level
@Domain.Include // meta annotation, in support of meta-model validation
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeNode.java b/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeNode.java
index e09ff5099a1..4a95ca2ea03 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeNode.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeNode.java
@@ -68,6 +68,25 @@ implements Vertex<T> {
// -- FACTORIES
+ /**
+ * Creates the root node of a tree structure as inferred from given treeAdapter.
+ */
+ public static <T> TreeNode<T> root(
+ final @NonNull T rootNode,
+ final @NonNull TreeAdapter<T> treeAdapter) {
+ return TreeNode.root(rootNode, treeAdapter, TreeState.rootCollapsed());
+ }
+
+ /**
+ * Creates the root node of a tree structure as inferred from given treeAdapter.
+ */
+ public static <T> TreeNode<T> root(
+ final @NonNull T rootNode,
+ final @NonNull Class<? extends TreeAdapter<T>> treeAdapterClass,
+ final @NonNull FactoryService factoryService) {
+ return root(rootNode, factoryService.getOrCreate(treeAdapterClass));
+ }
+
public static <T> TreeNode<T> root(
final T value,
final Class<? extends TreeAdapter<T>> treeAdapterClass,
@@ -271,27 +290,6 @@ implements Vertex<T> {
_NullSafe.stream(treePaths).forEach(selectedPaths::add);
}
- // -- CONSTRUCTION
-
- /**
- * Creates the root node of a tree structure as inferred from given treeAdapter.
- */
- public static <T> TreeNode<T> root(
- final @NonNull T rootNode,
- final @NonNull TreeAdapter<T> treeAdapter) {
- return TreeNode.root(rootNode, treeAdapter, TreeState.rootCollapsed());
- }
-
- /**
- * Creates the root node of a tree structure as inferred from given treeAdapter.
- */
- public static <T> TreeNode<T> root(
- final @NonNull T rootNode,
- final @NonNull Class<? extends TreeAdapter<T>> treeAdapterClass,
- final @NonNull FactoryService factoryService) {
- return root(rootNode, factoryService.getOrCreate(treeAdapterClass));
- }
-
// -- PARENT NODE ITERATION
public Iterator<TreeNode<T>> iteratorHierarchyUp(){
@@ -333,7 +331,7 @@ implements Vertex<T> {
// -- HELPER
private TreeNode<T> toTreeNode(final TreePath treePath, final T value){
- return new TreeNode<>(rootNode, treePath, value, treeAdapter, treeState);
+ return new TreeNode<>(rootNode(), treePath, value, treeAdapter, treeState);
}
}
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/Trees.adoc b/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/Trees.adoc
index dc2e51f19f6..5f6902920d1 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/Trees.adoc
+++ b/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/Trees.adoc
@@ -13,8 +13,12 @@ And also for code authors to quickly get an overview or refresher on the topic.
== TreeAdapter
-A `TreeAdapter` provides the parent/child relationship information between pojos to derive a tree-structure.
+A `TreeAdapter` provides the parent/child relationship information between pojos to derive a tree-structure.
+Given a 'root node value object' and a corresponding `TreeAdapter`
+we can infer a model of `TreeNode`(s). Each `TreeNode` holds a reference to the root-node,
+the shared `TreeState` and the location within the tree as `TreePath`.
+
[NOTE]
====
The model deliberately does *not* reflect a doubly linked tree, that is,
@@ -43,12 +47,28 @@ interface TreeConverter<U, T> {
}
class TreeAdapterWithConverter<U, T> << (R,#FF7700) internal >>{
- underlyingAdapter(): TreeAdapter<U>
- converter(): TreeConverter<U, T>
}
-TreeAdapter <|- TreeAdapterWithConverter: facade
-TreeAdapter ..> TreeConverter: uses for conversion
+class TreeNode<T> << (R,#FF7700) >> {
+ value: T
+}
+
+class TreePath << (R,#FF7700) >> {
+ canonicalPath: int[]
+}
+
+class TreeState << (R,#FF7700) >> {
+}
+
+TreeAdapter <|- TreeAdapterWithConverter: acts as facade
+TreeAdapterWithConverter --> TreeConverter: converter
+TreeAdapterWithConverter -> TreeAdapter: underlyingAdapter
+TreeNode --> TreeAdapter: treeAdapter
+TreeNode -> TreeNode: \nrootNode
+TreeNode -> TreePath: treePath
+TreePath <- TreeState: expandedNodePaths (Set)
+TreePath <- TreeState: selectedNodePaths (Set)
+TreeNode -> TreeState: \ntreeState
@enduml
----
@@ -56,7 +76,7 @@ TreeAdapter ..> TreeConverter: uses for conversion
The internal `TreeAdapterWithConverter` acts as a `TreeAdapter` facade by wrapping an underlying `TreeAdapter`
and translating the node type back and forth using a `TreeConverter`.
-A `TreeNode<T>` has value semantic, while the wrapped type `T` can be an entity, viewmodel or value type
+A `TreeNode<T>` has value semantics, while the wrapped type `T` can be an entity, viewmodel or value type
(which are all bookmarkable and hence resolve to a new page rendered when clicked in the UI).
[cols='1a,1a',options="header"]
@@ -68,6 +88,10 @@ A `TreeNode<T>` has value semantic, while the wrapped type `T` can be an entity,
|T |ENTITY, VIEWMODEL or VALUE
|===
+== Built-in TreeAdapter based on Reflection (WIP)
+
+A built-in `TreeAdapter` is provided, that establishes 'parent to child' relationships
+based on the `@CollectionLayout(navigableSubtree="..")` annotation.
== TreeProvider (Wicket Viewer)
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/FacetFactory.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/FacetFactory.java
index 6add5a9810e..276fdd7273b 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/FacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/FacetFactory.java
@@ -163,7 +163,7 @@ public interface FacetFactory {
// process class
// //////////////////////////////////////
- public static class ProcessClassContext
+ public static final class ProcessClassContext
extends AbstractProcessWithClsContext<FacetHolder>
implements MethodRemover, ProcessContextWithMetadataProperties<FacetHolder> {
@@ -217,7 +217,7 @@ public interface FacetFactory {
// process method
// //////////////////////////////////////
- public static class ProcessMethodContext
+ public static final class ProcessMethodContext
extends AbstractProcessWithMethodContext<FacetedMethod>
implements ProcessContextWithMetadataProperties<FacetedMethod> {
@@ -364,7 +364,7 @@ public interface FacetFactory {
// -- PROCESS PARAM
- public static class ProcessParameterContext
+ public static final class ProcessParameterContext
extends AbstractProcessWithMethodContext<FacetedMethodParameter> {
@Getter private final int paramNum;