44import java .util .HashMap ;
55
66import org .scijava .Priority ;
7+ import org .scijava .batch .input .BatchInput ;
8+ import org .scijava .batch .input .BatchInputProvider ;
79import org .scijava .command .CommandService ;
810import org .scijava .log .LogService ;
11+ import org .scijava .module .Module ;
912import org .scijava .module .ModuleInfo ;
13+ import org .scijava .module .ModuleItem ;
14+ import org .scijava .plugin .AbstractHandlerService ;
1015import org .scijava .plugin .Parameter ;
1116import org .scijava .plugin .Plugin ;
12- import org .scijava .service .AbstractService ;
1317import org .scijava .service .Service ;
1418
1519@ Plugin (type = Service .class , priority = Priority .LOW )
16- public final class FileBatchService extends AbstractService implements
17- BatchService {
20+ public final class FileBatchService extends AbstractHandlerService <BatchInput , BatchInputProvider <?>> implements BatchService {
1821
1922 @ Parameter
2023 private LogService log ;
21-
24+
2225 @ Parameter
2326 private CommandService commandService ;
2427
2528 /**
2629 * Returns true if {@code type} is a {@link File}.
2730 */
2831 @ Override
29- public boolean supports (Class <?> type ) {
30- return type .isAssignableFrom (File .class );
32+ public boolean supportsItem (ModuleItem <?> moduleItem ) {
33+ BatchInputProvider <?> handler = getHandler (new BatchInput (File .class , moduleItem ));
34+ if (handler == null ) {
35+ return false ;
36+ }
37+ return handler .canProvide (moduleItem );
38+ }
39+
40+ @ SuppressWarnings ("unchecked" )
41+ @ Override
42+ public <I > void fillInput (Module module , ModuleItem <?> moduleItem , I inputObject ) {
43+ BatchInputProvider <File > handler = (BatchInputProvider <File >) getHandler (new BatchInput (File .class , moduleItem ));
44+ if (handler == null ) {
45+ log .error ("No handler found for input: " + moduleItem .getName ());
46+ return ;
47+ }
48+ handler .populateInput (module , moduleItem , (File ) inputObject );
3149 }
3250
3351 @ Override
@@ -37,10 +55,30 @@ public void run(ModuleInfo moduleInfo) {
3755 log .error ("No compatible inputs (of type File) found." );
3856 return ;
3957 }
58+
59+ // 1) get input ModuleItems
60+ // 2) choose ModuleItem
61+ // 3) get suitable BatchInputProvider
62+ // 4) get Iterator for ModuleItem
63+
64+ //for (getHandler(new BatchInput(File.class, moduleItem)).iterate(fileList)) {
65+ //}
66+
4067 // Call ModuleBatchProcessor with input moduleInfo
4168 HashMap <String , Object > inputMap = new HashMap <>();
4269 inputMap .put ("moduleInfo" , moduleInfo );
4370 commandService .run (ModuleBatchProcessor .class , true , inputMap );
4471 }
4572
73+ @ SuppressWarnings ({ "unchecked" , "rawtypes" })
74+ @ Override
75+ public Class <BatchInputProvider <?>> getPluginType () {
76+ return (Class ) BatchInputProvider .class ;
77+ }
78+
79+ @ Override
80+ public Class <BatchInput > getType () {
81+ return BatchInput .class ;
82+ }
83+
4684}
0 commit comments