public class CommandModule extends AbstractModule implements Cancelable, Contextual
Command
instance.
The Module
interface describes an encapsulated piece of functionality
with inputs and outputs.
Conceptually, a command is such a piece of functionality. However, the
Command
interface is intended to be as simple to implement as
possible; the only required method is Runnable.run()
, which is
inherited from Runnable
. The command's inputs and outputs are
indicated using @Parameter
annotations.
To bridge the gap, this class adapts a Command
instance into an
object that fully implements the Module
interface.
- An adapter class that bridges the gap between SciJava
commands and the rich {@link ModuleInfo} interface.
,
- The interface which provides many methods for interrogating an
encapsulated piece of functionality with inputs and outputs.
Constructor and Description |
---|
CommandModule(CommandInfo info)
Creates a command module for the given
PluginInfo . |
CommandModule(CommandInfo info,
Command command)
Creates a command module for the given
CommandInfo , around the
specified Command instance. |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancels the command, undoing the effects of any
preview() calls. |
void |
cancel(String reason)
Cancels the operation execution, with the given reason for doing so.
|
Context |
context()
Gets the application context to which the object belongs.
|
String |
getCancelReason()
Gets a message describing why the operation was canceled.
|
Command |
getCommand()
Gets the command instance handled by this module.
|
Context |
getContext()
Gets the application context to which the object belongs, or null if
Contextual.setContext(Context) has not yet been called on this object. |
Object |
getDelegateObject()
Gets the object containing the module's actual implementation.
|
CommandInfo |
getInfo()
Gets metadata about this module.
|
Object |
getInput(String name)
Gets the value of the input with the given name.
|
Object |
getOutput(String name)
Gets the value of the output with the given name.
|
boolean |
isCanceled()
Gets whether the operation has been canceled.
|
void |
preview()
Computes a preview of the command's results.
|
void |
run() |
void |
setContext(Context context)
Sets the application context to which the object belongs.
|
void |
setInput(String name,
Object value)
Sets the value of the input with the given name.
|
void |
setOutput(String name,
Object value)
Sets the value of the output with the given name.
|
String |
toString() |
getInputs, getOutputs, initialize, isInputResolved, isOutputResolved, resolveInput, resolveOutput, setInputs, setOutputs, unresolveInput, unresolveOutput
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isResolved, setResolved
public CommandModule(CommandInfo info) throws ModuleException
PluginInfo
.ModuleException
public CommandModule(CommandInfo info, Command command)
CommandInfo
, around the
specified Command
instance.public Command getCommand()
public void preview()
Previewable
interface.preview
in interface Module
preview
in class AbstractModule
ModuleInfo.canPreview()
public void cancel()
preview()
calls.
For this method to do anything, the command must implement the
Previewable
interface.cancel
in interface Module
cancel
in class AbstractModule
ModuleInfo.canCancel()
public CommandInfo getInfo()
Module
public Object getDelegateObject()
Module
getInfo().getDelegateClassName()
. This object must possess all
callback methods specified by ModuleItem.getCallback()
.
The nature of this method is implementation-specific; e.g., a
CommandModule
will return its associated Command
. 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 return
this
.
getDelegateObject
in interface Module
getDelegateObject
in class AbstractModule
public Object getInput(String name)
Module
getInput
in interface Module
getInput
in class AbstractModule
public Object getOutput(String name)
Module
getOutput
in interface Module
getOutput
in class AbstractModule
public void setInput(String name, Object value)
Module
setInput
in interface Module
setInput
in class AbstractModule
public void setOutput(String name, Object value)
Module
setOutput
in interface Module
setOutput
in class AbstractModule
public boolean isCanceled()
Cancelable
isCanceled
in interface Cancelable
public void cancel(String reason)
Cancelable
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.
cancel
in interface Cancelable
reason
- A message describing why the operation is being canceled.public String getCancelReason()
Cancelable
getCancelReason
in interface Cancelable
public Context context()
Contextual
context
in interface Contextual
Contextual.getContext()
public Context getContext()
Contextual
Contextual.setContext(Context)
has not yet been called on this object.getContext
in interface Contextual
Contextual.context()
public void setContext(Context context)
Contextual
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 throw
IllegalStateException
if this method is invoked again.
setContext
in interface Contextual
Context.inject(Object)
Copyright © 2015–2022 SciJava. All rights reserved.