]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Allow SWTThread to be constructed to do execute(Runnable) asynchronously 03/403/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 5 Apr 2017 13:18:23 +0000 (16:18 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 5 Apr 2017 13:19:08 +0000 (16:19 +0300)
refs #7131

Change-Id: I0fa2072895253cf0fcf80f3de48efe536004c6b8

bundles/org.simantics.utils.thread.swt/src/org/simantics/utils/threads/SWTThread.java

index b5bb6722c43e8531dc42c80f32ac5043846752da..07102a102cd8b861210a31d9ec26de60478b8c6c 100644 (file)
@@ -22,25 +22,32 @@ import org.eclipse.swt.widgets.Widget;
 
 public class SWTThread implements IThreadWorkQueue, Executor {
 
-       final Display display;
+       private final Display display;
+       private final boolean executeAsync;
+       
+       public static IThreadWorkQueue getThreadAccess(Display display, boolean executeAsync)
+       {
+               return new SWTThread(display, executeAsync);
+       }
        
        public static IThreadWorkQueue getThreadAccess(Display display)
        {
-               return new SWTThread(display);
+               return getThreadAccess(display, false);
        }
        
        public static IThreadWorkQueue getThreadAccess(Widget widget)
        {
-               return new SWTThread(widget.getDisplay());
+               return new SWTThread(widget.getDisplay(), false);
        }
        
        public static IThreadWorkQueue getThreadAccess() {
-               return new SWTThread(Display.getDefault());
+               return new SWTThread(Display.getDefault(), false);
        }
        
-       SWTThread(Display display)
+       SWTThread(Display display, boolean executeAsync)
        {
                this.display = display;
+               this.executeAsync = executeAsync;
        }
        
        @Override
@@ -87,6 +94,7 @@ public class SWTThread implements IThreadWorkQueue, Executor {
 
        @Override
        public void execute(Runnable command) {
-               syncExec(command);
+               if (executeAsync) asyncExec(command);
+               else syncExec(command);
        }
 }