From: Tuukka Lehtonen Date: Wed, 5 Apr 2017 13:18:23 +0000 (+0300) Subject: Allow SWTThread to be constructed to do execute(Runnable) asynchronously X-Git-Tag: v1.29.0~118 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=24b69f15e78bfdd5cdb30d4b135c4c734061914e Allow SWTThread to be constructed to do execute(Runnable) asynchronously refs #7131 Change-Id: I0fa2072895253cf0fcf80f3de48efe536004c6b8 --- diff --git a/bundles/org.simantics.utils.thread.swt/src/org/simantics/utils/threads/SWTThread.java b/bundles/org.simantics.utils.thread.swt/src/org/simantics/utils/threads/SWTThread.java index b5bb6722c..07102a102 100644 --- a/bundles/org.simantics.utils.thread.swt/src/org/simantics/utils/threads/SWTThread.java +++ b/bundles/org.simantics.utils.thread.swt/src/org/simantics/utils/threads/SWTThread.java @@ -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); } }