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/04/03 14:50:35 UTC
(causeway) branch master updated (b1ae5d8cb6 -> 739b0ae79b)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/causeway.git
from b1ae5d8cb6 Merge pull request #2332 from apache/dependabot/maven/master/org.jacoco-jacoco-maven-plugin-0.8.12
new 6769e610c0 CAUSEWAY-3711: fixes optimized route (again)
new 739b0ae79b CAUSEWAY-3711: factors out TreeAdapterWithConverter
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../graph/tree/TreeAdapterWithConverter.java | 64 +++++++++++++++++
.../tree/TreeConverter.java} | 12 ++--
.../causeway/applib/graph/tree/TreeNode.java | 2 +-
.../causeway/applib/graph/tree/TreeState.java | 5 ++
.../tree/CausewayToWicketTreeAdapter.java | 4 +-
.../ui/components/tree/_TreeModelTreeAdapter.java | 82 ++++++++++------------
6 files changed, 116 insertions(+), 53 deletions(-)
create mode 100644 api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeAdapterWithConverter.java
copy api/applib/src/main/java/org/apache/causeway/applib/{layout/component/MemberRegionOwner.java => graph/tree/TreeConverter.java} (79%)
(causeway) 01/02: CAUSEWAY-3711: fixes optimized route (again)
Posted by ah...@apache.org.
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
commit 6769e610c0892fb731b52145c29d0aa060030759
Author: andi-huber <ah...@apache.org>
AuthorDate: Wed Apr 3 16:49:10 2024 +0200
CAUSEWAY-3711: fixes optimized route (again)
---
.../src/main/java/org/apache/causeway/applib/graph/tree/TreeNode.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 438b08840e..73504574c4 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
@@ -154,7 +154,7 @@ public class TreeNode<T> implements Vertex<T> {
* observe: the relative path /p3 would point to the sub-node itself
*/
return absolutePath.startsWith(treePath)
- ? resolveRelative(absolutePath.subPath(treePath.size()))
+ ? resolveRelative(absolutePath.subPath(treePath.size() - 1))
: rootNode.resolveRelative(absolutePath);
}
(causeway) 02/02: CAUSEWAY-3711: factors out TreeAdapterWithConverter
Posted by ah...@apache.org.
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
commit 739b0ae79b082d5b5ed924a08309097ca60f1400
Author: andi-huber <ah...@apache.org>
AuthorDate: Wed Apr 3 16:50:28 2024 +0200
CAUSEWAY-3711: factors out TreeAdapterWithConverter
---
.../graph/tree/TreeAdapterWithConverter.java | 64 +++++++++++++++++
.../tree/{TreeState.java => TreeConverter.java} | 31 +-------
.../causeway/applib/graph/tree/TreeState.java | 5 ++
.../tree/CausewayToWicketTreeAdapter.java | 4 +-
.../ui/components/tree/_TreeModelTreeAdapter.java | 82 ++++++++++------------
5 files changed, 112 insertions(+), 74 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeAdapterWithConverter.java b/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeAdapterWithConverter.java
new file mode 100644
index 0000000000..48f02d28ad
--- /dev/null
+++ b/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeAdapterWithConverter.java
@@ -0,0 +1,64 @@
+/*
+ * 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.causeway.applib.graph.tree;
+
+import java.util.function.Function;
+import java.util.stream.Stream;
+
+import org.springframework.lang.Nullable;
+
+import org.apache.causeway.commons.functional.IndexedFunction;
+
+import lombok.RequiredArgsConstructor;
+import lombok.val;
+
+@RequiredArgsConstructor
+public abstract class TreeAdapterWithConverter<U, T>
+implements TreeAdapter<T>{
+
+ protected abstract TreeAdapter<U> underlyingAdapter();
+ protected abstract TreeConverter<U, T> converter();
+
+ @Override
+ public final int childCountOf(final @Nullable T t) {
+ if(t==null) return 0;
+ val underlyingNode = converter().toUnderlyingNode(t);
+ return underlyingNode!=null
+ ? underlyingAdapter().childCountOf(underlyingNode)
+ : 0;
+ }
+
+ @Override
+ public final Stream<T> childrenOf(final @Nullable T t) {
+ if(t==null) return Stream.empty();
+ val underlyingNode = converter().toUnderlyingNode(t);
+ return underlyingNode!=null
+ ? underlyingAdapter().childrenOf(underlyingNode)
+ .map(childFactoryForParentNode(t))
+ : Stream.empty();
+ }
+
+ // -- HELPER
+
+ private Function<U, T> childFactoryForParentNode(final T parentNode) {
+ return IndexedFunction.zeroBased((indexWithinSiblings, pojo)->
+ converter().fromUnderlyingNode(pojo, parentNode, indexWithinSiblings));
+ }
+
+}
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeState.java b/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeConverter.java
similarity index 57%
copy from api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeState.java
copy to api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeConverter.java
index 70ccfa2e6e..f73b092c6e 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeState.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeConverter.java
@@ -18,34 +18,9 @@
*/
package org.apache.causeway.applib.graph.tree;
-import java.io.Serializable;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @since 2.0 {@index}
- */
-public class TreeState implements Serializable {
-
- // -- FACTORIES
+public interface TreeConverter<U, T> {
- public static TreeState rootCollapsed() {
- return new TreeState();
- }
-
- // -- CONSTRUCTION
+ public T fromUnderlyingNode(U value, T parentNode, int siblingIndex);
+ public U toUnderlyingNode(T value);
- private static final long serialVersionUID = 7971539034663543462L;
-
- private final Set<TreePath> expandedNodes = new HashSet<>();
- private final Set<TreePath> selectedNodes = new HashSet<>();
-
- public Set<TreePath> getExpandedNodePaths() {
- return expandedNodes;
- }
-
- public Set<TreePath> getSelectedNodePaths() {
- return selectedNodes;
- }
-
}
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeState.java b/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeState.java
index 70ccfa2e6e..046762dd93 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeState.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/graph/tree/TreeState.java
@@ -22,9 +22,14 @@ import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
+import org.apache.causeway.applib.annotation.Programmatic;
+
/**
+ * Holds information for a tree, which nodes are expanded and which are selected.
+ *
* @since 2.0 {@index}
*/
+@Programmatic
public class TreeState implements Serializable {
// -- FACTORIES
diff --git a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/tree/CausewayToWicketTreeAdapter.java b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/tree/CausewayToWicketTreeAdapter.java
index 8bc9248d5b..d881f695a7 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/tree/CausewayToWicketTreeAdapter.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/tree/CausewayToWicketTreeAdapter.java
@@ -84,9 +84,7 @@ class CausewayToWicketTreeAdapter {
final String id, final ManagedObject treeNodeObject) {
val treeNode = (TreeNode<?>) treeNodeObject.getPojo();
- val treeAdapterClass = treeNode.getTreeAdapter().getClass();
-
- val wrappingTreeAdapter = new _TreeModelTreeAdapter(treeAdapterClass);
+ val wrappingTreeAdapter = new _TreeModelTreeAdapter(treeNode.getTreeAdapter());
val treeModelTreeProvider = new _TreeModelTreeProvider(
wrappingTreeAdapter.mementify(treeNode.getValue(), treeNode.getPositionAsPath()),
diff --git a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/tree/_TreeModelTreeAdapter.java b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/tree/_TreeModelTreeAdapter.java
index 385995dd04..20560941be 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/tree/_TreeModelTreeAdapter.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/tree/_TreeModelTreeAdapter.java
@@ -19,89 +19,85 @@
package org.apache.causeway.viewer.wicket.ui.components.tree;
import java.io.Serializable;
-import java.util.function.Function;
-import java.util.stream.Stream;
import org.springframework.lang.Nullable;
import org.apache.causeway.applib.graph.tree.TreeAdapter;
+import org.apache.causeway.applib.graph.tree.TreeAdapterWithConverter;
+import org.apache.causeway.applib.graph.tree.TreeConverter;
import org.apache.causeway.applib.graph.tree.TreePath;
-import org.apache.causeway.commons.functional.IndexedFunction;
+import org.apache.causeway.commons.internal.exceptions._Exceptions;
import org.apache.causeway.core.metamodel.context.HasMetaModelContext;
import org.apache.causeway.core.metamodel.object.ManagedObject;
-import lombok.NonNull;
-import lombok.val;
-
/**
* {@link TreeAdapter} for _TreeModel nodes.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
class _TreeModelTreeAdapter
+extends TreeAdapterWithConverter<Object, _TreeNodeMemento>
implements
TreeAdapter<_TreeNodeMemento>,
+ TreeConverter<Object, _TreeNodeMemento>,
HasMetaModelContext,
Serializable {
private static final long serialVersionUID = 1L;
- private final Class<? extends TreeAdapter> treeAdapterClass;
+ private final Class<? extends TreeAdapter> delegateClass;
/** non serializable delegate */
private transient TreeAdapter delegate;
_TreeModelTreeAdapter(
- final Class<? extends TreeAdapter> treeAdapterClass) {
- this.treeAdapterClass = treeAdapterClass;
+ final TreeAdapter delegate) {
+ this.delegate = delegate;
+ this.delegateClass = delegate.getClass();
}
-
+
+ // -- TREE CONVERTER
+
@Override
- public int childCountOf(final @Nullable _TreeNodeMemento treeModel) {
- val pojoNode = demementify(treeModel);
- if(pojoNode==null) {
- return 0;
- }
- return delegateTreeAdapter().childCountOf(pojoNode);
+ public _TreeNodeMemento fromUnderlyingNode(
+ final Object pojoNode, final _TreeNodeMemento parentNode, final int siblingIndex) {
+ return mementify(pojoNode, parentNode.getTreePath().append(siblingIndex));
}
@Override
- public Stream<_TreeNodeMemento> childrenOf(final @Nullable _TreeNodeMemento treeModel) {
- val pojoNode = demementify(treeModel);
- if(pojoNode==null) {
- return Stream.empty();
- }
- return delegateTreeAdapter().childrenOf(pojoNode)
- .map(newPojoToTreeModelMapper(treeModel));
+ public @Nullable Object toUnderlyingNode(_TreeNodeMemento node) {
+ return node!=null
+ ? node.getPojo()
+ : null;
}
-
- // -- HELPER
- _TreeNodeMemento mementify(final @NonNull Object pojo, final @NonNull TreePath treePath) {
- return new _TreeNodeMemento(
- treePath,
- ManagedObject.adaptSingular(getSpecificationLoader(), pojo).getBookmark().orElseThrow());
- }
+ // -- TREE ADAPTER WITH CONVERTER
- private @Nullable Object demementify(final @Nullable _TreeNodeMemento model) {
- return model!=null
- ? model.getPojo()
- : null;
- }
-
- private Function<Object, _TreeNodeMemento> newPojoToTreeModelMapper(final _TreeNodeMemento parent) {
- return IndexedFunction.zeroBased((indexWithinSiblings, pojo)->
- mementify(pojo, parent.getTreePath().append(indexWithinSiblings)));
+ @Override
+ protected TreeConverter<Object, _TreeNodeMemento> converter() {
+ return this;
}
-
- private TreeAdapter delegateTreeAdapter() {
+
+ @Override
+ protected TreeAdapter<Object> underlyingAdapter() {
if(delegate!=null) {
return delegate;
}
try {
- return delegate = getFactoryService().getOrCreate(treeAdapterClass);
+ return getFactoryService().getOrCreate(delegateClass);
} catch (Exception e) {
- throw new RuntimeException("failed to instantiate tree adapter", e);
+ throw _Exceptions.unrecoverable(e, "failed to instantiate tree adapter of type %s",
+ delegateClass.getName());
}
}
+
+ // -- HELPER
+
+ _TreeNodeMemento mementify(final Object pojo, final TreePath treePath) {
+ return new _TreeNodeMemento(
+ treePath,
+ ManagedObject.adaptSingular(getSpecificationLoader(), pojo)
+ .getBookmark()
+ .orElseThrow());
+ }
}
\ No newline at end of file