Coder Social home page Coder Social logo

oliver-loeffler / fxfilechooser Goto Github PK

View Code? Open in Web Editor NEW
41.0 41.0 6.0 2.74 MB

Custom JavaFX file chooser which allows quick manual filtering, which allows to add Path predicates as filter and which is testable using TestFX.

License: Apache License 2.0

Java 94.11% CSS 5.89%
chooser custom-javafx file filechooser javafx javafx-component listview swing-component

fxfilechooser's People

Contributors

oliver-loeffler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fxfilechooser's Issues

Lack of tests

Review project and add tests.

Items

  • See how the model can be simplified and compacted when tests are used.
  • Model must work without JavaFX running
  • Decouple file update service from model
  • Add TestFX to verify if GUI is working correctly.

JUnit and TestFX dependencies are leaking into runtime

When FXFileChooser is used in custom projects, then JUnit 4.12 and TestFX dependencies are leaking into the custom project class path. This causes issues especially with JUnit 5.

POM.xml requires following fix:

current:

		<dependency>
			<groupId>org.testfx</groupId>
			<artifactId>testfx-junit</artifactId>
			<version>4.0.12-alpha</version>
		</dependency>
		<dependency>
			<groupId>org.testfx</groupId>
			<artifactId>testfx-junit5</artifactId>
			<version>4.0.12-alpha</version>
		</dependency>

expected:

		<dependency>
			<groupId>org.testfx</groupId>
			<artifactId>testfx-junit</artifactId>
			<version>4.0.12-alpha</version>
                        <scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.testfx</groupId>
			<artifactId>testfx-junit5</artifactId>
			<version>4.0.12-alpha</version>
                        <scope>test</scope>
		</dependency>

API & functionality cleanup

Remove all non-core functionalities and APIs.
File chooser use cases shall be limited to:

  • Run FileChooser from JavaFX within a separate window
  • Run FileChooser from JavaFX within JavaFX dialog
  • Run FileChooser from Swing within a separate window

For the first, FileChooser shall use JavaFX standard components.

Make the demos concise, concentrate on the important stuff.

Make JavaFX FileChooser and DirectoryChooser acessible from Swing

Create adapters so that JavaFX DirectoryChooser and FileChooser classes can be used instead of JFileChooser. Ideally the appearing dialogs shall be modal. If modality cannot be achieved, at least there should be a mechanism which prevents multiple dialogs to be started concurrently.

Also it would be nice if instance would remain configurable through JavaFX API and if there would be a central factory to create the now various instances of file choosers.

[Bug] Double click in FxFileChooserDialog does not return selected file

Hi, first of all thank ou for this piece of software, it will be very useful for me :)

However, I think I found a small bug.
It occurs for me, running Ubuntu Linux 21.10 Impish (I don't know if that makes a difference anywhere).

How it normally works

When I use FXFileChooserDialog#showOpenDialog this way, it works:

  • select the file I want
  • close the dialog with the "OK" button
  • resullt: the file got chosen, it is returned as an Optional

What I think is broken

When I instead do this I get an empty optional as the result:

  • select the flie I want
  • double-click the file
  • resullt: an empty Optional gets returned
    image

I don't exactly know why this happens - I debugged a bit, and double-click handling in net.raumzeitfalle.fx.filechooser.FileChooserController#handleDoubleClickInFilesList definitely gets triggered.
Just javafx.scene.control.Dialog#getResult does not seem to get the result then.

Workaround

I can work around the issue by getting FXFileChooserDialog.model.getSelectedFile() using reflection:

     private Optional<Path> getSelectedFile(FXFileChooserDialog fileChooser) {
        Optional<Path> selectedFile = fileChooser.showOpenDialog(getWindow());
        if (selectedFile.isEmpty()) {
            // workaround for bug https://github.com/Oliver-Loeffler/FXFileChooser/issues/44
            try {
                Field modelField = FXFileChooserDialog.class.getDeclaredField("model");
                modelField.setAccessible(true);
                Object model = modelField.get(fileChooser);
                Method getSelectedFileMethod = model.getClass().getDeclaredMethod("getSelectedFile");
                getSelectedFileMethod.setAccessible(true);
                Path result = (Path) getSelectedFileMethod.invoke(model);
                return Optional.ofNullable(result);
            } catch (NoSuchFieldException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
                throw new RuntimeException(e);
            }
        }
        return selectedFile;
    }

(the model is working, as verified by a test case)

  • Drawback:
    • With workaround in place, a file is selected even if the user clicks "Cancel" ๐Ÿ˜ž
    • A breakpoint in net.raumzeitfalle.fx.filechooser.FileChooserController#cancelAction gets no hits, I would have expected that code to prevent this
      • it seems usually the result converter defined in net.raumzeitfalle.fx.filechooser.FXFileChooserDialog#FXFileChooserDialog does the work to get things to the result, but it does not get called in case of the double click:
            setResultConverter(dialogButton -> {
                if (dialogButton  == okay) {
                    this.hide();
                    return model.getSelectedFile();
                }
                return null;
            });
        

More context

So far, I'm using FxFileChooserDialog in a playground project only. Find the latest code here as part of this PR:
https://github.com/ArchibaldBienetre/javaFxTestGradle/pull/1/files

Make locations configurable

Providing users default location might be helpful in some cases, or even as a fallback when the actual location is not reachable.

Some use cases are limited to one specific or require other specific locations.
Similar to path filter, in interface is desirable to configure or provide other special locations.

Another point is, in case or remote locations which require credentials, an automated logon would be helpful.

FXFileChooser shall show latest selected directory in window title

When FXFileChooser is opened in a dialog, the dialog shows the current searched directory.
The stage-version does not show the directory which has been selected.

The stage-version shall show the selected directory in the stage window title, so the user always knows where the file chooser is currently located in.

Add wild card support for live filtering

There was a request to use wild cards for file name filtering.

Wild cards asked for

  • '%' and '*' both indicate any string
  • ? should indicate any character or number
  • a wild card before and after the filter term basically should map to 'contains'
  • a trailing wild card should map to 'startsWith'
  • a leading wild card should map to 'endsWith'
  • Wild card filtering should be case insensitive

Wild card support shall be implemented guided by tests.

Cleanup JAR artifact contents

Beside classes, fxml and css, the jar also contains the icons.
But there are also the Fireworks PNG templates which do not belong into the artifact.

Update build file accordingly to exclude unwanted content.

Permit pasting of paths from clipboard

One strong feature of system file choosers is, that they allow to paste full paths from clipboard into the dialog and to continue with the pasted path.

  • The dialog then should indicate, if the pasted path is incorrect or does not exists.
  • If the pasted path is just a directory, the dialog should change the directory location.
  • If the pasted path is a file, the dialog should also change to the directory location.

Allow FXFileChooser to reuse an existing observable list of paths (or files)

In certain environments (with folders of 100 000s of files) it might be helpful to run a scheduled task to keep the list of files updated. Therefore it might be useful to have FXFileChooser to work with an externally populated observable list.

Furthermore, provide a scheduled Update service which can be used in Swing and JavaFX applications.

Idea

  • Decouple the directory update service from FXFileChooser
  • Make FXFileChooser to use this service

Questions

  • How to deal with manual refreshing? Hide it and rely only on scheduled refreshes?

Exclude demo code from build artifact

With the existing setup the demo code is part of the build artifact which is published to Maven Central.
The demos are not supposed to be part of the final JAR hence the POM requires an update to exclude the demos.

Testing of change location functionality

It turned out, that the change location (or change directory) functionality implemented is hard to test.
Therefore a rework is needed.

Points which turned out problematic:

  • PathSupplier is actually a path consumer - need to rethink the idea here
  • The SplitMenuButton seems to hard to reach with TestFX - found no way yet to interact with the button or the menu.

Improve visibility of some GUI elements (scrollbar, filter field)

There were complaints about the vertical scrollbar, which is too small.
CSS shall be updated in order to make the scrollbar more appearant.

Also the filter field can be improved. The filter symbol shall be replaced with a loupe. A button to clear the text field shall be added as well (clear by clicking [x]).

Rework mechanism how PathFilters are added.

PathFilter construction is clumsy. Also initialization of model with custom path filters is no partially done in controller class.
Rethink concept and rework classes accordingly.

Sorting by time is quite slow and blocks the UI

Implement sorting by lastModified date in a way that the UI does not block and the user gets a fast response from UI. Adding a progress indicator (e.g. like provided by ControlsFX) might improve the user experience.

Reduce memory consumption for large folders

With directories containing 100.000s of files memory consumption can be an issue.
For ~ 330.000 files on Windows 10 the FileChooserModel requires ~ 80 MiB of memory.
On macOS Monterey its ~ 40 Mib for 244.000 files.

As the FileChooser is used on systems where 300.000 files to 900.000 files are listed, reduced memory consumption should help to improve overall application performance.

Prepare POM.xml to be ready for JavaFX 11 and JavaFX 8 (multi-release jar)

The current build of SwingFileChooser does not integrate properly with JavaFX 11 projects when gradle is used and JavaFX 11 is linked into as a dependency.

Prepare FXFileChooser accordingly and provide example of plain JavaFX 11 app using the file chooser and running with a gradle wrapper build.

Rework FileChooserView internal structure

As FileChooserView only provides static factory methods, it cannot be used as an actual view.
Redesign of this class is needed in order to reduce amount of code needed for view construction and in order to have a single place where the FXML is loaded and a suitable Pane (StackPane or AnchorPane) is created.

This somehow should also solve the problem in SwingFileChooser to properly pass in a DirectoryChooser which works modal compared to any underlying Swing Window.

Make functionality to change directory in FXFileChooser configurable

FXFileChooser allows to change directory in different ways:

  • locations menu always shows the user data folder
  • locations menu may provide navigation linkts to other pre-defined locations
  • opening a directory chooser using the button or menu
  • manually pasting a valid directory into the search bar

There may be cases, where opening either all of these options or a subset is not permitted.
So ideally there should be a standard case and each of these options should be configurable programmatically.

Progress Indicator needed for sorting of huge lists of paths

In case of large folders, sorting may require a certain amount of time.
ListView shall be hidden by a progress indicator (indeterminate). All other function shall remain intact - consider implementation of sorting as a service so that cancellation is possible.

Rework dark theme

Instead of rounded black theme, following style might be worth a try:

Scrollbar styling:
ScrollBarStyling

Border decoration:
WindowBorderDecoration

Window decoration:
WindowDecoration

SwingDemo not working as expected

The SwingDemo seems to block or crash after initial start on Windows 8.1.

Steps to reproduce:

  • Launch net.raumzeitfalle.fx.SwingDemo
  • click on "show SwingFileChooser"
  • click on "Choose Directory"

The, the file chooser can be closed but the demo itself seems to be blocked.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.