Example usage for javax.swing.tree DefaultMutableTreeNode children

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

Introduction

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

Prototype

Vector children

To view the source code for javax.swing.tree DefaultMutableTreeNode children.

Click Source Link

Document

array of children, may be null if this node has no children

Usage

From source file:org.apache.jetspeed.portlets.site.PortalSiteManager.java

private void findTreeNodeByPath(DefaultMutableTreeNode node, String path,
        List<DefaultMutableTreeNode> treeNodeList, int maxSize) {
    SiteTreeNode siteTreeNode = (SiteTreeNode) node.getUserObject();

    if (siteTreeNode != null && path.equals(siteTreeNode.getNodePath())) {
        treeNodeList.add(node);/*  w w  w . j  a  va  2s  .c om*/
    }

    if (treeNodeList.size() >= maxSize) {
        return;
    }

    for (Enumeration children = node.children(); children.hasMoreElements();) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
        findTreeNodeByPath(child, path, treeNodeList, maxSize);

        if (treeNodeList.size() >= maxSize) {
            return;
        }
    }
}

From source file:org.codinjutsu.tools.nosql.redis.view.RedisFragmentedKeyTreeModel.java

private static void addChildren(DefaultMutableTreeNode parentNode, DefaultMutableTreeNode originalChildNode) {
    Enumeration children = originalChildNode.children();
    while (children.hasMoreElements()) {
        DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement();
        parentNode.add((MutableTreeNode) childNode.clone());
    }//w  w w  . ja v  a  2 s  .c o m
}

From source file:org.kepler.objectmanager.cache.LocalRepositoryManager.java

/**
 * // w  w  w.  j ava2 s. co m
 * @param dmtn
 * @param dir
 * @return the TreeNode that corresponds to the given directory name
 */
private DefaultMutableTreeNode checkChildren(DefaultMutableTreeNode dmtn, File folder) {

    Enumeration<?> children = dmtn.children();
    while (children.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
        if (child.getUserObject().equals(folder)) {
            return child;
        }

    }
    return null;
}

From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java

private DefaultMutableTreeNode findTestSuiteNodeByName(String platformName, String testSuiteName) {
    DefaultMutableTreeNode retval = null;

    DefaultMutableTreeNode platformNode = findPlatformNodeByName(platformName);

    if (platformNode != null) {
        Enumeration<RepositoryNode> children = platformNode.children();

        while (children.hasMoreElements()) {
            RepositoryNode node = children.nextElement();

            if (node.getUserObject() instanceof TestSuite) {
                TestSuite testSuite = (TestSuite) node.getUserObject();

                if (StringUtils.equalsIgnoreCase(testSuiteName, testSuite.getName())) {
                    retval = node;/*  ww w  .j a  v a2  s  . c  om*/
                    break;
                }
            }
        }
    }

    return retval;
}

From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java

private DefaultMutableTreeNode findSuiteTestNode(SuiteTest suiteTest) {
    DefaultMutableTreeNode retval = null;

    DefaultMutableTreeNode testSuiteNode = findTestSuiteNodeByName(suiteTest.getTestHeader().getPlatformName(),
            suiteTest.getTestHeader().getTestSuiteName());

    if (testSuiteNode != null) {
        Enumeration<RepositoryNode> children = testSuiteNode.children();

        while (children.hasMoreElements()) {
            RepositoryNode node = children.nextElement();

            if (node.getUserObject() instanceof SuiteTest) {
                SuiteTest cur = (SuiteTest) node.getUserObject();

                if (StringUtils.equalsIgnoreCase(suiteTest.getTestHeader().getTestName(),
                        cur.getTestHeader().getTestName()) && (suiteTest.getIndex() == cur.getIndex())) {
                    retval = node;//from w  ww  . j a  va  2s.c om
                    break;
                }
            }
        }
    }

    return retval;
}

From source file:org.mbari.aved.ui.classifier.knowledgebase.ConceptTree.java

/**
 * Expands all tree nodes from the root down to the specified node name. Does
 * not expand the final node as that node may not have any children.
 *
 * @param  name   The name of the final node.
 * @return    The final node, which itself has not been expanded.
 *///w ww.ja  va2 s  .  c  o m
DefaultMutableTreeNode expandDownToNode(String name) {

    /*
     * Get a list of the family tree for the parameter concept. This list is
     * used to travel down the tree to the desired concept node.
     */
    List list = null;

    try {
        list = KnowledgeBaseCache.getInstance().findConceptFamilyTree(name);
    } catch (DAOException e) {
        if (log.isErrorEnabled()) {
            log.error("Call to knowledgebase cache failed");
        }

        AppFrameDispatcher.showErrorDialog(
                "There was a problem talking" + " to the database. Unable to open '" + name + "' in the tree.");
    }

    Iterator familyTree = list.iterator();

    // Pop the root Concept off the stack since it is the degenerative case.
    familyTree.next();

    // Then walk down the family tree, starting at the root node.
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) getModel().getRoot();

    while (familyTree.hasNext()) {
        String nextConceptName = ((Concept) familyTree.next()).getPrimaryConceptNameAsString();

        // Need to ensure the tree node for the current family name is expanded.
        TreeConcept treeConcept = (TreeConcept) treeNode.getUserObject();

        treeConcept.lazyExpand(treeNode);

        // Find the child node for the next family member.
        boolean found = false;
        Enumeration childrenNodes = treeNode.children();

        while (!found && childrenNodes.hasMoreElements()) {
            treeNode = (DefaultMutableTreeNode) childrenNodes.nextElement();
            treeConcept = (TreeConcept) treeNode.getUserObject();

            if (nextConceptName.equals(treeConcept.getName())) {
                found = true;
            }
        }
    }

    /*
     * RxNOTE The final value of treeNode drops out of the above while loop
     * without a call to lazyExpand. This is purposeful as the final node may
     * or may not have children. We are only expanding down to the node, not
     * expanding the node itself.
     */
    return treeNode;
}

From source file:org.mbari.aved.ui.classifier.knowledgebase.ConceptTree.java

/**
 * Makes the children nodes under the specified node invisible.
 *
 * @param  node   The node on which to act.
 *//*from   w  ww  .j  ava2 s  . c o m*/
private void makeChildrenInvisible(DefaultMutableTreeNode node) {
    Enumeration children = node.children();

    while (children.hasMoreElements()) {
        DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement();

        if (!childNode.isLeaf()) {
            makeChildrenInvisible(childNode);

            TreeNode[] nodesFromRoot = childNode.getPath();
            TreePath pathFromRoot = new TreePath(nodesFromRoot);

            collapsePath(pathFromRoot);
        }
    }
}

From source file:org.mbari.aved.ui.classifier.knowledgebase.ConceptTree.java

/**
 * Makes the children nodes under the specified node visible.
 *
 * @param  node   The node on which to act.
 *///from ww  w.ja va  2s  .  co m
private void makeChildrenVisible(DefaultMutableTreeNode node) {

    // RxTBD wcpr The Java API interaction of using TreeNodes and TreePaths
    // doesn't seem to make sense. There should be a cleaner way to implement
    // this method.
    if (node.isLeaf()) {
        return;
    }

    // Expand the node
    TreeConcept treeConcept = (TreeConcept) node.getUserObject();

    treeConcept.lazyExpand(node);

    boolean allChildrenAreLeaves = true;
    Enumeration children = node.children();

    while (children.hasMoreElements()) {
        DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement();

        if (!childNode.isLeaf()) {
            makeChildrenVisible(childNode);
            allChildrenAreLeaves = false;
        }
    }

    if (allChildrenAreLeaves) {
        DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) node.getLastChild();
        TreeNode[] nodesFromRoot = node.getPath();
        TreePath pathFromRoot = new TreePath(nodesFromRoot).pathByAddingChild(lastNode);

        makeVisible(pathFromRoot);
    }
}

From source file:org.mbari.aved.ui.classifier.knowledgebase.ConceptTree.java

/**
 * Sets the parent node of the currently selected node to be the node
 * representing the <code>Concept</code> of the specified name.
 *
 * @param  newParentName   The name of the <code>Concept</code> for which the currently selected
 *  node is to become a child./*  w  w  w .  j av a  2 s.  c  o  m*/
 */
public void updateTreeNodeParent(String newParentName) {

    // Get the node being moved
    DefaultMutableTreeNode conceptNode = (DefaultMutableTreeNode) getSelectionPath().getLastPathComponent();
    String conceptNodeName = ((TreeConcept) conceptNode.getUserObject()).getName();
    DefaultTreeModel treeModel = (DefaultTreeModel) getModel();

    // Remove node from current parent node and update structure
    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) conceptNode.getParent();

    parentNode.remove(conceptNode);
    treeModel.nodeStructureChanged(parentNode);

    // Get the new parent node
    DefaultMutableTreeNode newParentNode = expandDownToNode(newParentName);
    TreeConcept treeConcept = (TreeConcept) newParentNode.getUserObject();
    boolean parentNeededExpanding = treeConcept.lazyExpand(newParentNode);

    // Branch on whether parent needed expanding:
    // - The parent node needed to be expanded. The call to lazyExpand()
    // updates the parent node's children so we don't need to explicitly add
    // the new child node. Find and select the new child node.
    // - The parent node is already expanded, so insert the new child node in
    // the appropriate slot and select the new child node.
    if (parentNeededExpanding) {
        Enumeration children = newParentNode.children();

        while (children.hasMoreElements()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();
            String nodeName = ((TreeConcept) node.getUserObject()).getName();

            if (nodeName.equals(conceptNodeName)) {
                setSelectionPath(new TreePath(node.getPath()));

                break;
            }
        }
    } else {

        // Insert the node at the appropriate point in the new parent node.
        int insertPosition = 0;
        Enumeration children = newParentNode.children();

        while (children.hasMoreElements()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();
            String nodeName = ((TreeConcept) node.getUserObject()).getName();

            if (0 < nodeName.compareTo(conceptNodeName)) {
                break;
            } else {
                insertPosition++;
            }
        }

        treeModel.insertNodeInto(conceptNode, newParentNode, insertPosition);
        setSelectionPath(new TreePath(conceptNode.getPath()));
    }
}

From source file:org.mbari.aved.ui.classifier.knowledgebase.SearchableConceptTreePanel.java

/**
 * Loads the branch of a particular concept. This method does the following
 * <ol>//from ww  w . ja  v a2s. co  m
 *      <li>Walks from the concept up the tree to the root concept, storing
 *      the concepts in a list. (This is very fast)</li>
 *  <li>Starts walking from the root down (using lazyExpand), searching each
 *      childnode for a matching primary name (which was stored in the first
 *      step</li>
 *  <li>If a matching primary name is found this stops otherwise
 *              it opens the next level and searches for the next mathc in the list.</li>
 *  <li></li>
 * </ol>
 * @param concept
 */
private void openNode(final Concept concept) {
    if (log.isDebugEnabled()) {
        log.debug("Opening node containing " + concept);
    }

    if (concept == null) {
        return;
    }

    // Get the list of concepts up to root
    final LinkedList conceptList = new LinkedList();
    Concept c = concept;

    while (c != null) {
        conceptList.add(c);
        c = (Concept) c.getParentConcept();
    }

    // Walk the tree from root on down opening nodes as we go
    final ListIterator i = conceptList.listIterator(conceptList.size());

    // Skip the root
    i.previous();

    final JTree tree = getJTree();
    final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
    final DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot();
    TreePath path = new TreePath(rootNode.getPath());

    tree.setSelectionPath(path);

    DefaultMutableTreeNode parentNode = rootNode;

    while (i.hasPrevious()) {
        c = (Concept) i.previous();

        final TreeConcept parentTreeConcept = (TreeConcept) parentNode.getUserObject();

        parentTreeConcept.lazyExpand(parentNode);

        // treeModel.reload(parentNode);
        final Enumeration enm = parentNode.children();

        while (enm.hasMoreElements()) {
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) enm.nextElement();
            final TreeConcept tc = (TreeConcept) node.getUserObject();

            if (tc.getName().equals(c.getPrimaryConceptNameAsString())) {
                parentNode = node;

                break;
            }
        }
    }

    final TreeNode _parentNode = parentNode;

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            treeModel.reload(_parentNode);
            tree.scrollPathToVisible(new TreePath(_parentNode));
        }
    });
}