DefaultTreeModel.isLeaf() must check if the node allows children, when
the field asksAllowsChildren is true.
2006-09-27 Roman Kennke <[EMAIL PROTECTED]>
PR 29218
* javax/swing/tree/DefaultTreeModel.java
(isLeaf): Check if the node allows children when
asksAllowsChildren is true, otherwise fall back
to return the node's leaf property.
/Roman
Index: javax/swing/tree/DefaultTreeModel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/tree/DefaultTreeModel.java,v
retrieving revision 1.23
diff -u -1 -5 -r1.23 DefaultTreeModel.java
--- javax/swing/tree/DefaultTreeModel.java 23 May 2006 16:01:38 -0000 1.23
+++ javax/swing/tree/DefaultTreeModel.java 27 Sep 2006 18:49:41 -0000
@@ -198,41 +198,56 @@
/**
* getChildCount
*
* @param node TODO
* @return int
*/
public int getChildCount(Object node)
{
if (node instanceof TreeNode)
return ((TreeNode) node).getChildCount();
else
return 0;
}
/**
- * isLeaf
+ * Returns if the specified node is a leaf or not. When
+ * [EMAIL PROTECTED] #asksAllowsChildren} is true, then this checks if the TreeNode
+ * allows children, otherwise it returns the TreeNode's <code>leaf</code>
+ * property.
*
- * @param node TODO
- * @return boolean
+ * @param node the node to check
+ *
+ * @return boolean <code>true</code> if the node is a leaf node,
+ * <code>false</code> otherwise
+ *
+ * @throws ClassCastException if the specified node is not a
+ * <code>TreeNode</code> instance
+ *
+ * @see TreeNode#getAllowsChildren()
+ * @see TreeNode#isLeaf()
*/
public boolean isLeaf(Object node)
{
- if (node instanceof TreeNode)
- return ((TreeNode) node).isLeaf();
+ // The RI throws a ClassCastException when node isn't a TreeNode, so do we.
+ TreeNode treeNode = (TreeNode) node;
+ boolean leaf;
+ if (asksAllowsChildren)
+ leaf = ! treeNode.getAllowsChildren();
else
- return true;
+ leaf = treeNode.isLeaf();
+ return leaf;
}
/**
* <p>
* Invoke this method if you've modified the TreeNodes upon which this model
* depends. The model will notify all of its listeners that the model has
* changed. It will fire the events, necessary to update the layout caches and
* repaint the tree. The tree will <i>not</i> be properly refreshed if you
* call the JTree.repaint instead.
* </p>
* <p>
* This method will refresh the information about whole tree from the root. If
* only part of the tree should be refreshed, it is more effective to call
* [EMAIL PROTECTED] #reload(TreeNode)}.
* </p>