Example usage for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode

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

Introduction

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

Prototype

public DefaultMutableTreeNode(Object userObject) 

Source Link

Document

Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.

Usage

From source file:com.moss.bdbadmin.client.ui.BdbAdminClient.java

private void loadConfig() {

    if (!configPath.exists()) {
        return;/*from ww  w .  j a v  a 2  s. c  o  m*/
    }

    root.removeAllChildren();
    model.nodeStructureChanged(root);

    Runnable load = new Runnable() {
        public void run() {

            LoadingDialog loading = new LoadingDialog(ancestor);
            try {
                loading.display("Loading Config", "Loading configuration details.");

                Unmarshaller u = configJaxbContext.createUnmarshaller();
                ServiceConfig config = (ServiceConfig) u.unmarshal(configPath);

                for (ServiceInfo info : config.services()) {

                    final ServiceContainer container = new ServiceContainer();
                    container.setInfo(info);

                    boolean success;
                    try {
                        refresh(container);
                        success = true;
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(ancestor, "Could not refresh service " + info.getUrl(),
                                "Service Refresh Failed", JOptionPane.ERROR_MESSAGE);
                        success = false;
                    }

                    class UpdateUI implements Runnable {

                        private final boolean success;

                        public UpdateUI(boolean success) {
                            this.success = success;
                        }

                        public void run() {

                            DefaultMutableTreeNode serviceNode = new DefaultMutableTreeNode(container);
                            root.add(serviceNode);
                            model.nodeStructureChanged(root);
                            //                           model.nodesWereInserted(root, new int[]{ root.getIndex(serviceNode) });

                            if (success) {
                                rebuild(container);
                            }
                        }
                    }

                    SwingUtilities.invokeLater(new UpdateUI(success));
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(ancestor, "Could not load configuration from file: " + configPath,
                        "Config Load Failed", JOptionPane.ERROR_MESSAGE);
            } finally {
                loading.dispose();
            }
        }
    };

    Thread loaderThread = new Thread(load, "LoaderThread");
    loaderThread.start();
}

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

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

    treeModel.insertNodeInto(childNode, top, top.getChildCount());
    if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) {
        treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    }//w ww  .  j  a  v  a2s  . c o m
    //Make sure the user can see the lovely new node.
    jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

    return childNode;
}

From source file:com.mindcognition.mindraider.ui.swing.trash.TrashJPanel.java

/**
 * Add discarded notebook node./*from w  ww .  j  ava  2 s  .c  o  m*/
 *
 * @param uri
 *            notebook node.
 * @return the node.
 */
public DefaultMutableTreeNode addDiscardedNotebookNode(String label, String uri) {
    DefaultMutableTreeNode parent = null;

    Object child = label;
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
    // store node to map to be able to get URI from node object
    treeNodeToResourceUriMap.put(childNode, uri);

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

    treeModel.insertNodeInto(childNode, parent, parent.getChildCount());
    return childNode;
}

From source file:FileTree2.java

public boolean expand(DefaultMutableTreeNode parent) {
    DefaultMutableTreeNode flag = (DefaultMutableTreeNode) parent.getFirstChild();
    if (flag == null) // No flag
        return false;
    Object obj = flag.getUserObject();
    if (!(obj instanceof Boolean))
        return false; // Already expanded

    parent.removeAllChildren(); // Remove Flag

    File[] files = listFiles();/*w  w  w .  j av  a2s  .c o m*/
    if (files == null)
        return true;

    Vector v = new Vector();

    for (int k = 0; k < files.length; k++) {
        File f = files[k];
        if (!(f.isDirectory()))
            continue;

        FileNode newNode = new FileNode(f);

        boolean isAdded = false;
        for (int i = 0; i < v.size(); i++) {
            FileNode nd = (FileNode) v.elementAt(i);
            if (newNode.compareTo(nd) < 0) {
                v.insertElementAt(newNode, i);
                isAdded = true;
                break;
            }
        }
        if (!isAdded)
            v.addElement(newNode);
    }

    for (int i = 0; i < v.size(); i++) {
        FileNode nd = (FileNode) v.elementAt(i);
        IconData idata = new IconData(FileTree2.ICON_FOLDER, FileTree2.ICON_EXPANDEDFOLDER, nd);
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(idata);
        parent.add(node);

        if (nd.hasSubDirs())
            node.add(new DefaultMutableTreeNode(new Boolean(true)));
    }

    return true;
}

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

/**
 * create a tree node with the provided information
 *
 * @param top     the parent node the new node should be added to.
 * @param title   the title of the new node
 * @param info    the info part of the new node
 * @param content the content part of the new node
 * @see ThreadInfo//ww  w  .  ja v  a  2s  .com
 */
protected void createNode(DefaultMutableTreeNode top, String title, String info, String content,
        int lineCount) {
    DefaultMutableTreeNode threadInfo = new DefaultMutableTreeNode(
            new ThreadInfo(title, info, content, lineCount, getThreadTokens(title)));
    top.add(threadInfo);
}

From source file:edu.ucla.stat.SOCR.chart.ChartTree.java

/**
 * Creates a tree node containing line chart items.
 * //w  ww  .  j av a  2 s .  c o  m
 * @return A tree node.
 */
private MutableTreeNode createLineChartsNode() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Line Charts");

    DefaultMutableTreeNode n1 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.AnnotationDemo1", "AnnotationDemo1"));
    DefaultMutableTreeNode n2 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.LineChartDemo1", "LineChartDemo1"));
    DefaultMutableTreeNode n3 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.LineChartDemo2", "LineChartDemo2"));
    DefaultMutableTreeNode n3a = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.ScatterChartDemo1", "ScatterChartDemo1"));
    DefaultMutableTreeNode n3b = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.QQNormalPlotDemo", "QQNormalPlotDemo"));
    DefaultMutableTreeNode n3c = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.QQData2DataDemo", "QQData2DataDemo"));
    DefaultMutableTreeNode n4 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.LineChartDemo3", "LineChartDemo3"));

    DefaultMutableTreeNode n5 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.LineChartDemo4", "LineChartDemo4"));
    DefaultMutableTreeNode n6 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.LineChartDemo5", "LineChartDemo5"));
    DefaultMutableTreeNode n7 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.LineChartDemo6", "LineChartDemo6"));
    DefaultMutableTreeNode n8 = new DefaultMutableTreeNode(new DemoDescription(
            "edu.ucla.stat.SOCR.chart.demo.NormalDistributionDemo", "NormalDistributionDemo"));
    DefaultMutableTreeNode n9 = new DefaultMutableTreeNode(new DemoDescription(
            "edu.ucla.stat.SOCR.chart.demo.StatisticalLineChartDemo1", "StatisticalLineChartDemo1"));
    DefaultMutableTreeNode n10 = new DefaultMutableTreeNode(new DemoDescription(
            "edu.ucla.stat.SOCR.chart.demo.StatisticalLineChartDemo2", "StatisticalLineChartDemo2"));

    DefaultMutableTreeNode n11 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.XYStepRendererDemo1", "XYStepRendererDemo1"));

    //  root.add(n1);
    root.add(n2);
    root.add(n3);
    root.add(n4);

    // root.add(n5);
    root.add(n6);
    //  root.add(n7);//same as n3
    root.add(n3a);
    root.add(n3b);// qqnormaldemo
    root.add(n3c); // qqdddemo
    root.add(n8);
    root.add(n9);
    root.add(n10);
    root.add(n11);

    return root;
}

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

/**
 * build the HTML tags for a tree like view
 * // w ww  .  ja va 2 s.  c o m
 * @param foldersSheet
 * @param treeview
 * @throws NetxiliaBusinessException
 * @throws NetxiliaResourceException
 */
private DefaultMutableTreeNode buildWorkbookTree(IWorkbook workbook, ISheet foldersSheet,
        Set<SheetFullName> sheetNames) throws NetxiliaResourceException, NetxiliaBusinessException {
    DefaultMutableTreeNode workbookNode = new DefaultMutableTreeNode(
            new TreeViewData(workbook.getId().getKey(), workbook.getName(), "workbook"));

    Stack<DefaultMutableTreeNode> stockNodes = new Stack<DefaultMutableTreeNode>();
    stockNodes.push(workbookNode);

    Set<SheetFullName> alreadyInsertedSheets = new HashSet<SheetFullName>();
    if (foldersSheet != null) {
        Matrix<CellData> folderCells = foldersSheet.receiveCells(AreaReference.ALL).getNonBlocking();
        for (List<CellData> row : folderCells.getRows()) {
            int level = 0;
            String nodeName = null;
            for (CellData cell : row) {
                if (cell.getValue() != null) {
                    nodeName = cell.getValue().getStringValue();
                    if (nodeName != null && nodeName.length() > 0) {
                        level = cell.getReference().getColumnIndex();
                        break;
                    }
                }
            }

            if (nodeName == null) {
                // empty line - ignored
                continue;
            }

            // first level for folders is 1 (under the root node)
            level = level + 1;
            SheetFullName sheetName = new SheetFullName(workbook.getName(), nodeName);
            boolean isSheet = sheetNames.contains(sheetName);
            if (isSheet) {
                alreadyInsertedSheets.add(sheetName);
            }
            DefaultMutableTreeNode crt = new DefaultMutableTreeNode(new TreeViewData(sheetName.toString(),
                    sheetName.getSheetName(), isSheet ? "sheet" : "folder"));
            while (!stockNodes.empty()) {
                DefaultMutableTreeNode node = stockNodes.peek();
                if (level > node.getLevel()) {
                    // make sure is the direct child
                    node.add(crt);
                    break;
                }
                stockNodes.pop();
            }
            stockNodes.push(crt);
        }
    }
    // add the sheets not already added
    for (SheetFullName sheetName : sheetNames) {
        if (alreadyInsertedSheets.contains(sheetName)) {
            continue;
        }
        DefaultMutableTreeNode sheetNode = new DefaultMutableTreeNode(
                new TreeViewData(sheetName.toString(), sheetName.getSheetName(), "sheet"));
        workbookNode.add(sheetNode);
    }

    return workbookNode;
}

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 {/*from  ww w.j  a  v a2  s. c o m*/
        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:SAXTreeValidator.java

/**
 * <p>/*from  w ww . j  a v  a2s  . co  m*/
 *   This reports the occurrence of an actual element. It includes
 *     the element's attributes, with the exception of XML vocabulary
 *     specific attributes, such as
 *     <code>xmlns:[namespace prefix]</code> and
 *     <code>xsi:schemaLocation</code>.
 * </p>
 *
 * @param namespaceURI <code>String</code> namespace URI this element
 *               is associated with, or an empty <code>String</code>
 * @param localName <code>String</code> name of element (with no
 *               namespace prefix, if one is present)
 * @param qName <code>String</code> XML 1.0 version of element name:
 *                [namespace prefix]:[localName]
 * @param atts <code>Attributes</code> list for this element
 * @throws <code>SAXException</code> when things go wrong
 */
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
        throws SAXException {

    DefaultMutableTreeNode element = new DefaultMutableTreeNode("Element: " + localName);
    current.add(element);
    current = element;

    // Determine namespace
    if (namespaceURI.length() > 0) {
        String prefix = (String) namespaceMappings.get(namespaceURI);
        if (prefix.equals("")) {
            prefix = "[None]";
        }
        DefaultMutableTreeNode namespace = new DefaultMutableTreeNode(
                "Namespace: prefix = '" + prefix + "', URI = '" + namespaceURI + "'");
        current.add(namespace);
    }

    // Process attributes
    for (int i = 0; i < atts.getLength(); i++) {
        DefaultMutableTreeNode attribute = new DefaultMutableTreeNode(
                "Attribute (name = '" + atts.getLocalName(i) + "', value = '" + atts.getValue(i) + "')");
        String attURI = atts.getURI(i);
        if (attURI.length() > 0) {
            String attPrefix = (String) namespaceMappings.get(namespaceURI);
            if (attPrefix.equals("")) {
                attPrefix = "[None]";
            }
            DefaultMutableTreeNode attNamespace = new DefaultMutableTreeNode(
                    "Namespace: prefix = '" + attPrefix + "', URI = '" + attURI + "'");
            attribute.add(attNamespace);
        }
        current.add(attribute);
    }
}

From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.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());
    }/*from   w  w  w  .  j a  v  a2  s  . c  om*/

    return childNode;
}