All Implemented Interfaces:
InputControl<Path>, Styleable, EventTarget, Skinnable

public class FileInput extends CustomControl<HBox> implements InputControl<Path>
FileInput is a custom control for selecting files using a FileChooser dialog. It is composed of a TextField that contains the file path and a button that opens a FileChooser to select a file.

The control can operate in different modes: OPEN, SAVE, or DIRECTORY, as specified by the FileDialogMode.

The control also includes properties for error messages and validation status. These properties are updated based on the path selected by the user and the specified validation function.

  • Property Details

  • Constructor Details

    • FileInput

      public FileInput(FileDialogMode mode, boolean existingOnly, Supplier<Path> dflt, Collection<FileChooser.ExtensionFilter> filters, Function<Path,Optional<String>> validate)
      Constructs a FileInput instance with specified parameters.
      Parameters:
      mode - the mode of the file dialog, which can be OPEN, SAVE, or DIRECTORY
      existingOnly - boolean indicating whether only existing files or directories should be selectable
      dflt - a supplier providing the default path
      filters - collection of file extension filters to apply in the file chooser
      validate - a function to validate the selected file path, returning an optional error message
  • Method Details

    • defaultValidate

      public static Function<Path,Optional<String>> defaultValidate(FileDialogMode mode, boolean existingOnly)
      Returns a function object that validates the file selection based on the specified file dialog mode and whether only existing files or directories are allowed.

      The returned function object is for example used in InputBuilder.chooseFile(String, String, Supplier, FileDialogMode, boolean, Collection) to add validation.

      Parameters:
      mode - the mode of the file dialog; can be OPEN, SAVE, or DIRECTORY
      existingOnly - indicates whether only existing files or directories should be selectable
      Returns:
      a function that takes a Path and returns an Optional containing an error message if validation fails, or an empty Optional if validation succeeds
    • node

      public Node node()
      Description copied from interface: InputControl
      Get the Node for this input element.
      Specified by:
      node in interface InputControl<Path>
      Returns:
      the node
    • reset

      public void reset()
      Description copied from interface: InputControl
      Reset value to default
      Specified by:
      reset in interface InputControl<Path>
    • valueProperty

      public Property<Path> valueProperty()
      Description copied from interface: InputControl
      Provides the property representing the value of this input control.
      Specified by:
      valueProperty in interface InputControl<Path>
      Returns:
      the property containing the current value
    • validProperty

      public ReadOnlyBooleanProperty validProperty()
      Description copied from interface: InputControl
      Provides a read-only property representing the validity of the input.
      Specified by:
      validProperty in interface InputControl<Path>
      Returns:
      a ReadOnlyBooleanProperty that is true if the input is valid and false otherwise
    • errorProperty

      public ReadOnlyStringProperty errorProperty()
      Description copied from interface: InputControl
      Provides a read-only property representing the error message for this input control.

      This property contains an error message if the input is invalid, otherwise it is empty.

      Specified by:
      errorProperty in interface InputControl<Path>
      Returns:
      a ReadOnlyStringProperty containing the error message if there is a validation error, otherwise empty