Example usage for javax.swing.tree DefaultMutableTreeNode getUserObject

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

Introduction

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

Prototype

public Object getUserObject() 

Source Link

Document

Returns this node's user object.

Usage

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

/**
 * Assemble the list of nodes into a tree, based on the directory structure.
 *//*from   w ww . java  2 s  .c  om*/
public DefaultMutableTreeNode getTree(File basedir, List<DefaultMutableTreeNode> nodes, String pomFile) {
    Map<String, DefaultMutableTreeNode> map = getMap(nodes);
    for (DefaultMutableTreeNode child : nodes) {
        Project project = (Project) child.getUserObject();
        File pom = project.getPom();
        File pomDir = pom.getParentFile();
        File parentPom = new File(pomDir.getParentFile(), pomFile);
        String parentPomPath = parentPom.getAbsolutePath();
        DefaultMutableTreeNode parent = map.get(parentPomPath);
        if (parent != null) {
            parent.add(child);
        }
    }
    String rootPom = basedir + File.separator + pomFile;
    DefaultMutableTreeNode root = map.get(rootPom);

    return root;
}

From source file:fr.jmmc.jmcs.logging.LogbackGui.java

/**
 * Process the tree selection events//from w w w . jav  a2s. co m
 * @param e tree selection event
 */
@Override
public void valueChanged(final TreeSelectionEvent e) {
    final DefaultMutableTreeNode currentNode = getTreeLoggers().getLastSelectedNode();

    if (currentNode != null) {
        /* retrieve the node that was selected */
        final Object userObject = currentNode.getUserObject();

        if (userObject instanceof Logger) {
            processLoggerSelection((Logger) userObject);
        }
    }
}

From source file:edu.purdue.cc.bionet.ui.DistributionAnalysisDisplayPanel.java

public void deselectOutliers() {
    Iterator<TreeNode> moleculeIterator = this.selectorTree
            .checkedDescendantIterator(this.selectorTree.getRoot(), MOLECULE);

    while (moleculeIterator.hasNext()) {
        DefaultMutableTreeNode moleculeNode = (DefaultMutableTreeNode) moleculeIterator.next();
        Molecule molecule = (Molecule) moleculeNode.getUserObject();

        Iterator<TreeNode> experimentIterator = this.selectorTree.checkedDescendantIterator(moleculeNode,
                EXPERIMENT);//from  w w  w  .  j  a  va  2 s  . co  m
        while (experimentIterator.hasNext()) {
            DefaultMutableTreeNode experimentNode = (DefaultMutableTreeNode) experimentIterator.next();

            Iterator<TreeNode> sampleIterator = this.selectorTree.checkedDescendantIterator(experimentNode,
                    SAMPLE);
            TreeSet<Sample> sampleSet = new TreeSet<Sample>();
            while (sampleIterator.hasNext()) {
                DefaultMutableTreeNode sampleNode = (DefaultMutableTreeNode) sampleIterator.next();
                sampleSet.add((Sample) sampleNode.getUserObject());
            }

            for (SampleGroup group : this.getSampleGroups()) {
                Collection<Sample> sampleUnion = new TreeSet<Sample>(group);
                sampleUnion.retainAll(sampleSet);
                Range range = Statistics.regularRange(molecule.getValues(sampleUnion).toDoubleArray());
                sampleIterator = this.selectorTree.checkedDescendantIterator(experimentNode, SAMPLE);

                while (sampleIterator.hasNext()) {
                    DefaultMutableTreeNode sampleNode = (DefaultMutableTreeNode) sampleIterator.next();
                    Sample sample = (Sample) sampleNode.getUserObject();
                    if (sampleUnion.contains(sample)
                            && !range.contains(molecule.getValue(sample).doubleValue()))
                        this.selectorTree.uncheck(sampleNode);
                }
            }
        }
    }
}

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

public boolean isValid(Properties properties, Mapping mapping, DefaultMutableTreeNode node) {
    DefaultMutableTreeNode match = findNode(node, mapping.getModule());
    Project project = (Project) match.getUserObject();
    GAV gav = project.getGav();/*from w ww.ja v  a2s .c o m*/
    String propertyVersion = properties.getProperty(mapping.getVersionProperty());
    String gavVersion = gav.getVersion();

    if (propertyVersion.equals(gavVersion)) {
        return true;
    } else {
        logger.error(String.format("(artifactId, propertyVersion, gavVersion) = (%s, %s, %s)",
                project.getGav().getArtifactId(), propertyVersion, gavVersion));
        return false;
    }
}

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 2s.  c o m
    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:org.kuali.maven.plugins.externals.MojoHelper.java

public void updateProperties(DefaultMutableTreeNode node, Properties properties, List<Mapping> mappings) {
    Project project = (Project) node.getUserObject();
    Properties versionProperties = getVersionProperties(properties, mappings, node);
    String oldXml = project.getPomContents();
    String newXml = pomUtils.updateProperties(oldXml, versionProperties);
    project.setPomContents(newXml);//  w  ww  . j  a v  a 2s.  com
}

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

protected DefaultMutableTreeNode findNode(DefaultMutableTreeNode node, String artifactId) {
    Enumeration<?> e = node.breadthFirstEnumeration();
    while (e.hasMoreElements()) {
        DefaultMutableTreeNode element = (DefaultMutableTreeNode) e.nextElement();
        Project project = (Project) element.getUserObject();
        GAV gav = project.getGav();/*w ww. j  ava2  s.  c  o m*/
        if (gav.getArtifactId().equals(artifactId)) {
            return element;
        }
    }
    throw new IllegalStateException("Unable to locate " + artifactId);
}

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

public Map<String, DefaultMutableTreeNode> getGavMap(DefaultMutableTreeNode node) {
    Enumeration<?> e = node.breadthFirstEnumeration();
    Map<String, DefaultMutableTreeNode> map = new HashMap<String, DefaultMutableTreeNode>();
    while (e.hasMoreElements()) {
        DefaultMutableTreeNode element = (DefaultMutableTreeNode) e.nextElement();
        Project project = (Project) element.getUserObject();
        GAV gav = project.getGav();// w ww . ja v  a 2  s  .  c om
        String gavId = toString(gav);
        map.put(gavId, element);
    }
    return map;
}

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

public void writePoms(DefaultMutableTreeNode node, File baseDir) {
    int count = 0;
    Enumeration<?> e = node.depthFirstEnumeration();
    while (e.hasMoreElements()) {
        DefaultMutableTreeNode element = (DefaultMutableTreeNode) e.nextElement();
        Project project = (Project) element.getUserObject();
        File pom = project.getPom();
        String oldContents = read(pom);
        String newContents = project.getPomContents();
        if (!oldContents.equals(newContents)) {
            logger.debug("Updating " + pom.getAbsolutePath());
            write(pom, newContents);//www .  j av a  2s . c o  m
            count++;
        }
    }
    logger.info("Updated " + count + " Maven pom's");
}

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

public void writePoms(DefaultMutableTreeNode node, File baseDir, File checkoutDir) {
    int count = 0;
    Enumeration<?> e = node.depthFirstEnumeration();
    while (e.hasMoreElements()) {
        DefaultMutableTreeNode element = (DefaultMutableTreeNode) e.nextElement();
        Project project = (Project) element.getUserObject();
        File pom = project.getPom();
        String relativePath = getRelativePath(baseDir, pom);
        File newPom = new File(checkoutDir.getAbsolutePath() + File.separator + relativePath);
        String oldContents = read(pom);
        String newContents = project.getPomContents();
        if (!oldContents.equals(newContents)) {
            logger.debug("Updating " + newPom.getAbsolutePath());
            write(newPom, newContents);//from   w  w  w.j a  v a2s.  c  o m
            count++;
        }
    }
    logger.info("Updated " + count + " Maven pom's");
}