Search code examples
eclipseeclipse-pluginterminateeclipse-pdecancellation

Eclipse Plugin Cancel Completely


When in an eclipse plugin you implement Job and Override the run()-method, you can make changes to the parameter IProgressMonitor and skip tasks if the user pushed Cancel like this:

        if (!monitor.isCanceled()){
            monitor.subTask("Doing stuff");
            //do task
        } else {
            returnedStatus = Status.CANCEL_STATUS;
        }

But that means that at least the currently active task has to be finished before skipping the rest. Is there any way to completely abort the plugin activity and execute a finally block when the user pushes cancel, without waiting for the next if (!monitor.isCanceled()) and without subdividing your whole program into subTasks?


Solution

  • No. Your Job has to be the one to react to cancellation, so you need to either break the job up into tasks for which you can report progress with worked() and check cancellation, or you have to send around sub-progressmonitors and do the same thing.

    https://eclipse.org/articles/Article-Progress-Monitors/article.html