Skip to content

Commit b80e7a0

Browse files
committed
Merge pull request #76 from scijava/non-cancelable-command
A Command need not be Cancelable...
2 parents a95801e + daf1407 commit b80e7a0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public class CommandModule extends AbstractModule implements Cancelable,
8686
@Parameter
8787
private Context context;
8888

89+
/** Reason for cancelation, or null if not canceled. */
90+
private String cancelReason;
91+
8992
/** Creates a command module for the given {@link PluginInfo}. */
9093
public CommandModule(final CommandInfo info) throws ModuleException {
9194
super();
@@ -202,19 +205,21 @@ public void run() {
202205

203206
@Override
204207
public boolean isCanceled() {
205-
if (!(command instanceof Cancelable)) return false;
206-
return ((Cancelable) command).isCanceled();
208+
return cancelReason != null;
207209
}
208210

209211
@Override
210212
public void cancel(final String reason) {
211-
((Cancelable) command).cancel(reason);
213+
cancelReason = reason == null ? "" : reason;
214+
if (command instanceof Cancelable) {
215+
// propagate cancelation to the command instance itself
216+
((Cancelable) command).cancel(reason);
217+
}
212218
}
213219

214220
@Override
215221
public String getCancelReason() {
216-
if (!(command instanceof Cancelable)) return null;
217-
return ((Cancelable) command).getCancelReason();
222+
return cancelReason;
218223
}
219224

220225
// -- Contextual methods --

0 commit comments

Comments
 (0)