You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/05/08 11:53:06 UTC

[isis] branch master updated: ISIS-1944: Tree View: adds convenient API for expand/collapse

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/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new ceed81b  ISIS-1944: Tree View: adds convenient API for expand/collapse
ceed81b is described below

commit ceed81bea6502cf4a61ccfb68a5ff504f7d7056a
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue May 8 13:53:01 2018 +0200

    ISIS-1944: Tree View: adds convenient API for expand/collapse
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1944
---
 .../java/org/apache/isis/applib/tree/TreeNode.java | 34 ++++++++++++++++++++--
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/tree/TreeNode.java b/core/applib/src/main/java/org/apache/isis/applib/tree/TreeNode.java
index 54f11d1..06413c3 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/tree/TreeNode.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/tree/TreeNode.java
@@ -19,6 +19,7 @@
 package org.apache.isis.applib.tree;
 
 import java.util.Iterator;
+import java.util.Set;
 import java.util.Spliterator;
 import java.util.Spliterators;
 import java.util.stream.Stream;
@@ -26,6 +27,9 @@ import java.util.stream.StreamSupport;
 
 import javax.annotation.Nullable;
 
+import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.applib.internal.base._NullSafe;
+
 public interface TreeNode<T> {
 
 	// -- VALUE
@@ -58,11 +62,35 @@ public interface TreeNode<T> {
 
 	// -- COLLAPSE/EXPAND
 	
+	/**
+	 * @return this tree's shared state object, holding e.g. the collapse/expand state
+	 */
 	public TreeState getTreeState();
 	
-//	public boolean isExpanded();
-//	
-//	public void setExpanded(boolean expanded);
+	public default boolean isExpanded(TreePath treePath) {
+		final Set<TreePath> expandedPaths = getTreeState().getExpandedNodePaths();
+		return expandedPaths.contains(treePath);
+	}
+	
+	/**
+	 * Adds {@code treePaths} to the set of expanded nodes, as held by this tree's shared state object. 
+	 * @param treePaths
+	 */
+	@Programmatic
+	public default void expand(TreePath ... treePaths) {
+		final Set<TreePath> expandedPaths = getTreeState().getExpandedNodePaths();
+		_NullSafe.stream(treePaths).forEach(expandedPaths::add);
+	}
+	
+	/**
+	 * Removes {@code treePaths} from the set of expanded nodes, as held by this tree's shared state object.
+	 * @param treePaths
+	 */
+	@Programmatic
+	public default void collapse(TreePath ... treePaths) {
+		final Set<TreePath> expandedPaths = getTreeState().getExpandedNodePaths();
+		_NullSafe.stream(treePaths).forEach(expandedPaths::remove);
+	}
 	
 	// -- CONSTRUCTION
 

-- 
To stop receiving notification emails like this one, please contact
ahuber@apache.org.