Class FWFileChooserFormComponent

All Implemented Interfaces:
ActionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, net.simplace.core.FWBusyIndicator, net.simplace.core.FWObserver

public class FWFileChooserFormComponent extends FWAbstractFormComponent implements ActionListener
Form component that displays a standard dialog to let the user select a file or directory. Multiple selection of files is possible with the attribute multiselect. Use a <file> tag in the XML configuration of the enclosing form to make this component select files or use a <dir> tag to make it select directories.

The component reckognizes the following parameters in its XML configuration:

Required:

id
id of the component, also the parameter key of its value

Optional:

enabled
Determines, if the value of the component can be changed. Possible values are expressions that evaluate to 0, 1, true or false. The default value is true.
default
An expression that evaluates to a file or directory name. If the component is configured for file selection, this sets the preselected file or the initial directory of the file selection dialog. If the component is configured for directory selection, this sets the preselected directory. Notice that this setting has no effect, if the components initial value is set using a FormFiller! If the component is configured for diectory selection and this parameter is not set, the initial directory will be set to the user's home directory.
required
Default: false.

If the component is used for file selection, the displayed file types can be limited by their extensions using <extension> child elements. Note however, that this does not limit the file types that can be selected! If specified for a directory chooser, these child elements are ignored.

An example configuration might look like this: <file id="mymodel.inputfile" required="true" enabled="true" default="data/myinputfile.dat"> <extension>dat</extension> <extension>txt</extension> </file>

Author:
Andreas Enders, ckunze
See Also:
  • Constructor Details

    • FWFileChooserFormComponent

      public FWFileChooserFormComponent(String aFormId, String aFieldId, boolean aShowBorder, org.jdom2.Element aParameters, net.simplace.core.FWObservable aObservabal, boolean aIsDirectoryChooser)
      Parameters:
      aFormId - id of the form the component is placed in
      aFieldId - id of the component, also the parameter key of its value
      aShowBorder - true to show a caption label
      aParameters - the form element (see class description)
      aObservabal - parameters of the functionality
      aIsDirectoryChooser - true to select directories, false for files
  • Method Details

    • getValue

      public String getValue()
      If used for file selection, returns the currently selected file or null if the current selection is a directory, does not exist or is not a valid file.

      If used for directory selection, returns the currently selected directory, the parent directory of the currently selected file or null if the current selection does not exist or is not a valid file or directory.

      Specified by:
      getValue in class FWAbstractFormComponent
      Returns:
      the selected file(s) (comma-separated) or directory; an empty string instead of null
    • setValue

      public void setValue(Object aValue)
      Constructs a File (for files: one per ,- or ;-separated entry, as returned by getValue(), unless the whole string is an existing file) from aValue and calls setValue(File) resp. setValue(File[]) with it. An empty value clears the selection.
      Specified by:
      setValue in class FWAbstractFormComponent
      Parameters:
      aValue - file or directory name(s)
    • setValue

      public void setValue(File aFile)
      Sets aFile as the current value, updates the text field and notifies dependent components. Accepted are existing files and, when selecting directories, any directory path (it may not exist yet, as for the default attribute); other values are rejected with a warning.
      Parameters:
      aFile - the file or directory, or null to clear the value
    • setValue

      public void setValue(File[] aFiles)
      Sets the selected files, updates the text field and notifies dependent components.
      Parameters:
      aFiles - the files
    • setEnabled

      public void setEnabled(boolean aNewState)
      Overrides:
      setEnabled in class JComponent
      Parameters:
      aNewState - true to enable text field and button
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      Displays a standard file/directory selection dialog (starting at the current value, the default or the last used folder) and saves the result.
      Specified by:
      actionPerformed in interface ActionListener
      Parameters:
      e - the button event
    • update

      public void update(net.simplace.core.FWObservable aObservable, Object aKeyOfParameterChanged)
      Description copied from class: FWAbstractFormComponent
      Reacts to a changed parameter: re-evaluates enabled and visible (a disabled or hidden component is reset to its default), resets the default value and re-runs the form filler, if the changed parameter is used in them. Changes of the component's own value are ignored.
      Specified by:
      update in interface net.simplace.core.FWObserver
      Overrides:
      update in class FWAbstractFormComponent
      Parameters:
      aObservable - the parameters
      aKeyOfParameterChanged - key of the changed parameter
    • processFormFiller

      public void processFormFiller()
      Takes the file name(s) from the form filler; the default attribute is then not applied. Note: this runs in the constructor of the base class, before the fields of this class are initialised.
      Specified by:
      processFormFiller in class FWAbstractFormComponent
    • getValueCell

      protected com.lowagie.text.Rectangle getValueCell(int aType)
      Description copied from class: FWAbstractFormComponent
      Returns the value cell used for generating the RTF, PDF or HTML version of the form.
      Specified by:
      getValueCell in class FWAbstractFormComponent
      Parameters:
      aType - output type, e.g. PrintHelper.TYPE_PDF
      Returns:
      an iText cell (PdfPCell for PDF, Cell otherwise)