- Timestamp:
- 19/08/10 12:43:30 (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/applications/NXconvertpy/src/org/nexusformat/nxvalidate/NXNodeMapper.java
r1504 r1507 1 /* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 1 /* NeXus - Neutron & X-ray Common Data Format 2 * 3 * NeXus file validation GUI tool. 4 * 5 * Copyright (C) 2010 Stephen Rankin 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * 21 * For further information, see <http://www.neutron.anl.gov/NeXus/> 22 * 23 * NXNodeMapper.java 24 * 4 25 */ 5 26 package org.nexusformat.nxvalidate; … … 12 33 import javax.swing.tree.TreeNode; 13 34 import org.w3c.dom.Document; 35 import org.w3c.dom.Element; 14 36 import org.w3c.dom.NamedNodeMap; 15 37 import org.w3c.dom.Node; … … 22 44 public class NXNodeMapper implements MutableTreeNode { 23 45 24 Node domNode = null;46 private Node domNode = null; 25 47 private String nodeName = null; 26 48 private boolean isRoot = false; … … 80 102 } 81 103 104 /** 105 * Check to see if this node is the root node. 106 * @return true is it is the root node, false otherwise. 107 */ 82 108 public boolean isRoot() { 83 109 return isRoot; 84 110 } 85 111 112 /** 113 * Check to see if this node is a document, i.e the list of nodes directly 114 * under the root note that are the open NXS documents. 115 * 116 * @return true if the node is a document node. 117 */ 86 118 public boolean isDocument() { 87 119 return isDocument; 88 120 } 89 121 122 /** 123 * Set the flag that says that this node is a documents node i.e. one of the 124 * list of nodes directly under the root note that are the open NXS documents. 125 * @param isDocument a flag which is true if the node is a document node. 126 */ 90 127 public void setDocument(boolean isDocument) { 91 128 this.isDocument = isDocument; 92 129 } 93 130 131 /** 132 * Set the root node that this node belongs to. 133 * @param the root node. 134 */ 94 135 public void setRoot(NXNodeMapper root) { 95 136 this.root = root; 96 137 } 97 138 98 public void insert(NXNodeMapper node) {139 /*public void insert(NXNodeMapper node) { 99 140 documents.add(node); 100 } 101 102 public void removeNode(NXNodeMapper node) { 103 if (!isRoot) { 104 documents.remove(node); 105 } 106 } 141 }*/ 107 142 108 143 public File getNXSFile() { … … 156 191 public boolean getBadNode() { 157 192 return badNode; 193 } 194 195 public Node getDomNode() { 196 return domNode; 158 197 } 159 198 … … 272 311 273 312 } 313 274 314 return childCount; 275 315 … … 413 453 414 454 public void insert(MutableTreeNode child, int index) { 415 if (isRoot) { 416 417 documents.add(index, (NXNodeMapper) child); 418 455 456 NXNodeMapper childNode = (NXNodeMapper) child; 457 458 if (isRoot) { 459 documents.add(index, childNode); 460 } else{ 461 NodeList list = domNode.getChildNodes(); 462 463 for (int i = 0; i < list.getLength(); ++i) { 464 if(i == index){ 465 domNode.insertBefore(childNode.domNode, list.item(i)); 466 } 467 } 419 468 } 420 469 } … … 425 474 documents.remove(index); 426 475 476 } else{ 477 478 NodeList list = domNode.getChildNodes(); 479 480 for (int i = 0; i < list.getLength(); ++i) { 481 if(i == index){ 482 domNode.removeChild(list.item(index)); 483 } 484 } 485 427 486 } 428 487 } 429 488 430 489 public void remove(MutableTreeNode node) { 431 if (isRoot) { 432 490 491 NXNodeMapper childNode = (NXNodeMapper) node; 492 493 if (isRoot) { 433 494 documents.remove((NXNodeMapper) node); 434 495 }else{ 496 NodeList list = domNode.getChildNodes(); 497 498 for (int i = 0; i < list.getLength(); ++i) { 499 if(list.item(i).isSameNode(childNode.domNode)){ 500 domNode.removeChild(childNode.domNode); 501 } 502 } 435 503 } 436 504 } 437 505 438 506 public void removeFromParent() { 439 if (!isRoot) { 440 documents.remove(this); 507 if (isRoot) { 508 return; 509 } else{ 510 NXNodeMapper parentNode = (NXNodeMapper)getParent(); 511 parentNode.remove(this); 441 512 } 442 513 }
Note: See TracChangeset
for help on using the changeset viewer.
