Author: agomes
Date: Fri Sep 16 20:48:32 2016
New Revision: 1761081

URL: http://svn.apache.org/viewvc?rev=1761081&view=rev
Log:
This closes #209

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/gui/util/FileDialoger.java
    jmeter/trunk/src/core/org/apache/jmeter/gui/util/FilePanel.java
    jmeter/trunk/src/core/org/apache/jmeter/gui/util/FilePanelEntry.java
    
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/util/FileDialoger.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/util/FileDialoger.java?rev=1761081&r1=1761080&r2=1761081&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/util/FileDialoger.java 
(original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/util/FileDialoger.java Fri Sep 
16 20:48:32 2016
@@ -45,7 +45,7 @@ public final class FileDialoger {
     }
 
     /**
-     * Prompts the user to choose a file from their filesystems for our own
+     * Prompts the user to choose a file or a directory from their filesystems 
for our own
      * devious uses. This method maintains the last directory the user visited
      * before dismissing the dialog. This does NOT imply they actually chose a
      * file from that directory, only that they closed the dialog there. It is
@@ -60,7 +60,7 @@ public final class FileDialoger {
     }
 
     /**
-     * Prompts the user to choose a file from their filesystems for our own
+     * Prompts the user to choose a file or a directory from their filesystems 
for our own
      * devious uses. This method maintains the last directory the user visited
      * before dismissing the dialog. This does NOT imply they actually chose a
      * file from that directory, only that they closed the dialog there. It is
@@ -78,7 +78,27 @@ public final class FileDialoger {
     }
     
     /**
-     * Prompts the user to choose a file from their filesystems for our own
+     * Prompts the user to choose a file or a directory from their filesystems 
for our own
+     * devious uses. This method maintains the last directory the user visited
+     * before dismissing the dialog. This does NOT imply they actually chose a
+     * file from that directory, only that they closed the dialog there. It is
+     * the caller's responsibility to check to see if the selected file is
+     * non-null.
+     * @param existingFileName The name of a file with path. If the filename 
points
+     *             to an existing file, the directory in which it lies, will 
be used
+     *             as the starting point for the returned JFileChooser.
+     * @param onlyDirectories If true, only directories are displayed in the 
FileChooser
+     *
+     * @return the JFileChooser that interacted with the user, after they are
+     *         finished using it - null if no file was chosen
+     */
+    public static JFileChooser promptToOpenFile(String existingFileName, 
boolean onlyDirectories) {
+        return promptToOpenFile(new String[0], existingFileName, 
onlyDirectories);
+    }
+    
+    
+    /**
+     * Prompts the user to choose a file or a directory from their filesystems 
for our own
      * devious uses. This method maintains the last directory the user visited
      * before dismissing the dialog. This does NOT imply they actually chose a
      * file from that directory, only that they closed the dialog there. It is
@@ -95,7 +115,7 @@ public final class FileDialoger {
     }
     
     /**
-     * Prompts the user to choose a file from their filesystems for our own
+     * Prompts the user to choose a file or a directory from their filesystems 
for our own
      * devious uses. This method maintains the last directory the user visited
      * before dismissing the dialog. This does NOT imply they actually chose a
      * file from that directory, only that they closed the dialog there. It is
@@ -111,38 +131,64 @@ public final class FileDialoger {
      *         finished using it - null if no file was chosen
      */
     public static JFileChooser promptToOpenFile(String[] exts, String 
existingFileName) {
-        if(!StringUtils.isEmpty(existingFileName)) {
-            File existingFileStart = new File(existingFileName);
-            if(existingFileStart.exists() && existingFileStart.canRead()) {
-                jfc.setCurrentDirectory(new File(existingFileName));
-            }
-        }
-        else if (lastJFCDirectory == null) {
-            String start = System.getProperty("user.dir", ""); 
//$NON-NLS-1$//$NON-NLS-2$
+        return promptToOpenFile(exts, null, false);
+    }
+  
+    /**
+    * Prompts the user to choose a file or a directory from their filesystems 
for our own
+    * devious uses. This method maintains the last directory the user visited
+    * before dismissing the dialog. This does NOT imply they actually chose a
+    * file from that directory, only that they closed the dialog there. It is
+    * the caller's responsibility to check to see if the selected file is
+    * non-null.
+    * @param exts The list of allowed file extensions. If empty, any
+    *             file extension is allowed
+    * @param existingFileName The name of a file with path. If the filename 
points
+    *             to an existing file, the directory in which it lies, will be 
used
+    *             as the starting point for the returned JFileChooser.
+     * @param onlyDirectories If true, only directories are displayed in the 
FileChooser
+    *
+    * @return the JFileChooser that interacted with the user, after they are
+    *         finished using it - null if no file was chosen
+    */
+   public static JFileChooser promptToOpenFile(String[] exts, String 
existingFileName, boolean onlyDirectories) {
+       if (onlyDirectories) {
+           jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+       } else {
+           jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
+       }
+       if(!StringUtils.isEmpty(existingFileName)) {
+           File existingFileStart = new File(existingFileName);
+           if(existingFileStart.exists() && existingFileStart.canRead()) {
+               jfc.setCurrentDirectory(new File(existingFileName));
+           }
+       }
+       else if (lastJFCDirectory == null) {
+           String start = System.getProperty("user.dir", ""); 
//$NON-NLS-1$//$NON-NLS-2$
 
-            if (start.length() > 0) {
-                jfc.setCurrentDirectory(new File(start));
-            }
-        }
-        clearFileFilters();
-        if(exts != null && exts.length > 0) {
-            JMeterFileFilter currentFilter = new JMeterFileFilter(exts);
-            jfc.addChoosableFileFilter(currentFilter);
-            jfc.setAcceptAllFileFilterUsed(true);
-            jfc.setFileFilter(currentFilter);
-        }
-        if(lastJFCDirectory==null) {
-            lastJFCDirectory = System.getProperty("user.dir", ""); 
//$NON-NLS-1$//$NON-NLS-2$
-        }
-        jfc.setCurrentDirectory(new File(lastJFCDirectory));
-        int retVal = 
jfc.showOpenDialog(GuiPackage.getInstance().getMainFrame());
-        lastJFCDirectory = jfc.getCurrentDirectory().getAbsolutePath();
+           if (start.length() > 0) {
+               jfc.setCurrentDirectory(new File(start));
+           }
+       }
+       clearFileFilters();
+       if(exts != null && exts.length > 0) {
+           JMeterFileFilter currentFilter = new JMeterFileFilter(exts);
+           jfc.addChoosableFileFilter(currentFilter);
+           jfc.setAcceptAllFileFilterUsed(true);
+           jfc.setFileFilter(currentFilter);
+       }
+       if(lastJFCDirectory==null) {
+           lastJFCDirectory = System.getProperty("user.dir", ""); 
//$NON-NLS-1$//$NON-NLS-2$
+       }
+       jfc.setCurrentDirectory(new File(lastJFCDirectory));
+       int retVal = 
jfc.showOpenDialog(GuiPackage.getInstance().getMainFrame());
+       lastJFCDirectory = jfc.getCurrentDirectory().getAbsolutePath();
 
-        if (retVal == JFileChooser.APPROVE_OPTION) {
-            return jfc;
-        }
-        return null;
-    }
+       if (retVal == JFileChooser.APPROVE_OPTION) {
+           return jfc;
+       }
+       return null;
+   }
 
     private static void clearFileFilters() {
         FileFilter[] filters = jfc.getChoosableFileFilters();

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/util/FilePanel.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/util/FilePanel.java?rev=1761081&r1=1761080&r2=1761081&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/util/FilePanel.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/util/FilePanel.java Fri Sep 16 
20:48:32 2016
@@ -35,19 +35,31 @@ public class FilePanel extends FilePanel
     public FilePanel(String title) {
         this(title, (String) null);
     }
+    
+    public FilePanel(String title, boolean onlyDirectories) {
+        this(title, (String) null, onlyDirectories);
+    }
 
     public FilePanel(String title, String filetype) {
-        super(JMeterUtils.getResString("file_visualizer_filename"), filetype); 
// $NON-NLS-1$
+        this(title, (String) null, false);
+    }
+    
+    public FilePanel(String title, String filetype, boolean onlyDirectories) {
+        super(JMeterUtils.getResString("file_visualizer_filename"), 
onlyDirectories, filetype); // $NON-NLS-1$
         this.title = title;
         init();
     }
 
     public FilePanel(ChangeListener l, String title) {
-        super(JMeterUtils.getResString("file_visualizer_filename"), l); // 
$NON-NLS-1$
+        this(l,title, false);
+    }
+
+    public FilePanel(ChangeListener l, String title, boolean onlyDirectories) {
+        
super(JMeterUtils.getResString("file_visualizer_filename"),onlyDirectories, l); 
// $NON-NLS-1$
         this.title = title;
         init();
     }
-
+    
     public FilePanel(String resString, String[] exts) {
         super(JMeterUtils.getResString("file_visualizer_filename"), exts); // 
$NON-NLS-1$
         title = resString;

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/util/FilePanelEntry.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/util/FilePanelEntry.java?rev=1761081&r1=1761080&r2=1761081&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/util/FilePanelEntry.java 
(original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/util/FilePanelEntry.java Fri 
Sep 16 20:48:32 2016
@@ -52,6 +52,8 @@ public class FilePanelEntry extends Hori
     private final List<ChangeListener> listeners = new LinkedList<>();
 
     private final String[] filetypes;
+    
+    private boolean onlyDirectories = false;
 
     // Mainly needed for unit test Serialisable tests
     public FilePanelEntry() {
@@ -66,7 +68,15 @@ public class FilePanelEntry extends Hori
         this(label, (ChangeListener) null, exts);
     }
 
+    public FilePanelEntry(String label, boolean onlyDirectories, String ... 
exts) {
+        this(label, onlyDirectories, (ChangeListener) null, exts);
+    }
+
     public FilePanelEntry(String label, ChangeListener listener, String ... 
exts) {
+        this(label, false, (ChangeListener) null, exts);
+    }
+    
+    public FilePanelEntry(String label, boolean onlyDirectories, 
ChangeListener listener, String ... exts) {
         this.label = new JLabel(label);
         if (listener != null) {
             listeners.add(listener);
@@ -79,6 +89,7 @@ public class FilePanelEntry extends Hori
         } else {
             this.filetypes = null;
         }
+        this.onlyDirectories=onlyDirectories;
         init();
     }
 
@@ -141,9 +152,9 @@ public class FilePanelEntry extends Hori
         if (e.getActionCommand().equals(ACTION_BROWSE)) {
             JFileChooser chooser;
             if(filetypes == null || filetypes.length == 0){
-                chooser = FileDialoger.promptToOpenFile(filename.getText());
+                chooser = 
FileDialoger.promptToOpenFile(filename.getText(),onlyDirectories);
             } else {
-                chooser = FileDialoger.promptToOpenFile(filetypes, 
filename.getText());
+                chooser = FileDialoger.promptToOpenFile(filetypes, 
filename.getText(),onlyDirectories);
             }
             if (chooser != null && chooser.getSelectedFile() != null) {
                 filename.setText(chooser.getSelectedFile().getPath());

Modified: 
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java?rev=1761081&r1=1761080&r2=1761081&view=diff
==============================================================================
--- 
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java
 (original)
+++ 
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java
 Fri Sep 16 20:48:32 2016
@@ -102,7 +102,7 @@ public class JMSPublisherGui extends Abs
 
     private final FilePanel messageFile = new 
FilePanel(JMeterUtils.getResString("jms_file")); //$NON-NLS-1$
 
-    private final FilePanel randomFile = new 
FilePanel(JMeterUtils.getResString("jms_random_file")); //$NON-NLS-1$
+    private final FilePanel randomFile = new 
FilePanel(JMeterUtils.getResString("jms_random_file"), true); //$NON-NLS-1$
 
     private final JSyntaxTextArea textMessage = 
JSyntaxTextArea.getInstance(10, 50); // $NON-NLS-1$
 


Reply via email to