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

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

Introduction

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

Prototype

@Override
    public void setCanceled(boolean b) 

Source Link

Usage

From source file:org.eclipse.rcptt.tesla.ecl.impl.rap.Utils.java

License:Open Source License

private static IStatus doCloseDialogs() {
    SWTDialogManager.setCancelMessageBoxesDisplay(true);
    try {/* w w w  .j av  a2s .co  m*/
        final Display display = RWTUtils.findDisplay();

        IWorkbenchWindow[] windows = RWTUtils.getWorkbenchWindows();
        if (windows.length == 0) {
            return Status.OK_STATUS;// Do not close dialogs in case there is no
            // workbench.
        }
        // Dummy call for E4, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=440850
        //workbench.getActiveWorkbenchWindow();

        Set<Shell> windowShells = new HashSet<Shell>();
        for (IWorkbenchWindow window : windows) {
            Shell shell = window.getShell();
            if (shell != null) {
                windowShells.add(shell);
            }
        }
        // Close all shells for non workbench display
        //         Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces();
        //         for (Thread t : map.keySet()) {
        //            final Display dd = Display.findDisplay(t);
        //            if (dd != null && !dd.equals(display)) {
        //               t.interrupt();
        //            }
        //         }

        MultiStatus status = new MultiStatus(PLUGIN_ID, 0, "Failed to close dialogs", null);
        Shell[] shells = display.getShells();
        for (int i = shells.length - 1; i >= 0; i--) {
            Shell shell = shells[i];
            if (!windowShells.contains(shell) && !shell.isDisposed() && shell.isVisible()) {
                Object data = shell.getData();
                if (data != null && data instanceof WizardDialog) {
                    try {
                        WizardDialog dialog = (WizardDialog) data;
                        if (TeslaSWTAccess.getWizardDialogHasActiveOperations(dialog)) {
                            // try to cancel active operations
                            ProgressMonitorPart part = TeslaSWTAccess.getProgressMonitorPart(dialog);
                            if (part != null) {
                                part.setCanceled(true);
                                part.clearBlocked();
                            }
                        }
                        TeslaSWTAccess.setWizardDialogHasActiveOperations(dialog, 0);
                        dialog.close();
                        // try to cancel monitor if there is one
                    } catch (Throwable e) {
                        TeslaCore.log(e);
                    }
                } else {
                    shell.close();
                }
                if (!shell.isDisposed() && shell.isVisible())
                    status.add(new Status(IStatus.ERROR, PLUGIN_ID, shell.getText()));
            }
        }
        if (status.isOK())
            return Status.OK_STATUS;
        return status;
    } finally {
        SWTDialogManager.setCancelMessageBoxesDisplay(false);
    }
}

From source file:org.eclipse.rcptt.tesla.ecl.impl.Utils.java

License:Open Source License

private static IStatus doCloseDialogs() {
    SWTDialogManager.setCancelMessageBoxesDisplay(true);
    try {//  w ww.  ja v  a2  s  .  co  m
        final IWorkbench workbench = PlatformUI.getWorkbench();
        final Display display = workbench.getDisplay();

        // Dummy call for E4, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=440850
        workbench.getActiveWorkbenchWindow();

        IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
        Set<Shell> windowShells = new HashSet<Shell>();
        for (IWorkbenchWindow window : windows) {
            Shell shell = window.getShell();
            if (shell != null) {
                windowShells.add(shell);
            }
        }
        // Close all shells for non workbench display
        Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces();
        for (Thread t : map.keySet()) {
            final Display dd = Display.findDisplay(t);
            if (dd != null && !dd.equals(display)) {
                t.interrupt();
            }
        }

        MultiStatus status = new MultiStatus(PLUGIN_ID, 0, "Failed to close dialogs", null);
        Shell[] shells = display.getShells();
        for (int i = shells.length - 1; i >= 0; i--) {
            Shell shell = shells[i];
            if (!windowShells.contains(shell) && !shell.isDisposed() && shell.isVisible()) {
                Object data = shell.getData();
                if (data != null && data instanceof WizardDialog) {
                    try {
                        WizardDialog dialog = (WizardDialog) data;
                        if (TeslaSWTAccess.getWizardDialogHasActiveOperations(dialog)) {
                            // try to cancel active operations
                            ProgressMonitorPart part = TeslaSWTAccess.getProgressMonitorPart(dialog);
                            if (part != null) {
                                part.setCanceled(true);
                                part.clearBlocked();
                            }
                        }
                        TeslaSWTAccess.setWizardDialogHasActiveOperations(dialog, 0);
                        dialog.close();
                        // try to cancel monitor if there is one
                    } catch (Throwable e) {
                        TeslaCore.log(e);
                    }
                } else {
                    shell.close();
                }
                if (!shell.isDisposed() && shell.isVisible())
                    status.add(new Status(IStatus.ERROR, PLUGIN_ID, shell.getText()));
            }
        }
        if (status.isOK())
            return Status.OK_STATUS;
        return status;
    } finally {
        SWTDialogManager.setCancelMessageBoxesDisplay(false);
    }
}