Class CommandModule
- java.lang.Object
-
- org.scijava.module.AbstractModule
-
- org.scijava.command.CommandModule
-
- All Implemented Interfaces:
Runnable,Cancelable,Contextual,Module
public class CommandModule extends AbstractModule implements Cancelable, Contextual
Module adapter class for working with aCommandinstance.The
Moduleinterface describes an encapsulated piece of functionality with inputs and outputs.Conceptually, a command is such a piece of functionality. However, the
Commandinterface is intended to be as simple to implement as possible; the only required method isRunnable.run(), which is inherited fromRunnable. The command's inputs and outputs are indicated using @Parameterannotations.To bridge the gap, this class adapts a
Commandinstance into an object that fully implements theModuleinterface.- Author:
- Curtis Rueden, Johannes Schindelin, Grant Harris
- See Also:
- An adapter class that bridges the gap between SciJava commands and the rich interface.,- The interface which provides many methods for interrogating an encapsulated piece of functionality with inputs and outputs.
-
-
Constructor Summary
Constructors Constructor Description CommandModule(CommandInfo info)Creates a command module for the givenPluginInfo.CommandModule(CommandInfo info, Command command)Creates a command module for the givenCommandInfo, around the specifiedCommandinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Cancels the command, undoing the effects of anypreview()calls.voidcancel(String reason)Cancels the operation execution, with the given reason for doing so.Contextcontext()Gets the application context to which the object belongs.StringgetCancelReason()Gets a message describing why the operation was canceled.CommandgetCommand()Gets the command instance handled by this module.ContextgetContext()Gets the application context to which the object belongs, or null ifContextual.setContext(Context)has not yet been called on this object.ObjectgetDelegateObject()Gets the object containing the module's actual implementation.CommandInfogetInfo()Gets metadata about this module.ObjectgetInput(String name)Gets the value of the input with the given name.ObjectgetOutput(String name)Gets the value of the output with the given name.booleanisCanceled()Gets whether the operation has been canceled.voidpreview()Computes a preview of the command's results.voidrun()voidsetContext(Context context)Sets the application context to which the object belongs.voidsetInput(String name, Object value)Sets the value of the input with the given name.voidsetOutput(String name, Object value)Sets the value of the output with the given name.StringtoString()-
Methods inherited from class org.scijava.module.AbstractModule
getInputs, getOutputs, initialize, isInputResolved, isOutputResolved, resolveInput, resolveOutput, setInputs, setOutputs, unresolveInput, unresolveOutput
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.scijava.module.Module
isResolved, setResolved
-
-
-
-
Constructor Detail
-
CommandModule
public CommandModule(CommandInfo info) throws ModuleException
Creates a command module for the givenPluginInfo.- Throws:
ModuleException
-
CommandModule
public CommandModule(CommandInfo info, Command command)
Creates a command module for the givenCommandInfo, around the specifiedCommandinstance.
-
-
Method Detail
-
getCommand
public Command getCommand()
Gets the command instance handled by this module.
-
preview
public void preview()
Computes a preview of the command's results. For this method to do anything, the command must implement thePreviewableinterface.- Specified by:
previewin interfaceModule- Overrides:
previewin classAbstractModule- See Also:
ModuleInfo.canPreview()
-
cancel
public void cancel()
Cancels the command, undoing the effects of anypreview()calls. For this method to do anything, the command must implement thePreviewableinterface.- Specified by:
cancelin interfaceModule- Overrides:
cancelin classAbstractModule- See Also:
ModuleInfo.canCancel()
-
getInfo
public CommandInfo getInfo()
Description copied from interface:ModuleGets metadata about this module.
-
getDelegateObject
public Object getDelegateObject()
Description copied from interface:ModuleGets the object containing the module's actual implementation. By definition, this is an object whose fully qualified class name is given bygetInfo().getDelegateClassName(). This object must possess all callback methods specified byModuleItem.getCallback().The nature of this method is implementation-specific; e.g., a
CommandModulewill return its associatedCommand. For modules that are not plugins, the result may be something else. If you are implementing this interface directly, a good rule of thumb is to returnthis.- Specified by:
getDelegateObjectin interfaceModule- Overrides:
getDelegateObjectin classAbstractModule
-
getInput
public Object getInput(String name)
Description copied from interface:ModuleGets the value of the input with the given name.- Specified by:
getInputin interfaceModule- Overrides:
getInputin classAbstractModule
-
getOutput
public Object getOutput(String name)
Description copied from interface:ModuleGets the value of the output with the given name.- Specified by:
getOutputin interfaceModule- Overrides:
getOutputin classAbstractModule
-
setInput
public void setInput(String name, Object value)
Description copied from interface:ModuleSets the value of the input with the given name.- Specified by:
setInputin interfaceModule- Overrides:
setInputin classAbstractModule
-
setOutput
public void setOutput(String name, Object value)
Description copied from interface:ModuleSets the value of the output with the given name.- Specified by:
setOutputin interfaceModule- Overrides:
setOutputin classAbstractModule
-
isCanceled
public boolean isCanceled()
Description copied from interface:CancelableGets whether the operation has been canceled.- Specified by:
isCanceledin interfaceCancelable
-
cancel
public void cancel(String reason)
Description copied from interface:CancelableCancels the operation execution, with the given reason for doing so.This method merely sets the operation status to canceled; it cannot necessarily stop the operation itself. That is, it is the responsibility of each individual operation to check
Cancelable.isCanceled()in a timely manner during execution, and stop doing whatever it is doing if the flag has been tripped.- Specified by:
cancelin interfaceCancelable- Parameters:
reason- A message describing why the operation is being canceled.
-
getCancelReason
public String getCancelReason()
Description copied from interface:CancelableGets a message describing why the operation was canceled.- Specified by:
getCancelReasonin interfaceCancelable- Returns:
- The reason for cancelation, which may be null if no reason was given, or if the operation was not in fact canceled.
-
context
public Context context()
Description copied from interface:ContextualGets the application context to which the object belongs.- Specified by:
contextin interfaceContextual- See Also:
Contextual.getContext()
-
getContext
public Context getContext()
Description copied from interface:ContextualGets the application context to which the object belongs, or null ifContextual.setContext(Context)has not yet been called on this object.- Specified by:
getContextin interfaceContextual- See Also:
Contextual.context()
-
setContext
public void setContext(Context context)
Description copied from interface:ContextualSets the application context to which the object belongs.Typically this method simply delegates to
Context.inject(Object), and should be called only once to populate the context. Most contextual objects do not support later alteration of the context, and will throwIllegalStateExceptionif this method is invoked again.- Specified by:
setContextin interfaceContextual- See Also:
Context.inject(Object)
-
-