List of usage examples for javax.swing.tree DefaultMutableTreeNode getPreviousNode
public DefaultMutableTreeNode getPreviousNode()
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); }