Example usage for javax.swing.tree DefaultTreeModel setRoot

List of usage examples for javax.swing.tree DefaultTreeModel setRoot

Introduction

In this page you can find the example usage for javax.swing.tree DefaultTreeModel setRoot.

Prototype

public void setRoot(TreeNode root) 

Source Link

Document

Sets the root to root.

Usage

From source file:de.codesourcery.eve.skills.ui.model.FilteringTreeModel.java

private static ITreeModel createTreeModel() {

    final DefaultTreeModel result = new DefaultTreeModel();

    ITreeNode root = new DefaultTreeNode("root");

    root.addChild(createNodeWithChildren("cat 1", "child 1 1", "child 1 2", "child 1 3 "));
    root.addChild(createNodeWithChildren("cat 2", "child 2 1", "child 2 2", "child 2 3 "));
    root.addChild(createNodeWithChildren("cat 3", "child 3 1", "child 3 2", "child 3 3 "));

    result.setRoot(root);
    return result;
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java

/**
 * @param viewDefs//from w  w w  .j  a v  a 2 s .  co m
 */
protected void buildTreeModel(Vector<ViewDefIFace> viewDefs) {
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("ViewDefs"); //$NON-NLS-1$
    model.setRoot(root);

    for (ViewDefIFace vd : viewDefs) {
        DefaultMutableTreeNode vdNode = new DefaultMutableTreeNode(vd.getName());
        vdNode.setUserObject(vd);
        if (vd instanceof FormViewDef) {
            root.add(vdNode);
            FormViewDef fvd = (FormViewDef) vd;
            for (FormRowIFace r : fvd.getRows()) {
                FormRow row = (FormRow) r;
                DefaultMutableTreeNode rowNode = new DefaultMutableTreeNode(row.getRowNumber());
                rowNode.setUserObject(row);
                vdNode.add(rowNode);

                for (FormCellIFace c : row.getCells()) {
                    FormCell cell = (FormCell) c;
                    DefaultMutableTreeNode cellNode = new DefaultMutableTreeNode(cell.toString());
                    cellNode.setUserObject(cell);
                    rowNode.add(cellNode);
                }
            }
        }
    }
    model.nodeStructureChanged(root);
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java

protected void buildTreeModel(final ViewDefIFace viewDef) {
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    DefaultMutableTreeNode vdNode = new DefaultMutableTreeNode(viewDef.getName());
    vdNode.setUserObject(viewDef);// w ww  .  j ava 2s . c o  m
    model.setRoot(vdNode);
    if (viewDef instanceof FormViewDef) {
        FormViewDef fvd = (FormViewDef) viewDef;
        for (FormRowIFace r : fvd.getRows()) {
            FormRow row = (FormRow) r;
            DefaultMutableTreeNode rowNode = new DefaultMutableTreeNode(row.getRowNumber());
            rowNode.setUserObject(row);
            vdNode.add(rowNode);

            for (FormCellIFace c : row.getCells()) {
                FormCell cell = (FormCell) c;
                DefaultMutableTreeNode cellNode = new DefaultMutableTreeNode(cell.toString());
                cellNode.setUserObject(cell);
                rowNode.add(cellNode);
            }
        }
    }
    model.nodeStructureChanged(vdNode);
}

From source file:GUI.MainWindow.java

private void ViewModeTabPaneStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_ViewModeTabPaneStateChanged
    JTabbedPane sourceTabbedPane = (JTabbedPane) evt.getSource();
    int index = sourceTabbedPane.getSelectedIndex();
    String title = sourceTabbedPane.getTitleAt(index);
    System.out.println("Tab changed to: " + sourceTabbedPane.getTitleAt(index));

    Object layout = RightPanelCardLayout.getLayout();
    if (layout instanceof java.awt.CardLayout) {
        java.awt.CardLayout cl = (java.awt.CardLayout) layout;
        if (title.equalsIgnoreCase("Vuln View")) {
            // Show the vuln view card
            cl.show(RightPanelCardLayout, "vulnView");

        } else if (title.equalsIgnoreCase("Host View")) {
            DefaultMutableTreeNode hostRoot = new TreeUtils()
                    .convertVulnViewToHostView((DefaultMutableTreeNode) this.VulnTree.getModel().getRoot());
            DefaultTreeModel dtm = ((DefaultTreeModel) this.HostTree.getModel());
            dtm.setRoot(hostRoot);
            dtm.reload(hostRoot);/*w w w.  ja  v  a2  s .c  o m*/
            // Expand all nodes to make everything visible
            new TreeUtils().expandAll(this.HostTree);
            // Show the host view card
            cl.show(RightPanelCardLayout, "hostView");
        }
    }

    //cardLayout.show(cardPanel, "CardToShow");
    //java.awt.CardLayout cl = (java.awt.CardLayout)(RightPanelCardLayout.getLayout()) ;
    //        

}

From source file:GUI.MainWindow.java

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
    System.out.println("file -> Open clicked");

    this.fileChooser.setMultiSelectionEnabled(false);
    int returnVal = this.fileChooser.showOpenDialog(this); // Disable people should only import RC Files here

    if (returnVal == JFileChooser.APPROVE_OPTION) {

        File impFile = this.fileChooser.getSelectedFile();
        // Update the properties files
        this.properties.setProperty("Last_Accessed_Directory", impFile.getParent());
        System.out.println("Last_Accessed_Directory Updated: " + impFile.getParent());
        ImportReportCompiler imprc = new ImportReportCompiler();
        if (imprc.isValid(impFile)) {
            System.out.println("Valid RC XML file: " + impFile.getAbsoluteFile());
            DefaultMutableTreeNode newroot = imprc.readFile(impFile);
            DefaultTreeModel dtm = (DefaultTreeModel) this.VulnTree.getModel();
            DefaultMutableTreeNode currentroot = (DefaultMutableTreeNode) dtm.getRoot();
            if (currentroot.getChildCount() == 0) {
                // No existing nodes so don't merge.
                dtm.setRoot(newroot);
            } else {

            }// www .j  a  va 2s.c  o  m
        } else {
            JOptionPane.showMessageDialog(null,
                    "The file -> Open menu only accepts ReportCompiler XML files. If you want to import scans try Vulnerabilities -> Import");
        }
    }
    this.fileChooser.setMultiSelectionEnabled(true);

}

From source file:GUI.MainWindow.java

private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem10ActionPerformed
    System.out.println("Trying to clash the current tree against personal vulns to auto merge");
    DefaultTreeModel dtm_vulntree = (DefaultTreeModel) this.VulnTree.getModel();
    DefaultMutableTreeNode existing_root = (DefaultMutableTreeNode) dtm_vulntree.getRoot();

    DefaultTreeModel dtm_personal_vulns = (DefaultTreeModel) this.personal_vulns_window.PersonalVulnsTree
            .getModel();/*from   w ww  . j  av a2s . com*/
    DefaultMutableTreeNode new_root = (DefaultMutableTreeNode) dtm_personal_vulns.getRoot();
    DefaultMutableTreeNode answer = new TreeUtils().autoMergePersonalVulns(existing_root, new_root);

    dtm_vulntree.setRoot(answer);
    dtm_vulntree.reload();
}

From source file:GUI.MainWindow.java

private void VulnTreeFilterCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_VulnTreeFilterCaretUpdate
    String search_term = VulnTreeFilter.getText();

    DefaultTreeModel dtm = (DefaultTreeModel) VulnTree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm.getRoot();
    TreeUtils tu = new TreeUtils();

    if (search_term == null || search_term.equals("")) {
        // Clear the highlighted attribute on all nodes
        tu.clearHighlighting(root);//from w  ww . j  ava 2s .co  m

    } else {
        // Loop through the tree and mark nodes that are highlighted.
        tu.searchTree(root, search_term);
    }
    root = tu.sortVulns(root);
    dtm.setRoot(root);
}

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;//from  w ww.j av a  2 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);
    }

}

From source file:ui.panel.UILicenseDetail.java

private JPanel createDetailsPnl() {
    JPanel panel = p.createPanel(Layouts.flow);
    panel.setLayout(new BorderLayout());

    tblInfo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    tblInfo.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    tblInfo.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            int selected = tblInfo.getSelectedRow();
            DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
            getData((String) tblInfo.getModel().getValueAt(selected, 0));
            model.setRoot(root);
        }//from ww w .ja v  a2 s  .co  m
    });
    spTable = new JScrollPane(tblInfo);
    spTable.setPreferredSize(new Dimension(600, 100));

    panel.add(spTable, BorderLayout.CENTER);
    return panel;
}