Re-enable a disabled cancel button in an Eclipse plug-in progress monitor?

513 views Asked by At

I've got a ProgressMonitorDialog in a plug-in with the cancel button enabled.

While the operation is running, If the user clicks the cancel button, I want to ask them if they are sure they want to cancel. I do this by checking the ProgressMonitorDialog.isCanceled() method.

To do this I use the MessageDialog openQuestion method. If they click Yes, then I throw an exception and cancel the operation.

If they click No, then I invoke the ProgressMonitorDialog.setCanceled(false) method and continue with the operation.

The problem I'm encounter is, once they click cancel, the button gets disabled and does not re-enable.

Is there a way to force the cancel button to re-enable so the user has an opportunity to cancel the request again?

This is roughly what my 'confirmCancel' method looks like now:

private void confirmCancel(IProgressMonitor monitor) {
    Display d = Display.getDefault();

    final MutableBoolean cancel = new MutableBoolean(false);

    d.syncExec(new Runnable() {

        @Override
        public void run() {
            cancel.setValue(MessageDialog.openQuestion(null, 
                    "Confirm Cancel", 
                    "Are you sure you want to cancel the download?"));
        }
    });

    if (cancel.booleanValue()) {
        logDebug("Download canceled in DownloadOperation");
        throw new OperationCanceledException("Copy canceled");
    } else {
        monitor.setCanceled(false);
        // this is where I would like to re-enable the cancel button
    }
}
1

There are 1 answers

1
David G On BEST ANSWER

As usual, the moment I post my question, I come up with an answer :)

I override the cancelPressed() method of ProgressMonitorDialog to display the question to the user and, if they say yes, I run the super.cancelPrssed() method.