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:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java

public boolean alterParameterTree(final IIntelliContext ctx) {
    // create initial population
    final DefaultMutableTreeNode root = ctx.getParameterTreeRootNode();
    final DefaultMutableTreeNode newRoot = getAlteredParameterTreeRootNode(ctx);

    if (root != null) {
        root.removeAllChildren();/*from   www  .ja  v  a2s.c o  m*/
        final int count = newRoot.getChildCount();

        for (int i = 0; i < count; ++i)
            root.add((DefaultMutableTreeNode) newRoot.getChildAt(0));
    }

    return true;
}

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

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

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

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

    // 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 (((QueryData) node1.getUserObject()).visualAttribute().equals("LAO")
                && ((QueryData) node1.getUserObject()).name().equals("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);
            QueryData adata = (QueryData) anode.getUserObject();
            if (adata.visualAttribute().equals("FAO")) {
                adata.visualAttribute("FA");
            } else if (adata.visualAttribute().equals("CAO")) {
                adata.visualAttribute("CA");
            }
        }
    }
}

From source file:eu.crisis_economics.abm.dashboard.GASearchHandler.java

public void addSubmodelParameter(final SubmodelInfo sInfo, final DefaultMutableTreeNode node)
        throws ModelInformationException {
    if (sInfo.getActualType() == null) {
        if (node.getChildCount() > 0) {
            node.removeAllChildren();//ww  w.ja v a  2s. c o  m
            chromosomeTree.nodeStructureChanged(node);
        }

        return;
    }

    final List<ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?>> subparameters = ParameterTreeUtils
            .fetchSubparameters(currentModelHandler, sInfo);

    final List<ParameterInfo> convertedSubparameters = new ArrayList<ParameterInfo>(subparameters.size());
    for (ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?> parameterInfo : subparameters) {
        final ParameterInfo converted = InfoConverter.parameterInfo2ParameterInfo(parameterInfo);
        converted.setRuns(0);
        convertedSubparameters.add(converted);
    }
    Collections.sort(convertedSubparameters);

    if (node.getChildCount() > 0) {
        node.removeAllChildren();
        chromosomeTree.nodeStructureChanged(node);
    }

    for (final ParameterInfo pInfo : convertedSubparameters) {
        final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(new ParameterOrGene(pInfo));
        chromosomeTree.insertNodeInto(newNode, node, node.getChildCount());

        if (pInfo instanceof SubmodelInfo) {
            final SubmodelInfo ssInfo = (SubmodelInfo) pInfo;
            if (ssInfo.getActualType() != null)
                addSubmodelParameter(ssInfo, newNode);
        }

    }
}

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

public DefaultMutableTreeNode insertNode(QueryMasterData node) {
    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);

    if (ascending) {
        treeModel.insertNodeInto(childNode, top, top.getChildCount());
    } else {/*w  ww  .  j  a v a 2  s  .  c  o m*/
        treeModel.insertNodeInto(childNode, top, 0);
    }

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

    previousQueries.add(node);

    return childNode;
}

From source file:com.lp.client.frame.component.PanelDokumentenablage.java

private void setSearchedDocumentsOnTree(DefaultMutableTreeNode top, ArrayList<DocPath> docPaths)
        throws ExceptionLP, RepositoryException, Throwable {
    if (docPaths.size() == 0)
        treeModel.insertNodeInto(new DefaultMutableTreeNode("..."), top, 0);

    DefaultMutableTreeNode treeNode;
    for (DocPath path : docPaths) {
        treeNode = top;/*from w w  w  . j  a  v a 2s .  c o  m*/
        boolean firstNode = true;
        for (DocNodeBase node : path.asDocNodeList()) {
            if (firstNode) {
                firstNode = false;
            } else {
                int i = getDocNodeChildPos(node, treeNode);
                if (i == -1) {
                    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(node);
                    treeModel.insertNodeInto(newNode, treeNode, treeNode.getChildCount());
                    treeNode = newNode;
                } else {
                    treeNode = (DefaultMutableTreeNode) treeNode.getChildAt(i);
                }
            }
        }
    }
    tree.setModel(treeModel);
}

From source file:com.lp.client.frame.component.PanelDokumentenablage.java

private void refresh() throws ExceptionLP, Throwable {
    List<DocNodeBase> parts = fullDocPath.getDeepCopy().asDocNodeList();
    boolean isSuche = wtfSuche.getText() != null && !"".equals(wtfSuche.getText());

    DefaultMutableTreeNode dmtNode = null;
    Object[] toSelect = new Object[parts.size()];
    if (parts.size() > 0) {
        dmtNode = new DefaultMutableTreeNode(parts.get(0));
        toSelect[0] = dmtNode;/* ww  w  .j  ava  2s.c  om*/
        treeModel = new DefaultTreeModel(dmtNode);
        treeModel.addTreeModelListener(this);
    }
    for (int i = 1; i < parts.size() && !isSuche; i++) {
        DefaultMutableTreeNode toAdd = new DefaultMutableTreeNode(parts.get(i));
        toSelect[i] = toAdd;
        treeModel.insertNodeInto(toAdd, dmtNode, dmtNode.getChildCount());
        dmtNode = toAdd;
    }
    TreePath treePath = new TreePath(toSelect);
    TreePath treePathOld = null;
    if (toSelect.length >= 2) {
        treePathOld = new TreePath(toSelect[toSelect.length - 2]);
    } else {
        treePathOld = new TreePath(toSelect);
    }
    // Value Changed damit die Buttons korrekt angezeigt werden
    valueChanged(new TreeSelectionEvent(tree, treePath, true, treePathOld, treePath));
    if (isSuche) {
        setSearchedDocumentsOnTree(dmtNode,
                DelegateFactory.getInstance().getJCRDocDelegate().searchDocNodes(wtfSuche.getText()));
        for (int i = tree.getRowCount(); i > 0; i--) {
            tree.collapseRow(i);
        }
    } else if (dmtNode.getChildCount() == 0) {
        List<DocNodeBase> childDocNodes = DelegateFactory.getInstance().getJCRDocDelegate()
                .getDocNodeChildrenFromNode(fullDocPath);
        if (childDocNodes != null) {
            setDocNodesOnTree(dmtNode, childDocNodes, fullDocPath);
            tree.expandPath(treePath);
        }
    }
    tree.setSelectionPath(treePath);
}

From source file:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java

/**
 * /* ww  w  . ja v a2  s  . c o  m*/
 */
private void addColObjAsChild(final DefaultMutableTreeNode parentNodeArg, final CollectionObject colObj) {
    DefaultMutableTreeNode parentNode = parentNodeArg == null ? getSelectedTreeNode() : parentNodeArg;
    if (parentNode != null) {
        if (colObj != null) {
            Container container = (Container) parentNode.getUserObject();

            colObj.setContainerOwner(container);
            container.getCollectionObjectKids().add(colObj);

            DefaultMutableTreeNode newNode = new DefaultMutableTreeNode();
            newNode.setUserObject(colObj);
            colObjIdHash.add(colObj.getId());
            int inx = parentNode.getChildCount();
            model.insertNodeInto(newNode, parentNode, inx);
            model.nodesWereInserted(parentNode, new int[] { inx });
            model.nodeChanged(parentNode);
            model.reload();
            tree.restoreTree();

            expandToNode(newNode);
        }
    }
}

From source file:com.SE.myPlayer.MusicPlayerGUI.java

private void treeReferesh() {
        DefaultTreeModel myModel = (DefaultTreeModel) folder_Playlist_Tree.getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) myModel.getRoot();
        root.removeAllChildren();//from ww w  .j a  va  2s . c o m

        DefaultMutableTreeNode library = new DefaultMutableTreeNode("library");
        DefaultMutableTreeNode playlist = new DefaultMutableTreeNode("playlist");

        myModel.insertNodeInto(library, root, root.getChildCount());
        myModel.insertNodeInto(playlist, root, root.getChildCount());

        try {
            con = db.getCon();
            stmt = con.createStatement();
            String node;

            ResultSet rs = stmt.executeQuery("select pn_name from playlist_name");

            while (rs.next()) {
                node = rs.getString(1);
                DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(node);
                myModel.insertNodeInto(newNode, playlist, playlist.getChildCount());
            }

            if (con != null) {
                stmt.close();
                con.close();
            }
        } catch (SQLException e) {
            System.out.println("Error in Stmt " + e);
        }

        myModel.reload();
        folder_Playlist_Tree.setModel(myModel);
    }

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

private int fillBlockingThreadMaps(final MonitorMap mmap,
        final Map<String, DefaultMutableTreeNode> directChildMap) {
    int blockedThread = 0;
    for (Iterator iter = mmap.iterOfKeys(); iter.hasNext();) {
        String monitor = (String) iter.next();
        Map<String, String>[] threads = mmap.getFromMonitorMap(monitor);

        // Only one thread can really be holding this monitor, so find the thread
        String threadLine = getLockingThread(threads);
        ThreadInfo tmi = new ThreadInfo("Thread - " + threadLine, null, "", 0, null);
        DefaultMutableTreeNode threadNode = new DefaultMutableTreeNode(tmi);

        ThreadInfo mmi = new ThreadInfo("Monitor - " + monitor, null, "", 0, null);
        DefaultMutableTreeNode monitorNode = new DefaultMutableTreeNode(mmi);
        threadNode.add(monitorNode);//from w w  w.j  a v  a 2s.c om

        // Look over all threads blocked on this monitor
        for (final Object o : threads[MonitorMap.WAIT_THREAD_POS].keySet()) {
            String thread = (String) o;
            // Skip the thread that has this monitor locked
            if (!threads[MonitorMap.LOCK_THREAD_POS].containsKey(thread)) {
                blockedThread++;
                createNode(monitorNode, "Thread - " + thread, null,
                        threads[MonitorMap.WAIT_THREAD_POS].get(thread), 0);
            }
        }

        final String blockingStackFrame = threads[MonitorMap.LOCK_THREAD_POS].get(threadLine);
        tmi.setContent(blockingStackFrame);
        mmi.setContent("This monitor (" + linkifyMonitor(monitor)
                + ") is held in the following stack frame:\n\n" + blockingStackFrame);

        // If no-one is blocked on or waiting for this monitor, don't show it
        if (monitorNode.getChildCount() > 0) {
            directChildMap.put(monitor, threadNode);
        }
    }
    return blockedThread;
}

From source file:edu.harvard.i2b2.query.ui.ConceptTreePanel.java

private 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());
    }/*ww w . ja va  2 s  . c om*/
    // Make sure the user can see the lovely new node.
    // jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

    return childNode;
}