/** * Runs task in Eclipse progress dialog. NOTE: this call can't be canceled if it will block in IO */ public static void runInProgressDialog(final DBRRunnableWithProgress runnable) throws InvocationTargetException { try { IRunnableContext runnableContext; IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); if (workbenchWindow != null) { runnableContext = new ProgressMonitorDialog(workbench.getActiveWorkbenchWindow().getShell()); } else { runnableContext = workbench.getProgressService(); } runnableContext.run( true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { runnable.run(RuntimeUtils.makeMonitor(monitor)); } }); } catch (InterruptedException e) { // do nothing } }
@NotNull public static IWorkbenchWindow getActiveWorkbenchWindow() { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { return window; } IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); if (windows.length > 0) { return windows[0]; } throw new IllegalStateException("No workbench window"); }
public static DBRRunnableContext getDefaultRunnableContext() { IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench != null && workbench.getActiveWorkbenchWindow() != null) { return new RunnableContextDelegate(workbench.getActiveWorkbenchWindow()); } else { return new DBRRunnableContext() { @Override public void run(boolean fork, boolean cancelable, DBRRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { runnable.run(VoidProgressMonitor.INSTANCE); } }; } }