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:com.lp.client.frame.component.PanelDokumentenablage.java

private void addNotExistingNodes(DocPath pathToAdd, DefaultMutableTreeNode top) {
    if (pathToAdd == null || pathToAdd.size() == 0) {
        treeModel.insertNodeInto(new DefaultMutableTreeNode(MUST_LOAD_CHILDREN), top, 0);
        return;/*from   w  ww. j  a va  2s.c  om*/
    }
    boolean exists = false;
    DefaultMutableTreeNode node = null;
    for (int i = 0; i < top.getChildCount(); i++) {
        node = (DefaultMutableTreeNode) top.getChildAt(i);
        if (pathToAdd.asDocNodeList().get(0).toString().equals(node.getUserObject().toString())) {
            exists = true;
            break;
        }
    }
    if (!exists) {
        node = new DefaultMutableTreeNode(pathToAdd.asDocNodeList().get(0));
        treeModel.insertNodeInto(node, top, top.getChildCount());
    }
    DocPath subPath = pathToAdd.getDeepCopy();
    subPath.asDocNodeList().remove(0);
    addNotExistingNodes(subPath, node);
}

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

public DefaultMutableTreeNode addNode(QueryResultData node, DefaultMutableTreeNode parent) {
    //QueryInstanceData rundata = (QueryInstanceData) parent.getUserObject();

    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

    QueryInstanceData tmpData = new QueryInstanceData();
    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  . j a  v  a 2  s.  c o  m*/
    //Make sure the user can see the lovely new node.
    jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

    DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) parent.getChildAt(0);
    QueryData tmpdata = (QueryData) tmpnode.getUserObject();
    if (tmpdata.name().equalsIgnoreCase("working ......")) {
        treeModel.removeNodeFromParent(tmpnode);
    }

    return childNode;
}

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

public DefaultMutableTreeNode addNode(QueryInstanceData node, DefaultMutableTreeNode parent) {
    QueryMasterData logicdata = (QueryMasterData) parent.getUserObject();
    logicdata.runs.add(node);//from  w w  w. j av a 2  s . c o  m

    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

    QueryInstanceData tmpData = new QueryInstanceData();
    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());
    }
    //Make sure the user can see the lovely new node.
    jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

    DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) parent.getChildAt(0);
    QueryData tmpdata = (QueryData) tmpnode.getUserObject();
    if (tmpdata.name().equalsIgnoreCase("working ......")) {
        treeModel.removeNodeFromParent(tmpnode);
    }

    return childNode;
}

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

public DefaultMutableTreeNode addNode(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);

    treeModel.insertNodeInto(childNode, top, top.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 om
    //Make sure the user can see the lovely new node.
    jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

    return childNode;
}

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

/**
 * Tells the tree model that a node hash changed.
 * @param parentNode the parent node//from  w  ww  . j  a  v  a2s .  c o  m
 * @param model the tree model
 * @param updateChildren update kids
 */
protected void updateTreeNodes(final DefaultMutableTreeNode parentNode, final DefaultTreeModel model,
        final boolean updateChildren) {
    model.nodeChanged(parentNode);
    if (updateChildren) {
        for (int i = 0; i < parentNode.getChildCount(); i++) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) parentNode.getChildAt(i);
            updateTreeNodes(node, model, true);
        }
    }
}

From source file:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java

private void addParameter(final ParameterOrGene parameterOrGene) {
    if (chromosomeTree == null) {
        chromosomeTree = new DefaultTreeModel(new DefaultMutableTreeNode());
        genes = null;//from www. j a v  a 2 s.co m
    }

    final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(parameterOrGene);
    final DefaultMutableTreeNode root = (DefaultMutableTreeNode) chromosomeTree.getRoot();
    chromosomeTree.insertNodeInto(newNode, root, root.getChildCount());

    if (listeners != null) {
        for (final ModelListener listener : listeners)
            listener.parameterAdded();
    }
}

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

public boolean alterParameterTree(final IIntelliContext ctx) {

    // create initial population
    final DefaultMutableTreeNode root = ctx.getParameterTreeRootNode();
    final DefaultMutableTreeNode newRoot = getAlteredParameterTreeRootNode(ctx);
    root.removeAllChildren();/*from   w  w w. ja  v a2s  .c om*/
    final int count = newRoot.getChildCount();

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

    return true;
}

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

public void addParameter(final ParameterOrGene parameterOrGene) throws ModelInformationException {
    if (chromosomeTree == null) {
        chromosomeTree = new DefaultTreeModel(new DefaultMutableTreeNode());
        genes = null;//from   w  ww  .j  a  v a2  s .  c o  m
    }

    final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(parameterOrGene);
    final DefaultMutableTreeNode root = (DefaultMutableTreeNode) chromosomeTree.getRoot();
    chromosomeTree.insertNodeInto(newNode, root, root.getChildCount());

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

    for (final ModelListener listener : listeners)
        listener.parameterAdded();
}

From source file:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java

public void setRecordableVariables(final DefaultMutableTreeNode root) {
    final List<RecordableInfo> newList = new ArrayList<RecordableInfo>();

    if (root.getChildCount() > 0) {
        final DefaultMutableTreeNode recorder = (DefaultMutableTreeNode) root.getChildAt(0);
        final ResultInfo resultInfo = (ResultInfo) recorder.getFirstLeaf().getUserObject();
        workspace = new File(resultInfo.getFile()).getParentFile();
        //first two children contains recorder meta data
        for (int j = 2; j < recorder.getChildCount(); ++j) {
            final RecordableElement re = (RecordableElement) ((DefaultMutableTreeNode) recorder.getChildAt(j))
                    .getUserObject();/*from ww  w .  jav  a  2 s  .c o m*/
            final RecordableInfo recInfo = new RecordableInfo(
                    re.getAlias() != null ? re.getAlias() : re.getInfo().getName(), re.getInfo().getJavaType(),
                    re.getInfo().getName());
            if (!newList.contains(recInfo) && re.getInfo().isNumeric()) {
                newList.add(recInfo);
            }
        }
    }

    final RecordableInfo oldSelectedFunction = selectedFunction;
    removeAllFitnessFunctions();
    fitnessFunctions.addAll(newList);

    if (listeners != null) {
        for (final ModelListener listener : listeners) {
            listener.fitnessFunctionAdded();
        }
    }

    if (oldSelectedFunction != null) {
        RecordableInfo selectedFunctionInTheList = null;
        for (final RecordableInfo ri : fitnessFunctions) {
            if (ri.equals(oldSelectedFunction)) {
                // accessible name equality
                selectedFunctionInTheList = ri;
            }
        }

        if (selectedFunctionInTheList != null) {
            selectedFunction = selectedFunctionInTheList;
            if (listeners != null) {
                for (final ModelListener listener : listeners) {
                    listener.fitnessFunctionSelected(selectedFunction);
                }
            }
        }

    }

}

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

/**
 * @param parentNode// w  w  w  .j av a  2s . c o  m
 * @param container
 * @param colObj
 */
private void loadContainerTree(final DefaultMutableTreeNode parentNode, final Container container,
        final CollectionObject colObj) {
    if (container != null) {
        container.forceLoad();

        int cnt = parentNode.getChildCount();
        Vector<CollectionObject> coKids = new Vector<CollectionObject>(container.getCollectionObjectKids());
        Collections.sort(coKids);
        for (CollectionObject co : coKids) {
            cnt = parentNode.getChildCount();
            DefaultMutableTreeNode node = new DefaultMutableTreeNode();
            node.setUserObject(co);
            colObjIdHash.add(co.getId());
            model.insertNodeInto(node, parentNode, cnt);
            loadContainerTree(node, null, co);
        }

        Vector<Container> cnKids = new Vector<Container>(container.getChildrenList());
        Collections.sort(cnKids);
        for (Container cn : cnKids) {
            cnt = parentNode.getChildCount();
            DefaultMutableTreeNode node = new DefaultMutableTreeNode();
            node.setUserObject(cn);
            containerIdHash.add(cn.getId());
            model.insertNodeInto(node, parentNode, cnt);
            loadContainerTree(node, cn, null);
        }

    } else if (colObj != null) {
        if (colObj.getContainer() != null) {
            loadContainerTree(parentNode, colObj.getContainer(), null);
        }
    } else {
        // error
    }
}