Example usage for javax.swing.tree DefaultMutableTreeNode getPath

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

Introduction

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

Prototype

public TreeNode[] getPath() 

Source Link

Document

Returns the path from the root, to get to this node.

Usage

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

public DefaultMutableTreeNode addNode(QueryConceptTreeNodeData node, DefaultMutableTreeNode parent) {
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

    QueryConceptTreeNodeData tmpData = new QueryConceptTreeNodeData();
    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());
    }//  w  w  w.  ja v 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.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java

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

    if (ascending) {
        treeModel.insertNodeInto(childNode, top, top.getChildCount());
    } else {/* w  w  w  .  j  a  v a 2s .c  om*/
        treeModel.insertNodeInto(childNode, top, 0);
    }

    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()));

    previousQueries.add(node);

    return childNode;
}

From source file:edu.harvard.i2b2.query.ui.ConceptTreePanel.java

private void populateChildNodes(DefaultMutableTreeNode node) {

    List concepts = getConceptsFromChildren((QueryConceptTreeNodeData) node.getUserObject(),
            (DefaultMutableTreeNode) node.getChildAt(0));
    if (concepts != null) {
        addNodesFromOntXML(concepts, node);
        DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) node.getChildAt(0);
        treeModel.removeNodeFromParent(tmpnode);
        jTree1.scrollPathToVisible(new TreePath(node.getPath()));
    }/*ww  w.j  a  v  a  2  s  .c  o  m*/

}

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

/**
 * Generate the tree from the current edited list of Loggers
 *///w ww.  ja va 2  s  .  co  m
private void generateTree() {

    visitJulLoggers();

    final GenericJTree<Logger> treeLoggers = getTreeLoggers();

    final LoggerContext loggerContext = _rootLogger.getLoggerContext();

    final DefaultMutableTreeNode rootNode = treeLoggers.getRootNode();

    // remove complete hierarchy:
    rootNode.removeAllChildren();

    // update the root node with the root logger (Logger[ROOT]):
    rootNode.setUserObject(_rootLogger);

    int pos;
    String path;
    DefaultMutableTreeNode parentNode;

    for (Logger logger : loggerContext.getLoggerList()) {

        // skip root logger
        if (logger != _rootLogger) {

            pos = logger.getName().lastIndexOf('.');

            if (pos == -1) {
                // no path
                path = null;
                parentNode = null;

            } else {
                path = logger.getName().substring(0, pos);

                parentNode = treeLoggers.findTreeNode(loggerContext.getLogger(path));
            }

            if (parentNode == null) {
                parentNode = rootNode;
            }

            if (parentNode != null) {
                treeLoggers.addNode(parentNode, logger);
            }
        }
    }

    // fire node structure changed :
    treeLoggers.fireNodeChanged(rootNode);

    // select root node
    treeLoggers.selectPath(new TreePath(rootNode.getPath()));
}

From source file:edu.harvard.i2b2.query.ui.ConceptTreePanel.java

public DefaultMutableTreeNode addNode(QueryConceptTreeNodeData node) {
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

    QueryConceptTreeNodeData tmpData = new QueryConceptTreeNodeData();
    tmpData.name("working ......");
    tmpData.tooltip("A tmp node");
    tmpData.visualAttribute("LAO");
    DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(tmpData);

    treeModel.insertNodeInto(childNode, top, top.getChildCount());
    treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    // Make sure the user can see the lovely new node.
    jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

    return childNode;
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java

public void exploreBean(DefaultMutableTreeNode root, String classname, String parentPath) {
    try {/*from  w  w w .  j a  v  a2  s  . c  om*/

        root.removeAllChildren();
        if (parentPath.length() > 0)
            parentPath += ".";

        Class clazz = Class.forName(classname, true, IReportManager.getInstance().getReportClassLoader());

        java.beans.PropertyDescriptor[] pd = org.apache.commons.beanutils.PropertyUtils
                .getPropertyDescriptors(clazz);
        for (int nd = 0; nd < pd.length; ++nd) {
            String fieldName = pd[nd].getName();
            if (pd[nd].getPropertyType() != null && pd[nd].getReadMethod() != null) {
                Class clazzRT = pd[nd].getPropertyType();

                if (clazzRT.isPrimitive()) {
                    clazzRT = MethodUtils.getPrimitiveWrapper(clazzRT);
                }

                String returnType = clazzRT.getName();

                JRDesignField field = new JRDesignField();
                field.setName(fieldName);
                field.setValueClassName(returnType);

                if (isPathOnDescription()) {
                    field.setDescription(parentPath + fieldName);
                } else {
                    field.setName(parentPath + fieldName);
                }

                TreeJRField jtf = new TreeJRField();

                jtf.setField(field);
                jtf.setObj(pd[nd].getPropertyType());

                boolean bChildrens = true;
                if (pd[nd].getPropertyType().isPrimitive()
                        || pd[nd].getPropertyType().getName().startsWith("java.lang.")) {
                    bChildrens = false;
                }
                root.add(new DefaultMutableTreeNode(jtf, bChildrens));
            }
        }

        jTree1.expandPath(new TreePath(root.getPath()));
        jTree1.updateUI();

    } catch (ClassNotFoundException cnf) {
        javax.swing.JOptionPane.showMessageDialog(this, Misc.formatString( //"messages.BeanInspectorPanel.classNotFoundError",
                I18n.getString("BeanInspectorPanel.Message.Error"), new Object[] { cnf.getMessage() }),
                I18n.getString("BeanInspectorPanel.Message.Error2"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    } catch (Exception ex) {
        ex.printStackTrace();
        javax.swing.JOptionPane.showMessageDialog(this, ex.getMessage(),
                I18n.getString("BeanInspectorPanel.Message.Error2"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
}

From source file:com.lp.client.frame.component.PanelDokumentenablage.java

@Override
public void treeExpanded(TreeExpansionEvent event) {
    if (treeInProgress)
        return;/*from   w w w.  j  av  a 2  s .c om*/
    setBusy(true);

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    DefaultMutableTreeNode firstChild = (DefaultMutableTreeNode) node.getFirstChild();
    TreePath selectionPath = tree.getSelectionPath();
    if (MUST_LOAD_CHILDREN.equals(firstChild.getUserObject())) {

        node.removeAllChildren();
        DocPath expandPath = new DocPath();

        for (Object obj : node.getUserObjectPath()) {
            try {
                expandPath.add((DocNodeBase) obj);
            } catch (ClassCastException ex) {
                expandPath.add(new DocNodeLiteral(obj.toString()));
            }
        }

        List<DocNodeBase> childList;
        try {
            childList = DelegateFactory.getInstance().getJCRDocDelegate()
                    .getDocNodeChildrenFromNode(expandPath);
            setDocNodesOnTree(node, childList, expandPath);
        } catch (Throwable e) {
            treeModel.insertNodeInto(new DefaultMutableTreeNode(e), node, 0);
        }
        tree.expandPath(new TreePath(node.getPath()));
        tree.setSelectionPath(selectionPath);
    }
    setBusy(false);
}

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")
 *///from   ww w.  j  a  v  a  2s .com
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);
    }
}

From source file:GUI.MainWindow.java

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed

    // Create a new vuln
    Vulnerability vuln = new Vulnerability();
    vuln.setTitle("NEW");
    vuln.setIs_custom_risk(true);//ww  w. j  a  v  a2  s. com
    vuln.setRisk_category("None");
    vuln.setImport_tool("ReportCompiler");
    vuln.setIdentifier();
    // Add it to the tree
    DefaultTreeModel dtm = (DefaultTreeModel) VulnTree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm.getRoot();
    DefaultMutableTreeNode new_vuln = new DefaultMutableTreeNode(vuln);
    root.add(new_vuln);
    // Refresh the GUI
    dtm.reload();
    // Now select 
    TreePath path = new TreePath(new_vuln.getPath());
    VulnTree.setSelectionPath(path);
    // Set focus on the title field
    this.VulnTitleTextField.requestFocus();
    this.VulnTitleTextField.selectAll();
}

From source file:it.imtech.metadata.MetaUtility.java

/**
 * Metodo che setta il TreeMap oefos_path con i valori del nodo selezionato
 * e aggiorna il label che descrive il path dei nodi selezionati
 *
 * @param e L'albero sul quale ricercare il path selezionato
 *///w w  w. jav  a 2  s. c  o m
private void setOEFOS(JTree e, String sequence, String panelname) throws Exception {
    try {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getLastSelectedPathComponent();
        String completePath = "";
        //OefosPaths path = new OefosPaths(panelname, sequence);

        BookImporter.getInstance()
                .createComponentMap(BookImporter.getInstance().metadatapanels.get(panelname).getPanel());
        Component controls = BookImporter.getInstance().getComponentByName("classification_path---" + sequence);

        //Se e' una foglia aggiorna il path nell'interfaccia e oefos_path
        if (node != null) {
            TreePath selpath = new TreePath(node.getPath());
            e.setSelectionPath(selpath);

            Object[] nodes = selpath.getPath();

            TreeMap<Integer, Integer> single_path = new TreeMap<Integer, Integer>();

            for (int i = 1; i < nodes.length; i++) {
                Object nodeInfo = nodes[i];
                DefaultMutableTreeNode nodeC = (DefaultMutableTreeNode) nodeInfo;
                ClassNode c = (ClassNode) nodeC.getUserObject();
                single_path.put(i, Integer.parseInt(c.getKey().toString()));

                completePath += nodes[i].toString();
                completePath += (i != nodes.length - 1) ? "/" : "";
            }

            this.oefos_path.put(panelname + "----" + sequence, single_path);
        } else {
            this.oefos_path.put(panelname + "----" + sequence, null);
        }

        JLabel label = (JLabel) controls;
        if (completePath.length() > 120) {
            label.setText(completePath.substring(0, 120));
        } else {
            label.setText(completePath);
        }

        label.revalidate();
    } catch (Exception ex) {
        throw new Exception("Exception in setOEFOS: " + ex.getStackTrace() + "\n");
    }
}