3939import org .scijava .Contextual ;
4040import org .scijava .NullContextException ;
4141import org .scijava .module .DefaultMutableModule ;
42+ import org .scijava .module .process .PreprocessorPlugin ;
43+ import org .scijava .module .process .SaveInputsPreprocessor ;
4244import org .scijava .plugin .Parameter ;
45+ import org .scijava .plugin .PluginInfo ;
46+ import org .scijava .plugin .PluginService ;
4347import org .scijava .util .ClassUtils ;
4448
4549/**
@@ -60,6 +64,9 @@ public abstract class DynamicCommand extends DefaultMutableModule implements
6064 @ Parameter
6165 private CommandService commandService ;
6266
67+ @ Parameter
68+ private PluginService pluginService ;
69+
6370 private DynamicCommandInfo info ;
6471
6572 /** Reason for cancelation, or null if not canceled. */
@@ -144,4 +151,21 @@ public String getCancelReason() {
144151 public void uncancel () {
145152 cancelReason = null ;
146153 }
154+
155+ // -- Internal methods --
156+
157+ /**
158+ * Persists current input values. Use e.g. for {@link InteractiveCommand}s
159+ * that want to persist values as they change, since interactive commands do
160+ * not complete the module execution lifecycle normally.
161+ */
162+ protected void saveInputs () {
163+ // https://forum.image.sc/t/how-to-save-interactivecommand-parameter-values/26645/5
164+ final PluginInfo <PreprocessorPlugin > saveInputsPreprocessorInfo =
165+ pluginService .getPlugin (SaveInputsPreprocessor .class ,
166+ PreprocessorPlugin .class );
167+ final PreprocessorPlugin saveInputsPreprocessor = //
168+ pluginService .createInstance (saveInputsPreprocessorInfo );
169+ saveInputsPreprocessor .process (this );
170+ }
147171}
0 commit comments