Example usage for javax.swing.tree DefaultMutableTreeNode getDepth

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

Introduction

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

Prototype

public int getDepth() 

Source Link

Document

Returns the depth of the tree rooted at this node -- the longest distance from this node to a leaf.

Usage

From source file:org.spf4j.ui.TSDBViewJInternalFrame.java

@edu.umd.cs.findbugs.annotations.SuppressWarnings("CLI_CONSTANT_LIST_INDEX")
private static List<String> getSelectedTables(@Nullable final TreePath[] selectionPaths) {
    if (selectionPaths == null) {
        return Collections.EMPTY_LIST;
    }//from   w w w. j a v  a  2 s. c  om
    List<String> result = new ArrayList<String>();
    for (TreePath path : selectionPaths) {
        Object[] pathArr = path.getPath();
        if (pathArr.length < 2) {
            continue;
        }
        DefaultMutableTreeNode colNode = (DefaultMutableTreeNode) pathArr[1];
        int depth = colNode.getDepth();
        String tableName;
        if (depth == 1) {
            result.add((String) colNode.getUserObject());
        } else {
            Enumeration childEnum = colNode.children();
            while (childEnum.hasMoreElements()) {
                DefaultMutableTreeNode child = (DefaultMutableTreeNode) childEnum.nextElement();
                tableName = Pair.of((String) colNode.getUserObject(), (String) child.getUserObject())
                        .toString();
                result.add(tableName);
            }
        }
    }
    return result;
}

From source file:com.mindcognition.mindraider.ui.swing.explorer.NotebooksTreeToolbar.java

public void actionPerformed(ActionEvent e) {
    logger.debug("Going to update Outline...");

    DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) explorerJPanel.getNotebooksTree()
            .getLastSelectedPathComponent();
    if (selectedNode.getDepth() == 0) {
        // it is leaf node - a notebook

        final String notebookUri = ((NotebookNodeUserObject) selectedNode.getUserObject()).getNotebookUri();
        ResourceDescriptor resourceDescriptor = MindRaider.labelCustodian.getOutlineDescriptor(notebookUri);

        new UpdateOutlineJDialog(resourceDescriptor);
        explorerJPanel.refresh();/* w  ww . j av a  2  s. co m*/
        return;
    } else {
        JOptionPane.showMessageDialog(MindRaider.mainJFrame, "Please select Outline to be updated!");
    }
}

From source file:com.mindcognition.mindraider.ui.swing.explorer.NotebooksTreeToolbar.java

public void actionPerformed(ActionEvent e) {
    // find notebook through node's user object URI, discard notebook (move it to the archive), 
    // tags are preserved until notebook is erased

    DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) explorerJPanel.getNotebooksTree()
            .getLastSelectedPathComponent();
    if (selectedNode.getDepth() == 0) {
        // it is leaf node - a notebook

        final String notebookUri = ((NotebookNodeUserObject) selectedNode.getUserObject()).getNotebookUri();
        ResourceDescriptor resourceDescriptor = MindRaider.labelCustodian.getOutlineDescriptor(notebookUri);
        if (JOptionPane.showConfirmDialog(MindRaider.mainJFrame,
                "Do you really want to discard Outline '"
                        + (resourceDescriptor != null ? resourceDescriptor.getLabel() : notebookUri) + "'?",
                "Archive Outline", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

            // discard the notebook from ALL folders where it presents
            MindRaider.labelCustodian.discardOutline(notebookUri);
            explorerJPanel.refresh();//  www. j a  va2  s .co  m
            OutlineJPanel.getInstance().clear();
            MindRaider.spidersGraph.clear();
            MindRaider.profile.setActiveOutlineUri(null);
            return;
        }
    } else {
        JOptionPane.showMessageDialog(MindRaider.mainJFrame, "Please select Outline to be discarded!");
    }
}