1 19 20 package org.netbeans.modules.tasklist.usertasks.treetable; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.Collections ; 25 import java.util.Enumeration ; 26 import java.util.List ; 27 28 import javax.swing.tree.TreeNode ; 29 30 33 public abstract class AbstractTreeTableNode implements TreeTableNode { 34 35 protected static TreeTableNode[] EMPTY_CHILDREN = {}; 36 37 protected TreeTableNode parent; 38 39 40 protected TreeTableNode children[]; 41 42 47 public AbstractTreeTableNode(TreeTableNode parent) { 48 this.parent = parent; 49 } 50 51 54 protected abstract void loadChildren(); 55 56 61 public TreeTableNode[] getChildren() { 62 if (children == null) 63 loadChildren(); 64 return children; 65 } 66 67 public boolean isCellEditable(int column) { 68 return false; 69 } 70 71 public TreeNode getChildAt(int childIndex) { 72 return getChildren()[childIndex]; 73 } 74 75 public int getChildCount() { 76 return getChildren().length; 77 } 78 79 public TreeNode getParent() { 80 return parent; 81 } 82 83 public int getIndex(TreeNode node) { 84 TreeTableNode[] ch = getChildren(); 85 for (int i = 0; i < ch.length; i++) { 86 if (ch[i] == node) 87 return i; 88 } 89 return -1; 90 } 91 92 public boolean getAllowsChildren() { 93 return true; 94 } 95 96 public boolean isLeaf() { 97 return false; 98 } 99 100 public Enumeration children() { 101 return Collections.enumeration(Arrays.asList(getChildren())); 102 } 103 104 107 public void refreshChildren() { 108 this.children = null; 109 } 110 111 116 public TreeTableNode[] getPathToRoot() { 117 List <TreeTableNode> path = new ArrayList <TreeTableNode>(); 118 TreeTableNode n = this; 119 while (n != null) { 120 path.add(0, n); 121 n = (TreeTableNode) n.getParent(); 122 } 123 return path.toArray(new TreeTableNode[path.size()]); 124 } 125 126 132 public TreeTableNode findNextNodeAfterDelete() { 133 if (getParent() == null) 134 return null; 135 if (getParent().getChildCount() == 1) 136 return (TreeTableNode) getParent(); 137 int index = getParent().getIndex(this); 138 if (index == getParent().getChildCount() - 1) 139 return (TreeTableNode) getParent().getChildAt(index - 1); 140 else 141 return (TreeTableNode) getParent().getChildAt(index + 1); 142 } 143 } 144 | Popular Tags |