Example usage for javax.swing.tree DefaultTreeModel removeNodeFromParent

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

Introduction

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

Prototype

public void removeNodeFromParent(MutableTreeNode node) 

Source Link

Document

Message this to remove node from its parent.

Usage

From source file:org.fseek.simon.swing.util.TreeUtil.java

public static void addChilds(final LinkTreeNode child, final DefaultTreeModel model, boolean showFiles,
        boolean showHidden, boolean fake) {

    if (child != null) {
        File linkDir = child.getLinkDir();
        if (linkDir == null)
            return;
        if (linkDir.canRead()) {
            File[] listFiles = linkDir.listFiles((FileFilter) new TreeFileFilter(showHidden, showFiles));
            if (listFiles != null) {
                final int length = listFiles.length;
                if (fake) {
                    EventQueue.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            if (length > 0) {
                                fakeNode(child, model);
                            }//from   w ww  .j a v  a2s  .co m
                        }
                    });
                    return;
                }
                final DefaultMutableTreeNode clear = clear(child);
                if (clear == null && child.getChildCount() > 0) {
                    return;
                }
                deleteAllChilds(child, model, clear);
                if (Thread.interrupted()) {
                    return;
                }
                Arrays.sort(listFiles, DirectoryFileComparator.DIRECTORY_COMPARATOR);
                Debug.println("Filling node with real data: " + child.getUserObject().toString());
                addFiles(listFiles, child, model, showFiles, showHidden);
                if (clear != null) {
                    EventQueue.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            model.removeNodeFromParent(clear);
                        }
                    });
                }
            }
        }
    }
}

From source file:org.fseek.simon.swing.util.TreeUtil.java

public static void deleteAllChilds(final LinkTreeNode node, final DefaultTreeModel model,
        DefaultMutableTreeNode clearNode) {
    for (int i = 0; i < node.getChildCount(); i++) {
        if (Thread.interrupted()) {
            break;
        }//from ww  w. j a  v  a2s .  c o  m
        final MutableTreeNode childAt = (MutableTreeNode) node.getChildAt(i);
        if (childAt != null && clearNode != null && clearNode != childAt) {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    model.removeNodeFromParent(childAt);
                }
            });
        }
    }
}

From source file:ser321.media.MediaJavaClient.java

private void clearTree(DefaultMutableTreeNode root, DefaultTreeModel model) {
    try {//from w  w  w.j a va2s . c o  m
        DefaultMutableTreeNode next = null;
        int subs = model.getChildCount(root);
        for (int k = subs - 1; k >= 0; k--) {
            next = (DefaultMutableTreeNode) model.getChild(root, k);
            debug("removing node labelled:" + (String) next.getUserObject());
            model.removeNodeFromParent(next);
        }
    } catch (Exception ex) {
        System.out.println("Exception while trying to clear tree:");
        ex.printStackTrace();
    }
}