Skip to content

Commit 7d03b51

Browse files
committed
DynamicCommand: add method to persist input values
See: https://forum.image.sc/t/how-to-save-interactivecommand-parameter-values/26645/5
1 parent 72ce14a commit 7d03b51

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/main/java/org/scijava/command/DynamicCommand.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
import org.scijava.Contextual;
4040
import org.scijava.NullContextException;
4141
import org.scijava.module.DefaultMutableModule;
42+
import org.scijava.module.process.PreprocessorPlugin;
43+
import org.scijava.module.process.SaveInputsPreprocessor;
4244
import org.scijava.plugin.Parameter;
45+
import org.scijava.plugin.PluginInfo;
46+
import org.scijava.plugin.PluginService;
4347
import 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

Comments
 (0)