1 15 package org.apache.tapestry.contrib.tree.simple; 16 17 import java.util.Collection ; 18 import java.util.HashSet ; 19 import java.util.Iterator ; 20 import java.util.Set ; 21 22 import org.apache.tapestry.contrib.tree.model.IMutableTreeNode; 23 import org.apache.tapestry.contrib.tree.model.ITreeNode; 24 25 28 public class TreeNode implements IMutableTreeNode { 29 30 protected Set m_setChildren; 31 protected IMutableTreeNode m_objParentNode; 32 33 36 public TreeNode() { 37 this(null); 38 } 39 public TreeNode(IMutableTreeNode parentNode) { 40 super(); 41 m_objParentNode = parentNode; 42 m_setChildren = new HashSet (); 43 } 44 45 46 public int getChildCount() { 47 return m_setChildren.size(); 48 } 49 50 public ITreeNode getParent() { 51 return m_objParentNode; 52 } 53 54 public boolean getAllowsChildren() { 55 return true; 56 } 57 58 public boolean isLeaf() { 59 return m_setChildren.size() == 0 ? true:false; 60 } 61 62 public Collection children() { 63 return m_setChildren; 64 } 65 66 67 public void insert(IMutableTreeNode child) { 68 child.setParent(this); 69 m_setChildren.add(child); 70 } 71 72 public void remove(IMutableTreeNode node) { 73 m_setChildren.remove(node); 74 } 75 76 public void removeFromParent() { 77 m_objParentNode.remove(this); 78 m_objParentNode = null; 79 } 80 81 public void setParent(IMutableTreeNode newParent) { 82 m_objParentNode = newParent; 83 } 84 85 public void insert(Collection colChildren){ 86 for (Iterator iter = colChildren.iterator(); iter.hasNext();) { 87 IMutableTreeNode element = (IMutableTreeNode) iter.next(); 88 element.setParent(this); 89 m_setChildren.add(element); 90 } 91 } 92 93 96 public boolean containsChild(ITreeNode node) { 97 return m_setChildren.contains(node); 98 } 99 100 103 public Collection getChildren() { 104 return m_setChildren; 105 } 106 107 } 108 | Popular Tags |