|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| FileUtil.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* EJTools, the Enterprise Java Tools
|
|
| 3 |
*
|
|
| 4 |
* Distributable under LGPL license.
|
|
| 5 |
* See terms of license at www.gnu.org.
|
|
| 6 |
*/
|
|
| 7 |
package org.ejtools.adwt;
|
|
| 8 |
|
|
| 9 |
import java.io.File;
|
|
| 10 |
import java.net.URL;
|
|
| 11 |
import java.util.ResourceBundle;
|
|
| 12 |
|
|
| 13 |
import javax.swing.JFileChooser;
|
|
| 14 |
import javax.swing.filechooser.FileFilter;
|
|
| 15 |
|
|
| 16 |
import org.apache.log4j.Logger;
|
|
| 17 |
|
|
| 18 |
/**
|
|
| 19 |
* Description of the Class
|
|
| 20 |
*
|
|
| 21 |
* @author Laurent Etiemble
|
|
| 22 |
* @version $Revision: 1.1 $
|
|
| 23 |
* @todo Javadoc to complete
|
|
| 24 |
*/
|
|
| 25 |
public class FileUtil |
|
| 26 |
{
|
|
| 27 |
/** Description of the Field */
|
|
| 28 |
public static FileFilter WORKSPACE_FILE_FILTER = |
|
| 29 |
new FileFilter()
|
|
| 30 |
{
|
|
| 31 | 0 |
public boolean accept(File file) |
| 32 |
{
|
|
| 33 | 0 |
return file.getName().endsWith(".xml"); |
| 34 |
} |
|
| 35 |
|
|
| 36 |
|
|
| 37 | 0 |
public String getDescription()
|
| 38 |
{
|
|
| 39 | 0 |
return resources.getString("workspace.file.dialog.extension.description"); |
| 40 |
} |
|
| 41 |
}; |
|
| 42 |
/** Default logger */
|
|
| 43 |
private static Logger logger = Logger.getLogger(FileUtil.class); |
|
| 44 |
/** Bundle for I18N */
|
|
| 45 |
private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.adwt.Resources"); |
|
| 46 |
|
|
| 47 |
|
|
| 48 |
/**Constructor for the FileUtil object */
|
|
| 49 | 0 |
private FileUtil() { }
|
| 50 |
|
|
| 51 |
|
|
| 52 |
/**
|
|
| 53 |
* Description of the Method
|
|
| 54 |
*
|
|
| 55 |
* @param title Description of the Parameter
|
|
| 56 |
* @param type Description of the Parameter
|
|
| 57 |
* @return Description of the Return Value
|
|
| 58 |
* @exception Exception Description of the Exception
|
|
| 59 |
*/
|
|
| 60 | 0 |
public static URL selectWorkspaceFile(String title, int type) |
| 61 |
throws Exception
|
|
| 62 |
{
|
|
| 63 |
// Fix for JFileChooser/SecurityManager bug (#4264750)
|
|
| 64 | 0 |
SecurityManager s = System.getSecurityManager(); |
| 65 | 0 |
System.setSecurityManager(null);
|
| 66 |
|
|
| 67 |
// Choose file
|
|
| 68 | 0 |
JFileChooser chooser = new JFileChooser(System.getProperty("user.dir")); |
| 69 | 0 |
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); |
| 70 | 0 |
chooser.setDialogTitle(title); |
| 71 | 0 |
chooser.setDialogType(type); |
| 72 | 0 |
chooser.setFileFilter(WORKSPACE_FILE_FILTER); |
| 73 |
|
|
| 74 | 0 |
int returnVal = chooser.showDialog(null, title); |
| 75 | 0 |
System.setSecurityManager(s); |
| 76 | 0 |
if (returnVal != JFileChooser.APPROVE_OPTION)
|
| 77 |
{
|
|
| 78 | 0 |
return null; |
| 79 |
} |
|
| 80 |
|
|
| 81 | 0 |
return chooser.getSelectedFile().toURL();
|
| 82 |
} |
|
| 83 |
} |
|
| 84 |
|
|
||||||||||