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:org.isatools.gui.datamanager.studyaccess.StudyAccessionGUI.java

private void createTree() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("  available studies");

    for (String key : availableStudies.keySet()) {
        log.info("adding " + key + " to tree");
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(new CheckableNode(key));

        if (availableStudies.get(key) != null) {
            for (String study : availableStudies.get(key)) {
                CheckableNode studyNode = new CheckableNode(study);
                node.add(new DefaultMutableTreeNode(studyNode));
            }//  www  .  j  a v  a 2  s.  c  o  m
        }
        root.add(node);
    }

    DefaultTreeModel model = new DefaultTreeModel(root);
    studyAvailabilityTree = new CheckableTree(model);
    configureTreeLook();
}

From source file:org.isatools.isacreator.common.filterableTree.TreeFilterModel.java

private void rebuildTree() {
    Set<String> expandedPaths = targetJTree.getExpandedTreePaths();

    DefaultMutableTreeNode root = createRootNode();
    for (T key : filterItems.keySet()) {
        if (filterItems.get(key).size() > 0) {
            DefaultMutableTreeNode nodeForKey = new DefaultMutableTreeNode(key);
            for (V value : filterItems.get(key)) {
                nodeForKey.add(new DefaultMutableTreeNode(value));
            }/*from   w  ww . ja v a  2s  . c o  m*/
            root.add(nodeForKey);
        }
    }
    setRoot(root);
    targetJTree.showExpandedKeys(expandedPaths);
}

From source file:org.jbpcc.admin.beans.navigation.TreeBean.java

private void buildTree(DefaultMutableTreeNode rootTreeNode, Element docElement) {
    ((UrlNodeUserObject) rootTreeNode.getUserObject()).setText(getLabelResource(docElement));

    // get nodelist of elements & loop through items
    NodeList nodeList = docElement.getElementsByTagName(ELEM_MODULE);
    if (nodeList != null && nodeList.getLength() > 0) {
        for (int i = 0; i < nodeList.getLength(); i++) {
            Element itemElement = (Element) nodeList.item(i);
            DefaultMutableTreeNode itemNode = createParentMenuItem(itemElement);

            if (itemElement.hasChildNodes()) {
                NodeList childNodeList = itemElement.getChildNodes();
                for (int j = 0; j < childNodeList.getLength(); j++) {
                    if (childNodeList.item(j).getNodeType() == Node.ELEMENT_NODE) {
                        Element childElement = (Element) childNodeList.item(j);
                        if (ELEM_PAGE.equals(childElement.getNodeName())) {
                            createChildMenuItem(itemNode, childElement);
                        }/*from ww  w. j  av a  2 s  .  c o m*/
                    }
                }
            }
            rootTreeNode.add(itemNode);
        }
    }
}

From source file:org.jbpcc.admin.beans.navigation.TreeBean.java

private void createChildMenuItem(DefaultMutableTreeNode parentNode, Element childElement) {
    DefaultMutableTreeNode subNode = createParentMenuItem(childElement);
    NodeList childNodeList = childElement.getChildNodes();

    if (childElement.hasChildNodes()) {
        childNodeList = childElement.getChildNodes();
        for (int i = 0; i < childNodeList.getLength(); i++) {
            if (childNodeList.item(i).getNodeType() == Node.ELEMENT_NODE) {
                createChildMenuItem(subNode, (Element) childNodeList.item(i));
            }//  ww  w.ja v a 2s. c o m
        }
    }

    parentNode.add(subNode);
}

From source file:org.jreversepro.gui.ClassEditPanel.java

/**
 * Creates the tree model of the GUI version.
 * //from   w  ww. j  a  v  a  2s .co m
 * @param aParent
 *          Parent Frame
 * @param aFileName
 *          Name of the File.
 * @param aChildren
 *          Children nodes of the tree root.
 **/
public void createModel(JFrame aParent, String aFileName, List<String> aChildren) {
    mRoot.removeAllChildren();
    DefaultMutableTreeNode ClassName = new DefaultMutableTreeNode(aFileName);

    for (String str : aChildren) {
        ClassName.add(new DefaultMutableTreeNode(str));
    }
    mRoot.add(ClassName);
    SwingUtilities.updateComponentTreeUI(aParent);
    mTreeFieldMethod.expandRow(1);
}

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

/**
 * Recursive function for finding files that end in ".kar" (case
 * insensitive)./* w  w  w. ja  v a 2s  .  c om*/
 * 
 * @param dir
 *            The root of the local repository that contains KAR files
 * @param depth
 *            The maximum recursion depth
 */
private void findKarsRecursive(File dir, int depth, DefaultMutableTreeNode tn) {
    if (isDebugging)
        log.debug(depth + ": " + dir.toString());
    if (!dir.exists()) {
        log.warn(dir.toString() + " does not exist");
        return;
    }
    if (!dir.isDirectory()) {
        log.warn(dir.toString() + " is not a directory");
        return;
    }
    if (depth < 0) {
        log.warn(dir.toString() + " is too deep");
        return;
    }

    File[] listing = dir.listFiles();
    for (int i = 0; i < listing.length; i++) {
        File currentListing = listing[i];
        if (currentListing.isDirectory()) {
            if (currentListing.getName().equals(".svn")) {
                // skip .svn folders
            } else if (currentListing.getName().contains(".")) {
                // skip any folders that contain periods
                // ptolemy cannot handle periods in NamedObj Names.
                System.out.println("WARNING: skipping due to periods: " + currentListing);
            } else {
                DefaultMutableTreeNode dmtn = new DefaultMutableTreeNode(currentListing);
                tn.add(dmtn);
                findKarsRecursive(currentListing, (depth - 1), dmtn);
            }
        } else {
            if (currentListing.getName().toLowerCase().endsWith(".kar")) {
                _karFiles.addElement(currentListing);
            } else if (currentListing.getName().toLowerCase().endsWith(".xml")) {
                _xmlFiles.addElement(currentListing);
            }
        }
    }
}

From source file:org.kuali.test.ui.components.sqlquerypanel.DatabasePanel.java

private void loadTables(TableData td, DefaultMutableTreeNode rootNode) throws Exception {
    Connection conn = null;/*ww  w.j a v a  2 s.com*/
    ResultSet res = null;

    try {
        DatabaseConnection dbconn = Utils.findDatabaseConnectionByName(getMainframe().getConfiguration(),
                getPlatform().getDatabaseConnectionName());

        if (dbconn != null) {
            conn = Utils.getDatabaseConnection(getMainframe().getEncryptionPassword(), dbconn);
            DatabaseMetaData dmd = conn.getMetaData();
            SqlQueryNode baseTableNode = new SqlQueryNode(getMainframe().getConfiguration(), td);
            rootNode.add(baseTableNode);
            loadTableRelationships(dbconn, dmd, td, 0, baseTableNode);
        }
    }

    catch (Exception ex) {
        UIUtils.showError(this, "Error loading table relationships",
                "An error occurred while loading table relationships - " + ex.toString());
    }

    finally {
        Utils.closeDatabaseResources(conn, null, res);
    }
}

From source file:org.languagetool.gui.ConfigurationDialog.java

private DefaultMutableTreeNode createTree(List<Rule> rules, boolean isStyle, String tabName) {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Rules");
    String lastRuleId = null;//from  w  w w .  ja  v  a2s . co  m
    Map<String, DefaultMutableTreeNode> parents = new TreeMap<>();
    for (Rule rule : rules) {
        if ((tabName == null && !config.isSpecialTabCategory(rule.getCategory().getName())
                && ((isStyle && config.isStyleCategory(rule.getCategory().getName()))
                        || (!isStyle && !config.isStyleCategory(rule.getCategory().getName()))))
                || (tabName != null && config.isInSpecialTab(rule.getCategory().getName(), tabName))) {
            if (rule.hasConfigurableValue()) {
                configurableRules.add(rule);
            } else {
                if (!parents.containsKey(rule.getCategory().getName())) {
                    boolean enabled = true;
                    if (config.getDisabledCategoryNames() != null
                            && config.getDisabledCategoryNames().contains(rule.getCategory().getName())) {
                        enabled = false;
                    }
                    if (rule.getCategory().isDefaultOff() && (config.getEnabledCategoryNames() == null
                            || !config.getEnabledCategoryNames().contains(rule.getCategory().getName()))) {
                        enabled = false;
                    }
                    DefaultMutableTreeNode categoryNode = new CategoryNode(rule.getCategory(), enabled);
                    root.add(categoryNode);
                    parents.put(rule.getCategory().getName(), categoryNode);
                }
                if (!rule.getId().equals(lastRuleId)) {
                    RuleNode ruleNode = new RuleNode(rule, getEnabledState(rule));
                    parents.get(rule.getCategory().getName()).add(ruleNode);
                }
                lastRuleId = rule.getId();
            }
        }
    }
    return root;
}

From source file:org.lnicholls.galleon.gui.MainFrame.java

public DefaultTreeModel getAppsModel() {

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("ROOT");

    if (Galleon.getApps() != null) {

        Iterator iterator = Galleon.getApps().iterator();

        while (iterator.hasNext()) {

            AppContext app = (AppContext) iterator.next();

            root.add(new DefaultMutableTreeNode(getAppNode(app)));

        }//from  w w  w. j  a va2  s  .  co m

    }

    return new DefaultTreeModel(root);

}

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

/**
 * Adds a node to the specifed tree node for each of the children of the
 * specified <code>Concept./*  w w w.jav a2  s.c o  m*/
 *
 * @param  node   The node to which to add children nodes.
 * @param  concept   The <code>Concept</code> whose children are to be added.
 */
private void addChildrenNodes(DefaultMutableTreeNode node, Concept concept) {
    Iterator iterator = concept.getChildConceptColl().iterator();

    while (iterator.hasNext()) {
        Concept childConcept = (Concept) iterator.next();
        DefaultMutableTreeNode childNode = new SortedTreeNode(new TreeConcept(childConcept));

        node.add(childNode);
        addChildrenNodes(childNode, childConcept);
    }
}