3333
3434import org .scijava .Priority ;
3535import org .scijava .module .Module ;
36+ import org .scijava .module .ModuleCanceledException ;
3637import org .scijava .module .ModuleException ;
38+ import org .scijava .module .ModuleItem ;
3739
3840/**
3941 * An input harvester collects {@link Module} input values, according to the
@@ -62,7 +64,16 @@ public interface InputHarvester<P, W> {
6264 * @param module The module whose inputs should be harvest.
6365 * @throws ModuleException If the process goes wrong, or is canceled.
6466 */
65- void harvest (Module module ) throws ModuleException ;
67+ default void harvest (final Module module ) throws ModuleException {
68+ final InputPanel <P , W > inputPanel = createInputPanel ();
69+ buildPanel (inputPanel , module );
70+ if (!inputPanel .hasWidgets ()) return ; // no inputs left to harvest
71+
72+ final boolean ok = harvestInputs (inputPanel , module );
73+ if (!ok ) throw new ModuleCanceledException ();
74+
75+ processResults (inputPanel , module );
76+ }
6677
6778 /**
6879 * Constructs an empty {@link InputPanel}. Widgets are added later using the
@@ -89,7 +100,15 @@ void buildPanel(InputPanel<P, W> inputPanel, Module module)
89100 boolean harvestInputs (InputPanel <P , W > inputPanel , Module module );
90101
91102 /** Does any needed processing, after input values have been harvested. */
92- void processResults (InputPanel <P , W > inputPanel , Module module )
93- throws ModuleException ;
103+ @ SuppressWarnings ("unused" )
104+ default void processResults (final InputPanel <P , W > inputPanel ,
105+ final Module module ) throws ModuleException
106+ {
107+ final Iterable <ModuleItem <?>> inputs = module .getInfo ().inputs ();
94108
109+ for (final ModuleItem <?> item : inputs ) {
110+ final String name = item .getName ();
111+ module .resolveInput (name );
112+ }
113+ }
95114}
0 commit comments