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.
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.
Created attachment 87475 [details] Patch to FileChooserBuilder to implement this enhancement
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.
Y01 No versioning info (@since, version increment, apichanges) Y02 No test.
Created attachment 87798 [details] Patch including apichanges, tests and spec version increment
Attached patch addresses Y01 and Y02. Any other objections?
Fixed in core/main/ 25bf4adc5cb2
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 }