1 package com.proalpha.pds.ui;
4 import org.eclipse.core.resources.ResourcesPlugin;
5 import org.eclipse.core.runtime.jobs.ISchedulingRule;
6 import org.eclipse.jface.dialogs.MessageDialog;
7 import org.eclipse.jface.operation.IRunnableContext;
8 import org.eclipse.jface.operation.IRunnableWithProgress;
9 import org.eclipse.swt.widgets.Display;
10 import org.eclipse.ui.PlatformUI;
14 public static void runInProgressService(String taskName,
15 IRunnableWithProgress runnableWithProgress) {
18 PlatformUI.getWorkbench().getProgressService()
19 .busyCursorWhile(runnableWithProgress);
21 }
catch (Exception e) {
22 showAndLogError(taskName, e);
26 public static void runInUI(String taskName,
27 IRunnableWithProgress runnableWithProgress) {
30 ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot();
31 IRunnableContext context = PlatformUI.getWorkbench()
32 .getProgressService();
34 PlatformUI.getWorkbench().getProgressService()
35 .runInUI(context, runnableWithProgress, rule);
37 }
catch (Exception e) {
38 showAndLogError(taskName, e);
42 public static void runInNewThread(String taskName,
43 IRunnableWithProgress runnableWithProgress) {
46 PlatformUI.getWorkbench().getProgressService()
47 .run(Boolean.TRUE, Boolean.TRUE, runnableWithProgress);
49 }
catch (Exception e) {
50 showAndLogError(taskName, e);
54 private static void showAndLogError(String taskName, Exception e) {
55 String message = e.getMessage();
56 if (message ==
null || message.isEmpty()){
57 message = e.getCause().getMessage();
60 MessageDialog.openError(Display.getCurrent().getActiveShell(),