Example usage for org.eclipse.jface.wizard ProgressMonitorPart attachToCancelComponent

List of usage examples for org.eclipse.jface.wizard ProgressMonitorPart attachToCancelComponent

Introduction

In this page you can find the example usage for org.eclipse.jface.wizard ProgressMonitorPart attachToCancelComponent.

Prototype

public void attachToCancelComponent(Control cancelComponent) 

Source Link

Document

Attaches the progress monitor part to the given cancel component.

Usage

From source file:org.kalypso.contribs.eclipse.jface.wizard.WizardDialog2.java

License:Open Source License

/**
 * Executes the given runnable in this dialog (similar to
 * {@link org.eclipse.jface.operation.IRunnableContext#run(boolean, boolean, org.eclipse.jface.operation.IRunnableWithProgress)}
 * , but does NOT block the user interface while the operation is running.
 *///ww  w . j  ava 2s  .c  o  m
public IStatus executeUnblocked(final boolean cancelable, final boolean enablePageNavigation,
        final ICoreRunnableWithProgress runnable) {
    final ProgressMonitorPart progressMonitorPart = (ProgressMonitorPart) getProgressMonitor();
    final boolean needsProgressMonitor = getWizard().needsProgressMonitor();
    final Button cancelButton = getButton(IDialogConstants.CANCEL_ID);

    try {
        /* Disable buttons */
        enableButton(IDialogConstants.FINISH_ID, false);
        if (!cancelable)
            enableButton(IDialogConstants.CANCEL_ID, false);

        if (!enablePageNavigation) {
            enableButton(IDialogConstants.NEXT_ID, false);
            enableButton(IDialogConstants.BACK_ID, false);
        }

        if (needsProgressMonitor) {
            progressMonitorPart.attachToCancelComponent(cancelButton);
            progressMonitorPart.setVisible(true);
        }

        final ModalRunnableContext rc = new ModalRunnableContext(progressMonitorPart, getShell().getDisplay());
        return RunnableContextHelper.execute(rc, true, cancelable, runnable);
    } finally {
        // shell may be disposed, if dialog was canceled
        final Shell shell = getShell();
        if (shell != null && !shell.isDisposed()) {
            enableButton(IDialogConstants.CANCEL_ID, true);

            progressMonitorPart.setVisible(false);
            progressMonitorPart.removeFromCancelComponent(cancelButton);

            updateButtons();
        }
    }
}