Example usage for javax.swing.tree DefaultMutableTreeNode getChildBefore

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

Introduction

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

Prototype

public TreeNode getChildBefore(TreeNode aChild) 

Source Link

Document

Returns the child in this node's child array that immediately precedes aChild, which must be a child of this node.

Usage

From source file:com.emental.mindraider.ui.outline.OutlineJPanel.java

/**
 * Demote concept./*  w w  w.ja v  a2  s  .  c  om*/
 */
public void conceptDemote() {
    // current node becomes the first child of the previous sibling, if node
    // has index 0, then do nothing
    DefaultMutableTreeNode node = getSelectedTreeNode();
    if (node != null) {
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
        if (parent != null) {
            DefaultMutableTreeNode previous = (DefaultMutableTreeNode) parent.getChildBefore(node);
            if (previous != null) {
                parent.remove(node);
                previous.insert(node, previous.getChildCount());
                treeTable.updateUI();

                logger.debug(Messages.getString("NotebookOutlineJPanel.conceptDemoted"));

                MindRaider.noteCustodian.demote(MindRaider.outlineCustodian.getActiveOutlineResource(),
                        ((OutlineNode) parent).getUri(), ((OutlineNode) node).getUri());

                setSelectedTreeNodeConcept(((OutlineNode) node).getUri());
            } else {
                logger.debug(Messages.getString("NotebookOutlineJPanel.isTheFirstChild"));
            }
        } else {
            logger.debug(Messages.getString("NotebookOutlineJPanel.noParent"));
        }
    } else {
        logger.debug(Messages.getString("NotebookOutlineJPanel.noNodeSelected!"));
    }
}

From source file:org.artifactory.webapp.wicket.actionable.tree.ActionableItemsTree.java

public TreeNode getPrevTreeNode(TreeNode node) {
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
    if (parent == null) {
        return null;
    }/* w w w. j  a  va 2  s . co  m*/

    TreeNode prevNode = parent.getChildBefore(node);
    if (prevNode != null) {
        ITreeState state = getTreeState();
        node = prevNode;
        while (!node.isLeaf() && node.getAllowsChildren() && state.isNodeExpanded(node)) {
            node = node.getChildAt(node.getChildCount() - 1);
        }
        return node;
    }

    DefaultTreeModel treeModel = getTreeModel();
    if (parent == treeModel.getRoot()) {
        return null;
    }
    return parent;
}