Example usage for javax.swing.tree MutableTreeNode remove

List of usage examples for javax.swing.tree MutableTreeNode remove

Introduction

In this page you can find the example usage for javax.swing.tree MutableTreeNode remove.

Prototype

void remove(MutableTreeNode node);

Source Link

Document

Removes node from the receiver.

Usage

From source file:plugin.notes.gui.NotesTreeNode.java

/**
 * Inserts a new MutableTreeNode into this node as a child.
 *
 * @param child//w  w w .  ja v a 2 s  . co m
 *          Child to insert
 * @param index
 *          Location to insert it.
 */
@Override
public void insert(MutableTreeNode child, int index) {
    if (!allowsChildren) {
        throw new IllegalStateException("node does not allow children");
    } else if (child == null) {
        throw new IllegalArgumentException("new child is null");
    } else if (isNodeAncestor(child)) {
        throw new IllegalArgumentException("new child is an ancestor");
    }

    if (!hasBeenPopulated) {
        populate();
    }

    MutableTreeNode oldParent = (MutableTreeNode) child.getParent();

    if (oldParent != null) {
        oldParent.remove(child);
    }

    child.setParent(this);

    if (children == null) {
        children = new Vector<>();
    }

    children.insertElementAt(child, index);
}

From source file:plugin.notes.gui.NotesTreeNode.java

/** Removes this node from it's parent */
@Override//from  w  w  w .  ja  v  a2 s  .  c  o m
public void removeFromParent() {
    MutableTreeNode aParent = (MutableTreeNode) getParent();

    if (aParent != null) {
        aParent.remove(this);
    }
}