예제 #1
0
  public static void removeTextNodes(Node node) {
    NodeList nl = node.getChildNodes();

    int i = 0;
    while (i < nl.getLength())
      if (nl.item(i).getNodeType() == Node.TEXT_NODE) node.removeChild(nl.item(i));
      else i++;
  }
예제 #2
0
  public static void removeNodesByName(Node node, String name) {
    NodeList nl = node.getChildNodes();

    int i = 0;
    while (i < nl.getLength())
      if (nl.item(i).getNodeName().equals(name)) node.removeChild(nl.item(i));
      else i++;
  }
예제 #3
0
 private void removeNodes(NodeList nl) {
   int count = nl.getLength();
   for (int i = 0; i < count; i++) {
     Node node = nl.item(i);
     Node parent = node.getParentNode();
     if (parent == null) continue;
     parent.removeChild(node);
   }
 }
예제 #4
0
 private void setXmlEntry(Document doc, Node opSet) {
   NodeList targetNodes = findNodes(doc, opSet);
   NodeList valueNodes = getValueNodes(opSet);
   if (targetNodes == null) {
     return;
   }
   int targetNodesCount = targetNodes.getLength();
   for (int i = 0; i < targetNodesCount; i++) {
     Node target = targetNodes.item(i);
     for (Node child; (child = target.getFirstChild()) != null; target.removeChild(child)) ;
     appendNodes(doc, target, valueNodes);
   }
 }
  /** Collapse node - reassign parent child relationships as needed */
  public void redo() {
    Node parent = node.getParent();

    if (nodeToCollapse == null) {
      parent.setChildrenChanged(true);
      parent.removeChild(node);
      return;
    }

    if (nodeToCollapse == parent) {
      // Node otherChild = parent.getChildAtIndex(1 - parent.indexOfChild(node));
      parentIndex = oldGrandParent.indexOfChild(parent);
      oldGrandParent.removeChild(parent);
      int tempIndex = parentIndex;
      Iterator it = parent.getChildren().iterator();
      while (it.hasNext()) {
        Node ch = (Node) it.next();
        if (ch != node) {
          oldGrandParent.addToChildren(tempIndex++, ch);
        }
      }
      oldGrandParent.setChildrenChanged(true);
    } else {
      // nodeToCollapse is the other child
      parent.removeChild(node);
      parent.removeChild(nodeToCollapse);

      Iterator it = nodeToCollapse.getChildren().iterator();
      while (it.hasNext()) {
        Node ch = (Node) it.next();
        parent.addToChildren(ch);
      }
      parent.setChildrenChanged(true);
      parent.setChildCountOnServer(parent.getChildren().size());
    }
    NodeGraveyard.getGraveyard().addNode(nodeToCollapse);
  }
예제 #6
0
 private void replaceXmlEntry(Document doc, Node opReplace) {
   NodeList targetNodes = findNodes(doc, opReplace);
   NodeList valueNodes = getValueNodes(opReplace);
   if (targetNodes == null) {
     return;
   }
   int targetNodesCount = targetNodes.getLength();
   for (int i = 0; i < targetNodesCount; i++) {
     Node target = targetNodes.item(i);
     Node parent = target.getParentNode();
     if (parent == null) continue;
     parent.removeChild(target);
     appendNodes(doc, parent, valueNodes);
   }
 }
예제 #7
0
 public void actionPerformed(ActionEvent event) {
   JTree tree = getTree();
   TreePath path = tree.getSelectionPath();
   if (path == null) {
     sheet.getLogger().warning("Warning: User must select a node to delete");
     // XXX add message telling users to select a node
   } else {
     Node selected = (Node) path.getLastPathComponent();
     try {
       Node parent = selected.getParent();
       if (parent != null) {
         parent.removeChild(selected);
         select(parent);
       }
     } catch (UnsupportedOperationException uox) {
       sheet.getLogger().warning("Cannot delete node: " + selected);
     }
   }
 }
예제 #8
0
  public static void removeChildNodes(Node node) {
    NodeList nl = node.getChildNodes();

    // for (int i = 0; i < nl.getLength(); i++)
    while (nl.getLength() > 0) node.removeChild(nl.item(0));
  }