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:lcmc.gui.ClusterBrowser.java

/** Updates common block devices. */
public void updateCommonBlockDevices() {
    if (commonBlockDevicesNode != null) {
        DefaultMutableTreeNode resource;
        final List<String> bd = cluster.getCommonBlockDevices();
        @SuppressWarnings("unchecked")
        final Enumeration<DefaultMutableTreeNode> e = commonBlockDevicesNode.children();
        final List<DefaultMutableTreeNode> nodesToRemove = new ArrayList<DefaultMutableTreeNode>();
        while (e.hasMoreElements()) {
            final DefaultMutableTreeNode node = e.nextElement();
            final Info cbdi = (Info) node.getUserObject();
            if (bd.contains(cbdi.getName())) {
                /* keeping */
                bd.remove(bd.indexOf(cbdi.getName()));
            } else {
                /* remove not existing block devices */
                cbdi.setNode(null);// w  w  w.jav  a2  s .co  m
                nodesToRemove.add(node);
            }
        }

        /* remove nodes */
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                for (DefaultMutableTreeNode node : nodesToRemove) {
                    node.removeFromParent();
                }
            }
        });

        /* block devices */
        for (String device : bd) {
            /* add new block devices */
            resource = new DefaultMutableTreeNode(
                    new CommonBlockDevInfo(device, cluster.getHostBlockDevices(device), this));
            setNode(resource);
            addNode(commonBlockDevicesNode, resource);
        }
        if (!bd.isEmpty() || !nodesToRemove.isEmpty()) {
            reload(commonBlockDevicesNode, false);
            reloadAllComboBoxes(null);
        }
    }
}

From source file:lcmc.gui.ClusterBrowser.java

/**
 * Finds VMSVirtualDomainInfo object that contains the VM specified by
 * name./*from   w  w  w .  j  a v  a2  s.  c  om*/
 */
public VMSVirtualDomainInfo findVMSVirtualDomainInfo(final String name) {
    if (vmsNode != null && name != null) {
        @SuppressWarnings("unchecked")
        final Enumeration<DefaultMutableTreeNode> e = vmsNode.children();
        while (e.hasMoreElements()) {
            final DefaultMutableTreeNode node = e.nextElement();
            final VMSVirtualDomainInfo vmsvdi = (VMSVirtualDomainInfo) node.getUserObject();
            if (name.equals(vmsvdi.getName())) {
                return vmsvdi;
            }
        }
    }
    return null;
}

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

/**
 * Required by TreeSelectionListener interface.
 */// ww w  .  j a v a  2s.  c o  m
public void valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();

    if (node == null) {
        return;
    }

    Object nodeInfo = node.getUserObject();
    if (nodeInfo instanceof ThreadInfo) {
        displayThreadInfo(nodeInfo);
        setThreadDisplay(true);
    } else if (nodeInfo instanceof ThreadDumpInfo) {
        displayThreadDumpInfo(nodeInfo);
    } else if (nodeInfo instanceof HistogramInfo) {
        HistogramInfo tdi = (HistogramInfo) nodeInfo;
        displayTable((HistogramTableModel) tdi.content);
        setThreadDisplay(false);
    } else if (nodeInfo instanceof LogFileContent) {
        displayLogFileContent(nodeInfo);
    } else if (nodeInfo instanceof Logfile
            && ((String) ((Logfile) nodeInfo).getContent()).startsWith("Thread Dumps")) {
        displayLogFile();
        setThreadDisplay(false);
    } else if (nodeInfo instanceof Category) {
        displayCategory(nodeInfo);
        setThreadDisplay(true);
    } else {
        setThreadDisplay(false);
        displayContent(null);
    }
}

From source file:lcmc.gui.ClusterBrowser.java

/** Checks all fields in the application. */
void checkAccessOfEverything() {
    servicesInfo.checkResourceFieldsChanged(null, servicesInfo.getParametersFromXML());
    servicesInfo.updateAdvancedPanels();
    rscDefaultsInfo.updateAdvancedPanels();
    Tools.getGUIData().updateGlobalItems();
    for (final ServiceInfo si : getExistingServiceList(null)) {
        si.checkResourceFieldsChanged(null, si.getParametersFromXML());
        si.updateAdvancedPanels();/*  w ww .j av  a  2s . c om*/
    }

    drbdGraph.getDrbdInfo().checkResourceFieldsChanged(null, drbdGraph.getDrbdInfo().getParametersFromXML());
    drbdGraph.getDrbdInfo().updateAdvancedPanels();
    for (final DrbdResourceInfo dri : getDrbdResHashValues()) {
        dri.checkResourceFieldsChanged(null, dri.getParametersFromXML());
        dri.updateAdvancedPanels();
        dri.updateAllVolumes();
    }

    if (vmsNode != null) {
        @SuppressWarnings("unchecked")
        final Enumeration<DefaultMutableTreeNode> e = vmsNode.children();
        while (e.hasMoreElements()) {
            final DefaultMutableTreeNode node = e.nextElement();
            final VMSVirtualDomainInfo vmsvdi = (VMSVirtualDomainInfo) node.getUserObject();
            vmsvdi.checkResourceFieldsChanged(null, vmsvdi.getParametersFromXML());
            vmsvdi.updateAdvancedPanels();
            @SuppressWarnings("unchecked")
            final Enumeration<DefaultMutableTreeNode> ce = node.children();
            while (ce.hasMoreElements()) {
                final DefaultMutableTreeNode cnode = ce.nextElement();
                final VMSHardwareInfo vmshi = (VMSHardwareInfo) cnode.getUserObject();
                vmshi.checkResourceFieldsChanged(null, vmshi.getParametersFromXML());
                vmshi.updateAdvancedPanels();
            }
        }
    }

    for (final HbConnectionInfo hbci : crmGraph.getAllHbConnections()) {
        hbci.checkResourceFieldsChanged(null, hbci.getParametersFromXML());
        hbci.updateAdvancedPanels();
    }

    for (final Host clusterHost : getClusterHosts()) {
        final HostBrowser hostBrowser = clusterHost.getBrowser();
        hostBrowser.getHostInfo().updateAdvancedPanels();
    }
}

From source file:GUI.MainWindow.java

private void showNotes() {
    DefaultTreeModel dtm = (DefaultTreeModel) VulnTree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm.getRoot();
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) VulnTree.getLastSelectedPathComponent();
    Object obj = node.getUserObject();
    if (obj instanceof Vulnerability) {
        ShowNotesWindow shownotes = new ShowNotesWindow(this, this.VulnTree, true, node, null,
                this.fileChooser.getCurrentDirectory().getAbsolutePath());
        shownotes.setVisible(true);/*from   w ww .ja va  2s . c  om*/
    }
}

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

/**
 * navigate to the currently selected dump in logfile
 *///ww  w . j av a  2  s.com
private void navigateToDumpInLogfile() {
    Object userObject = ((DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent())
            .getUserObject();
    if (userObject instanceof ThreadDumpInfo) {
        ThreadDumpInfo ti = (ThreadDumpInfo) userObject;
        int lineNumber = ti.getLogLine();

        // find log file node.
        TreePath selPath = tree.getSelectionPath();
        while (selPath != null && !checkNameFromNode((DefaultMutableTreeNode) selPath.getLastPathComponent(),
                File.separator)) {

            selPath = selPath.getParentPath();
        }

        tree.setSelectionPath(selPath);
        tree.scrollPathToVisible(selPath);
        if (selPath == null) {
            return;
        }

        Enumeration childs = ((DefaultMutableTreeNode) selPath.getLastPathComponent()).children();
        boolean found = false;
        DefaultMutableTreeNode logfileContent = null;
        while (!found && childs.hasMoreElements()) {
            logfileContent = (DefaultMutableTreeNode) childs.nextElement();
            found = logfileContent.getUserObject() instanceof LogFileContent;
        }

        if (found) {
            TreePath monitorPath = new TreePath(logfileContent.getPath());
            tree.setSelectionPath(monitorPath);
            tree.scrollPathToVisible(monitorPath);
            displayLogFileContent(logfileContent.getUserObject());
            jeditPane.setFirstLine(lineNumber - 1);
        }
    }
}

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

/**
 * check menu and button events.//from w w w  .  j av a2  s.  c o m
 */
public void actionPerformed(ActionEvent e) {
    if (e.getSource() instanceof JMenuItem) {
        JMenuItem source = (JMenuItem) (e.getSource());
        if (source.getText().substring(1).startsWith(":\\") || source.getText().startsWith("/")) {
            if (source.getText().endsWith(".tsf")) {
                try {
                    loadSession(new File(source.getText()), true);
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            } else {
                dumpFile = source.getText();
                openFiles(new File[] { new File(dumpFile) }, true);
            }
        } else if ("Open...".equals(source.getText())) {
            chooseFile();
        } else if ("Open loggc file...".equals(source.getText())) {
            openLoggcFile();
        } else if ("Save Logfile...".equals(source.getText())) {
            saveLogFile();
        } else if ("Save Session...".equals(source.getText())) {
            saveSession();
        } else if ("Open Session...".equals(source.getText())) {
            openSession();
        } else if ("Preferences".equals(source.getText())) {
            showPreferencesDialog();
        } else if ("Filters".equals(source.getText())) {
            showFilterDialog();
        } else if ("Categories".equals(source.getText())) {
            showCategoriesDialog();
        } else if ("Get Logfile from clipboard".equals(source.getText())) {
            getLogfileFromClipboard();
        } else if ("Exit TDA".equals(source.getText())) {
            saveState();
            frame.dispose();
        } else if (ResourceManager.translate("help.contents").equals(source.getText())) {
            showHelp();
        } else if ("Help".equals(source.getText())) {
            showHelp();
        } else if ("Release Notes".equals(source.getText())) {
            showInfoFile("Release Notes", "doc/README", Const.ICON_DOCUMENT);
        } else if ("License".equals(source.getText())) {
            showInfoFile("License Information", "doc/COPYING", Const.ICON_DOCUMENT);
        } else if ("Forum".equals(source.getText())) {
            try {
                Browser.open("https://tda.dev.java.net/servlets/ForumMessageList?forumID=1967");
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this.getRootPane(),
                        "Error opening TDA Online Forum\nPlease open https://tda.dev.java.net/servlets/ForumMessageList?forumID=1967 in your browser!",
                        "Error", JOptionPane.ERROR_MESSAGE);
            }
        } else if ("About TDA".equals(source.getText())) {
            showInfo();
        } else if ("Search...".equals(source.getText())) {
            showSearchDialog();
        } else if ("Parse loggc-logfile...".equals(source.getText())) {
            parseLoggcLogfile();
        } else if ("Find long running threads...".equals(source.getText())) {
            findLongRunningThreads();
        } else if (("Close logfile...".equals(source.getText())) || ("Close...".equals(source.getText()))) {
            closeCurrentDump();
        } else if ("Close all...".equals(source.getText())) {
            closeAllDumps();
        } else if ("Diff Selection".equals(source.getText())) {
            final TreePath[] paths = tree.getSelectionPaths();
            if (paths != null) {
                if ((paths.length < 2)) {
                    JOptionPane.showMessageDialog(this.getRootPane(),
                            "You must select at least two dumps for getting a diff!\n", "Error",
                            JOptionPane.ERROR_MESSAGE);

                } else {
                    DefaultMutableTreeNode mergeRoot = fetchTop(tree.getSelectionPath());
                    Map dumpMap = dumpStore.getFromDumpFiles(mergeRoot.getUserObject().toString());
                    ((Logfile) mergeRoot.getUserObject()).getUsedParser().mergeDumps(mergeRoot, dumpMap, paths,
                            paths.length, null);
                    createTree();
                    this.getRootPane().revalidate();
                }
            }
        } else if ("Show selected Dump in logfile".equals(source.getText())) {
            navigateToDumpInLogfile();
        } else if ("Show Toolbar".equals(source.getText())) {
            setShowToolbar(((JCheckBoxMenuItem) source).getState());
        } else if ("Request Thread Dump...".equals(source.getText())) {
            addMXBeanDump();
        } else if ("Expand all nodes".equals(source.getText())) {
            expandAllCatNodes(true);
        } else if ("Collapse all nodes".equals(source.getText())) {
            expandAllCatNodes(false);
        } else if ("Sort by thread count".equals(source.getText())) {
            sortCatByThreads();
        } else if ("Expand all Dump nodes".equals(source.getText())) {
            expandAllDumpNodes(true);
        } else if ("Collapse all Dump nodes".equals(source.getText())) {
            expandAllDumpNodes(false);
        }
    } else if (e.getSource() instanceof JButton) {
        JButton source = (JButton) e.getSource();
        if ("Open Logfile".equals(source.getToolTipText())) {
            chooseFile();
        } else if ("Close selected Logfile".equals(source.getToolTipText())) {
            closeCurrentDump();
        } else if ("Get Logfile from clipboard".equals(source.getToolTipText())) {
            getLogfileFromClipboard();
        } else if ("Preferences".equals(source.getToolTipText())) {
            showPreferencesDialog();
        } else if ("Find long running threads".equals(source.getToolTipText())) {
            findLongRunningThreads();
        } else if ("Expand all nodes".equals(source.getToolTipText())) {
            expandAllDumpNodes(true);
        } else if ("Collapse all nodes".equals(source.getToolTipText())) {
            expandAllDumpNodes(false);
        } else if ("Find long running threads".equals(source.getToolTipText())) {
            findLongRunningThreads();
        } else if ("Filters".equals(source.getToolTipText())) {
            showFilterDialog();
        } else if ("Custom Categories".equals(source.getToolTipText())) {
            showCategoriesDialog();
        } else if ("Request a Thread Dump".equals(source.getToolTipText())) {
            addMXBeanDump();
        } else if ("Help".equals(source.getToolTipText())) {
            showHelp();
        }
        source.setSelected(false);
    }
}

From source file:lcmc.gui.ClusterBrowser.java

/** Updates VM nodes. */
public void updateVMS() {
    Tools.debug(this, "VM status update", 1);
    final Set<String> domainNames = new TreeSet<String>();
    for (final Host host : getClusterHosts()) {
        final VMSXML vxml = getVMSXML(host);
        if (vxml != null) {
            domainNames.addAll(vxml.getDomainNames());
        }/*w w  w .j  ava 2 s. c  o m*/
    }
    final List<DefaultMutableTreeNode> nodesToRemove = new ArrayList<DefaultMutableTreeNode>();
    boolean nodeChanged = false;
    final List<VMSVirtualDomainInfo> currentVMSVDIs = new ArrayList<VMSVirtualDomainInfo>();

    mVMSUpdateLock.lock();
    if (vmsNode != null) {
        @SuppressWarnings("unchecked")
        final Enumeration<DefaultMutableTreeNode> ee = vmsNode.children();
        while (ee.hasMoreElements()) {
            final DefaultMutableTreeNode node = ee.nextElement();
            final VMSVirtualDomainInfo vmsvdi = (VMSVirtualDomainInfo) node.getUserObject();
            if (domainNames.contains(vmsvdi.toString())) {
                /* keeping */
                currentVMSVDIs.add(vmsvdi);
                domainNames.remove(vmsvdi.toString());
                vmsvdi.updateParameters(); /* update old */
            } else {
                if (!vmsvdi.getResource().isNew()) {
                    /* remove not existing vms */
                    vmsvdi.setNode(null);
                    nodesToRemove.add(node);
                    nodeChanged = true;
                }
            }
        }
    }

    /* remove nodes */
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            for (final DefaultMutableTreeNode node : nodesToRemove) {
                node.removeFromParent();
            }
        }
    });

    if (vmsNode == null) {
        mVMSUpdateLock.unlock();
        return;
    }
    for (final String domainName : domainNames) {
        @SuppressWarnings("unchecked")
        final Enumeration<DefaultMutableTreeNode> e = vmsNode.children();
        int i = 0;
        while (e.hasMoreElements()) {
            final DefaultMutableTreeNode node = e.nextElement();
            final VMSVirtualDomainInfo vmsvdi = (VMSVirtualDomainInfo) node.getUserObject();
            final String name = vmsvdi.getName();
            if (domainName != null && name != null && domainName.compareTo(vmsvdi.getName()) < 0) {
                break;
            }
            i++;
        }
        /* add new vms nodes */
        final VMSVirtualDomainInfo vmsvdi = new VMSVirtualDomainInfo(domainName, this);
        currentVMSVDIs.add(vmsvdi);
        final DefaultMutableTreeNode resource = new DefaultMutableTreeNode(vmsvdi);
        setNode(resource);
        vmsvdi.updateParameters();
        final int index = i;
        Tools.invokeAndWait(new Runnable() {
            public void run() {
                vmsNode.insert(resource, index);
            }
        });
        nodeChanged = true;
    }
    mVMSUpdateLock.unlock();
    if (nodeChanged) {
        reload(vmsNode, false);
    }
    for (final ServiceInfo si : getExistingServiceList(null)) {
        final VMSVirtualDomainInfo vmsvdi = si.connectWithVMS();
        if (vmsvdi != null) {
            /* keep the not connected ones.*/
            currentVMSVDIs.remove(vmsvdi);
        }
    }
    for (final VMSVirtualDomainInfo vmsvdi : currentVMSVDIs) {
        vmsvdi.setUsedByCRM(false);
    }
    final VMSInfo vmsi = (VMSInfo) vmsNode.getUserObject();
    if (vmsi != null) {
        vmsi.updateTable(VMSInfo.MAIN_TABLE);
    }
}

From source file:GUI.MainWindow.java

private void handleCVELookup(File save_file) {

    final File sf = save_file;
    // Best to do this as a background task it'll take time
    Runnable r = new Runnable() {
        public void run() {
            HashSet cves = new HashSet();
            // Find all selected vulns in the tree.
            TreePath[] paths = VulnTree.getSelectionPaths();
            for (int i = 0; i < paths.length; i++) {
                // Loop through them and merge all CVEs into the cves HashSet
                TreePath path = paths[i];
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
                Object obj = node.getUserObject();
                if (obj instanceof Vulnerability) {
                    Vulnerability vuln = (Vulnerability) obj;
                    // add these references to the HashSet
                    cves.addAll(vuln.getCVEReferences());
                }//from   w  w  w. jav a 2  s .c  o m
            }

            // Get the answers from our local CSV file
            CVEUtils cveu = new CVEUtils();
            Vector answers = cveu.getCVEs(cves);

            try {
                String[] headerrow = { "CVE ID", "Risk Score", "Summary" };
                // Write header column to file
                writeCSVLine(sf, headerrow);
                // Now get all the details and make a CSV for the user.
                Enumeration enums = answers.elements();
                while (enums.hasMoreElements()) {
                    CVE c = (CVE) enums.nextElement();
                    System.out.println(c.getCveId() + ":" + c.getRiskScore());
                    writeCSVLine(sf, c.toStringArray());
                }

                // Open file in user's default programme
                Desktop.getDesktop().open(sf);

            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage());
            }
        }
    };

    new Thread(r).start();
}

From source file:GUI.MainWindow.java

private void AddToPersonalVulnsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddToPersonalVulnsActionPerformed

    System.out.println("Add to personal vulns section");

    DefaultTreeModel dtm = (DefaultTreeModel) VulnTree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm.getRoot();
    TreePath[] paths = VulnTree.getSelectionPaths();

    // If there are no paths then no nodes have been selected, ignore the request
    if (paths == null) {
        return;/* w ww.  j  a  v a2  s  .  c  o  m*/
    }

    DefaultTreeModel personaldtm = (DefaultTreeModel) this.personal_vulns_window.PersonalVulnsTree.getModel();
    DefaultMutableTreeNode personalroot = (DefaultMutableTreeNode) personaldtm.getRoot();

    // For each selected node
    for (int i = 0; i < paths.length; i++) {
        TreePath path = paths[i]; // Get the node
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        Object obj = node.getUserObject();
        // Make sure it has an object of type Vulnerability
        if (obj != null && obj instanceof Vulnerability) {
            Vulnerability vuln = (Vulnerability) obj;
            if (vuln.containsIdentifier("24d459a81449d721c8f9a86c2913034", "ReportCompiler")) {
                JOptionPane.showMessageDialog(null,
                        "Attempting to add a personal vuln with the title 'NEW' has a dangerous identifier, please change the title first\n"
                                + vuln.getTitle());
                return;
            }
            // Clone that vulnerability so it isn't the same object that is in the main tree
            Vulnerability newvuln = new Vulnerability();
            newvuln.setTitle(vuln.getTitle());
            newvuln.setRecommendation(vuln.getRecommendation());
            newvuln.setDescription(vuln.getDescription());
            newvuln.cloneReferences(vuln);
            newvuln.cloneRisk(vuln);
            newvuln.cloneIdentifiers(vuln);
            // Add the clone to the personal vulns database
            // TODO do something clever where a vuln exists that has an ID in this one.
            if (new TreeUtils().OkToaddToPersonalVulns(personalroot, newvuln)) {
                personalroot.add(new DefaultMutableTreeNode(newvuln));
                System.out.println("Added to personal vulns: " + newvuln);
                System.out.println("Hosts: " + newvuln.getAffectedHosts().size());
            } else {
                JOptionPane.showMessageDialog(null, "A personal vuln exists that may match that already");
            }

        }
    }

    // Sort the tree
    personalroot = new TreeUtils().sortVulns(personalroot);
    // Update the model
    personaldtm.setRoot(personalroot);

    try {

        // Save the tree again
        new SaveFileExporter().save(this.personal_vulns_window.person_vulns_file, personalroot);
        System.out.println(
                "Personal Vulns Saved: " + this.personal_vulns_window.person_vulns_file.getAbsolutePath());
    } catch (Exception ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
    }

}