JFileChooser file filters bug

Discuss here any questions about the WebLaF library.
Bugs can be posted directly to GitHub issues tracker.

JFileChooser file filters bug

Postby invian-kmartimo » Fri Apr 24, 2015 2:07 pm

Hi,

We have a third party library (let's call it Foo) which does something similar to this when saving a file:

Code: Select all
JFileChooser chooser = new JFileChooser();

for (FooFileFilter f : saveFileFilters) {
    // f is a class that inherits FooFileFilter
    chooser.addChoosableFileFilter(f);
}

chooser.setFileFilter(saveFileFilters.get(0));

if (c.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
    FileFilter filter = chooser.getFileFilter();
    File file = chooser.getSelectedFile();

    if (filter instanceof FooFileFilter) {
        // the filter itself contains the logic for saving the data as the selected file format (!!!)
        filter.save(sourceData, file);
    } else {
        new FooDefaultFileFilter().save(sourceData, file);
    }
}


Now, this doesn't work for two reasons:

1) When selecting a filter from the file chooser dropdown, WebFileChooserPanel doesn't tell the underlying JFileChooser instance that the filter has been changed, so chooser.getFileFilter() always returns the first one

I fixed this by patching WebFileChooserPanel.setActiveFileFilter(AbstactFileFilter fileFilter, boolean select) to do fileChooser.setFileFilter(fileFilter) also, which fixed the problem.

However, this didn't fix the overall situation, because
2) WebFileChooserPanel converts all FileFilters it gets to com.alee.utils.CustomFileFilter instances and throws away the originals, so chooser.getFileFilter() returns CustomFileFilter instances which is not what the Foo library expects and the end result is that FooDefaultFileFilter is always called. I think baking the file-format specific saving logic in the filter itself is fairly dumb, but I wouldn't expect the filters to be transformed when put through JFileChooser either ;)
invian-kmartimo
 
Posts: 1
Joined: Mon Sep 22, 2014 5:02 pm

Re: JFileChooser file filters bug

Postby mgarin » Mon May 11, 2015 5:43 pm

Thanks for this feedback!
I am aware of this and a few other issues with current implementation of file chooser.

Unfortunately those issues are tied to current implementation and cannot be solved quickly. But I will be addressing those issues in next update and will add a lot of visual and functional changes and improvements to the file chooser itself. It will include proper listeners events and settings implementation from the base JFileChooser and some other minor improvements.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: JFileChooser file filters bug

Postby mgarin » Mon May 11, 2015 5:46 pm

I have added your issue into GitHub tracker to have it in sight: https://github.com/mgarin/weblaf/issues/278
You can also keep track of it if you have GitHub account.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg


Return to Questions

Who is online

Users browsing this forum: No registered users and 1 guest

cron