Permalink
Browse files

Fix issues for menu handlers not in the right UIThread under Ubuntu

11.10
  • Loading branch information...
1 parent 3676ac8 commit aee0389e2008446f8b43907da200f32c9d8e57e0 @mickaelistria committed Nov 7, 2011
@@ -14,8 +14,9 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
/**
* Our sample handler extends AbstractHandler, an IHandler base class.
@@ -34,8 +35,12 @@ public SampleHandler() {
* the command has been executed, so extract extract the needed information from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
- MessageDialog.openInformation(window.getShell(), "Simple Dialog", "Hello, Eclipse world");
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ MessageDialog.openInformation(shell, "Simple Dialog", "Hello, Eclipse world");
+ }
+ });
return null;
}
}
@@ -15,8 +15,9 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
/**
* Our sample handler extends AbstractHandler, an IHandler base class.
@@ -34,9 +35,13 @@ public SampleParameterizedHandler() {
/**
* the command has been executed, so extract extract the needed information from the application context.
*/
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
- MessageDialog.openInformation(window.getShell(), "Simple Dialog", "My parameters:" + event.getParameters().toString());
+ public Object execute(final ExecutionEvent event) throws ExecutionException {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ MessageDialog.openInformation(shell, "Simple Dialog", "My parameters:" + event.getParameters().toString());
+ }
+ });
return null;
}
}

0 comments on commit aee0389

Please sign in to comment.