Example usage for javax.swing.tree DefaultMutableTreeNode getUserObject

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

Introduction

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

Prototype

public Object getUserObject() 

Source Link

Document

Returns this node's user object.

Usage

From source file:com.pironet.tda.TDA.java

/**
 * check if name of node starts with passed string
 *
 * @param node       the node name to check
 * @param startIndex the index to start with comparing, 0 if comparing should happen
 *                   from the beginning.
 * @param startsWith the string to compare.
 * @return true if startsWith and beginning of node name matches.
 */// www  . j  av a 2s.  c o  m
private boolean checkNameFromNode(DefaultMutableTreeNode node, int startIndex, String startsWith) {
    Object info = node.getUserObject();
    String result = null;
    if ((info != null) && (info instanceof AbstractInfo)) {
        result = ((AbstractInfo) info).getName();
    } else if ((info != null) && (info instanceof String)) {
        result = (String) info;
    }

    if (startIndex > 0 && result != null) {
        result = result.substring(startIndex);
    }

    return (result != null && result.startsWith(startsWith));
}

From source file:com.pironet.tda.TDA.java

/**
 * search for dump root node of for given node
 *
 * @param node starting to search for//from  ww  w  .  j a  v a 2 s.  c  om
 * @return root node returns null, if no root was found.
 */
private DefaultMutableTreeNode getDumpRootNode(DefaultMutableTreeNode node) {
    // search for starting node
    while (node != null && !(node.getUserObject() instanceof ThreadDumpInfo)) {
        node = (DefaultMutableTreeNode) node.getParent();
    }

    return (node);
}

From source file:com.pironet.tda.TDA.java

/**
 * sort monitors by thread amount//from w  ww.j av a2  s.  c o  m
 */
private void sortCatByThreads() {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    ((TreeCategory) node.getUserObject()).sort(new MonitorComparator());
    displayCategory(node.getUserObject());
}

From source file:com.pironet.tda.TDA.java

/**
 * open and parse loggc file/*from   www  .  ja  va  2 s .  c  o  m*/
 */
private void openLoggcFile() {
    int returnVal = fc.showOpenDialog(this.getRootPane());

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        final String loggcFile = file.getAbsolutePath();
        try {
            final InputStream loggcFileStream = new ProgressMonitorInputStream(this, "Parsing " + loggcFile,
                    new FileInputStream(loggcFile));

            final SwingWorker worker = new SwingWorker() {
                public Object construct() {
                    try {
                        DefaultMutableTreeNode top = fetchTop(tree.getSelectionPath());

                        ((Logfile) top.getUserObject()).getUsedParser().parseLoggcFile(loggcFileStream, top);

                        addThreadDumps(top, loggcFileStream);
                        createTree();
                        getRootPane().revalidate();
                        displayContent(null);
                    } finally {
                        try {
                            loggcFileStream.close();
                        } catch (IOException ex) {
                            ex.printStackTrace();
                        }
                    }
                    return null;
                }
            };
            worker.start();
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:com.pironet.tda.TDA.java

/**
 * navigate to monitor//w w w. j a v a2  s .c  om
 *
 * @param monitorLink the monitor link to navigate to
 */
private void navigateToMonitor(String monitorLink) {
    String monitor = monitorLink.substring(monitorLink.lastIndexOf('/') + 1);

    // find monitor node for this thread info
    DefaultMutableTreeNode dumpNode;
    if (monitorLink.indexOf("Dump No.") > 0) {
        dumpNode = getDumpRootNode(
                monitorLink.substring(monitorLink.indexOf('/') + 1, monitorLink.lastIndexOf('/')),
                (DefaultMutableTreeNode) tree.getLastSelectedPathComponent());
    } else {
        dumpNode = getDumpRootNode((DefaultMutableTreeNode) tree.getLastSelectedPathComponent());
    }
    final Enumeration children = dumpNode.children();
    DefaultMutableTreeNode monitorNode = null;
    DefaultMutableTreeNode monitorWithoutLocksNode = null;
    while (children.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
        if (child.getUserObject() instanceof TreeCategory) {
            if (((TreeCategory) child.getUserObject()).getName().startsWith("Monitors (")) {
                monitorNode = child;
            } else if (((TreeCategory) child.getUserObject()).getName().startsWith("Monitors without")) {
                monitorWithoutLocksNode = child;
            }
        }
    }

    // highlight chosen monitor
    JTree searchTree = (JTree) ((TreeCategory) monitorNode.getUserObject()).getCatComponent(this);
    TreePath searchPath = searchTree.getNextMatch(monitor, 0, Position.Bias.Forward);
    if ((searchPath == null) && (monitorWithoutLocksNode != null)) {
        searchTree = (JTree) ((TreeCategory) monitorWithoutLocksNode.getUserObject()).getCatComponent(this);
        searchPath = searchTree.getNextMatch(monitor, 0, Position.Bias.Forward);
        monitorNode = monitorWithoutLocksNode;
    }

    if (searchPath != null) {
        TreePath monitorPath = new TreePath(monitorNode.getPath());
        tree.setSelectionPath(monitorPath);
        tree.scrollPathToVisible(monitorPath);

        displayCategory(monitorNode.getUserObject());

        TreePath threadInMonitor = searchPath
                .pathByAddingChild(((DefaultMutableTreeNode) searchPath.getLastPathComponent()).getLastChild());
        searchTree.setSelectionPath(threadInMonitor);
        searchTree.scrollPathToVisible(searchPath);
        searchTree.setSelectionPath(searchPath);
    }
}

From source file:com.pironet.tda.TDA.java

/**
 * find long running threads either in all parsed thread dumps or in marked thread
 * dump range./*from   w  ww  .  ja va2  s.  co  m*/
 */
private void findLongRunningThreads() {
    TreePath[] paths = tree.getSelectionPaths();
    if ((paths == null) || (paths.length < 2)) {
        JOptionPane.showMessageDialog(this.getRootPane(),
                "You must select at least two dumps for long thread run detection!\n", "Error",
                JOptionPane.ERROR_MESSAGE);

    } else {
        DefaultMutableTreeNode mergeRoot = fetchTop(tree.getSelectionPath());
        Map dumpMap = dumpStore.getFromDumpFiles(mergeRoot.getUserObject().toString());

        LongThreadDialog longThreadDialog = new LongThreadDialog(this, paths, mergeRoot, dumpMap);

        if (frame != null) {
            frame.setEnabled(false);
        }

        //Display the window.
        longThreadDialog.reset();
        longThreadDialog.pack();
        longThreadDialog.setLocationRelativeTo(frame);
        longThreadDialog.setVisible(true);

    }
}

From source file:com.pironet.tda.TDA.java

/**
 * expand all nodes of the currently selected category, only works for tree categories.
 *//*from ww w . j av  a  2s . c  om*/
private void expandAllCatNodes(boolean expand) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    JTree catTree = (JTree) ((TreeCategory) node.getUserObject()).getCatComponent(this);
    if (expand) {
        for (int i = 0; i < catTree.getRowCount(); i++) {
            catTree.expandRow(i);
        }
    } else {
        for (int i = 0; i < catTree.getRowCount(); i++) {
            catTree.collapseRow(i);
        }
    }
}

From source file:com.pironet.tda.TDA.java

/**
 * display search dialog for current category
 *///from   w ww  . j  ava  2s  .co m
private void showSearchDialog() {
    // get the currently select category tree
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    JComponent catComp = ((Category) node.getUserObject()).getCatComponent(this);

    //Create and set up the window.
    searchDialog = new SearchDialog(getFrame(), catComp);

    getFrame().setEnabled(false);
    //Display the window.
    searchDialog.reset();
    searchDialog.pack();
    searchDialog.setLocationRelativeTo(getFrame());
    searchDialog.setVisible(true);

    searchDialog.addWindowListener(new WindowAdapter() {
        public void windowClosed(WindowEvent e) {
            getFrame().setEnabled(true);
        }
    });
}

From source file:com.pironet.tda.TDA.java

private void addThreadDumps(DefaultMutableTreeNode top, InputStream dumpFileStream) {
    DumpParser dp = null;/*from  w  w  w . j  av  a2s  . c o m*/
    try {
        String fileName = top.getUserObject().toString();
        Map<String, Map<String, String>> dumpMap = null;
        if (runningAsJConsolePlugin || runningAsVisualVMPlugin) {
            dumpMap = dumpStore.getFromDumpFiles(fileName);
        }

        if (dumpMap == null) {
            dumpMap = new HashMap<>();
            dumpStore.addFileToDumpFiles(fileName, dumpMap);
        }
        dp = DumpParserFactory.get().getDumpParserForLogfile(dumpFileStream, dumpMap, runningAsJConsolePlugin,
                dumpCounter);
        ((Logfile) top.getUserObject()).setUsedParser(dp);

        while ((dp != null) && dp.hasMoreDumps()) {
            top.add(dp.parseNext());
            if (!isFoundClassHistogram) {
                isFoundClassHistogram = dp.isFoundClassHistograms();
            }
        }
    } finally {
        if (dp != null) {
            try {
                dp.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}

From source file:com.pironet.tda.TDA.java

/**
 * get the dump with the given name, starting from the provided node.
 *//*from w  w w . ja v  a2s. c o m*/
private DefaultMutableTreeNode getDumpRootNode(String dumpName, DefaultMutableTreeNode node) {
    DefaultMutableTreeNode lastNode = null;
    // search for starting node
    while (node != null && !(node.getUserObject() instanceof Logfile)) {
        lastNode = node;
        node = (DefaultMutableTreeNode) node.getParent();
    }

    if (node == null) {
        node = lastNode;
    }

    DefaultMutableTreeNode dumpNode = null;
    if (node != null) {
        for (int i = 0; i < node.getChildCount(); i++) {
            Object userObject = ((DefaultMutableTreeNode) node.getChildAt(i)).getUserObject();
            if ((userObject instanceof ThreadDumpInfo)
                    && ((ThreadDumpInfo) userObject).getName().startsWith(dumpName)) {
                dumpNode = (DefaultMutableTreeNode) node.getChildAt(i);
                break;
            }
        }
    }

    return (dumpNode);
}