1 19 package org.netbeans.tax; 20 21 27 public abstract class TreeChild extends TreeNode { 28 29 30 public static final String PROP_PARENT_NODE = "parentNode"; 32 33 34 private TreeParentNode parentNode; 35 36 37 41 42 protected TreeChild () { 43 } 44 45 46 50 protected TreeChild (TreeChild child) { 51 super (child); 52 } 53 54 55 59 61 public final TreeDocumentRoot getOwnerDocument () { 62 if ( this instanceof TreeDocumentRoot ) { 63 return (TreeDocumentRoot)this; 64 } 65 if ( getParentNode () == null ) { 66 return null; 67 } 68 return getParentNode ().getOwnerDocument (); 69 } 70 71 72 76 78 public final boolean isInContext () { 79 return ( getParentNode () != null ); 80 } 81 82 84 public final void removeFromContext () throws ReadOnlyException { 85 if ( isInContext () ) { 86 getParentNode ().removeChild (this); 87 } 88 } 89 90 91 95 97 public final TreeParentNode getParentNode () { 98 return parentNode; 99 } 100 101 103 protected final void setParentNode (TreeParentNode newParentNode) { 104 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("TreeChild::setParentNode [ " + this + " ] : newParentNode = " + newParentNode); 106 if ( Util.equals (this.parentNode, newParentNode) ) 110 return; 111 112 TreeParentNode oldParentNode = this.parentNode; 116 117 this.parentNode = newParentNode; 118 119 firePropertyChange (PROP_PARENT_NODE, oldParentNode, newParentNode); 120 } 121 122 123 127 129 public final TreeChild getPreviousSibling () { 130 int index = index (); 131 if ( index == -1 ) { return null; 133 } 134 if ( index == 0 ) { return null; 136 } 137 return (TreeChild)getParentNode ().getChildNodes ().get (index - 1); 138 } 139 140 142 public final TreeChild getNextSibling () { 143 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("TreeChild [ " + this + " ] ::getNextSibling: parentNode = " + getParentNode ()); 145 int index = index (); 146 147 if ( Util.THIS.isLoggable() ) Util.THIS.debug (" index : " + index); 149 if ( index == -1 ) { return null; 151 } 152 153 if ( Util.THIS.isLoggable() ) Util.THIS.debug (" parentNode.childNodes.size : " + getParentNode ().getChildNodes ().size ()); 155 if ( (index + 1) == getParentNode ().getChildNodes ().size () ) { return null; 157 } 158 return (TreeChild)getParentNode ().getChildNodes ().get (index + 1); 159 } 160 161 164 public final int index () { 165 if ( getParentNode () == null ) { 166 return -1; 167 } 168 return getParentNode ().indexOf (this); 169 } 170 171 172 176 178 public final boolean isDescendantOf (TreeParentNode testParentNode) { 179 TreeParentNode ancestor = getParentNode (); 180 181 while ( ancestor != null ) { 182 if ( ancestor == testParentNode ) 183 return true; 184 ancestor = ancestor.getParentNode (); 185 } 186 187 return false; 188 } 189 190 } 191 | Popular Tags |