Example usage for javax.swing.tree DefaultMutableTreeNode getChildCount

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

Introduction

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

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children of this node.

Usage

From source file:edu.harvard.i2b2.query.QueryConceptTreePanel.java

public DefaultMutableTreeNode addNode(QueryConceptTreeNodeData node) {
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

    QueryConceptTreeNodeData tmpData = new QueryConceptTreeNodeData();
    tmpData.name("working ......");
    tmpData.tooltip("A tmp node");
    tmpData.visualAttribute("LAO");
    DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(tmpData);

    treeModel.insertNodeInto(childNode, top, top.getChildCount());
    treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    //Make sure the user can see the lovely new node.
    jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

    return childNode;
}

From source file:SuitaDetails.java

public void setComboTBs() {
    if (parent == null)
        return;/*from w  w  w.j a v  a 2 s. com*/
    for (ListSelectionListener l : combo.getListSelectionListeners()) {
        combo.removeListSelectionListener(l);
    }
    StringBuilder b = new StringBuilder();
    DefaultMutableTreeNode root = RunnerRepository.window.mainpanel.p4.getSut().sut.root;
    int sutsnr = root.getChildCount();
    for (int i = 0; i < sutsnr; i++) {
        b.append(root.getChildAt(i).toString());
        b.append(";");
    }

    //         StringBuilder b = new StringBuilder();

    //         Node parentnode = RunnerRepository.window.mainpanel.p4.getTB().getParentNode();
    //         HashMap children =  parentnode.getChildren();
    //         if(children!=null&&children.size()!=0){
    //             Set keys = children.keySet();
    //             Iterator iter = keys.iterator();
    //             while(iter.hasNext()){
    //                 String n = iter.next().toString();
    //                 String name = parentnode.getChild(n).getName();
    //                 b.append(name);
    //                 b.append(";");
    //             }
    //         }
    String[] vecresult = b.toString().split(";");

    combo.setModel(new DefaultComboBoxModel(vecresult));

    String[] strings = parent.getEpId();
    ArrayList<String> array = new ArrayList<String>(Arrays.asList(vecresult));
    int[] sel = new int[strings.length];
    for (int i = 0; i < strings.length; i++) {
        sel[i] = array.indexOf(strings[i]);
    }
    combo.setSelectedIndices(sel);
    combo.addListSelectionListener(new MyListSelectionListener());

}

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

private void renormalizeMonitorDepth(DefaultMutableTreeNode monitorNode, int index) {
    // First, remove all duplicates of the item at index "index"
    DefaultMutableTreeNode threadNode1 = (DefaultMutableTreeNode) monitorNode.getChildAt(index);
    ThreadInfo mi1 = (ThreadInfo) threadNode1.getUserObject();
    int i = index + 1;
    while (i < monitorNode.getChildCount()) {
        DefaultMutableTreeNode threadNode2 = (DefaultMutableTreeNode) monitorNode.getChildAt(i);
        ThreadInfo mi2 = (ThreadInfo) threadNode2.getUserObject();
        if (mi1.getName().equals(mi2.getName())) {
            if (threadNode2.getChildCount() > 0) {
                threadNode1.add((DefaultMutableTreeNode) threadNode2.getFirstChild());
                monitorNode.remove(i);//  w ww  .j ava2  s . c o  m
                continue;
            }
        }
        i++;
    }

    // Second, recurse into item "index"
    renormalizeThreadDepth(threadNode1);
}

From source file:TreeEditTest.java

/**
 * Makes the buttons to add a sibling, add a child, and delete a node.
 *//* w  w  w. ja v a 2 s .co  m*/
public void makeButtons() {
    JPanel panel = new JPanel();
    JButton addSiblingButton = new JButton("Add Sibling");
    addSiblingButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

            if (selectedNode == null)
                return;

            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent();

            if (parent == null)
                return;

            DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("New");

            int selectedIndex = parent.getIndex(selectedNode);
            model.insertNodeInto(newNode, parent, selectedIndex + 1);

            // now display new node

            TreeNode[] nodes = model.getPathToRoot(newNode);
            TreePath path = new TreePath(nodes);
            tree.scrollPathToVisible(path);
        }
    });
    panel.add(addSiblingButton);

    JButton addChildButton = new JButton("Add Child");
    addChildButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

            if (selectedNode == null)
                return;

            DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("New");
            model.insertNodeInto(newNode, selectedNode, selectedNode.getChildCount());

            // now display new node

            TreeNode[] nodes = model.getPathToRoot(newNode);
            TreePath path = new TreePath(nodes);
            tree.scrollPathToVisible(path);
        }
    });
    panel.add(addChildButton);

    JButton deleteButton = new JButton("Delete");
    deleteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

            if (selectedNode != null && selectedNode.getParent() != null)
                model.removeNodeFromParent(selectedNode);
        }
    });
    panel.add(deleteButton);
    add(panel, BorderLayout.SOUTH);
}

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

private void reNormalizeBlockingThreadTree(final MonitorMap mmap,
        final Map<String, DefaultMutableTreeNode> directChildMap) {
    Map<String, DefaultMutableTreeNode> allBlockingThreadsMap = new HashMap<>(directChildMap); // All threads that are blocking at least one other thread

    // First, re-normalize based on monitors to get our unique tree
    // Tree will be unique as long as there are no deadlocks aka monitor loops
    for (Iterator iter = mmap.iterOfKeys(); iter.hasNext();) {
        String monitor1 = (String) iter.next();
        Map<String, String>[] threads1 = mmap.getFromMonitorMap(monitor1);

        final DefaultMutableTreeNode thread1Node = allBlockingThreadsMap.get(monitor1);
        if (thread1Node == null) {
            continue;
        }// w  w w.  j a  v  a 2 s  .  c o m

        // Get information on the one thread holding this lock
        Iterator it = threads1[MonitorMap.LOCK_THREAD_POS].keySet().iterator();
        if (!it.hasNext()) {
            continue;
        }
        String threadLine1 = (String) it.next();

        for (Iterator iter2 = mmap.iterOfKeys(); iter2.hasNext();) {
            String monitor2 = (String) iter2.next();
            if (monitor1 == monitor2) {
                continue;
            }

            Map<String, String>[] threads2 = mmap.getFromMonitorMap(monitor2);
            if (threads2[MonitorMap.WAIT_THREAD_POS].containsKey(threadLine1)) {
                // Get the node of the thread that is holding this lock
                DefaultMutableTreeNode thread2Node = (DefaultMutableTreeNode) allBlockingThreadsMap
                        .get(monitor2);
                // Get the node of the monitor itself
                DefaultMutableTreeNode monitor2Node = (DefaultMutableTreeNode) thread2Node.getFirstChild();

                // If a redundant node for thread2 exists with no children, remove it
                // To compare, we have to remove "Thread - " from the front of display strings
                for (int i = 0; i < monitor2Node.getChildCount(); i++) {
                    DefaultMutableTreeNode child2 = (DefaultMutableTreeNode) monitor2Node.getChildAt(i);
                    if (child2.toString().substring(9).equals(threadLine1) && child2.getChildCount() == 0) {
                        monitor2Node.remove(i);
                        break;
                    }
                }

                // Thread1 is blocked by monitor2 held by thread2, so move thread1 under thread2
                monitor2Node.insert(thread1Node, 0);
                directChildMap.remove(monitor1);
                break;
            }
        }
    }

    allBlockingThreadsMap.clear();

    // Second, re-normalize top level based on threads for cases where one thread holds multiple monitors
    boolean changed;
    do {
        changed = false;
        for (final Object o : directChildMap.entrySet()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((Map.Entry) o).getValue();
            if (checkForDuplicateThreadItem(directChildMap, node)) {
                changed = true;
                break;
            }
        }
    } while (changed);

    // Third, renormalize lower levels of the tree based on threads for cases where one thread holds multiple monitors
    for (final Object o : directChildMap.entrySet()) {
        renormalizeThreadDepth((DefaultMutableTreeNode) ((Map.Entry) o).getValue());
    }
}

From source file:com.emental.mindraider.ui.outline.OutlineJPanel.java

/**
 * Demote concept.// www.  j  ava 2s  .c  o m
 */
public void conceptDemote() {
    // current node becomes the first child of the previous sibling, if node
    // has index 0, then do nothing
    DefaultMutableTreeNode node = getSelectedTreeNode();
    if (node != null) {
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
        if (parent != null) {
            DefaultMutableTreeNode previous = (DefaultMutableTreeNode) parent.getChildBefore(node);
            if (previous != null) {
                parent.remove(node);
                previous.insert(node, previous.getChildCount());
                treeTable.updateUI();

                logger.debug(Messages.getString("NotebookOutlineJPanel.conceptDemoted"));

                MindRaider.noteCustodian.demote(MindRaider.outlineCustodian.getActiveOutlineResource(),
                        ((OutlineNode) parent).getUri(), ((OutlineNode) node).getUri());

                setSelectedTreeNodeConcept(((OutlineNode) node).getUri());
            } else {
                logger.debug(Messages.getString("NotebookOutlineJPanel.isTheFirstChild"));
            }
        } else {
            logger.debug(Messages.getString("NotebookOutlineJPanel.noParent"));
        }
    } else {
        logger.debug(Messages.getString("NotebookOutlineJPanel.noNodeSelected!"));
    }
}

From source file:edu.harvard.i2b2.query.QueryConceptTreePanel.java

public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    QueryConceptTreeNodeData data = (QueryConceptTreeNodeData) node.getUserObject();

    //System.out.println("Node will expand: "+data.dimcode());   

    if (data.visualAttribute().equals("FA")) {
        data.visualAttribute("FAO");
    } else if (data.visualAttribute().equals("CA")) {
        data.visualAttribute("CAO");
    }/*from  w ww . j  a v a 2  s  . com*/

    // check to see if child is a placeholder ('working...')
    //   if so, make Web Service call to update children of node
    if (node.getChildCount() == 1
            && !(node.getChildAt(0).toString().equalsIgnoreCase("Over 300 child nodes"))) {
        DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getChildAt(0);
        if (((QueryConceptTreeNodeData) node1.getUserObject()).visualAttribute().equals("LAO")) {
            populateChildNodes(node);
        }
    } else {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode anode = (DefaultMutableTreeNode) node.getChildAt(0);
            QueryConceptTreeNodeData adata = (QueryConceptTreeNodeData) anode.getUserObject();
            if (adata.visualAttribute().equals("FAO")) {
                adata.visualAttribute("FA");
            } else if (adata.visualAttribute().equals("CAO")) {
                adata.visualAttribute("CA");
            }
        }
    }
}

From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java

public DefaultMutableTreeNode addNode(QueryMasterData node, DefaultMutableTreeNode parent) {
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

    QueryMasterData tmpData = new QueryMasterData();
    tmpData.name("working ......");
    tmpData.tooltip("A tmp node");
    tmpData.visualAttribute("LAO");
    DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(tmpData);

    treeModel.insertNodeInto(childNode, parent, parent.getChildCount());
    if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) {
        treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    }//  w  w w.ja  va  2 s  . com
    //Make sure the user can see the lovely new node.
    jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

    return childNode;
}

From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java

public DefaultMutableTreeNode addNode(QueryConceptTreeNodeData node, DefaultMutableTreeNode parent) {
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

    QueryConceptTreeNodeData tmpData = new QueryConceptTreeNodeData();
    tmpData.name("working ......");
    tmpData.tooltip("A tmp node");
    tmpData.visualAttribute("LAO");
    DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(tmpData);

    treeModel.insertNodeInto(childNode, parent, parent.getChildCount());
    if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) {
        treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    }/*from   w  w w  . j av  a 2  s .c o  m*/
    //Make sure the user can see the lovely new node.
    jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

    return childNode;
}

From source file:edu.harvard.i2b2.query.QueryConceptTreePanel.java

public void treeExpanded(TreeExpansionEvent event) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    QueryConceptTreeNodeData data = (QueryConceptTreeNodeData) node.getUserObject();
    jTree1.scrollPathToVisible(new TreePath(node));

    //System.out.println("Node expanded: "+data.dimcode());   

    if (data.visualAttribute().equals("FA")) {
        data.visualAttribute("FAO");
    } else if (data.visualAttribute().equals("CA")) {
        data.visualAttribute("CAO");
    }// w w w.  j av  a 2s  .co m

    // check to see if child is a placeholder ('working...')
    //   if so, make Web Service call to update children of node
    if (node.getChildCount() == 1) {
        final DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getChildAt(0);
        if (((QueryConceptTreeNodeData) node1.getUserObject()).name().equalsIgnoreCase("working ......")) {
            final DefaultMutableTreeNode anode = node;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    populateChildNodes(anode);
                }
            });
        }
    } else {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode anode = (DefaultMutableTreeNode) node.getChildAt(0);
            QueryConceptTreeNodeData adata = (QueryConceptTreeNodeData) anode.getUserObject();
            if (adata.visualAttribute().equals("FAO")) {
                adata.visualAttribute("FA");
            } else if (adata.visualAttribute().equals("CAO")) {
                adata.visualAttribute("CA");
            }
        }
    }
}