Class FileDialog
- java.lang.Object
-
- org.eclipse.swt.widgets.Dialog
-
- org.eclipse.swt.widgets.FileDialog
-
public class FileDialog extends Dialog
Instances of this class allow the user to navigate the file system and select or enter a file name.- Styles:
- SAVE, OPEN, MULTI
- Events:
- (none)
Note: Only one of the styles SAVE and OPEN may be specified.
IMPORTANT: This class is not intended to be subclassed.
-
-
Constructor Summary
Constructors Constructor Description FileDialog(Shell parent)
Constructs a new instance of this class given only its parent.FileDialog(Shell parent, int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getFileName()
Returns the path of the first file that was selected in the dialog relative to the filter path, or an empty string if no such file has been selected.java.lang.String[]
getFileNames()
Returns a (possibly empty) array with the paths of all files that were selected in the dialog relative to the filter path.java.lang.String[]
getFilterExtensions()
Returns the file extensions which the dialog will use to filter the files it shows.int
getFilterIndex()
Get the 0-based index of the file extension filter which was selected by the user, or -1 if no filter was selected.java.lang.String[]
getFilterNames()
Returns the names that describe the filter extensions which the dialog will use to filter the files it shows.java.lang.String
getFilterPath()
Returns the directory path that the dialog will use, or an empty string if this is not set.boolean
getOverwrite()
Returns the flag that the dialog will use to determine whether to prompt the user for file overwrite if the selected file already exists.java.lang.String
open()
Makes the dialog visible and brings it to the front of the display.void
setFileName(java.lang.String string)
Set the initial filename which the dialog will select by default when opened to the argument, which may be null.void
setFilterExtensions(java.lang.String[] extensions)
Set the file extensions which the dialog will use to filter the files it shows to the argument, which may be null.void
setFilterIndex(int index)
Set the 0-based index of the file extension filter which the dialog will use initially to filter the files it shows to the argument.void
setFilterNames(java.lang.String[] names)
Sets the names that describe the filter extensions which the dialog will use to filter the files it shows to the argument, which may be null.void
setFilterPath(java.lang.String string)
Sets the directory path that the dialog will use to the argument, which may be null.void
setOverwrite(boolean overwrite)
Sets the flag that the dialog will use to determine whether to prompt the user for file overwrite if the selected file already exists.
-
-
-
Constructor Detail
-
FileDialog
public FileDialog(Shell parent)
Constructs a new instance of this class given only its parent.- Parameters:
parent
- a shell which will be the parent of the new instance- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the parent is null
SWTException
-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
-
FileDialog
public FileDialog(Shell parent, int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.The style value is either one of the style constants defined in class
SWT
which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using theint
"|" operator) two or more of thoseSWT
style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.- Parameters:
parent
- a shell which will be the parent of the new instancestyle
- the style of dialog to construct- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the parent is null
SWTException
-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
- See Also:
SWT.SAVE
,SWT.OPEN
,SWT.MULTI
-
-
Method Detail
-
getFileName
public java.lang.String getFileName()
Returns the path of the first file that was selected in the dialog relative to the filter path, or an empty string if no such file has been selected.- Returns:
- the relative path of the file
-
getFileNames
public java.lang.String[] getFileNames()
Returns a (possibly empty) array with the paths of all files that were selected in the dialog relative to the filter path.- Returns:
- the relative paths of the files
-
getFilterExtensions
public java.lang.String[] getFilterExtensions()
Returns the file extensions which the dialog will use to filter the files it shows.- Returns:
- the file extensions filter
-
getFilterIndex
public int getFilterIndex()
Get the 0-based index of the file extension filter which was selected by the user, or -1 if no filter was selected.This is an index into the FilterExtensions array and the FilterNames array.
- Returns:
- index the file extension filter index
- Since:
- 3.4
- See Also:
getFilterExtensions()
,getFilterNames()
-
getFilterNames
public java.lang.String[] getFilterNames()
Returns the names that describe the filter extensions which the dialog will use to filter the files it shows.- Returns:
- the list of filter names
-
getFilterPath
public java.lang.String getFilterPath()
Returns the directory path that the dialog will use, or an empty string if this is not set. File names in this path will appear in the dialog, filtered according to the filter extensions.- Returns:
- the directory path string
- See Also:
setFilterExtensions(java.lang.String[])
-
getOverwrite
public boolean getOverwrite()
Returns the flag that the dialog will use to determine whether to prompt the user for file overwrite if the selected file already exists.- Returns:
- true if the dialog will prompt for file overwrite, false otherwise
- Since:
- 3.4
-
open
public java.lang.String open()
Makes the dialog visible and brings it to the front of the display.- Returns:
- a string describing the absolute path of the first selected file, or null if the dialog was cancelled or an error occurred
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the dialog has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog
-
setFileName
public void setFileName(java.lang.String string)
Set the initial filename which the dialog will select by default when opened to the argument, which may be null. The name will be prefixed with the filter path when one is supplied.- Parameters:
string
- the file name
-
setFilterExtensions
public void setFilterExtensions(java.lang.String[] extensions)
Set the file extensions which the dialog will use to filter the files it shows to the argument, which may be null.The strings are platform specific. For example, on some platforms, an extension filter string is typically of the form "*.extension", where "*.*" matches all files. For filters with multiple extensions, use semicolon as a separator, e.g. "*.jpg;*.png".
Note: On Mac, setting the file extension filter affects how app bundles are treated by the dialog. When a filter extension having the app extension (.app) is selected, bundles are treated as files. For all other extension filters, bundles are treated as directories. When no filter extension is set, bundles are treated as files.
- Parameters:
extensions
- the file extension filter- See Also:
to specify the user-friendly names corresponding to the extensions
-
setFilterIndex
public void setFilterIndex(int index)
Set the 0-based index of the file extension filter which the dialog will use initially to filter the files it shows to the argument.This is an index into the FilterExtensions array and the FilterNames array.
- Parameters:
index
- the file extension filter index- Since:
- 3.4
- See Also:
setFilterExtensions(java.lang.String[])
,setFilterNames(java.lang.String[])
-
setFilterNames
public void setFilterNames(java.lang.String[] names)
Sets the names that describe the filter extensions which the dialog will use to filter the files it shows to the argument, which may be null.Each name is a user-friendly short description shown for its corresponding filter. The
names
array must be the same length as theextensions
array.- Parameters:
names
- the list of filter names, or null for no filter names- See Also:
setFilterExtensions(java.lang.String[])
-
setFilterPath
public void setFilterPath(java.lang.String string)
Sets the directory path that the dialog will use to the argument, which may be null. File names in this path will appear in the dialog, filtered according to the filter extensions. If the string is null, then the operating system's default filter path will be used.Note that the path string is platform dependent. For convenience, either '/' or '\' can be used as a path separator.
- Parameters:
string
- the directory path- See Also:
setFilterExtensions(java.lang.String[])
-
setOverwrite
public void setOverwrite(boolean overwrite)
Sets the flag that the dialog will use to determine whether to prompt the user for file overwrite if the selected file already exists.Note: On some platforms where suppressing the overwrite prompt is not supported, the prompt is shown even when invoked with overwrite false.
- Parameters:
overwrite
- true if the dialog will prompt for file overwrite, false otherwise- Since:
- 3.4
-
-