Example usage for javax.swing.tree DefaultMutableTreeNode removeAllChildren

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

Introduction

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

Prototype

public void removeAllChildren() 

Source Link

Document

Removes all of this node's children, setting their parents to null.

Usage

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

/**
 *
 * @param e/*  w  ww. ja va2 s .com*/
 */
@Override
protected void handleUnprocessedActionEvent(ActionEvent e) {
    if (e.getSource() == tableDropdown) {
        final TableData td = (TableData) tableDropdown.getSelectedItem();

        if (StringUtils.isNotBlank(td.getName())) {

            spinner.startSpinner("Loading table relationships...");
            new SwingWorker() {
                @Override
                protected Object doInBackground() throws Exception {
                    Object retval = null;
                    try {
                        DefaultMutableTreeNode rootNode = sqlQueryTree.getRootNode();
                        rootNode.removeAllChildren();
                        loadTables(td, rootNode);
                    }

                    catch (Exception ex) {
                        retval = ex.toString();
                    }
                    return retval;
                };

                @Override
                protected void done() {
                    spinner.stopSpinner();
                    try {
                        Object result = get();

                        if (result != null) {
                            UIUtils.showError(getMainframe(), "Error loading table relationships",
                                    "An error occured while loading table relationships - "
                                            + result.toString());
                        } else {
                            DefaultMutableTreeNode rootNode = sqlQueryTree.getRootNode();
                            sqlQueryTree.getModel().nodeStructureChanged(rootNode);
                            sqlQueryTree.expandNode(rootNode, 1);
                            sqlSelectPanel.clear();
                            sqlWherePanel.clear();
                        }
                    }

                    catch (Exception ex) {
                        LOG.error(ex.toString(), ex);
                    }
                }
            }.execute();
        }
    }
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.ConsentCreatorUtilities.java

/**
 * Sorts all Nodes and children of these Nodes by the name of their OIDObjects
 * // w w w  .  j av  a  2 s.  c  o m
 * @param root
 */
public void sortTree(DefaultMutableTreeNode root) {

    Vector<DefaultMutableTreeNode> childrenV = new Vector<DefaultMutableTreeNode>();

    if (root.getChildCount() > 1) {

        for (int i = 0; i < root.getChildCount(); i++) {

            childrenV.add((DefaultMutableTreeNode) root.getChildAt(i));

        }

        root.removeAllChildren();

        boolean swapped = true;

        while (swapped) {
            swapped = false;

            for (int i = 0; i < childrenV.size() - 1; i++) {

                if (childrenV.elementAt(i).getChildCount() > 0) {
                    sortTree(childrenV.elementAt(i));
                }

                OIDObject oo1 = (OIDObject) childrenV.elementAt(i).getUserObject();
                OIDObject oo2 = (OIDObject) childrenV.elementAt(i + 1).getUserObject();

                DefaultMutableTreeNode node1 = childrenV.elementAt(i);
                DefaultMutableTreeNode node2 = childrenV.elementAt(i + 1);

                if (oo1.getName().compareTo(oo2.getName()) > 0) {

                    childrenV.setElementAt(node2, i);
                    childrenV.setElementAt(node1, i + 1);

                    swapped = true;
                }
            }
        }
        for (int i = 0; i < childrenV.size(); i++) {

            root.add(childrenV.elementAt(i));

        }
    }
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/** 
 * Collapses the node when an on-going data loading is cancelled.
 * //from  www  .j  av  a  2  s .  c  o m
 * @param node The node to collapse.
 */
void cancel(DefaultMutableTreeNode node) {
    if (node == null)
        return;
    if (node.getChildCount() <= 1) {
        if (node.getUserObject() instanceof String) {
            node.removeAllChildren();
            buildEmptyNode(node);
        }
    }
    //in this order otherwise the node is not collapsed.
    ((DefaultTreeModel) treeDisplay.getModel()).reload(node);
    collapsePath(node);
}

From source file:ropes.MainWindow.java

private void jButton_clear_fileListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_clear_fileListActionPerformed
    DefaultTreeModel model = (DefaultTreeModel) jTree_fileList.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    root.removeAllChildren(); //this removes all nodes
    model.reload(); //this notifies the listeners and changes the GUI
}

From source file:streamme.visuals.Main.java

public void askTree() {
    if (client == null) {
        this.setMessage("Connect first...");
        return;//from   w  w  w . j  a  va2 s  .c o  m
    }
    this.setMessage("Asking path...");
    askedFiles = true;

    new Thread() {
        @Override
        public void run() {
            JSONArray json = client.askJSON();
            tree_model = (DefaultTreeModel) tree_files.getModel();
            //DefaultMutableTreeNode allNode = (DefaultMutableTreeNode) new DefaultMutableTreeNode("Folders");
            //tree_model.setRoot(allNode);
            DefaultMutableTreeNode allNode = (DefaultMutableTreeNode) tree_model.getRoot();
            allNode.removeAllChildren();
            tree_model.reload();

            for (Object obj : json) {
                JSONObject jsonObj = (JSONObject) obj;
                fillTree(jsonObj, allNode);
            }

            DefaultMutableTreeNode currentNode = allNode;
            while (currentNode != null) {
                if (currentNode.getLevel() == 0)
                    tree_files.expandPath(new javax.swing.tree.TreePath(currentNode.getPath()));
                currentNode = currentNode.getNextNode();
            }
            setMessage("Path loaded");
        }
    }.start();
}

From source file:UserInterface.CustomerRole.CustomerOrderSchedulingJPanel.java

public void populateTree() {
    DefaultTreeModel model = (DefaultTreeModel) jTree.getModel();
    ArrayList<Network> networkList = system.getNetworkList();
    ArrayList<Enterprise> enterpriseList;
    ArrayList<Organization> organizationList;

    Network network;/* w w w .j  av a 2 s .c  o m*/
    Enterprise enterprise;
    Organization organization;

    DefaultMutableTreeNode networks = new DefaultMutableTreeNode("Networks");
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    root.removeAllChildren();
    root.insert(networks, 0);

    DefaultMutableTreeNode networkNode;
    DefaultMutableTreeNode enterpriseNode;

    DefaultMutableTreeNode organizationNode;

    for (int i = 0; i < networkList.size(); i++) {
        network = networkList.get(i);
        networkNode = new DefaultMutableTreeNode(network.getName());
        networks.insert(networkNode, i);

        enterpriseList = network.getEnterpriseDirectory().getEnterpriseList();

        for (int j = 0; j < enterpriseList.size(); j++) {
            enterprise = enterpriseList.get(j);
            enterpriseNode = new DefaultMutableTreeNode(enterprise.getName());
            networkNode.insert(enterpriseNode, j);

            organizationList = enterprise.getOrganizationDirectory().getOrganizationList();

            for (int k = 0; k < organizationList.size(); k++) {
                organization = organizationList.get(k);
                organizationNode = new DefaultMutableTreeNode(organization.getName());
                enterpriseNode.insert(organizationNode, k);
            }
        }
    }
    model.reload();
}