Example usage for javax.swing.tree DefaultTreeModel reload

List of usage examples for javax.swing.tree DefaultTreeModel reload

Introduction

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

Prototype

public void reload() 

Source Link

Document

Invoke this method if you've modified the TreeNode s upon which this model depends.

Usage

From source file:org.openmicroscopy.shoola.agents.util.SelectionWizardUI.java

/**
 * Updates the specified tree.//from ww  w. j  a  v  a 2  s .c o  m
 *
 * @param tree The tree to update.
 * @param nodes The collection of nodes to handle.
 */
private void populateTreeItems(JTree tree, List<TreeImageDisplay> nodes) {
    DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel();
    TreeImageDisplay parent = (TreeImageDisplay) dtm.getRoot();
    parent.removeAllChildrenDisplay();
    parent.removeAllChildren();
    Iterator<TreeImageDisplay> i = nodes.iterator();
    TreeImageDisplay node, child;
    Iterator<TreeImageDisplay> j;
    Set<TreeImageDisplay> toExpand = new HashSet<TreeImageDisplay>();
    while (i.hasNext()) {
        node = i.next();
        node.setDisplayItems(false);
        Object ho = node.getUserObject();
        if (ho instanceof TagAnnotationData) {
            TagAnnotationData tag = (TagAnnotationData) ho;
            if (!TagAnnotationData.INSIGHT_TAGSET_NS.equals(tag.getNameSpace()) || node.hasChildrenDisplay()) {
                dtm.insertNodeInto(node, parent, parent.getChildCount());
            }
        } else {
            dtm.insertNodeInto(node, parent, parent.getChildCount());
        }
        if (node.hasChildrenDisplay()) {
            node.removeAllChildren();
            tree.expandPath(new TreePath(node.getPath()));
            Collection<TreeImageDisplay> l = node.getChildrenDisplay();
            l = sorter.sort(l);
            j = l.iterator();
            while (j.hasNext()) {
                child = j.next();
                child.setDisplayItems(false);
                if (!isSelected(child) && !isFiltered(child)) {
                    dtm.insertNodeInto(child, node, node.getChildCount());
                    toExpand.add(node);
                    tree.expandPath(new TreePath(node.getPath()));
                }
            }
        }
    }
    dtm.reload();
    i = toExpand.iterator();
    while (i.hasNext()) {
        tree.expandPath(new TreePath(i.next().getPath()));
    }
}

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:ropes.MainWindow.java

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    DefaultTreeModel model = (DefaultTreeModel) jTree_fileList.getModel();
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree_fileList.getLastSelectedPathComponent();
    //DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    // TreePath parent_node = null; 
    if (node != null) {
        // parent_node = new TreePath(node.getParent());
        node.removeFromParent();/*ww w.  ja va2 s . c o  m*/

    } else {
        JOptionPane.showMessageDialog(this, "Please select an item first", "Error", JOptionPane.ERROR_MESSAGE);
    }
    model.reload();

    //TODO expand jtree after removing of a node

}

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;// www. ja  v  a2s.  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();
}