Example #1
0
 /**
  * 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
   }
 }
Example #2
0
 @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");
 }
Example #3
0
 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);
       }
     };
   }
 }
Example #4
0
 public static void runInUI(IRunnableContext context, final DBRRunnableWithProgress runnable) {
   try {
     PlatformUI.getWorkbench()
         .getProgressService()
         .runInUI(
             context,
             new IRunnableWithProgress() {
               @Override
               public void run(IProgressMonitor monitor)
                   throws InvocationTargetException, InterruptedException {
                 runnable.run(RuntimeUtils.makeMonitor(monitor));
               }
             },
             DBeaverActivator.getWorkspace().getRoot());
   } catch (InvocationTargetException e) {
     UIUtils.showErrorDialog(null, null, null, e.getTargetException());
   } catch (InterruptedException e) {
     // do nothing
   }
 }