1 package net.sourceforge.pmd.util.viewer.model; 2 3 4 import net.sourceforge.pmd.ast.SimpleNode; 5 6 import javax.swing.tree.TreeNode ; 7 import java.util.ArrayList ; 8 import java.util.Collections ; 9 import java.util.Enumeration ; 10 import java.util.List ; 11 12 13 19 20 public class SimpleNodeTreeNodeAdapter implements TreeNode { 21 22 private SimpleNode node; 23 private List children; 24 private SimpleNodeTreeNodeAdapter parent; 25 26 31 public SimpleNodeTreeNodeAdapter(SimpleNodeTreeNodeAdapter parent, SimpleNode node) { 32 this.parent = parent; 33 this.node = node; 34 } 35 36 41 public SimpleNode getSimpleNode() { 42 return node; 43 } 44 45 46 49 public TreeNode getChildAt(int childIndex) { 50 checkChildren(); 51 return (TreeNode ) children.get(childIndex); 52 } 53 54 55 58 public int getChildCount() { 59 checkChildren(); 60 return children.size(); 61 } 62 63 64 67 public TreeNode getParent() { 68 return parent; 69 } 70 71 74 public int getIndex(TreeNode node) { 75 checkChildren(); 76 return children.indexOf(node); 77 } 78 79 80 83 public boolean getAllowsChildren() { 84 return true; 85 } 86 87 88 91 92 public boolean isLeaf() { 93 checkChildren(); 94 return children.isEmpty(); 95 } 96 97 98 101 102 public Enumeration children() { 103 return Collections.enumeration(children); 104 } 105 106 107 110 private void checkChildren() { 111 if (children == null) { 112 children = new ArrayList (node.jjtGetNumChildren()); 113 for (int i = 0; i < node.jjtGetNumChildren(); i++) { 114 children.add(new SimpleNodeTreeNodeAdapter(this, (SimpleNode) node.jjtGetChild(i))); 115 } 116 } 117 } 118 119 122 public String toString() { 123 return node.toString(); 124 } 125 } 126 127 | Popular Tags |