Display now accessed via PlatformUI for e.g. highlight requests
[Mograsim.git] / plugins / net.mograsim.plugin.core / src / net / mograsim / plugin / util / SingleSWTRequest.java
index fa4d558..9ffa772 100644 (file)
@@ -2,25 +2,31 @@ package net.mograsim.plugin.util;
 
 import java.util.concurrent.atomic.AtomicBoolean;
 
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
 
+/**
+ * A utility class that requests the asynchronous execution of a Runnable in the SWT Thread. Making a new request before the old one is
+ * processed will override the old request.
+ */
 public class SingleSWTRequest
 {
        private AtomicBoolean waiting = new AtomicBoolean();
+       private Runnable request;
 
        public void request(Runnable request)
        {
                synchronized (waiting)
                {
+                       this.request = request;
                        if (!waiting.get())
                        {
                                waiting.set(true);
-                               Display.getDefault().asyncExec(() ->
+                               PlatformUI.getWorkbench().getDisplay().asyncExec(() ->
                                {
                                        synchronized (waiting)
                                        {
                                                waiting.set(false);
-                                               request.run();
+                                               this.request.run();
                                        }
                                });
                        }