psmith      2004/05/19 20:57:23

  Modified:    src/java/org/apache/log4j/chainsaw/vfs VFSPlugin.java
  Log:
  Thanks to Mario of the VFS team, no longer have to manually work out

  what VFS schemes are available on the class path.  Much cleaner!  Thanks Mario.

  

  Added an inner action object to handle the population of the file children

  inside the Table.  You can now see the file size and last modified stamps

  of the files in each directory.

  

  Still can't drill down any futher than the first directory, coming soon.
  
  Revision  Changes    Path
  1.4       +85 -17    
logging-log4j/src/java/org/apache/log4j/chainsaw/vfs/VFSPlugin.java
  
  Index: VFSPlugin.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/vfs/VFSPlugin.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- VFSPlugin.java    19 May 2004 06:12:46 -0000      1.3
  +++ VFSPlugin.java    20 May 2004 03:57:23 -0000      1.4
  @@ -2,14 +2,22 @@
   
   import java.awt.BorderLayout;
   import java.io.File;
  +import java.util.ArrayList;
  +import java.util.Arrays;
  +import java.util.Collection;
   import java.util.HashSet;
  +import java.util.Iterator;
   import java.util.Set;
   
   import javax.swing.JSplitPane;
  +import javax.swing.event.TreeSelectionEvent;
  +import javax.swing.event.TreeSelectionListener;
   import javax.swing.tree.DefaultMutableTreeNode;
  +import javax.swing.tree.TreePath;
   
   import org.apache.commons.vfs.FileObject;
   import org.apache.commons.vfs.FileSystemException;
  +import org.apache.commons.vfs.SystemInfo;
   import org.apache.commons.vfs.VFS;
   import org.apache.commons.vfs.impl.StandardFileSystemManager;
   import org.apache.log4j.chainsaw.plugins.GUIPluginSkeleton;
  @@ -33,6 +41,8 @@
        private final JSplitPane splitPane = new JSplitPane();
       
        private StandardFileSystemManager fileSystemManager;
  +    
  +    private final AOFileTablePopulater aoTablePopulator = new 
AOFileTablePopulater(fileObjectTable.getTableModel());
        
        private Set supportedSchemes = new HashSet();
        
  @@ -72,7 +82,7 @@
        /**
         * Ensures that there is at least a Local FileSystem with the Current 
directory loaded.
        * 
  -     * This probably shouldn't be here after we've completed all the VFS preference 
loading stuff.
  +     * TODO This probably shouldn't be here after we've completed all the VFS 
preference loading stuff.
        * 
         */
        private void loadLocalFileSystem() {
  @@ -92,23 +102,14 @@
         * Works out which of the supported File Systems are available.
         */
        private void determineSupportedFileSystems() {
  -//           TODO This seems really lame to have to do this, but there you go...
  -             String[] schemes = new String[] {"file","zip", "jar", "sftp", "http", 
"https", "ftp", "CIFS" };
  -             for (int i = 0; i < schemes.length; i++) {
  -                     String scheme = schemes[i];
  -                     try {
  -                             if(fileSystemManager.hasProvider(scheme)) {
  -                                     supportedSchemes.add(scheme);
  -                                     LogLog.info("VFS scheme '" + scheme + "' 
supported");
  -                             }else {
  -                                     LogLog.error("VFS scheme '" + scheme + "' NOT 
supported");
  -                             }
  -                     } catch (Exception e) {
  -                             LogLog.error("Failed test for VFS scheme '" + scheme + 
"'", e);
  -                     }
  -             }
  +        SystemInfo info = fileSystemManager.getSystemInfo();
  +        String[] schemes = info.getSchemes();
  +        supportedSchemes.addAll(Arrays.asList(schemes));
  +        
  +        LogLog.info("Supported schemes: " + supportedSchemes);
        }
  -     /**
  +
  +    /**
         * 
         */
        private void initGUI() {
  @@ -118,7 +119,74 @@
           splitPane.add(this.fileSystemTree, JSplitPane.LEFT);
           splitPane.add(this.fileObjectTable, JSplitPane.RIGHT);
                add(splitPane, BorderLayout.CENTER);
  +        
  +        fileSystemTree.getTree().addTreeSelectionListener(this.aoTablePopulator);
        }
        
        
  +    /**
  +     * Triggered when the user selects a node in the tree, it automatically 
populates all the child node 
  +     * information in the table
  +     * 
  +     * @author psmith
  +     *
  +     */
  +    private static class AOFileTablePopulater implements TreeSelectionListener{
  +
  +        private DirectoryListTableModel tableModel;
  +        
  +        /**
  +         * @param tableModel
  +         */
  +        public AOFileTablePopulater(DirectoryListTableModel tableModel) {
  +            this.tableModel = tableModel;
  +        }
  +        
  +             /* (non-Javadoc)
  +              * @see 
javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
  +              */
  +             public void valueChanged(TreeSelectionEvent e) {
  +                     Object object = e.getSource();
  +                     TreePath path = e.getNewLeadSelectionPath();
  +            // if there is no path, then there is nothing selected, so we need to 
clear the table model... that's it!
  +            if(path == null) {
  +              this.tableModel.clear();
  +              return;
  +            }
  +            DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) 
path.getLastPathComponent();
  +            
  +            Object userObject = treeNode.getUserObject();
  +            if(!(userObject instanceof VFSNode)) {
  +             LogLog.error("User Object of selected item is not a VFSNode, 
ignoring");   
  +             return;
  +            }
  +            final VFSNode vfsNode = (VFSNode) userObject;
  +            
  +            // IN a background thread, we now populate the children in the 
tableModel
  +            Runnable runnable = new Runnable() {
  +
  +                             public void run() {
  +                    try {
  +                        FileObject[] fos = vfsNode.getFileObject().getChildren();
  +                        Collection objects = new ArrayList(Arrays.asList(fos));
  +                        for (Iterator iter = objects.iterator(); iter.hasNext();) {
  +                                                     FileObject fo = (FileObject) 
iter.next();
  +                                                     if(fo.getType().hasChildren()) 
{
  +                                                             iter.remove();
  +                            }
  +                                             }
  +                        tableModel.setFiles(objects);
  +                    } catch (FileSystemException ex) {
  +                        LogLog.error("Failed to retrieve children for " + 
vfsNode,ex);
  +                        return;
  +                    }
  +                             }};
  +                
  +            Thread thread = new Thread(runnable);
  +            thread.setPriority(Thread.MIN_PRIORITY);
  +            thread.start();
  +            
  +             }
  +        
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to