77import java .util .Map .Entry ;
88import java .util .concurrent .ExecutionException ;
99import java .util .concurrent .Future ;
10+ import java .util .stream .Collectors ;
1011
1112import net .imagej .table .Column ;
1213import net .imagej .table .DefaultGenericTable ;
1516import org .scijava .ItemIO ;
1617import org .scijava .command .Command ;
1718import org .scijava .command .DynamicCommand ;
18- import org .scijava .convert .ConvertService ;
19- import org .scijava .log .LogService ;
19+ import org .scijava .log .Logger ;
2020import org .scijava .module .Module ;
2121import org .scijava .module .ModuleInfo ;
2222import org .scijava .module .ModuleItem ;
2929@ Plugin (type = Command .class , label = "Choose batch processing parameters" , initializer = "initInputChoice" )
3030public class ModuleBatchProcessor extends DynamicCommand {
3131 @ Parameter
32- private ModuleService modules ;
32+ private ModuleService moduleService ;
3333
3434 @ Parameter
35- private ConvertService convert ;
36-
35+ private BatchService batchService ;
36+
3737 @ Parameter
38- private LogService log ;
39-
38+ private Logger log ;
39+
4040 @ Parameter
4141 private ModuleInfo moduleInfo ; // to be provided at runtime!
42-
42+
4343 @ Parameter (label = "Which input parameter to batch?" , persist = false )
4444 private String inputChoice ;
4545
@@ -57,23 +57,15 @@ public class ModuleBatchProcessor extends DynamicCommand {
5757
5858 protected void initInputChoice () {
5959 MutableModuleItem <String > choiceInput = getInfo ().getMutableInput ("inputChoice" , String .class );
60- // get compatible inputs from module
61- ArrayList <String > compatibleInputs = new ArrayList <>();
62- for (ModuleItem <?> input : moduleInfo .inputs ()) {
63- // TODO consider replacing by isAssignableFrom
64- if (convert .supports (new File ("" ), input .getType ())) {
65- // if we can convert a File to the given input,
66- // add it to the list of compatible inputs
67- compatibleInputs .add (input .getName ());
68- }
69- }
70- // if only single input left, fill module input and resolve 'inputChoice'
60+ // Get compatible inputs for moduleInfo
61+ List <ModuleItem <?>> compatibleInputs = batchService
62+ .batchableInputs (moduleInfo );
7163 if (compatibleInputs .size () == 1 ) {
72- choiceInput .setValue (this , compatibleInputs .get (0 ));
64+ choiceInput .setValue (this , compatibleInputs .get (0 ). getName () );
7365 resolveInput ("inputChoice" );
74- }
75- else if (compatibleInputs .size () > 1 ) {
76- choiceInput . setChoices ( compatibleInputs );
66+ } else if ( compatibleInputs . size () > 1 ) {
67+ choiceInput . setChoices (compatibleInputs .stream ()
68+ . map ( ModuleItem :: getName ). collect ( Collectors . toList ()) );
7769 }
7870 }
7971
@@ -84,7 +76,7 @@ public void run() {
8476 // mark inputChoice as resolved, then harvest script parameters (i.e. run)
8577 ModuleItem <File > fileInput = moduleInfo .getInput (inputChoice , File .class );
8678 // TODO check if conversion needed?
87- Module scriptModule = modules .createModule (moduleInfo );
79+ Module scriptModule = moduleService .createModule (moduleInfo );
8880 scriptModule .resolveInput (inputChoice );
8981
9082 /* Create output Table and mark all outputs as resolved */
@@ -117,7 +109,7 @@ private boolean processFile(Module module, ModuleItem<File> fileInput, File file
117109 fileInput .setValue (module , file );
118110 outputTable .appendRow (file .getName ());
119111
120- Future <Module > instance = modules .run (module , true );
112+ Future <Module > instance = moduleService .run (module , true );
121113 try {
122114 // run the script
123115 Map <String , Object > outputs = instance .get ().getOutputs ();
0 commit comments