You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2010/10/22 22:22:52 UTC

svn commit: r1026481 - /wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java

Author: mgrigorov
Date: Fri Oct 22 20:22:52 2010
New Revision: 1026481

URL: http://svn.apache.org/viewvc?rev=1026481&view=rev
Log:
WICKET-3127 Adding node to a collapsed tree node should not cause it to expand

Do not expand a collapsed non-leaf node when adding a sub-node to it.

patch-provided-by: Mike Hefner
merge-from-1.4: r1026477


Modified:
    wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java

Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java?rev=1026481&r1=1026480&r2=1026481&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java Fri Oct 22 20:22:52 2010
@@ -847,12 +847,17 @@ public abstract class AbstractTree exten
 
 		if (parentItem != null && isNodeVisible(parentNode))
 		{
-			// parentNode was a leaf before this insertion event only if every one of
-			// its current children is in the event's list of children
 			List<?> eventChildren = Arrays.asList(e.getChildren());
-			List<TreeItem> itemChildren = parentItem.getChildren();
-			boolean wasLeaf = itemChildren == null || eventChildren.containsAll(itemChildren);
 
+			// parentNode was a leaf before this insertion event only if every one of
+			// its current children is in the event's list of children
+			boolean wasLeaf = true;
+			int nodeChildCount = getChildCount(parentNode);
+			for (int i = 0; wasLeaf && i < nodeChildCount; i++) 
+			{
+				wasLeaf = eventChildren.contains(getChildAt(parentNode, i));
+			}
+			
 			if (wasLeaf)
 			{
 				// parentNode now has children for the first time, so we need to invalidate
@@ -865,17 +870,17 @@ public abstract class AbstractTree exten
 			{
 				if (isNodeExpanded(parentNode))
 				{
+					List<TreeItem> itemChildren = parentItem.getChildren();
+					int childLevel = parentItem.getLevel() + 1;
 					final int[] childIndices = e.getChildIndices();
 					for (int i = 0; i < eventChildren.size(); ++i)
 					{
-						Object node = eventChildren.get(i);
-						int index = childIndices[i];
-						TreeItem item = newTreeItem(parentItem, node, parentItem.getLevel() + 1);
+						TreeItem item = newTreeItem(parentItem, eventChildren.get(i), childLevel);
 						itemContainer.add(item);
 
 						if (itemChildren != null)
 						{
-							itemChildren.add(index, item);
+							itemChildren.add(childIndices[i], item);
 							markTheLastButOneChildDirty(parentItem, item);
 						}