Example usage for javax.swing.tree DefaultMutableTreeNode add

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

Introduction

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

Prototype

public void add(MutableTreeNode newChild) 

Source Link

Document

Removes newChild from its parent and makes it a child of this node by adding it to the end of this node's child array.

Usage

From source file:gdt.jgui.entity.index.JIndexPanel.java

private DefaultMutableTreeNode instantiateNode(Sack index, String nodeKey$) {
    try {//from  w  w  w.j  a va 2  s.c  o  m
        //   System.out.println("IndexPanel:instantiateNode:"+nodeKey$);
        String nodeLocator$ = index.getElementItemAt("index.jlocator", nodeKey$);
        if (nodeLocator$ == null)
            return null;
        //   System.out.println("IndexPanel:instantiateNode:locator="+nodeLocator$);
        DefaultMutableTreeNode node = new DefaultMutableTreeNode();
        node.setUserObject(nodeLocator$);
        Properties locator = Locator.toProperties(nodeLocator$);
        if (!NODE_TYPE_GROUP.equals(locator.getProperty(NODE_TYPE)))
            return node;
        String[] sa = listOrderedGroupMembers(index, nodeKey$);
        if (sa == null || sa.length < 1) {
            System.out.println("IndexPanel:instantiateNode:no member in group=" + nodeKey$);
            return node;
        }
        DefaultMutableTreeNode member;
        //  System.out.println("IndexPanel:instantiateNode:members="+sa.length);

        for (String aSa : sa) {
            //nodeLocator$=index.getElementItemAt("index.jlocator", aSa);
            member = instantiateNode(index, aSa);
            if (member != null)
                node.add(member);
        }
        return node;
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
    return null;
}

From source file:dataviewer.DataViewer.java

private void fill_tree() {
    txt_count.setText("");

    DefaultTreeModel tm = (DefaultTreeModel) tr_files.getModel();
    DefaultMutableTreeNode top;
    cur_path = new File(cur_path).getAbsolutePath();
    if (cur_path.charAt(cur_path.length() - 1) == '.') {
        cur_path = cur_path.substring(0, cur_path.length() - 1);
    }/*from  w  w w .ja  v a 2s .com*/
    if (cur_path.charAt(cur_path.length() - 1) == File.separatorChar) {
        cur_path = cur_path.substring(0, cur_path.length() - 1);
    }
    if (tm != null) {
        top = (DefaultMutableTreeNode) tm.getRoot();
        top.removeAllChildren();
        top.setUserObject(cur_path);
    } else {
        top = new DefaultMutableTreeNode(cur_path);
    }

    // get all children nodes and remove them
    // rename the user object
    ArrayList<String> files = this.getAllFileNames(cur_path);
    Collections.sort(files);

    int j = 1;
    int selected_index = -1;
    for (String f : files) {
        String ex = this.getExtension(f);
        boolean is_folder = (new File(cur_path + File.separator + f)).isDirectory();
        if (is_folder || ex.equals(".txt") || ex.equals(".dat") || ex.equals(".csv") || ex.equals(".tsv")) {
            DefaultMutableTreeNode node = new DefaultMutableTreeNode(f);
            top.add(node);
            if (f.equals(selected_file)) {
                selected_index = j;
            }
            j++;
        }
    }

    //DefaultTreeModel treeModel = new DefaultTreeModel(top);
    //tr_files.setModel(treeModel);
    if (tm == null) {
        tr_files.setModel(new DefaultTreeModel(top));
    } else {
        try {
            tm.reload();
        } catch (Exception e) {
            tm.reload();
        }
    }

    if (selected_index > -1) {
        tr_files.setSelectionRow(selected_index);
    }

    tr_files.grabFocus();
}

From source file:gov.nih.nci.ncicb.cadsr.contexttree.service.impl.CDEBrowserTreeServiceImpl.java

/**
 * @returns a map with contextid as key and value a list of Classification nodes
 *//*from w ww.j  a  v  a  2  s. c  om*/
public Map getAllClassificationNodes(TreeFunctions treeFunctions, TreeIdGenerator idGen) throws Exception {
    Map csNodeByContextMap = new HashMap();

    FormDAO dao = daoFactory.getFormDAO();
    List allCscsi = dao.getCSCSIHierarchy();
    CDEBrowserParams params = CDEBrowserParams.getInstance();
    String[] regStatusArr = params.getCsTypeRegStatus().split(",");

    Map csMap = new HashMap(); //this map stores the webnode for cs given cs_idseq
    Map csiMap = new HashMap();
    Map<String, Map> regStatusMapByCsId = new HashMap();
    Map<String, Map> csiMapByRegStatus = new HashMap();
    for (int i = 0; i < regStatusArr.length; i++)
        csiMapByRegStatus.put(regStatusArr[i], new HashMap());

    Iterator iter = allCscsi.iterator();

    while (iter.hasNext()) {
        ClassSchemeItem cscsi = (ClassSchemeItem) iter.next();

        String csContextId = cscsi.getCsConteIdseq();

        DefaultMutableTreeNode classifcationNode = (DefaultMutableTreeNode) csNodeByContextMap.get(csContextId);

        if (classifcationNode == null) {
            //create a classification node for this context
            classifcationNode = getWebNode("Classifications", idGen.getNewId());

            csNodeByContextMap.put(csContextId, classifcationNode);
            csiMap.clear();
            csMap.clear();
        }

        String csId = cscsi.getCsIdseq();
        // create classification scheme node if necessary
        DefaultMutableTreeNode csNode = (DefaultMutableTreeNode) csMap.get(csId);

        if (csNode == null) {
            csNode = getClassificationSchemeNode(idGen.getNewId(), cscsi, treeFunctions);

            classifcationNode.add(csNode);
            csMap.put(csId, csNode);

            if (cscsi.getClassSchemeType().equalsIgnoreCase(params.getRegStatusCsTree())) {
                Map<String, DefaultMutableTreeNode> regStatusMap = new HashMap();
                for (int i = 0; i < regStatusArr.length; i++) {
                    DefaultMutableTreeNode regNode = getRegStatusNode(idGen.getNewId(), regStatusArr[i],
                            csContextId, csId, treeFunctions);
                    csNode.add(regNode);
                    regStatusMap.put(regStatusArr[i], regNode);
                }
                regStatusMapByCsId.put(csId, regStatusMap);
            }
        }

        // add csi node

        String parentId = cscsi.getParentCscsiId();
        DefaultMutableTreeNode parentNode = null;
        DefaultMutableTreeNode csiNode = null;

        if (!cscsi.getClassSchemeType().equalsIgnoreCase(params.getRegStatusCsTree())) {
            //this is a regular cs tree stucture
            csiNode = getClassificationSchemeItemNode(idGen.getNewId(), cscsi, treeFunctions);
            if (parentId != null)
                parentNode = (DefaultMutableTreeNode) csiMap.get(parentId);
            else
                parentNode = csNode;

            parentNode.add(csiNode);
            csiMap.put(cscsi.getCsCsiIdseq(), csiNode);

        } else {//this is the CS tree with registration status
            if (parentId == null) {
                //this is the first level csi link to reg status         
                Map<String, DefaultMutableTreeNode> regStatusNodesMap = regStatusMapByCsId.get(csId);
                for (int i = 0; i < regStatusArr.length; i++) {
                    if (dao.hasRegisteredAC(cscsi.getCsCsiIdseq(), regStatusArr[i])) {
                        csiNode = this.getRegStatusCSINode(idGen.getNewId(), cscsi, regStatusArr[i],
                                treeFunctions);
                        regStatusNodesMap.get(regStatusArr[i]).add(csiNode);
                        csiMapByRegStatus.get(regStatusArr[i]).put(cscsi.getCsCsiIdseq(), csiNode);
                    }
                }
            } else {
                for (int i = 0; i < regStatusArr.length; i++) {
                    if (dao.hasRegisteredAC(cscsi.getCsCsiIdseq(), regStatusArr[i])) {
                        csiNode = this.getRegStatusCSINode(idGen.getNewId(), cscsi, regStatusArr[i],
                                treeFunctions);
                        ((DefaultMutableTreeNode) csiMapByRegStatus.get(regStatusArr[i]).get(parentId))
                                .add(csiNode);
                        csiMapByRegStatus.get(regStatusArr[i]).put(cscsi.getCsCsiIdseq(), csiNode);
                    }
                }
            }
        }

        // for CTEP disease, add core, none core sub node
        if (treeFunctions.getTreeType().equals(TreeConstants.DE_SEARCH_TREE)) {
            if (cscsi.getClassSchemeItemType().equals("DISEASE_TYPE")) {
                if (cscsi.getClassSchemePrefName().equals("DISEASE")) {
                    csiNode.add(
                            this.getDiseaseSubNode(idGen.getNewId(), cscsi, treeFunctions, "Core Data Set"));

                    csiNode.add(this.getDiseaseSubNode(idGen.getNewId(), cscsi, treeFunctions,
                            "Non-Core Data Set"));
                }
            }
        }
    }

    return csNodeByContextMap;
}

From source file:it.imtech.metadata.MetaUtility.java

/**
 * Metodo che costruisce l'albero delle classificazione e setta il nodo
 * selezionato se esistente/*from   w  ww.  ja  v  a2 s  .  c  o  m*/
 *
 * @param nodes Il nodo nel quale aggiungere i nuovi nodi (Nodo Padre)
 * @param taxons La lista di nodi per livello
 */

private void recursiveOefosTreeviewBuild(DefaultMutableTreeNode nodes, TreeMap<Object, Taxon> taxons,
        String sequence, String panelname) throws Exception {
    try {
        for (Map.Entry<Object, Taxon> kv : taxons.entrySet()) {
            ClassNode iNode = new ClassNode("" + kv.getKey(),
                    kv.getValue().upstream_identifier + ": " + kv.getValue().description);

            ClassMutableNode inner = new ClassMutableNode(iNode);
            nodes.add(inner);
            String oefosname = panelname + "----" + sequence;
            if (this.oefos_path.get(oefosname) != null) {
                if (this.oefos_path.get(oefosname).containsValue(kv.getValue().TID)) {
                    selected = inner;
                }
            }

            recursiveOefosTreeviewBuild(inner, kv.getValue().subtaxons, sequence, panelname);
        }

        //          Utility.sortTreeChildren(nodes);
    } catch (Exception ex) {
        throw new Exception("Exception in recursiveOefosTreeviewBuild: " + ex.getStackTrace() + "\n");
    }
}

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

protected void createTree() {
    //Create a tree that allows multiple selection at a time.
    if (topNodes.size() == 1) {
        treeModel = new DefaultTreeModel((DefaultMutableTreeNode) topNodes.get(0));
        tree = new JTree(treeModel);
        tree.setRootVisible(!runningAsJConsolePlugin && !runningAsVisualVMPlugin);
        addTreeListener(tree);/*from   ww  w .  j  a  va 2 s  .c  om*/
        if (!runningAsJConsolePlugin && !runningAsVisualVMPlugin) {
            frame.setTitle("TDA - Thread Dumps of " + dumpFile);
        }
    } else {
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Thread Dump Nodes");
        treeModel = new DefaultTreeModel(root);
        for (Object topNode : topNodes) {
            root.add((DefaultMutableTreeNode) topNode);
        }
        tree = new JTree(root);
        tree.setRootVisible(false);
        addTreeListener(tree);
        if (!runningAsJConsolePlugin && !runningAsVisualVMPlugin) {
            if (!frame.getTitle().endsWith("...")) {
                frame.setTitle(frame.getTitle() + " ...");
            }
        }
    }

    tree.setShowsRootHandles(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);

    tree.setCellRenderer(new TreeRenderer());

    //Create the scroll pane and add the tree to it.
    ViewScrollPane treeView = new ViewScrollPane(tree, runningAsVisualVMPlugin);

    topSplitPane.setLeftComponent(treeView);

    Dimension minimumSize = new Dimension(200, 50);
    treeView.setMinimumSize(minimumSize);

    //Listen for when the selection changes.
    tree.addTreeSelectionListener(this);

    if (!runningAsJConsolePlugin && !runningAsVisualVMPlugin) {
        dt = new DropTarget(tree, new FileDropTargetListener());
    }

    createPopupMenu();

}

From source file:GUI.MainWindow.java

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

    // Create a new vuln
    Vulnerability vuln = new Vulnerability();
    vuln.setTitle("NEW");
    vuln.setIs_custom_risk(true);//from   ww  w .  j  av  a  2s .  c o  m
    vuln.setRisk_category("None");
    vuln.setImport_tool("ReportCompiler");
    vuln.setIdentifier();
    // Add it to the tree
    DefaultTreeModel dtm = (DefaultTreeModel) VulnTree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm.getRoot();
    DefaultMutableTreeNode new_vuln = new DefaultMutableTreeNode(vuln);
    root.add(new_vuln);
    // Refresh the GUI
    dtm.reload();
    // Now select 
    TreePath path = new TreePath(new_vuln.getPath());
    VulnTree.setSelectionPath(path);
    // Set focus on the title field
    this.VulnTitleTextField.requestFocus();
    this.VulnTitleTextField.selectAll();
}

From source file:org.jfree.chart.demo.SuperDemo.java

private MutableTreeNode createMultipleAxisChartsNode() {
    DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Multiple Axis Charts");
    DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode(
            new DemoDescription("DualAxisDemo1", "DualAxisDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode(
            new DemoDescription("DualAxisDemo2", "DualAxisDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode(
            new DemoDescription("DualAxisDemo3", "DualAxisDemo3.java"));
    DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode(
            new DemoDescription("DualAxisDemo4", "DualAxisDemo4.java"));
    DefaultMutableTreeNode defaultmutabletreenode5 = new DefaultMutableTreeNode(
            new DemoDescription("DualAxisDemo5", "DualAxisDemo5.java"));
    DefaultMutableTreeNode defaultmutabletreenode6 = new DefaultMutableTreeNode(
            new DemoDescription("MultipleAxisDemo1", "MultipleAxisDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode7 = new DefaultMutableTreeNode(
            new DemoDescription("MultipleAxisDemo2", "MultipleAxisDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode8 = new DefaultMutableTreeNode(
            new DemoDescription("MultipleAxisDemo3", "MultipleAxisDemo3.java"));
    DefaultMutableTreeNode defaultmutabletreenode9 = new DefaultMutableTreeNode(
            new DemoDescription("ParetoChartDemo1", "ParetoChartDemo1.java"));
    defaultmutabletreenode.add(defaultmutabletreenode1);
    defaultmutabletreenode.add(defaultmutabletreenode2);
    defaultmutabletreenode.add(defaultmutabletreenode3);
    defaultmutabletreenode.add(defaultmutabletreenode4);
    defaultmutabletreenode.add(defaultmutabletreenode5);
    defaultmutabletreenode.add(defaultmutabletreenode6);
    defaultmutabletreenode.add(defaultmutabletreenode7);
    defaultmutabletreenode.add(defaultmutabletreenode8);
    defaultmutabletreenode.add(defaultmutabletreenode9);
    return defaultmutabletreenode;
}

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

private void addDumpStream(InputStream inputStream, String file, boolean withLogfile) {
    final InputStream parseFileStream = new ProgressMonitorInputStream(this, "Parsing " + file, inputStream);

    //Create the nodes.
    if (!runningAsJConsolePlugin || topNodes.size() == 0) {
        topNodes.add(new DefaultMutableTreeNode(new Logfile(file)));
    }/*w ww  .  j av  a2  s . c  om*/
    final DefaultMutableTreeNode top = topNodes.get(topNodes.size() - 1);

    if ((!withLogfile && logFile == null) || isLogfileSizeOk(file)) {
        logFile = new DefaultMutableTreeNode(new LogFileContent(file));
        if (!runningAsVisualVMPlugin) {
            top.add(logFile);
        }
    }
    setFileOpen(true);

    final SwingWorker worker = new SwingWorker() {

        public Object construct() {
            synchronized (syncObject) {
                int divider = topSplitPane.getDividerLocation();
                addThreadDumps(top, parseFileStream);
                createTree();
                tree.expandRow(1);

                topSplitPane.setDividerLocation(divider);
            }

            return null;
        }
    };
    worker.start();
}

From source file:org.jfree.chart.demo.SuperDemo.java

private MutableTreeNode createStatisticalChartsNode() {
    DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Statistical Charts");
    DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode(
            new DemoDescription("BoxAndWhiskerChartDemo1", "BoxAndWhiskerChartDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode(
            new DemoDescription("HistogramDemo1", "HistogramDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode(
            new DemoDescription("NormalDistributionDemo1", "NormalDistributionDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode(
            new DemoDescription("RegressionDemo1", "RegressionDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode5 = new DefaultMutableTreeNode(
            new DemoDescription("ScatterPlotDemo1", "ScatterPlotDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode6 = new DefaultMutableTreeNode(
            new DemoDescription("ScatterPlotDemo2", "ScatterPlotDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode7 = new DefaultMutableTreeNode(
            new DemoDescription("ScatterPlotDemo3", "ScatterPlotDemo3.java"));
    DefaultMutableTreeNode defaultmutabletreenode8 = new DefaultMutableTreeNode(
            new DemoDescription("ScatterPlotDemo4", "ScatterPlotDemo4.java"));
    DefaultMutableTreeNode defaultmutabletreenode9 = new DefaultMutableTreeNode(
            new DemoDescription("XYErrorRendererDemo1", "XYErrorRendererDemo1.java"));
    defaultmutabletreenode.add(defaultmutabletreenode1);
    defaultmutabletreenode.add(defaultmutabletreenode2);
    defaultmutabletreenode.add(defaultmutabletreenode3);
    defaultmutabletreenode.add(defaultmutabletreenode4);
    defaultmutabletreenode.add(defaultmutabletreenode5);
    defaultmutabletreenode.add(defaultmutabletreenode6);
    defaultmutabletreenode.add(defaultmutabletreenode7);
    defaultmutabletreenode.add(defaultmutabletreenode8);
    defaultmutabletreenode.add(defaultmutabletreenode9);
    return defaultmutabletreenode;
}

From source file:gdt.jgui.entity.JEntityDigestDisplay.java

private void instantiateFacetNode(DefaultMutableTreeNode facetNode) {
    try {//  w w  w .  j  av  a2s .  c  om
        String facetNodeLocator$ = (String) facetNode.getUserObject();
        Properties locator = Locator.toProperties(facetNodeLocator$);
        Entigrator entigrator = console.getEntigrator(entihome$);
        String facetClass$ = locator.getProperty(BaseHandler.HANDLER_CLASS);
        //      System.out.println("EntityDigestDisplay:instantiateFacetNode:facet class="+facetClass$);
        JFacetOpenItem facetOpenItem = (JFacetOpenItem) JConsoleHandler.getHandlerInstance(entigrator,
                facetClass$);
        FacetHandler facetHandler = facetOpenItem.getFacetHandler();
        //      System.out.println("EntityDigestDisplay:instantiateFacetNode:facet handler="+facetHandler.getClassName());
        Sack entity = entigrator.getEntityAtKey(entityKey$);
        String entityLocator$ = EntityHandler.getEntityLocator(entigrator, entity);
        //      System.out.println("EntityDigestDisplay:instantiateFacetNode:entity locator="+entityLocator$);
        DefaultMutableTreeNode facetComponentNode;
        if (facetHandler.isApplied(entigrator, entityLocator$)) {
            //      System.out.println("EntityDigestDisplay:instantiateFacetNode:entity locator="+entityLocator$);
            entityLocator$ = Locator.append(entityLocator$, Locator.LOCATOR_TYPE, LOCATOR_FACET_COMPONENT);
            entityLocator$ = Locator.append(entityLocator$, BaseHandler.HANDLER_CLASS, facetClass$);
            entityLocator$ = Locator.append(entityLocator$, NODE_TYPE, NODE_TYPE_FACET_OWNER);
            entityLocator$ = Locator.append(entityLocator$, NODE_NUMBER, String.valueOf(nodeNumber++));
            facetComponentNode = new DefaultMutableTreeNode();
            facetComponentNode.setUserObject(entityLocator$);
            instantiateComponentNode(facetComponentNode);
            facetNode.add(facetComponentNode);
        }
        String[] sa = entigrator.ent_listComponents(entity);
        if (sa != null) {
            Sack component;
            for (String aSa : sa) {
                component = entigrator.getEntityAtKey(aSa);
                if (component == null)
                    continue;
                entityLocator$ = EntityHandler.getEntityLocator(entigrator, component);
                if (facetHandler.isApplied(entigrator, entityLocator$)) {
                    entityLocator$ = Locator.append(entityLocator$, Locator.LOCATOR_TYPE,
                            LOCATOR_FACET_COMPONENT);
                    entityLocator$ = Locator.append(entityLocator$, BaseHandler.HANDLER_CLASS, facetClass$);
                    facetComponentNode = new DefaultMutableTreeNode();
                    facetComponentNode.setUserObject(entityLocator$);
                    instantiateComponentNode(facetComponentNode);
                    facetNode.add(facetComponentNode);
                }
            }
        }
    } catch (Exception e) {
        Logger.getLogger(getClass().getName()).severe(e.toString());
    }
}