Example usage for javax.swing.tree DefaultMutableTreeNode getPreviousNode

List of usage examples for javax.swing.tree DefaultMutableTreeNode getPreviousNode

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode getPreviousNode.

Prototype

public DefaultMutableTreeNode getPreviousNode() 

Source Link

Document

Returns the node that precedes this node in a preorder traversal of this node's tree.

Usage

From source file:org.apache.cayenne.modeler.ProjectTreeView.java

/**
 * Removes current node from the tree. Selects a new node adjacent to the currently
 * selected node instead.//from  w w  w  .  ja v  a2 s .c  om
 */
protected void removeNode(DefaultMutableTreeNode toBeRemoved) {

    // lookup for the new selected node
    Object selectedNode = null;

    TreePath selectionPath = getSelectionPath();
    if (selectionPath != null) {
        selectedNode = selectionPath.getLastPathComponent();
    }

    if (toBeRemoved == selectedNode) {

        // first search siblings
        DefaultMutableTreeNode newSelection = toBeRemoved.getNextSibling();
        if (newSelection == null) {
            newSelection = toBeRemoved.getPreviousSibling();

            // try parent
            if (newSelection == null) {
                newSelection = (DefaultMutableTreeNode) toBeRemoved.getParent();

                // search the whole tree
                if (newSelection == null) {

                    newSelection = toBeRemoved.getNextNode();
                    if (newSelection == null) {

                        newSelection = toBeRemoved.getPreviousNode();
                    }
                }
            }
        }

        showNode(newSelection);
    }

    // remove this node
    getProjectModel().removeNodeFromParent(toBeRemoved);
}