[Schmitzm-commits] r1870 - in trunk/schmitzm-core/src/main: java/de/schmitzm/io java/de/schmitzm/swing/table resources/de/schmitzm/swing/resource/locales

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Wed Feb 22 17:39:23 CET 2012


Author: mojays
Date: 2012-02-22 17:39:23 +0100 (Wed, 22 Feb 2012)
New Revision: 1870

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/FilesSelectionTable.java
   trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties
   trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties
Log:
IOUtil.listFilesAndDirectoriesFromURL(.)
FileSelectionTable: constructor flag to make selection column optional

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2012-02-22 15:43:08 UTC (rev 1869)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2012-02-22 16:39:23 UTC (rev 1870)
@@ -1234,18 +1234,54 @@
     public static List<URL> listFilesFromURL(URL url) throws IOException {
       // #### TODO: improve this workaround method! ####
 
+      List<URL> files = new ArrayList<URL>();
+      listFilesAndDirectoriesFromURL(url, files, null);
+      return files;
+    }
+
+    /**
+     * Determines all (sub)directories from an web directory. Because the files can not (yet)
+     * be determines automatically this method simply extracts all html {@code href} tags from
+     * the URL stream! So be sure that the given URL specifies a "directory" on the
+     * web server without any index.html (or something like that).
+     * Otherwise (e.g. if URL specifies a website) this method might have an unexpected result!
+     * @param url URL of a webserver directory
+     */
+    public static List<URL> listDirectoriesFromURL(URL url) throws IOException {
+      // #### TODO: improve this workaround method! ####
+
+      List<URL> dirs = new ArrayList<URL>();
+      listFilesAndDirectoriesFromURL(url, null, dirs);
+      return dirs;
+    }
+
+    /**
+     * Determines all files and (sub)directories from an web directory. Because the files can not (yet)
+     * be determines automatically this method simply extracts all html {@code href} tags from
+     * the URL stream! So be sure that the given URL specifies a "directory" on the
+     * web server without any index.html (or something like that).
+     * Otherwise (e.g. if URL specifies a website) this method might have an unexpected result!
+     * @param url URL of a webserver directory
+     * @param files destination list to store the file urls in
+     * @param dirs  destination list to store the directory urls in
+     */
+    public static void listFilesAndDirectoriesFromURL(URL url,  List<URL> files,  List<URL> dirs) throws IOException {
+      // #### TODO: improve this workaround method! ####
+
       // extract links from URL
       List<String> fileNames = extractLinksFromURL(url);
       // combine file names with source URL
-      List<URL> files = new ArrayList<URL>();
       for (String fileName : fileNames) {
-        // Ignore directory links!
-        if ( fileName.endsWith("/") )
-          continue; 
         URL fileURL = new URL(url,fileName);
-        files.add(fileURL);
+        // Differ between files and directories
+        if ( fileName.endsWith("/") ) {
+          if ( dirs != null )
+            dirs.add(fileURL);
+        } else {
+          if ( files != null )
+            files.add(fileURL);
+        }
       }
-      return files;
     }
 
     /**

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/FilesSelectionTable.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/FilesSelectionTable.java	2012-02-22 15:43:08 UTC (rev 1869)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/FilesSelectionTable.java	2012-02-22 16:39:23 UTC (rev 1870)
@@ -53,27 +53,38 @@
   
   /**
    * Creates a new table.
+   * @param selectionColumn indicates whether selection column is added to table
    */
-  public FilesSelectionTable(FilesSelectionTableModel<FILETYPE> tableModel) {
+  public FilesSelectionTable(boolean selectionColumn, FilesSelectionTableModel<FILETYPE> tableModel) {
     super(tableModel);
-    setModel( new SelectionTableModel(tableModel, this));
-    getColumnModel().getColumn(0).setMaxWidth(30);
-//    getModel().fireTableStructureChanged();
+    if ( selectionColumn ) {
+      setModel( new SelectionTableModel(tableModel, this));
+      getColumnModel().getColumn(0).setMaxWidth(30);
+    }
   }
 
   /**
    * Creates a new table.
    * @param showCompletePath indicates whether the complete path is shown in table or only the file name
+   * @param selectionColumn indicates whether selection column is added to table
    */
-  public FilesSelectionTable(boolean showCompletePath) {
-    this( new FilesSelectionTableModel<FILETYPE>(showCompletePath) );
+  public FilesSelectionTable(boolean selectionColumn, boolean showCompletePath) {
+    this( selectionColumn, new FilesSelectionTableModel<FILETYPE>(showCompletePath) );
   }
   
   /**
    * Creates a new table which shows only the filename.
+   * @param selectionColumn indicates whether selection column is added to table
    */
+  public FilesSelectionTable(boolean selectionColumn) {
+    this( selectionColumn, false );
+  }
+
+  /**
+   * Creates a new table with selection column which shows only the filename.
+   */
   public FilesSelectionTable() {
-    this( false );
+    this( true );
   }
 
   /**
@@ -135,7 +146,7 @@
    * @param <FILETYPE> defines whether the class works with {@link File} or {@link URL}; other
    *                   values will cause an {@link Exception} when showing the table
    */
-  protected static class FilesSelectionTableModel<FILETYPE> extends AbstractTableModel  {
+  public static class FilesSelectionTableModel<FILETYPE> extends AbstractTableModel  {
     
     /** Holds the {@link File}- or {@link URL}-Objects. */
     protected List<FILETYPE> files = null;

Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties	2012-02-22 15:43:08 UTC (rev 1869)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties	2012-02-22 16:39:23 UTC (rev 1870)
@@ -276,3 +276,5 @@
 URLAddressPanel.Button.Tooltip=Open URL in browser
 
 FilesSelectionTable.Files=Files
+FilesSelectionTable.Dirs=Directories
+

Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties	2012-02-22 15:43:08 UTC (rev 1869)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties	2012-02-22 16:39:23 UTC (rev 1870)
@@ -249,3 +249,4 @@
 URLAddressPanel.Button.Tooltip=URL in Browser \u00D6ffnen
 
 FilesSelectionTable.Files=Dateien
+FilesSelectionTable.Dirs=Verzeichnisse



More information about the Schmitzm-commits mailing list