changeset 5290:9d2e2252eb11

RT-33258: Event locking when SWT-Shell opened via JavaFX Summary: The InvokeLaterDispatcher was disabled when running embedded with SWT Reviewed-by: ixmal, anthony
author snorthov
date Mon, 07 Oct 2013 14:30:43 -0400
parents 68546f1ae3cd
children 18781eb28d4e
files modules/graphics/src/main/java/com/sun/glass/ui/gtk/GtkApplication.java modules/graphics/src/main/java/com/sun/glass/ui/mac/MacApplication.java modules/graphics/src/main/java/com/sun/glass/ui/win/WinApplication.java
diffstat 3 files changed, 105 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/glass/ui/gtk/GtkApplication.java	Fri Oct 04 12:53:34 2013 -0400
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/gtk/GtkApplication.java	Mon Oct 07 14:30:43 2013 -0400
@@ -43,6 +43,7 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.Map;
+import java.util.concurrent.CountDownLatch;
 
 final class GtkApplication extends Application implements InvokeLaterDispatcher.InvokeLaterSubmitter {
 
@@ -62,8 +63,19 @@
     private final InvokeLaterDispatcher invokeLaterDispatcher;
 
     GtkApplication() {
-        invokeLaterDispatcher = new InvokeLaterDispatcher(this);
-        invokeLaterDispatcher.start();
+        boolean isEventThread = AccessController
+                .doPrivileged(new PrivilegedAction<Boolean>() {
+                    public Boolean run() {
+                        // Embedded in SWT, with shared event thread
+                        return Boolean.getBoolean("javafx.embed.isEventThread");
+                    }
+                });
+        if (!isEventThread) {
+            invokeLaterDispatcher = new InvokeLaterDispatcher(this);
+            invokeLaterDispatcher.start();
+        } else {
+            invokeLaterDispatcher = null;
+        }
     }
 
     private void initDisplay() {
@@ -164,8 +176,23 @@
     private native void _runLoop(Runnable launchable, boolean noErrorTrap);
 
     @Override
-    protected void _invokeAndWait(Runnable runnable) {
-        invokeLaterDispatcher.invokeAndWait(runnable);
+    protected void _invokeAndWait(final Runnable runnable) {
+        if (invokeLaterDispatcher != null) {
+            invokeLaterDispatcher.invokeAndWait(runnable);
+        } else {
+            CountDownLatch latch = new CountDownLatch(1);
+            submitForLaterInvocation(new Runnable() {
+                public void run() {
+                    if (runnable != null) runnable.run();
+                    latch.countDown();
+                }
+            });
+            try {
+                latch.await();
+            } catch (InterruptedException e) {
+                //FAIL SILENTLY
+            }
+        }
     }
 
     private native void _submitForLaterInvocation(Runnable r);
@@ -175,7 +202,11 @@
     }
 
     @Override protected void _invokeLater(Runnable runnable) {
-        invokeLaterDispatcher.invokeLater(runnable);
+        if (invokeLaterDispatcher != null) {
+            invokeLaterDispatcher.invokeLater(runnable);
+        } else {
+            submitForLaterInvocation(runnable);
+        }
     }
 
     private Object eventLoopExitEnterPassValue;
@@ -186,20 +217,26 @@
 
     @Override
     protected Object _enterNestedEventLoop() {
-        invokeLaterDispatcher.notifyEnteringNestedEventLoop();
+        if (invokeLaterDispatcher != null) {
+            invokeLaterDispatcher.notifyEnteringNestedEventLoop();
+        }
         try {
             enterNestedEventLoopImpl();
             final Object retValue = eventLoopExitEnterPassValue;
             eventLoopExitEnterPassValue = null;
             return retValue;
         } finally {
-            invokeLaterDispatcher.notifyLeftNestedEventLoop();
+            if (invokeLaterDispatcher != null) {
+                invokeLaterDispatcher.notifyLeftNestedEventLoop();
+            }
         }
     }
 
     @Override
     protected void _leaveNestedEventLoop(Object retValue) {
-        invokeLaterDispatcher.notifyLeavingNestedEventLoop();
+        if (invokeLaterDispatcher != null) {
+            invokeLaterDispatcher.notifyLeavingNestedEventLoop();
+        }
         eventLoopExitEnterPassValue = retValue;
         leaveNestedEventLoopImpl();
     }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/mac/MacApplication.java	Fri Oct 04 12:53:34 2013 -0400
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/mac/MacApplication.java	Mon Oct 07 14:30:43 2013 -0400
@@ -57,8 +57,19 @@
     private final InvokeLaterDispatcher invokeLaterDispatcher;
 
     MacApplication() {
-        invokeLaterDispatcher = new InvokeLaterDispatcher(this);
-        invokeLaterDispatcher.start();
+        boolean isEventThread = AccessController
+                .doPrivileged(new PrivilegedAction<Boolean>() {
+                    public Boolean run() {
+                        // Embedded in SWT, with shared event thread
+                        return Boolean.getBoolean("javafx.embed.isEventThread");
+                    }
+                });
+        if (!isEventThread) {
+            invokeLaterDispatcher = new InvokeLaterDispatcher(this);
+            invokeLaterDispatcher.start();
+        } else {
+            invokeLaterDispatcher = null;
+        }
     }
 
     private Menu appleMenu;
@@ -95,17 +106,23 @@
 
     native private Object _enterNestedEventLoopImpl();
     @Override protected Object _enterNestedEventLoop() {
-        invokeLaterDispatcher.notifyEnteringNestedEventLoop();
+        if (invokeLaterDispatcher != null) {
+            invokeLaterDispatcher.notifyEnteringNestedEventLoop();
+        }
         try {
             return _enterNestedEventLoopImpl();
         } finally {
-            invokeLaterDispatcher.notifyLeftNestedEventLoop();
+            if (invokeLaterDispatcher != null) {
+                invokeLaterDispatcher.notifyLeftNestedEventLoop();
+            }
         }
     }
 
     native private void _leaveNestedEventLoopImpl(Object retValue);
     @Override protected void _leaveNestedEventLoop(Object retValue) {
-        invokeLaterDispatcher.notifyLeavingNestedEventLoop();
+        if (invokeLaterDispatcher != null) {
+            invokeLaterDispatcher.notifyLeavingNestedEventLoop();
+        }
         _leaveNestedEventLoopImpl(retValue);
     }
 
@@ -273,7 +290,11 @@
     }
 
     @Override protected void _invokeLater(Runnable runnable) {
-        invokeLaterDispatcher.invokeLater(runnable);
+        if (invokeLaterDispatcher != null) {
+            invokeLaterDispatcher.invokeLater(runnable);
+        } else {
+            submitForLaterInvocation(runnable);
+        }
     }
 
     @Override
--- a/modules/graphics/src/main/java/com/sun/glass/ui/win/WinApplication.java	Fri Oct 04 12:53:34 2013 -0400
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/win/WinApplication.java	Mon Oct 07 14:30:43 2013 -0400
@@ -62,8 +62,19 @@
 
     private final InvokeLaterDispatcher invokeLaterDispatcher;
     WinApplication() {
-        invokeLaterDispatcher = new InvokeLaterDispatcher(this);
-        invokeLaterDispatcher.start();
+        boolean isEventThread = AccessController
+                .doPrivileged(new PrivilegedAction<Boolean>() {
+                    public Boolean run() {
+                        // Embedded in SWT, with shared event thread
+                        return Boolean.getBoolean("javafx.embed.isEventThread");
+                    }
+                });
+        if (!isEventThread) {
+            invokeLaterDispatcher = new InvokeLaterDispatcher(this);
+            invokeLaterDispatcher.start();
+        } else {
+            invokeLaterDispatcher = null;
+        }
     }
 
     private static boolean verbose;
@@ -124,16 +135,22 @@
     native private void _leaveNestedEventLoopImpl(Object retValue);
 
     @Override protected Object _enterNestedEventLoop() {
-        invokeLaterDispatcher.notifyEnteringNestedEventLoop();
+        if (invokeLaterDispatcher != null) {
+            invokeLaterDispatcher.notifyEnteringNestedEventLoop();
+        }
         try {
             return _enterNestedEventLoopImpl();
         } finally {
-            invokeLaterDispatcher.notifyLeftNestedEventLoop();
+            if (invokeLaterDispatcher != null) {
+                invokeLaterDispatcher.notifyLeftNestedEventLoop();
+            }
         }
     }
 
     @Override protected void _leaveNestedEventLoop(Object retValue) {
-        invokeLaterDispatcher.notifyLeavingNestedEventLoop();
+        if (invokeLaterDispatcher != null) {
+            invokeLaterDispatcher.notifyLeavingNestedEventLoop();
+        }
         _leaveNestedEventLoopImpl(retValue);
     }
 
@@ -208,12 +225,16 @@
 
     @Override protected FileChooserResult staticCommonDialogs_showFileChooser(Window owner, String folder, String filename, String title, int type,
                                              boolean multipleMode, ExtensionFilter[] extensionFilters, int defaultFilterIndex) {
-        invokeLaterDispatcher.notifyEnteringNestedEventLoop();
+        if (invokeLaterDispatcher != null) {
+            invokeLaterDispatcher.notifyEnteringNestedEventLoop();
+        }
         return WinCommonDialogs.showFileChooser_impl(owner, folder, filename, title, type, multipleMode, extensionFilters, defaultFilterIndex);
     }
 
     @Override protected File staticCommonDialogs_showFolderChooser(Window owner, String folder, String title) {
-        invokeLaterDispatcher.notifyEnteringNestedEventLoop();
+        if (invokeLaterDispatcher != null) {
+            invokeLaterDispatcher.notifyEnteringNestedEventLoop();
+        }
         return WinCommonDialogs.showFolderChooser_impl(owner, folder, title);
     }
 
@@ -238,7 +259,11 @@
     }
 
     @Override protected void _invokeLater(Runnable runnable) {
-        invokeLaterDispatcher.invokeLater(runnable);
+        if (invokeLaterDispatcher != null) {
+            invokeLaterDispatcher.invokeLater(runnable);
+        } else {
+            submitForLaterInvocation(runnable);
+        }
     }
 
     @Override