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.

See Also:
  • Constructor Details

    • 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:
      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 the int "|" operator) two or more of those SWT 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 instance
      style - the style of dialog to construct
      Throws:
      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 Details

    • getFileName

      public 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 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(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 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:
    • 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(File directory)
      Set the directory where the files should be uploaded to. If no directory is set or it is set to null a temporary directory is used.
      Parameters:
      directory - the directory to upload to
      Since:
      3.7
    • getUploadDirectory

      public File getUploadDirectory()
      Returns the directory where the files should be uploaded to, or null 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:
    • getUploadTimeLimit

      public long getUploadTimeLimit()
      Returns the maximum upload duration in milliseconds. The default value of -1 indicates no limit.
      Since:
      3.3
    • getExceptions

      public List<Exception> getExceptions()
      Returns a list with exceptions thrown during the file upload. Will never return null.
      Since:
      3.3
      See Also:
    • open

      public 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 class Dialog
    • createFileUpload

      protected FileUpload createFileUpload(Composite parent, String text)
    • createButton

      protected Button createButton(Composite parent, String text)