psmith 2004/05/20 16:11:14 Modified: src/java/org/apache/log4j/chainsaw/vfs VFSUtils.java Log: removed (moved) a method into a more appropriate class, it is not
really a utility method, as it is really specific to a particular function. Revision Changes Path 1.2 +3 -108 logging-log4j/src/java/org/apache/log4j/chainsaw/vfs/VFSUtils.java Index: VFSUtils.java =================================================================== RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/vfs/VFSUtils.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- VFSUtils.java 19 May 2004 06:11:37 -0000 1.1 +++ VFSUtils.java 20 May 2004 23:11:14 -0000 1.2 @@ -1,119 +1,14 @@ package org.apache.log4j.chainsaw.vfs; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import javax.swing.JTree; -import javax.swing.SwingUtilities; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreePath; + import org.apache.commons.vfs.FileObject; -import org.apache.log4j.helpers.LogLog; /** * @author psmith * */ class VFSUtils { - /** - * Given a tree node, first determine if the user object is a VFSNode, and - * if not, ignores the request and returns immediately. Otherwise a new, - * low-priority thread is started to go look for any potential children of - * the fileObject. As each child is located, an new child TreeNode is added - * to the passed in node, and done within the Swing's EventDispatchThread. - * - * Child TreeNodes' that are added to this node will have a VFSNode as it's - * UserObject. - * - * @param node - */ - static void lookForChildren(final JTree tree, - final DefaultMutableTreeNode node) { - Object object = node.getUserObject(); - if (!(object instanceof VFSNode)) { - return; - } - final VFSNode vfsNode = (VFSNode) object; - Thread thread = new Thread(new BackgroundChildFileObjectPopulator(tree, - node, vfsNode)); - thread.setPriority(Thread.MIN_PRIORITY); - thread.start(); - } - /** - * A background task that scans a vfsNode for Children, and creates Child - * nodes for them dynamically. - * - * @author psmith - * - */ - private static final class BackgroundChildFileObjectPopulator - implements - Runnable { - private final VFSNode vfsNode; - private final DefaultMutableTreeNode node; - private final JTree tree; - /** - * @param node - * @param vfsNode - */ - public BackgroundChildFileObjectPopulator(JTree tree, - DefaultMutableTreeNode node, VFSNode vfsNode) { - this.tree = tree; - this.node = node; - this.vfsNode = vfsNode; - } - /* - * (non-Javadoc) - * - * @see java.lang.Runnable#run() - */ - public void run() { - LogLog.debug("Looking for children of node " + vfsNode.getName()); - // first, lets add a tempopary node that says "Pending..." in it - // while we work out what's going on. - final DefaultMutableTreeNode pendingNode = new DefaultMutableTreeNode( - "Pending..."); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - node.add(pendingNode); - tree.makeVisible(new TreePath(pendingNode.getPath())); - } - }); - try { - List children = new ArrayList(Arrays.asList(this.vfsNode - .getFileObject().getChildren())); - Collections.sort(children, FILE_OBJECT_COMPARATOR); - LogLog.debug("Found " + children.size() + " children"); - for (Iterator iter = children.iterator(); iter.hasNext();) { - FileObject child = (FileObject) iter.next(); - // we only add non-leaf nodes, as the leaf nodes get - // displayed in the table - if (child.getType().hasChildren()) { - final DefaultMutableTreeNode childNode = new DefaultMutableTreeNode( - new VFSNode(child.getName().getBaseName(), - child)); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - node.add(childNode); - } - }); - } - } - } catch (Exception e) { - // TODO feedback to the user about the error... - LogLog.error("Failed to populate Children", e); - } finally { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - node.remove(pendingNode); - ((DefaultTreeModel) tree.getModel()).reload(node); - } - }); - } - } - } + + private VFSUtils() { } /** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]