Merge remote-tracking branch 'origin/master' into YaSp
[scilab.git] / scilab / modules / external_objects_java / src / java / org / scilab / modules / external_objects_java / ScilabJavaCompiler.java
index c5106aa..da636d2 100644 (file)
@@ -32,6 +32,7 @@ import java.util.Locale;
 import java.util.ServiceLoader;
 import java.util.logging.Level;
 
+import javax.swing.SwingUtilities;
 import javax.tools.Diagnostic;
 import javax.tools.DiagnosticCollector;
 import javax.tools.FileObject;
@@ -116,7 +117,29 @@ public class ScilabJavaCompiler {
      * @return an integer corresponding to the compiled and loaded class.
      */
     public static int compileCode(String className, String[] code) throws ScilabJavaException {
-        findCompiler();
+        if (SwingUtilities.isEventDispatchThread()) {
+            findCompiler();
+        } else {
+            try {
+                SwingUtilities.invokeAndWait(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            findCompiler();
+                        } catch (ScilabJavaException e) {
+                            // TODO Auto-generated catch block
+                            e.printStackTrace();
+                        }
+                    }
+                });
+            } catch (InvocationTargetException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            } catch (InterruptedException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
 
         DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
         StandardJavaFileManager stdFileManager = compiler.getStandardFileManager(null, Locale.getDefault(), null);