Skip to content

Commit 1731a78

Browse files
imagejanctrueden
authored andcommitted
Improve multiple file input API
* Change the chooseFiles() method signature to support pre-selected files, a starting folder, and style attributes. * Add style constants to FileListWidget. Normally, we would deprecate the old method signatures for backwards compatibility, but since no scijava-common release has occurred since this API was introduced, we are free to change it. Signed-off-by: Curtis Rueden <ctrueden@wisc.edu>
1 parent e2601e2 commit 1731a78

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

src/main/java/org/scijava/ui/DefaultUIService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,15 @@ public File chooseFile(final File file, final String style) {
321321
}
322322

323323
@Override
324-
public File[] chooseFiles(File[] files, FileFilter filter) {
324+
public File[] chooseFiles(File parent, File[] files, FileFilter filter, String style) {
325325
final UserInterface ui = getDefaultUI();
326-
return ui == null ? null : ui.chooseFiles(files, filter);
326+
return ui == null ? null : ui.chooseFiles(parent, files, filter, style);
327327
}
328328

329329
@Override
330-
public List<File> chooseFiles(List<File> fileList, FileFilter filter) {
330+
public List<File> chooseFiles(File parent, List<File> fileList, FileFilter filter, String style) {
331331
final UserInterface ui = getDefaultUI();
332-
return ui == null ? null : ui.chooseFiles(fileList, filter);
332+
return ui == null ? null : ui.chooseFiles(parent, fileList, filter, style);
333333
}
334334

335335
@Override

src/main/java/org/scijava/ui/FileListPreprocessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ public void process(final Module module) {
5656
final File[] files = fileInput.getValue(module);
5757

5858
// show file chooser dialog box
59-
final File[] result = uiService.chooseFiles(files, null);
59+
// TODO decide how to create filter from style attributes
60+
// TODO retrieve parent folder??
61+
final File[] result = uiService.chooseFiles(null, files, null, fileInput.getWidgetStyle());
6062
if (result == null) {
6163
cancel("");
6264
return;

src/main/java/org/scijava/ui/UIService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ DialogPrompt.Result showDialog(String message, String title,
304304
* @param files The initial value displayed in the file chooser prompt.
305305
* @param filter A filter allowing to restrict the choice of files
306306
*/
307-
File[] chooseFiles(File[] files, FileFilter filter);
307+
File[] chooseFiles(File parent, File[] files, FileFilter filter, String style);
308308

309309
/**
310310
* Prompts the user to select one or multiple files.
@@ -315,7 +315,7 @@ DialogPrompt.Result showDialog(String message, String title,
315315
* @param fileList The initial value displayed in the file chooser prompt.
316316
* @param filter A filter allowing to restrict the choice of files
317317
*/
318-
List<File> chooseFiles(List<File> fileList, FileFilter filter);
318+
List<File> chooseFiles(File parent, List<File> fileList, FileFilter filter, String style);
319319

320320
/**
321321
* Displays a popup context menu for the given display at the specified

src/main/java/org/scijava/ui/UserInterface.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,26 +191,30 @@ default File chooseFile(String title, File file, String style) {
191191
/**
192192
* Prompts the user to choose a list of files.
193193
*
194+
* @param parent Parent folder for file selection
194195
* @param files The initial value displayed in the file chooser prompt.
195196
* @param filter A filter allowing to restrict file choice.
197+
* @param style File selection style (files, directories, or both) and optional filters
196198
* @return The selected {@link File}s chosen by the user, or null if the
197199
* user cancels the prompt.
198200
*/
199-
default File[] chooseFiles(File[] files, FileFilter filter) {
201+
default File[] chooseFiles(File parent, File[] files, FileFilter filter, String style) {
200202
throw new UnsupportedOperationException();
201203
}
202204

203205
/**
204206
* Prompts the user to choose a list of files.
205207
*
208+
* @param parent Parent folder for file selection
206209
* @param fileList The initial value displayed in the file chooser prompt.
207210
* @param filter A filter allowing to restrict file choice.
211+
* @param style File selection style (files, directories, or both) and optional filters
208212
* @return The selected {@link File}s chosen by the user, or null if the
209213
* user cancels the prompt.
210214
*/
211-
default List<File> chooseFiles(List<File> fileList, FileFilter filter) {
215+
default List<File> chooseFiles(File parent, List<File> fileList, FileFilter filter, String style) {
212216
final File[] initialFiles = fileList.toArray(new File[fileList.size()]);
213-
final File[] chosenFiles = chooseFiles(initialFiles, filter);
217+
final File[] chosenFiles = chooseFiles(parent, initialFiles, filter, style);
214218
return chosenFiles == null ? null : Arrays.asList(chosenFiles);
215219
}
216220

src/main/java/org/scijava/widget/FileListWidget.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,24 @@
3434
import java.io.File;
3535

3636
public interface FileListWidget<U> extends InputWidget<File[], U> {
37-
// NB: No changes to interface.
37+
/**
38+
* Widget style to allow file selection only
39+
*
40+
* @see org.scijava.plugin.Parameter#style()
41+
*/
42+
String FILES_ONLY = "files";
43+
44+
/**
45+
* Widget style to allow directory selection only
46+
*
47+
* @see org.scijava.plugin.Parameter#style()
48+
*/
49+
String DIRECTORIES_ONLY = "directories";
50+
51+
/**
52+
* Widget style to allow selection of both files and directories
53+
*
54+
* @see org.scijava.plugin.Parameter#style()
55+
*/
56+
String FILES_AND_DIRECTORIES = "both";
3857
}

0 commit comments

Comments
 (0)