-
Notifications
You must be signed in to change notification settings - Fork 11
Multiple file input #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Great progress, and sorry for the delay in my reply. I took a look. Here are the steps I took:
So all works well so far. But then, if you add Investigating now, but I may run out of time for the day; we'll see! 💨 |
One problem is caused by improper persistence of After adding |
@imagejan Here is a patch for scijava-ui-swing which fixes the issues you are having: diff --git a/src/main/java/org/scijava/ui/swing/widget/SwingFileListWidget.java b/src/main/java/org/scijava/ui/swing/widget/SwingFileListWidget.java
index 113d9ed..21592a3 100644
--- a/src/main/java/org/scijava/ui/swing/widget/SwingFileListWidget.java
+++ b/src/main/java/org/scijava/ui/swing/widget/SwingFileListWidget.java
@@ -92,6 +92,7 @@ public class SwingFileListWidget extends SwingInputWidget<File[]> implements
model.addElement(file);
}
paths.setModel(model);
+ updateModel();
}
// -- AbstractUIInputWidget methods ---
@@ -100,8 +101,10 @@ public class SwingFileListWidget extends SwingInputWidget<File[]> implements
protected void doRefresh() {
File[] files = (File[]) get().getValue();
DefaultListModel<File> model = new DefaultListModel<>();
- for (File file : files) {
- model.addElement(file);
+ if (files != null) {
+ for (File file : files) {
+ model.addElement(file);
+ }
}
paths.setModel(model);
} And here is a patch for scijava-common which fixes a bug if you cancel the file chooser dialog: diff --git a/src/main/java/org/scijava/module/DefaultModuleService.java b/src/main/java/org/scijava/module/DefaultModuleService.java
index f7a7f7a4..974e1845 100644
--- a/src/main/java/org/scijava/module/DefaultModuleService.java
+++ b/src/main/java/org/scijava/module/DefaultModuleService.java
@@ -296,6 +296,8 @@ public class DefaultModuleService extends AbstractService implements
return;
}
+ // FIXME: Convert to string, instead of just calling toString.
+ // Otherwise many things (e.g. File[]) are persisted improperly.
final String sValue = value == null ? "" : value.toString();
// do not persist if object cannot be converted back from a string
diff --git a/src/main/java/org/scijava/ui/UserInterface.java b/src/main/java/org/scijava/ui/UserInterface.java
index 9f298013..35329e32 100644
--- a/src/main/java/org/scijava/ui/UserInterface.java
+++ b/src/main/java/org/scijava/ui/UserInterface.java
@@ -192,8 +192,8 @@ public interface UserInterface extends RichPlugin, Disposable {
*
* @param files The initial value displayed in the file chooser prompt.
* @param filter A filter allowing to restrict file choice.
- * @return The selected {@link File}s chosen by the user, or null if prompt is not
- * available
+ * @return The selected {@link File}s chosen by the user, or null if user
+ * cancels the prompt.
*/
default File[] chooseFiles(File[] files, FileFilter filter) {
throw new UnsupportedOperationException();
@@ -204,12 +204,13 @@ public interface UserInterface extends RichPlugin, Disposable {
*
* @param fileList The initial value displayed in the file chooser prompt.
* @param filter A filter allowing to restrict file choice.
- * @return The selected {@link File}s chosen by the user, or null if prompt is not
- * available
+ * @return The selected {@link File}s chosen by the user, or null if user
+ * cancels the prompt. not available
*/
default List<File> chooseFiles(List<File> fileList, FileFilter filter) {
- File[] files = fileList.toArray(new File[fileList.size()]);
- return Arrays.asList(chooseFiles(files, filter));
+ final File[] initialFiles = fileList.toArray(new File[fileList.size()]);
+ final File[] chosenFiles = chooseFiles(initialFiles, filter);
+ return chosenFiles == null ? null : Arrays.asList(chosenFiles);
}
/** |
e4f598d
to
4a23ef1
Compare
Great, thanks a lot, @ctrueden! I pushed your diffs (after having some issues merging them into my workspace somehow) as separate commits to the respective branches (and therefore the associated PRs).
Alternatively, we could disable persisting for list and array values by changing the return value of // do not persist if object cannot be converted back from a string
if (!convertService.supports(sValue, item.getType())) return; (I actually wonder why it seems to support But of course, if we can make it properly persist lists of files and read them back, that would be more desirable. |
Note: now I'm getting the following exception when testing with a groovy script in Fiji:
Somehow |
Ping me again if you are still stuck on Monday, July 31, and I'll investigate some more. Unfortunately, I will not have time before that. In the meantime: good luck! |
391b0fc
to
754d52f
Compare
Running fine now. Tests are failing because of the |
This makes the following improvements: * Implement UserInterface#chooseFiles method, for multi-file selection. * Add SwingFileListWidget, to allow input harvesting for File[] inputs. * Add drag and drop functionality for Swing file widgets. These changes require scijava-common version 2.66.0.
f7e2e28
to
73281ec
Compare
After intense hacking with @imagejan, this branch is good to go! 👍 |
This PR depends on scijava/scijava-common#276.
It implements the
chooseFiles
method, adds a newSwingFileListWidget
, and adds drag-and-drop support to both the new widget andSwingFileWidget
.The current remaining issue is that the returned value is a
File
array of size one, with the file name being theString
representation of the desired file list.@ctrueden could you have a look at why this doesn't return an array of all files in the list? I couldn't figure out what's wrong...