Changeset 4406
- Timestamp:
- 2003-05-29T15:26:37+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/valuetree/GValueNode.java
r4364 r4406 57 57 import java.util.Hashtable; 58 58 import java.util.Vector; 59 import javax.swing.tree.DefaultMutableTreeNode; 60 import javax.swing.tree.TreeNode; 61 import javax.swing.tree.TreePath; 62 import javax.swing.tree.MutableTreeNode; 59 import javax.swing.tree.*; 63 60 import org.greenstone.gatherer.Gatherer; 64 61 import org.greenstone.gatherer.msm.ElementWrapper; … … 73 70 public class GValueNode 74 71 extends DefaultMutableTreeNode { 72 75 73 private String element_name = null; 76 74 private String default_value = null; 75 77 76 public GValueNode(Element element) { 78 77 this.children = null; … … 155 154 /** Returns the child <I>TreeNode</I> at index <I>childIndex</I>.*/ 156 155 public TreeNode getChildAt(int index) { 157 GValueNode result = null;158 156 if(default_value != null) { 159 157 return this; 160 158 } 161 else { 162 if(children == null) { 163 map(); 164 } 165 for(int i = 0; index >= 0 && i < children.size(); i++) { 166 GValueNode child = (GValueNode) children.get(i); 167 if(child.getEnabled()) { 168 result = child; 169 index--; 170 } 171 } 172 } 173 return result; 159 if(children == null) { 160 map(); 161 } 162 return (GValueNode) children.get(index); 174 163 } 175 164 /** Returns the number of children <I>TreeNode</I>s the reciever contains. */ … … 179 168 size = 0; 180 169 } 181 else { 182 if(children == null) { 183 map(); 184 } 185 for(int i = 0; i < children.size(); i++) { 186 GValueNode child = (GValueNode) children.get(i); 187 if(child.getEnabled()) { 188 size++; 189 } 190 } 191 } 192 return size; 193 } 170 if(children == null) { 171 map(); 172 } 173 return children.size(); 174 } 175 194 176 public Element getElement() { 195 177 return (Element) userObject; 196 }197 public boolean getEnabled() {198 return !(((Element)userObject).getAttribute("enabled").equals("false"));199 178 } 200 179 … … 267 246 } 268 247 if(index >= children.size()) { 269 248 // Append to children. 270 249 children.add(child); 271 250 // And to document 272 251 getElement().appendChild(((GValueNode)child).getElement()); 273 252 } 274 253 else { 275 254 GValueNode sibling = (GValueNode) children.get(index); 276 255 // Insert in children 277 256 children.add(index, child); 278 257 // And in document 279 258 getElement().insertBefore(((GValueNode)child).getElement(), sibling.getElement()); 280 259 } 281 260 child.setParent(this); 282 261 } 262 283 263 /** Returns <I>true</I> if the reciever is a leaf. */ 284 264 public boolean isLeaf() { … … 315 295 } 316 296 317 /** Removes the child at <I>index</I> from the reciever. */318 public void remove(int index) {319 // Can't ever remove Elements from here. Have to use editor. */320 }321 322 /** Removes <I>node</I> from the reciever. <I>setParent</I> will be323 * messaged on node.324 */325 public void remove(MutableTreeNode node) {326 // Can't ever remove Elements from here. Have to use editor. */327 }328 329 /** Removes the reciever from its parent. */330 public void removeFromParent() {331 // Can't ever remove Elements from here. Have to use editor. */332 }333 334 297 public void setAlias(String alias) { 335 298 setNodeValue("Alias", alias); 336 }337 338 public void setEnabled(boolean state) {339 Element element = (Element) userObject;340 if(state) {341 element.setAttribute("enabled", "true");342 }343 else {344 element.setAttribute("enabled", "false");345 }346 299 } 347 300 … … 382 335 } 383 336 return Utility.stripNL(result); 384 }385 386 public void unmap() {387 children = null;388 337 } 389 338 … … 396 345 children.add(child); 397 346 } 347 } 348 } 349 350 /** Removes the child at index from the receiver. */ 351 public void remove(int index) { 352 remove((MutableTreeNode)getChildAt(index)); 353 } 354 355 /** Removes node from the receiver. */ 356 public void remove(MutableTreeNode node) { 357 children.remove(node); 358 parent = null; 359 // Remove from DOM 360 Node child_node = (Node) userObject; 361 Node parent_node = child_node.getParentNode(); 362 parent_node.removeChild(child_node); 363 } 364 365 /** Removes the receiver from its parent. */ 366 public void removeFromParent() { 367 if(parent != null) { 368 parent.remove(this); 398 369 } 399 370 }
Note:
See TracChangeset
for help on using the changeset viewer.