[yocto] [PATCH] Fix Thread Access exception for systemtap Dialogs
Ioana Grigoropol
ioanax.grigoropol at intel.com
Fri May 31 05:07:46 PDT 2013
- when displaying MessageDialogs an error occurs due to illegal thread accessing GUI classes
- in order to fix this, a new DialogRunnable is used, that will use invoke synchronous to display the message dialog
[Yocto #4585]
Signed-off-by: Ioana Grigoropol <ioanax.grigoropol at intel.com>
---
.../src/org/yocto/remote/utils/DialogRunnable.java | 26 ++++++++++++++++++++
.../src/org/yocto/remote/utils/ShellSession.java | 13 ++++++----
2 files changed, 34 insertions(+), 5 deletions(-)
create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/DialogRunnable.java
diff --git a/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/DialogRunnable.java b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/DialogRunnable.java
new file mode 100644
index 0000000..5fbab76
--- /dev/null
+++ b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/DialogRunnable.java
@@ -0,0 +1,26 @@
+package org.yocto.remote.utils;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+
+public class DialogRunnable implements Runnable{
+ int type = 0;
+ boolean result;
+ public static final int QUESTION = 1;
+ public static final int ERROR = 2;
+ String title;
+ String message;
+
+ DialogRunnable(String title, String message, int type){
+ this.title = title;
+ this.message = message;
+ this.type = type;
+ }
+ @Override
+ public void run() {
+ if (type == QUESTION) {
+ result = MessageDialog.openQuestion(null, title, message);
+ } else if (type == ERROR) {
+ MessageDialog.openError(null, title, message);
+ }
+ }
+}
\ No newline at end of file
diff --git a/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ShellSession.java b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ShellSession.java
index 0f4097b..4ac8001 100644
--- a/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ShellSession.java
+++ b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ShellSession.java
@@ -22,7 +22,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Display;
public class ShellSession {
/**
@@ -242,7 +242,9 @@ public class ShellSession {
int keys = new Integer(m.group(1));
if (keys == 0) {
proc.destroy();
- accepted = MessageDialog.openQuestion(null, "Host authenticity", "The authenticity of host '" + host + "(" + host + ")' can't be established.\nAre you sure you want to continue connecting ?");
+ DialogRunnable runnable = new DialogRunnable("Host authenticity", "The authenticity of host '" + host + "(" + host + ")' can't be established.\nAre you sure you want to continue connecting ?", DialogRunnable.QUESTION);
+ Display.getDefault().syncExec(runnable);
+ accepted = runnable.result;
if (accepted){
proc = Runtime.getRuntime().exec("ssh -o StrictHostKeyChecking=no " + user + "@" + host);//add host key to known_hosts
try {
@@ -252,7 +254,7 @@ public class ShellSession {
}
proc.destroy();
} else {
- MessageDialog.openError(null, "Host authenticity", "Host key verification failed.");
+ Display.getDefault().syncExec( new DialogRunnable("Host authenticity", "Host key verification failed.", DialogRunnable.ERROR));
}
} else {
String errorMsg = "";
@@ -280,8 +282,9 @@ public class ShellSession {
buffer.delete(0, buffer.length());
}
}
- if (!accepted && !errorMsg.isEmpty())
- MessageDialog.openError(null, "Host authenticity", errorMsg);
+ if (!accepted && !errorMsg.isEmpty()) {
+ Display.getDefault().syncExec( new DialogRunnable("Host authenticity", errorMsg, DialogRunnable.ERROR));
+ }
}
loadKeysMatch = true;
break;
--
1.7.9.5
More information about the yocto
mailing list