This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 171928 - FileChooserBuilder Enhancements
Summary: FileChooserBuilder Enhancements
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Filesystems (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 blocker (vote)
Assignee: _ tboudreau
URL:
Keywords: API, API_REVIEW_FAST
Depends on:
Blocks:
 
Reported: 2009-09-10 14:10 UTC by dasousa
Modified: 2010-08-02 21:30 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Patch to FileChooserBuilder to implement this enhancement (4.60 KB, patch)
2009-09-11 03:26 UTC, _ tboudreau
Details | Diff
Patch including apichanges, tests and spec version increment (10.01 KB, patch)
2009-09-16 20:37 UTC, _ tboudreau
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description dasousa 2009-09-10 14:10:30 UTC
It would be helpful to have 2 enhancements to the FileChooserBuilder:

1) Add the ability to have a message display if the user is about to overwrite a file when using a save dialog.
2) Provide the ability to add more than one FileFilter through a mechanism to use the 
JFileChooser.addChoosableFileFilter method.
Comment 1 _ tboudreau 2009-09-11 03:26:00 UTC
Created attachment 87475 [details]
Patch to FileChooserBuilder to implement this enhancement
Comment 2 _ tboudreau 2009-09-11 03:29:31 UTC
The attached patch is a compatible addition to FileChooserBuilder adding the following interface
public interface SelectionApprover {
  public boolean approve (File[] selection);
}

which is called by the resulting JFileChooser's approveSelection() method if set to non-null, and the following methods
  public FileChooserBuilder addFileFilter (FileFilter filter);
  public FileChooserBuilder setSelectionApprover (SelectionApprover approver);

to FileChooserBuilder.  Would like fast-track API review for this, as it is a compatible addition which cannot cause any
regression, and enhances the usefulness of FileChooserBuilder.


Comment 3 Jaroslav Tulach 2009-09-11 06:25:59 UTC
Y01 No versioning info (@since, version increment, apichanges)
Y02 No test.
Comment 4 _ tboudreau 2009-09-16 20:37:25 UTC
Created attachment 87798 [details]
Patch including apichanges, tests and spec version increment
Comment 5 _ tboudreau 2009-09-16 20:38:02 UTC
Attached patch addresses Y01 and Y02.  Any other objections?
Comment 6 _ tboudreau 2009-09-20 04:17:45 UTC
Fixed in core/main/ 25bf4adc5cb2
Comment 7 lkrylov 2010-08-02 21:30:20 UTC
SelectionApprover does not seem to work as designed in single selection mode. When file chooser is shown using showOpenDialog, the SelectionApprover callback does not get the file selected in the array. See test below.

This is because FileShooserBuilder#approveSelection() method does this:

 boolean approved = approver.approve(getSelectedFiles());

and getFilesSelected() only returns files in multiple selection mode.

Or is there an alternative way of approving file selection for single-selection choosers?

    @Test
    public void testFileApprover() {
        FileChooserBuilder chooser = new FileChooserBuilder("");
        chooser.setTitle("Test");
        chooser.setSelectionApprover(new FileChooserBuilder.SelectionApprover() {
            @Override
            public boolean approve(File[] files) {
                DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message("files to approve: " + files.length));
                return files.length > 0;
            }
        });
        chooser.showMultiOpenDialog(); // THIS WORKS
        chooser.showOpenDialog(); // THIS DOES NOT
    }