*
* @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
*/
public void valueChanged(TreeSelectionEvent e) {
final JTree sourceTree = (JTree) e.getSource();
final DefaultTreeModel treeModel = (DefaultTreeModel) sourceTree
.getModel();
TreePath path = e.getPath();
if (path == null) { return; }
final DefaultMutableTreeNode lastPathComponent = (DefaultMutableTreeNode) path
.getLastPathComponent();
// TODO this method will NEVER remove the children and repopulates
// if the node already has
// children, be nice to find out
// whether VFS can help determine whether it should 'relook' for
// changes or something.
if (lastPathComponent == null) {
return;
} else if (lastPathComponent.getChildCount() > 0) {
// already determined Children
return;
}
Object userObject = lastPathComponent.getUserObject();
if (userObject == null || !(userObject instanceof VFSNode)) { return; }
final VFSNode vfsNode = (VFSNode) userObject;
Thread thread = new Thread(new Runnable() {
public void run() {
USER_MESSAGE_LOGGER.info("Scanning directory...");
sourceTree.setCursor(Cursor
.getPredefinedCursor(Cursor.WAIT_CURSOR));
lastPathComponent.removeAllChildren();
new BackgroundChildFileObjectPopulator(lastPathComponent,
vfsNode).run();
treeModel.reload(lastPathComponent);
sourceTree.setCursor(Cursor.getDefaultCursor());
}
});
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();