7
7
import java .util .Map .Entry ;
8
8
import java .util .concurrent .ExecutionException ;
9
9
import java .util .concurrent .Future ;
10
+ import java .util .stream .Collectors ;
10
11
11
12
import net .imagej .table .Column ;
12
13
import net .imagej .table .DefaultGenericTable ;
15
16
import org .scijava .ItemIO ;
16
17
import org .scijava .command .Command ;
17
18
import org .scijava .command .DynamicCommand ;
18
- import org .scijava .convert .ConvertService ;
19
- import org .scijava .log .LogService ;
19
+ import org .scijava .log .Logger ;
20
20
import org .scijava .module .Module ;
21
21
import org .scijava .module .ModuleInfo ;
22
22
import org .scijava .module .ModuleItem ;
29
29
@ Plugin (type = Command .class , label = "Choose batch processing parameters" , initializer = "initInputChoice" )
30
30
public class ModuleBatchProcessor extends DynamicCommand {
31
31
@ Parameter
32
- private ModuleService modules ;
32
+ private ModuleService moduleService ;
33
33
34
34
@ Parameter
35
- private ConvertService convert ;
36
-
35
+ private BatchService batchService ;
36
+
37
37
@ Parameter
38
- private LogService log ;
39
-
38
+ private Logger log ;
39
+
40
40
@ Parameter
41
41
private ModuleInfo moduleInfo ; // to be provided at runtime!
42
-
42
+
43
43
@ Parameter (label = "Which input parameter to batch?" , persist = false )
44
44
private String inputChoice ;
45
45
@@ -57,23 +57,15 @@ public class ModuleBatchProcessor extends DynamicCommand {
57
57
58
58
protected void initInputChoice () {
59
59
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 );
71
63
if (compatibleInputs .size () == 1 ) {
72
- choiceInput .setValue (this , compatibleInputs .get (0 ));
64
+ choiceInput .setValue (this , compatibleInputs .get (0 ). getName () );
73
65
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 ()) );
77
69
}
78
70
}
79
71
@@ -84,7 +76,7 @@ public void run() {
84
76
// mark inputChoice as resolved, then harvest script parameters (i.e. run)
85
77
ModuleItem <File > fileInput = moduleInfo .getInput (inputChoice , File .class );
86
78
// TODO check if conversion needed?
87
- Module scriptModule = modules .createModule (moduleInfo );
79
+ Module scriptModule = moduleService .createModule (moduleInfo );
88
80
scriptModule .resolveInput (inputChoice );
89
81
90
82
/* Create output Table and mark all outputs as resolved */
@@ -117,7 +109,7 @@ private boolean processFile(Module module, ModuleItem<File> fileInput, File file
117
109
fileInput .setValue (module , file );
118
110
outputTable .appendRow (file .getName ());
119
111
120
- Future <Module > instance = modules .run (module , true );
112
+ Future <Module > instance = moduleService .run (module , true );
121
113
try {
122
114
// run the script
123
115
Map <String , Object > outputs = instance .get ().getOutputs ();
0 commit comments