final CommandCompleteListener listener) {
ExceptionHelper.checkNotNullArgument(executor, "executor");
ExceptionHelper.checkNotNullArgument(taskDefFactory, "taskDefFactory");
ExceptionHelper.checkNotNullArgument(listener, "listener");
final CancellationSource cancel = Cancellation.createCancellationSource();
final String origDisplayName = taskDefFactory.getDisplayName();
final ReplaceableProgressHandle progress = new ReplaceableProgressHandle(cancel.getController());
final AtomicBoolean inProgress = new AtomicBoolean(false);
cancel.getToken().addCancellationListener(new Runnable() {
@Override
public void run() {
if (!inProgress.get()) {
progress.finish();
}
}
});
progress.start(origDisplayName);
executor.execute(cancel.getToken(), new CancelableTask() {
@Override
public void execute(CancellationToken cancelToken) throws Exception {
inProgress.set(true);
cancelToken.checkCanceled();