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:Exporters.SaveFileExporter.java

public void save(File outfile, DefaultMutableTreeNode root) throws Exception {
    System.out.println("===SaveFileExporter==save:" + outfile.getAbsolutePath());

    // Create new XML document
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

    // Create the root element
    Document doc = docBuilder.newDocument();
    Element rootElement = doc.createElement("reportCompiler");
    rootElement.setAttribute("date", getNow()); // Debugging to say when saved
    // TODO - figure out a universal means to get the current version of the generating tool
    // Initial thoughts would be to create a convenience class in Utils package with some
    // final variables that can be updated when issuing a release.
    doc.appendChild(rootElement);/*from  w  w  w. j  a va  2 s  . c o m*/

    Element vulnerabilitiesElement = doc.createElement("vulnerabilities");

    Enumeration enums = root.children();
    while (enums.hasMoreElements()) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) enums.nextElement();
        Object obj = node.getUserObject();
        if (obj instanceof Vulnerability) {
            Vulnerability vuln = (Vulnerability) obj;
            Element vulnElement = getVulnAsElement(vuln, doc);
            if (vulnElement != null) {
                vulnerabilitiesElement.appendChild(vulnElement);
            }
        }
    }

    rootElement.appendChild(vulnerabilitiesElement);

    // now write the XML file
    // write the content into xml file
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();

    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(outfile);

    // Output to console for testing
    //StreamResult result = new StreamResult(System.out);
    transformer.transform(source, result);

    System.out.println("File saved!");

}

From source file:org.kuali.maven.plugins.externals.MojoHelper.java

protected List<DefaultMutableTreeNode> getChildren(DefaultMutableTreeNode node) {
    Enumeration<?> e = node.children();
    List<DefaultMutableTreeNode> children = new ArrayList<DefaultMutableTreeNode>();
    while (e.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) e.nextElement();
        children.add(child);//from  w  ww . j  a v a2  s .  c  o m
    }
    return children;
}

From source file:org.kuali.maven.plugins.externals.MojoHelper.java

public void updateGavs(DefaultMutableTreeNode node) {
    Project project = (Project) node.getUserObject();
    if (project.getNewGav() != null) {
        project.setGav(project.getNewGav());
    }//from w  ww. j  av  a2  s.  c  o m
    Enumeration<?> children = node.children();
    while (children.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
        Project childProject = (Project) child.getUserObject();
        String oldParentVersion = childProject.getParent().getVersion();
        String newParentVersion = getVersion(node);
        if (!oldParentVersion.equals(newParentVersion)) {
            childProject.getParent().setVersion(newParentVersion);
        }
        updateGavs(child);
    }
}

From source file:org.netxilia.server.rest.HomeResource.java

/**
 * walk the tree and dump the node to the tree
 * /*from   www.j a  v a2s .  co  m*/
 * @param node
 * @param treeview
 */
@SuppressWarnings("unchecked")
private void buildTreeView(DefaultMutableTreeNode node, StringBuilder treeview) {
    // <ul id="example" class="filetree">
    // <li><span class="folder">Folder 1</span>
    // <ul>
    // <li><span class="file">Item 1.1</span></li>
    // </ul>
    // </li>
    // <li><span class="folder">Folder 2</span>

    TreeViewData viewData = (TreeViewData) node.getUserObject();
    if (node.isLeaf()) {
        if (viewData != null) {
            treeview.append("<li><span id='").append(viewData.getId()).append("' class='")
                    .append(viewData.getCssClass()).append("'>").append(viewData.getName())
                    .append("</span></li>");
        }
    } else {
        if (viewData != null) {
            if (viewData.isCollapsed()) {
                treeview.append("<li class='closed'>");
            } else {
                treeview.append("<li>");
            }
            treeview.append("<span class='folder ").append(viewData.getCssClass()).append("'>")
                    .append(viewData.getName()).append("</span><ul>");
        }
        Enumeration<DefaultMutableTreeNode> childrenEnum = node.children();
        while (childrenEnum.hasMoreElements()) {
            buildTreeView(childrenEnum.nextElement(), treeview);
        }
        if (viewData != null) {
            treeview.append("</ul></li>");
        }
    }
}

From source file:org.kuali.maven.plugins.externals.MojoHelper.java

public String getDisplayString(DefaultMutableTreeNode node) {
    Project project = (Project) node.getUserObject();
    GAV gav = project.getGav();/*from w  w w  .  j av a 2 s . c  o  m*/
    GAV parent = project.getParent();
    int level = node.getLevel();
    StringBuilder sb = new StringBuilder();
    sb.append(StringUtils.repeat(" ", level));
    sb.append(toString(parent));
    sb.append(" -> ");
    sb.append(toString(gav));
    sb.append("\n");
    Enumeration<?> children = node.children();
    while (children.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
        sb.append(getDisplayString(child));
    }
    return sb.toString();
}

From source file:org.kuali.maven.plugins.externals.MojoHelper.java

public void fillInGavs(DefaultMutableTreeNode node) {
    Project project = (Project) node.getUserObject();
    GAV gav = project.getGav();//ww  w.j  a  v a 2 s .co  m
    String groupId = getGroupId(node);
    String version = getVersion(node);
    if (gav.getGroupId() == null) {
        gav.setGroupId(groupId);
        logger.debug("Update " + gav.getArtifactId() + "->" + groupId);
    }
    if (gav.getVersion() == null) {
        gav.setVersion(version);
        logger.debug("Update " + gav.getArtifactId() + "->" + version);
    }
    Enumeration<?> e = node.children();
    while (e.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) e.nextElement();
        fillInGavs(child);
    }
}

From source file:org.kuali.maven.plugins.externals.MojoHelper.java

public void updateXml(DefaultMutableTreeNode node) {
    Project project = (Project) node.getUserObject();
    String version = project.getGav().getVersion();
    if (!StringUtils.isBlank(version)) {
        String oldXml = project.getPomContents();
        String newXml = pomUtils.updateVersion(oldXml, version);
        project.setPomContents(newXml);//ww  w . j  av  a  2s .  c  om
    }
    String parentVersion = project.getParent().getVersion();
    String oldXml = project.getPomContents();
    String newXml = pomUtils.updateParentVersion(oldXml, parentVersion);
    project.setPomContents(newXml);
    Enumeration<?> children = node.children();
    while (children.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
        updateXml(child);
    }
}

From source file:org.kuali.maven.plugins.externals.MojoHelper.java

public String getDisplayString(DefaultMutableTreeNode node, File basedir, String pomFile) {
    Project project = (Project) node.getUserObject();
    File pom = project.getPom();/*from w  w w .j  a  v  a  2  s .com*/
    String pomPath = pom.getAbsolutePath();
    String displayPath = pomPath.replace(basedir.getAbsolutePath(), "");
    displayPath = displayPath.replace(pomFile, "");
    if (!node.isRoot()) {
        displayPath = displayPath.substring(0, displayPath.length() - 1);
        int pos = displayPath.lastIndexOf(File.separator);
        displayPath = displayPath.substring(pos);
        displayPath = displayPath.replace("/", "");
    }
    int level = node.getLevel();
    StringBuilder sb = new StringBuilder();
    sb.append(StringUtils.repeat(" ", level));
    sb.append(displayPath);
    sb.append("\n");
    Enumeration<?> children = node.children();
    while (children.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
        sb.append(getDisplayString(child, basedir, pomFile));
    }
    return sb.toString();
}

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

private void updateChildCount(DefaultMutableTreeNode threadOrMonitorNode, boolean isThreadNode) {
    int count = 0;
    for (Enumeration e = threadOrMonitorNode.depthFirstEnumeration(); e.hasMoreElements();) {
        Object element = e.nextElement();
        ThreadInfo mi = (ThreadInfo) (((DefaultMutableTreeNode) element).getUserObject());
        if (mi.getName().startsWith("Thread")) {
            count++;//w w  w  .  j  a va2s. com
        }
    }

    ThreadInfo mi = (ThreadInfo) threadOrMonitorNode.getUserObject();
    if (ThreadDumpInfo.areALotOfWaiting(count)) {
        mi.setALotOfWaiting(true);
    }
    if (isThreadNode) {
        count--;
    }

    mi.setChildCount(count);
    if (count > 1) {
        mi.setName(mi.getName() + ":    " + count + " Blocked threads");
    } else if (count == 1) {
        mi.setName(mi.getName() + ":    " + count + " Blocked thread");
    }

    // Recurse
    for (Enumeration e = threadOrMonitorNode.children(); e.hasMoreElements();) {
        updateChildCount((DefaultMutableTreeNode) e.nextElement(), !isThreadNode);
    }
}

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

/**
 * navigate to child of currently selected node with the given prefix in name
 *
 * @param startsWith node name prefix (e.g. "Threads waiting")
 *//*  w  w  w .  j  a va2s  .co  m*/
private void navigateToChild(String startsWith) {
    TreePath currentPath = tree.getSelectionPath();
    DefaultMutableTreeNode dumpNode = (DefaultMutableTreeNode) currentPath.getLastPathComponent();
    Enumeration childs = dumpNode.children();

    TreePath searchPath = null;
    while ((searchPath == null) && childs.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) childs.nextElement();
        String name = child.toString();
        if (name != null && name.startsWith(startsWith)) {
            searchPath = new TreePath(child.getPath());
        }
    }

    if (searchPath != null) {
        tree.makeVisible(searchPath);
        tree.setSelectionPath(searchPath);
        tree.scrollPathToVisible(searchPath);
    }
}