Example usage for javax.swing.tree DefaultTreeModel getRoot

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

Introduction

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

Prototype

public Object getRoot() 

Source Link

Document

Returns the root of the tree.

Usage

From source file:results.report.java

private boolean generateApplicationsReportComplex(String filename) {
    try {/*w w  w .ja  v a  2s.c o  m*/
        //--The tools tree: easier beacause it's already shorted
        Toolbox toolbox = new Toolbox();
        JTree applications_tree = toolbox.getApplicationTree();
        DefaultTreeModel mode = (DefaultTreeModel) applications_tree.getModel();
        ToolboxMutableTreeNode treeroot = (ToolboxMutableTreeNode) mode.getRoot();

        //--Exceptions (do not put in the report)
        String[] exception_name = { "Blast Download", "Blast (Web Ncbi)", "Create Local BlastDB", "LocalBlast",
                "dbFetch (Web EBI)", "EB-Eye (Web EBI)", "Ncbi eUtils", "Fetch Sequences Ncbi", "DNAML-Erate",
                "Custom Program _Old_", "Kalign - Custom Program" };
        HashMap<String, Boolean> dict_exception_name = new HashMap<String, Boolean>();
        for (String s : exception_name)
            dict_exception_name.put(s, Boolean.TRUE);

        for (int i = 0; i < treeroot.getChildCount(); i++) {
            ToolboxMutableTreeNode cat = (ToolboxMutableTreeNode) treeroot.getChildAt(i);
            //--Get applications
            if (cat.getProperties().getName().equals("Alignment")) {
                for (int j = 0; j < cat.getChildCount(); j++) {
                    ToolboxMutableTreeNode appli = (ToolboxMutableTreeNode) cat.getChildAt(j);
                    workflow_properties prop = appli.getProperties();
                    if (dict_exception_name.containsKey(prop.getName())) {
                        prop.put("done_report", true);
                    }
                }
            }
        } //--End exception

        //--HTML
        Util report = new Util(filename);
        System.out.println(filename);
        report.println(
                "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
        report.println(this.generateTopApplicationReport("Included Applications - (Extended)"));
        //--Report style 1
        //-- Table (1)            
        report.println(
                "<table style='text-align: left; width: 100%;' border='1' cellpadding='0' cellspacing='0'>"
                        + "<tbody><tr>"
                        + "<td style='background-color: silver; text-align: center; color: black;'><big><span style='font-weight: bold;'>Categories</span></big></td>"
                        + "<td style='background-color: silver; text-align: center; color: black;'><big><span style='font-weight: bold;'>Internal</span></big></td>"
                        + "<td style='background-color: silver; text-align: center; color: black;'><big><span style='font-weight: bold;'>Name</span></big></td>"
                        + "<td style='background-color: silver; text-align: center; color: black;'><big><span style='font-weight: bold;'>Version</span></big></td>"
                        + "<td style='background-color: silver; text-align: center; color: black;'><big><span style='font-weight: bold;'>Website</span></big></td>"
                        + "<td style='background-color: silver; text-align: center; color: black;'><big><span style='font-weight: bold;'>Help</span></big></td>"
                        + "<td style='background-color: silver; text-align: center; color: black;'><big><span style='font-weight: bold;'>Sample</span></big></td>"
                        + "<td style='background-color: silver; text-align: center; color: black;'><big><span style='font-weight: bold;'><a title='Description'>Desc</a></span></big></td>"
                        + "<td style='background-color: silver; text-align: center; color: black;'><big><span style='font-weight: bold;'><a title='Publication'>Publ</a></span></big></td>"
                        + "<td style='background-color: silver; text-align: center; color: black;'><big><span style='font-weight: bold;'>Windows</span></big></td>"
                        + "<td style='background-color: silver; text-align: center; color: black;'><big><span style='font-weight: bold;'>MacOSX</span></big></td>"
                        + "<td style='background-color: silver; text-align: center; color: black;'><big><span style='font-weight: bold;'>Linux</span></big></td>");
        report.println("</tr>");

        //--Report style 2
        //report.println("<table border='1'><thead> <TR><TH SCOPE=colgroup COLSPAN=4>Applications</TH><TH SCOPE=colgroup COLSPAN=3>Operating system</TH></TR><TR><TH SCOPE=col ROWSPAN=2>Type</TH><TH SCOPE=col ROWSPAN=2>Name</TH><TH SCOPE=col ROWSPAN=2>Version</TH><TH SCOPE=col ROWSPAN=2>Website</TH>      <TH SCOPE=col>Windows</TH>      <TH SCOPE=col>MAC OSX</TH>      <TH SCOPE=col>Centos (Linux)</TH></TR></thead>");
        //report.println("<tbody>");

        //--Get categories
        if (config.getBoolean("debug"))
            System.out.println("Generating applications reports");
        for (int i = 0; i < treeroot.getChildCount(); i++) {
            ToolboxMutableTreeNode cat = (ToolboxMutableTreeNode) treeroot.getChildAt(i);
            //--Get applications
            if (config.getBoolean("debug"))
                System.out.println(cat.getProperties().getName());

            for (int j = 0; j < cat.getChildCount(); j++) {
                ToolboxMutableTreeNode appli = (ToolboxMutableTreeNode) cat.getChildAt(j);
                workflow_properties prop = appli.getProperties();
                //--Report only the external program for now...

                report.println("<TR style='background-color: white; text-align: center; color: black;'><TD>"
                        + cat.getProperties().getName() + "</TD>" + "<TD>"
                        + (prop.getBoolean("InternalArmadilloApplication") ? "X" : " ") + "</TD>" + "<TD>"
                        + prop.getName() + "</TD>" + "<TD>"
                        + (prop.isSet("Version") ? prop.get("Version")
                                : prop.getBoolean("InternalArmadilloApplication") ? "NA" : "")
                        + "</TD>" + "<TD>"
                        + (prop.getBoolean("InternalArmadilloApplication") ? ""
                                : prop.isSet("Website") ? "<a href='" + prop.get("Website") + "'>web</a>" : "")
                        + "</TD>" + (helpFound(prop) ? "<TD BGCOLOR='lime'>" : "<TD BGCOLOR='red'>")
                        + (helpFound(prop)
                                ? "<a title='" + config.dataPath() + File.separator + "help" + File.separator
                                        + prop.getName() + ".html" + "' href='" + config.dataPath()
                                        + File.separator + "help" + File.separator + prop.getName() + ".html"
                                        + "'>X</a>"
                                : "")
                        + "</TD>" + (sampleWorkflowFound(prop) ? "<TD BGCOLOR='lime'>" : "<TD BGCOLOR='red'>")
                        + (sampleWorkflowFound(prop) ? "<a title='" + prop.get("SampleWorkflow") + "'>X</a>"
                                : "")
                        + "</TD>" + (prop.isSet("Description") ? "<TD BGCOLOR='lime'>" : "<TD BGCOLOR='red'>")
                        + (prop.isSet("Description") ? "<a title='" + prop.get("Description") + "'>X</a>" : "")
                        + "</TD>" + (prop.isSet("Publication") ? "<TD BGCOLOR='lime'>" : "<TD BGCOLOR='red'>")
                        + (prop.isSet("Publication") ? "<a title='" + prop.get("Publication") + "'>X</a>" : "")
                        + "</TD>"
                        + (Util.FileExists(prop.get("Executable")) ? "<TD BGCOLOR='lime'>"
                                : "<TD BGCOLOR='red'>")
                        + (prop.isSet("Executable") ? "<a title='" + prop.get("Executable") + "'>X</a>" : "")
                        + "</TD>"
                        + (Util.FileExists(prop.get("ExecutableMACOSX")) ? "<TD BGCOLOR='lime'>"
                                : "<TD BGCOLOR='red'>")
                        + (prop.isSet("ExecutableMacOSX")
                                ? "<a title='" + prop.get("ExecutableMacOSX") + "'>X</a>"
                                : "")
                        + "</TD>"
                        + (Util.FileExists(prop.get("ExecutableLinux")) ? "<TD BGCOLOR='lime'>"
                                : "<TD BGCOLOR='red'>")
                        + (prop.isSet("ExecutableLinux")
                                ? "<a title='" + prop.get("ExecutableLinux") + "'>X</a>"
                                : "")
                        + "</TD>" + "</TR>");

                if (config.getBoolean("debug"))
                    System.out.println("\t" + appli.getProperties().getName() + "\t"
                            + (prop.isSet("version") ? prop.get("version") : "") + "\t"
                            + (prop.isSet("Website") ? prop.get("Website") : "") + "\t"
                            + (prop.isSet("Executable") ? prop.getExecutable() : ""));
            }
        }
        report.println("</tbody></table></div></div></div>");
        report.println(this.foot());
        report.println("</body></html>");
        report.close();
        report.close();
    } catch (Exception e) {
        e.printStackTrace();
        Config.log("Error in generation application report (2) " + filename + "\n" + e.getMessage() + "\n"
                + e.getLocalizedMessage());
        return false;
    }
    return true;
}

From source file:ropes.MainWindow.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    //TODO display loader animation while liberys are loading
    DefaultTreeModel model = (DefaultTreeModel) jTree_fileList.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();

    final JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fc.setMultiSelectionEnabled(true);/*  www  .  j a va 2 s .  com*/

    int returnVal = fc.showOpenDialog(MainWindow.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File[] files = fc.getSelectedFiles();
        for (File file : files) {

            if (file.isFile()) {
                addFileToList(file);
            } else if (file.isDirectory()) {
                //adds the parent to tree
                root.add(new DefaultMutableTreeNode(file));
                //adds all the subfolders and files to the parent
                addFileRecursive(file.toString());

            }

        }

    }

}

From source file:ropes.MainWindow.java

private void addFileToList(File path) {
    DefaultTreeModel model = (DefaultTreeModel) jTree_fileList.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    //get perent directory to see if such node exist
    File perentDir = path.getParentFile();

    DefaultMutableTreeNode node = findNode(root, perentDir.toString());
    if (node != null)
        node.add(new DefaultMutableTreeNode(path));
    else {//  ww  w .  j av a  2 s  .  c om
        root.add(new DefaultMutableTreeNode(path));
    }
    //update jtree
    model.reload(root);

}

From source file:ropes.MainWindow.java

private void jButton_clear_fileListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_clear_fileListActionPerformed
    DefaultTreeModel model = (DefaultTreeModel) jTree_fileList.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    root.removeAllChildren(); //this removes all nodes
    model.reload(); //this notifies the listeners and changes the GUI
}

From source file:ru.apertum.qsystem.client.forms.FReception.java

private void setModelForComboBoxServices(DefaultTreeModel model) {
    comboBoxServices = new JTreeComboBox(model);
    panelTreeCmbx.removeAll();/*w w w.ja  va 2s.co m*/
    panelTreeCmbx.setLayout(new GridLayout(1, 1));
    panelTreeCmbx.add(comboBoxServices);

    comboBoxServices.addItemListener((ItemEvent e) -> {
        if (((QService) e.getItem()).isLeaf()) {
            lastSelected = (QService) e.getItem();
            preRegChange(false);
        } else {
            comboBoxServices.setSelectedItem(lastSelected);
        }
    });
    comboBoxServices.setSelectedItem(model.getRoot());
}

From source file:ser321.media.MediaJavaClient.java

public void rebuildTree() {
    //String[] musicList = {"Come Monday","Fins","Crazy"};
    //String[] musicAlbum = {"Greatest Hits","Greatest Hits","Single"};
    //String[] videoList = {"Minions Banana Song","Minions Banana"};
    //String[] videoGenre = {"Animation","Animation"};

    cc.clear();/* w  w  w  .  jav a 2  s.co m*/

    cc.getTitles();
    cc.getVideoTitles();
    cc.getMusicTitles();

    tree.removeTreeSelectionListener(this);
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    clearTree(root, model);

    DefaultMutableTreeNode musicNode = new DefaultMutableTreeNode("Music");
    model.insertNodeInto(musicNode, root, model.getChildCount(root));

    DefaultMutableTreeNode videoNode = new DefaultMutableTreeNode("Video");
    model.insertNodeInto(videoNode, root, model.getChildCount(root));

    // put nodes in the tree for all  registered with the library
    for (int i = 0; i < cc.musicTitles.size(); i++) {
        String aMTitle = cc.musicTitles.get(i);
        DefaultMutableTreeNode toAdd = new DefaultMutableTreeNode(aMTitle);
        model.insertNodeInto(toAdd, musicNode, i);
    }
    // put nodes in the tree for all video registered with the library
    for (int i = 0; i < cc.videoTitles.size(); i++) {
        String aTitle = cc.videoTitles.get(i);
        DefaultMutableTreeNode toAdd = new DefaultMutableTreeNode(aTitle);
        model.insertNodeInto(toAdd, videoNode, i);
    }
    // expand all the nodes in the JTree
    for (int r = 0; r < tree.getRowCount(); r++) {
        tree.expandRow(r);
    }
    tree.addTreeSelectionListener(this);
}

From source file:UserInterface.CustomerRole.CustomerOrderSchedulingJPanel.java

public void populateTree() {
    DefaultTreeModel model = (DefaultTreeModel) jTree.getModel();
    ArrayList<Network> networkList = system.getNetworkList();
    ArrayList<Enterprise> enterpriseList;
    ArrayList<Organization> organizationList;

    Network network;/*from ww w.java2s.c om*/
    Enterprise enterprise;
    Organization organization;

    DefaultMutableTreeNode networks = new DefaultMutableTreeNode("Networks");
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    root.removeAllChildren();
    root.insert(networks, 0);

    DefaultMutableTreeNode networkNode;
    DefaultMutableTreeNode enterpriseNode;

    DefaultMutableTreeNode organizationNode;

    for (int i = 0; i < networkList.size(); i++) {
        network = networkList.get(i);
        networkNode = new DefaultMutableTreeNode(network.getName());
        networks.insert(networkNode, i);

        enterpriseList = network.getEnterpriseDirectory().getEnterpriseList();

        for (int j = 0; j < enterpriseList.size(); j++) {
            enterprise = enterpriseList.get(j);
            enterpriseNode = new DefaultMutableTreeNode(enterprise.getName());
            networkNode.insert(enterpriseNode, j);

            organizationList = enterprise.getOrganizationDirectory().getOrganizationList();

            for (int k = 0; k < organizationList.size(); k++) {
                organization = organizationList.get(k);
                organizationNode = new DefaultMutableTreeNode(organization.getName());
                enterpriseNode.insert(organizationNode, k);
            }
        }
    }
    model.reload();
}