Class FileDialog
- java.lang.Object
-
- org.eclipse.swt.widgets.Dialog
-
- org.eclipse.swt.widgets.FileDialog
-
- All Implemented Interfaces:
Adaptable
public class FileDialog extends Dialog
Instances of this class allow the user to navigate the file system and select a file name. The selected file will be uploaded to the server and the path made available as the result of the dialog.- Styles:
- MULTI
- Events:
- (none)
The OPEN style is applied by default and setting any other styles has no effect.
IMPORTANT: This class is intended to be subclassed only within the SWT implementation.
-
-
Field Summary
-
Fields inherited from class org.eclipse.swt.widgets.Dialog
returnCode, shell
-
-
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 protected Button
createButton(Composite parent, java.lang.String text)
protected FileUpload
createFileUpload(Composite parent, java.lang.String text)
java.util.List<java.lang.Exception>
getExceptions()
Returns a list with exceptions thrown during the file upload.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.java.io.File
getUploadDirectory()
Returns the directory where the files should be uploaded to, ornull
when a temporary directory is used.long
getUploadSizeLimit()
Returns the maximum upload size in bytes.long
getUploadTimeLimit()
Returns the maximum upload duration in milliseconds.java.lang.String
open()
Makes the dialog visible and brings it to the front of the display.protected void
prepareOpen()
void
setClientFiles(ClientFile[] files)
Sets initial client files to be uploaded.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
setUploadDirectory(java.io.File directory)
Set the directory where the files should be uploaded to.void
setUploadSizeLimit(long limit)
Sets the maximum upload size in bytes.void
setUploadTimeLimit(long limit)
Sets the maximum upload duration in milliseconds.-
Methods inherited from class org.eclipse.swt.widgets.Dialog
checkOperationMode, checkSubclass, getAdapter, getParent, getStyle, getText, open, runEventLoop, setText
-
-
-
-
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
-
-
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
-
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.An extension filter string must be of the form ".extension".
- Parameters:
extensions
- the file extension filter- Since:
- 3.2
-
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
- Since:
- 3.2
-
setClientFiles
public void setClientFiles(ClientFile[] files)
Sets initial client files to be uploaded. The upload of these files will start immediately after opening the dialog. Hence, this method must be called before opening the dialog.A user can drag and drop files from the client operating system on any control with a drop listener attached. In this case, the client files can be obtained from the
ClientFileTransfer
object. This FileDialog can then be used to handle the upload and display upload progress.- Parameters:
files
- an array of client files to be added to the dialog- Since:
- 3.1
-
setUploadSizeLimit
public void setUploadSizeLimit(long limit)
Sets the maximum upload size in bytes. If upload size is bigger it will be interrupted. A value of -1 indicates no limit.- Parameters:
limit
- the maximum upload size in bytes- Since:
- 3.3
- See Also:
UploadSizeLimitExceededException
-
getUploadSizeLimit
public long getUploadSizeLimit()
Returns the maximum upload size in bytes. The default value of -1 indicates no limit.- Since:
- 3.3
-
setUploadDirectory
public void setUploadDirectory(java.io.File directory)
Set the directory where the files should be uploaded to. If no directory is set or it is set tonull
a temporary directory is used.- Parameters:
directory
- the directory to upload to- Since:
- 3.7
-
getUploadDirectory
public java.io.File getUploadDirectory()
Returns the directory where the files should be uploaded to, ornull
when a temporary directory is used.- Since:
- 3.7
-
setUploadTimeLimit
public void setUploadTimeLimit(long limit)
Sets the maximum upload duration in milliseconds. If upload takes longer it will be interrupted. The default value of -1 indicates no limit.- Parameters:
limit
- the maximum upload duration in milliseconds- Since:
- 3.3
- See Also:
UploadTimeLimitExceededException
-
getUploadTimeLimit
public long getUploadTimeLimit()
Returns the maximum upload duration in milliseconds. The default value of -1 indicates no limit.- Since:
- 3.3
-
getExceptions
public java.util.List<java.lang.Exception> getExceptions()
Returns a list with exceptions thrown during the file upload. Will never return null.- Since:
- 3.3
- See Also:
UploadSizeLimitExceededException
,UploadTimeLimitExceededException
-
open
public java.lang.String open()
Makes the dialog visible and brings it to the front of the display.RAP Note: This method is not supported when running the application in JEE_COMPATIBILITY mode. Use
Dialog#open(DialogCallback)
instead.- 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
-
prepareOpen
protected void prepareOpen()
- Overrides:
prepareOpen
in classDialog
-
createFileUpload
protected FileUpload createFileUpload(Composite parent, java.lang.String text)
-
-