psmith      2004/05/18 17:11:08

  Modified:    src/java/org/apache/log4j/chainsaw/vfs
                        FileSystemTreePanel.java VFSPlugin.java
  Added:       src/java/org/apache/log4j/chainsaw/vfs VFSNode.java
                        FileObjectTable.java DirectoryListTableModel.java
  Log:
  VFSPlugin now looking a bit better, although still no actual functionality yet

  

  This plugin automatically adds a 'local' VFS file system node to the tree just for 
testing purposes.

  

  Eventually one will be able to browse the file system root to find the children, and 
navigate

  a directory hierachy, and then select a file to view in the detail table.

  

  I will also add a 'preview' panel below the table which, hopefully, will be able to 
display

  the first X lines of text in the file.
  
  Revision  Changes    Path
  1.2       +55 -17    
logging-log4j/src/java/org/apache/log4j/chainsaw/vfs/FileSystemTreePanel.java
  
  Index: FileSystemTreePanel.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/vfs/FileSystemTreePanel.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileSystemTreePanel.java  15 May 2004 06:31:48 -0000      1.1
  +++ FileSystemTreePanel.java  19 May 2004 00:11:08 -0000      1.2
  @@ -1,33 +1,71 @@
   package org.apache.log4j.chainsaw.vfs;
   
   import java.awt.BorderLayout;
  +import java.awt.Dimension;
   
   import javax.swing.JPanel;
  +import javax.swing.JScrollPane;
   import javax.swing.JTree;
  +import javax.swing.SwingUtilities;
   import javax.swing.tree.DefaultMutableTreeNode;
  +import javax.swing.tree.DefaultTreeCellRenderer;
   import javax.swing.tree.DefaultTreeModel;
  +import javax.swing.tree.TreePath;
  +
  +import org.apache.commons.vfs.FileObject;
  +import org.apache.log4j.chainsaw.icons.ChainsawIcons;
   
   /**
    * @author psmith
    *
    */
   class FileSystemTreePanel extends JPanel {
  - 
  -  private final JTree tree = new JTree();
  -  
  -  FileSystemTreePanel(){
  -    initGUI();
  -  }
  -
  -  /**
  -   * 
  -   */
  -  private void initGUI() {
  -    
  -    tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("VFS")));
  -    
  -    setLayout(new BorderLayout());
  +     
  +     private final DefaultTreeModel treeModel;
  +     private final JTree tree = new JTree();
  +     private final DefaultMutableTreeNode rootNode = new 
DefaultMutableTreeNode("VFS");
  +     
  +     private static final String TOOLTIP = "Displays all the known VFS 
repositories";
       
  -    add(tree, BorderLayout.CENTER);  }
  -  
  +     FileSystemTreePanel(){
  +             treeModel = new DefaultTreeModel(rootNode);
  +             initGUI();
  +     }
  +     
  +     /**
  +      * 
  +      */
  +     private void initGUI() {
  +             tree.setModel(treeModel);
  +        tree.expandPath(new TreePath(rootNode.getPath()));
  +        
  +             tree.setRootVisible(false);
  +             setLayout(new BorderLayout());
  +             setPreferredSize(new Dimension(150,400));
  +             add(new JScrollPane(tree), BorderLayout.CENTER);
  +             
  +        // We make the Leaf Icons a nice Server-style icon to represent the 
repository.
  +        DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) 
tree.getCellRenderer();
  +        renderer.setLeafIcon(ChainsawIcons.ICON_SERVER);
  +        
  +             setToolTipText(TOOLTIP);
  +             tree.setToolTipText(TOOLTIP);
  +     }
  +     
  +     /**
  +     * Adds a FileObject with a label to the list of known VFS repositories, and 
makes sure the 
  +     * Tree gets updated.
  +      * @param fileObject
  +      */
  +     public void addFileObject(String name, FileObject fileObject) {
  +             VFSNode vfsNode = new VFSNode(name, fileObject);
  +             final DefaultMutableTreeNode node = new 
DefaultMutableTreeNode(vfsNode);
  +             SwingUtilities.invokeLater(new Runnable() {
  +                     
  +                     public void run() {
  +                             rootNode.add(node);
  +                tree.makeVisible(new TreePath(node.getPath()));
  +                     }});
  +     }
  +     
   }
  
  
  
  1.2       +90 -68    
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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- VFSPlugin.java    15 May 2004 06:31:48 -0000      1.1
  +++ VFSPlugin.java    19 May 2004 00:11:08 -0000      1.2
  @@ -1,11 +1,13 @@
   package org.apache.log4j.chainsaw.vfs;
   
   import java.awt.BorderLayout;
  +import java.io.File;
   import java.util.HashSet;
   import java.util.Set;
   
  -import javax.swing.JLabel;
  +import javax.swing.JSplitPane;
   
  +import org.apache.commons.vfs.FileObject;
   import org.apache.commons.vfs.FileSystemException;
   import org.apache.commons.vfs.VFS;
   import org.apache.commons.vfs.impl.StandardFileSystemManager;
  @@ -23,73 +25,93 @@
    *
    */
   public class VFSPlugin extends GUIPluginSkeleton {
  -
  -  
  -  private final FileSystemTreePanel fileSystemTree = new FileSystemTreePanel();
  -  
  -  private StandardFileSystemManager fileSystemManager;
  -
  -  private Set supportedSchemes = new HashSet();
  -  
  -  public VFSPlugin() {
  -    setName("VFS");
  -    initGUI();
  -  }
  -  /* (non-Javadoc)
  -   * @see org.apache.log4j.plugins.Plugin#shutdown()
  -   */
  -  public void shutdown() {
  -  }
  -
  -  /* (non-Javadoc)
  -   * @see org.apache.log4j.spi.OptionHandler#activateOptions()
  -   */
  -  public void activateOptions() {
  -    try {
  -      this.fileSystemManager = (StandardFileSystemManager) VFS.getManager();
  -      
  -    } catch (FileSystemException e) {
  -      LogLog.error("Failed to initialise VFS", e);
  -      e.printStackTrace();
  -      setActive(false);
  -      return;
  -    }
  -    
  -    determineSupportedFileSystems();
  -    
  -    setActive(true);
  -  }
  -
  -  /**
  -   * 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);
  -      }
  -    }
  -  }
  -  /**
  -   * 
  -   */
  -  private void initGUI() {
  +     
  +     
  +     private final FileSystemTreePanel fileSystemTree = new FileSystemTreePanel();
  +     private final FileObjectTable fileObjectTable = new FileObjectTable();
  +     private final JSplitPane splitPane = new JSplitPane();
       
  -    setLayout(new BorderLayout());
  +     private StandardFileSystemManager fileSystemManager;
  +     
  +     private Set supportedSchemes = new HashSet();
  +     
  +     public VFSPlugin() {
  +             setName("VFS");
  +             initGUI();
  +     }
       
  -    add(new JLabel("Work In Progress"), BorderLayout.CENTER);
  -    add(fileSystemTree, BorderLayout.WEST);
  -  }
  -  
  -  
  +     /* (non-Javadoc)
  +      * @see org.apache.log4j.plugins.Plugin#shutdown()
  +      */
  +     public void shutdown() {
  +     }
  +     
  +     /* (non-Javadoc)
  +      * @see org.apache.log4j.spi.OptionHandler#activateOptions()
  +      */
  +     public void activateOptions() {
  +             try {
  +                     this.fileSystemManager = (StandardFileSystemManager) 
VFS.getManager();
  +                     
  +             } catch (FileSystemException e) {
  +                     LogLog.error("Failed to initialise VFS", e);
  +                     e.printStackTrace();
  +                     setActive(false);
  +                     return;
  +             }
  +             
  +             determineSupportedFileSystems();
  +             loadLocalFileSystem();
  +             setActive(true);
  +     }
  +     
  +     /**
  +      * 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.
  +     * 
  +      */
  +     private void loadLocalFileSystem() {
  +             try {
  +                     FileObject fileObject = 
this.fileSystemManager.createVirtualFileSystem(new File("").toURL().toExternalForm());
  +                     
  +                     this.fileSystemTree.addFileObject("local", fileObject);
  +             } catch (Exception e) {
  +                     LogLog.error("error creating local VFS",e);
  +             }
  +             
  +     }
  +     /**
  +      * 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);
  +                     }
  +             }
  +     }
  +     /**
  +      * 
  +      */
  +     private void initGUI() {
  +             
  +             setLayout(new BorderLayout());
  +
  +        splitPane.add(this.fileSystemTree, JSplitPane.LEFT);
  +        splitPane.add(this.fileObjectTable, JSplitPane.RIGHT);
  +             add(splitPane, BorderLayout.CENTER);
  +     }
  +     
  +     
   }
  
  
  
  1.1                  
logging-log4j/src/java/org/apache/log4j/chainsaw/vfs/VFSNode.java
  
  Index: VFSNode.java
  ===================================================================
  package org.apache.log4j.chainsaw.vfs;
  
  import org.apache.commons.vfs.FileObject;
  
  /**
   * @author psmith
   *
   */
  public class VFSNode {
      
      private String name="";
      private FileObject fileObject;
      
        /**
         * @return Returns the fileObject.
         */
        public final FileObject getFileObject() {
                return fileObject;
        }
        /**
         * @return Returns the name.
         */
        public final String getName() {
                return name;
        }
      
      public String toString() {
          // TODO display name, but with Schema too
       return getName();   
      }
      
        /**
         * @param name
         * @param fileObject
         */
        public VFSNode(String name, FileObject fileObject) {
                super();
                this.name = name;
                this.fileObject = fileObject;
        }
  }
  
  
  
  1.1                  
logging-log4j/src/java/org/apache/log4j/chainsaw/vfs/FileObjectTable.java
  
  Index: FileObjectTable.java
  ===================================================================
  package org.apache.log4j.chainsaw.vfs;
  
  import java.awt.BorderLayout;
  
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JTable;
  
  /**
   * @author psmith
   *
   */
  public class FileObjectTable extends JPanel {
      
      private final DirectoryListTableModel tableModel = new DirectoryListTableModel();
      private final JTable table = new JTable(tableModel);
      private final JScrollPane scrollPane = new JScrollPane(table);
      
      public FileObjectTable(){
       initGUI();   
      }
  
  
        /**
         * 
         */
        private void initGUI() {
                setLayout(new BorderLayout());
          add(scrollPane, BorderLayout.CENTER);
        }
        /**
         * @return Returns the tableModel.
         */
        public final DirectoryListTableModel getTableModel() {
                return tableModel;
        }
  }
  
  
  
  1.1                  
logging-log4j/src/java/org/apache/log4j/chainsaw/vfs/DirectoryListTableModel.java
  
  Index: DirectoryListTableModel.java
  ===================================================================
  package org.apache.log4j.chainsaw.vfs;
  
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.List;
  
  import javax.swing.table.AbstractTableModel;
  
  import org.apache.commons.vfs.FileObject;
  import org.apache.log4j.helpers.LogLog;
  
  /**
   * @author psmith
   *
   */
  public class DirectoryListTableModel extends AbstractTableModel {
  
      private final String[] COLUMN_NAMES = new String[] {"Name", "Size", "Last 
Modified"};
      
      private List data = new ArrayList();
      
        /* (non-Javadoc)
         * @see javax.swing.table.TableModel#getColumnCount()
         */
        public int getColumnCount() {
          return COLUMN_NAMES.length;
        }
  
        /* (non-Javadoc)
         * @see javax.swing.table.TableModel#getRowCount()
         */
        public int getRowCount() {
                return data.size();
        }
  
        /* (non-Javadoc)
         * @see javax.swing.table.TableModel#getValueAt(int, int)
         */
        public Object getValueAt(int rowIndex, int columnIndex) {
          FileObject fileObject = (FileObject) data.get(rowIndex);
          
          try {
                        switch (columnIndex) {
                                case 0 :
                                        return fileObject.getName();
                                case 1 :
                                        return new 
Long(fileObject.getContent().getSize());
                                case 2 :
                                        return new Date(fileObject.getContent()
                                                        .getLastModifiedTime());
                        }
                } catch (Exception e) {
                        LogLog.error("error determining value", e);
                }
          return "{Error}";
          
        }
        /* (non-Javadoc)
         * @see javax.swing.table.TableModel#getColumnName(int)
         */
        public String getColumnName(int column) {
                return COLUMN_NAMES[column];
        }
  }
  
  
  

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

Reply via email to