|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.scijava.AbstractContextual
org.scijava.command.ContextCommand
public abstract class ContextCommand
A command that knows its context. Its service parameters are automatically
populated when AbstractContextual.setContext(org.scijava.Context)
is called, to make it easier to use via
Java API calls (i.e., without invoking it via CommandService.run(java.lang.String, boolean, java.lang.Object...)
).
This improves compile-time safety of downstream code that calls the command.
Here is an example command execution using CommandService.run(java.lang.String, boolean, java.lang.Object...)
:
Future<CommandModule<FindEdges>> future =<br/>
commandService.run(findEdges.class, "display", myDisplay);<br/>
CommandModule<FindEdges> module = future.get(); // block till complete<br/>
ImageDisplay outDisplay = (ImageDisplay) module.getOutput("display");
Note that FindEdges
also has two other inputs, an
ImageDisplayService
and an OverlayService
, which get
automatically populated when the application context is injected.
Here is the same command execution via direct Java calls:
FindEdges findEdges = new FindEdges();<br/>
findEdges.setContext(context); // populates service parameters<br/>
findEdges.setDisplay(myDisplay);<br/>
findEdges.run(); // execute on the same thread<br/>
ImageDisplay outDisplay = findEdges.getDisplay();
We believe the latter is more intuitive for most Java programmers, and so encourage commands to extend this class and provide API to use them directly.
That said, there are times when you cannot extend a particular class (usually
because you must extend a different class instead). In that case, you can
still implement the Command
interface and end up with a perfectly
serviceable command. The consequence is only that other Java programmers will
not be able to use the latter paradigm above to invoke your code in a fully
compile-time-safe way.
Constructor Summary | |
---|---|
ContextCommand()
|
Method Summary | |
---|---|
void |
cancel(String reason)
Cancels the command execution, with the given reason for doing so. |
String |
getCancelReason()
Gets a message describing why the operation was canceled. |
boolean |
isCanceled()
Gets whether the operation has been canceled. |
Methods inherited from class org.scijava.AbstractContextual |
---|
context, getContext, setContext |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.lang.Runnable |
---|
run |
Constructor Detail |
---|
public ContextCommand()
Method Detail |
---|
public boolean isCanceled()
Cancelable
isCanceled
in interface Cancelable
public void cancel(String reason)
cancel
in interface Cancelable
reason
- A message describing why the operation is being canceled.public String getCancelReason()
Cancelable
getCancelReason
in interface Cancelable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |