]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fix SimanticsConsole activation invalid thread access problem 63/3563/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 19 Nov 2019 08:11:44 +0000 (10:11 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 19 Nov 2019 08:11:44 +0000 (10:11 +0200)
gitlab #400

Change-Id: I80a054fc44da6030ad9da9c566b0ce072cb08d8c

bundles/org.simantics.platform.ui/src/org/simantics/platform/ui/internal/Activator.java

index 50c4ff590c358e3af690609fd7c78ed5a3d49673..bd910dd27d13fd98717bef339e9993202a28043a 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.platform.ui.internal;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -23,16 +24,32 @@ import org.slf4j.LoggerFactory;
 
 public class Activator extends AbstractUIPlugin {
 
+    private BundleContext context;
+
     public Activator() {
     }
 
     @Override
     public void start(BundleContext context) throws Exception {
-
         super.start(context);
+        this.context = context;
+
+        if (PlatformUI.isWorkbenchRunning())
+            PlatformUI.getWorkbench().getDisplay().asyncExec(this::initConsole);
+    }
+
+    @Override
+    public void stop(BundleContext context) throws Exception {
+        context = null;
+        super.stop(context);
+    }
+
+    private void initConsole() {
+        if (PlatformUI.getWorkbench().getDisplay().isDisposed())
+             return;
 
         SimanticsConsole console = SimanticsConsole.findConsole();
-        if(console != null) {
+        if (console != null) {
             ServiceReference<?> ref = context.getServiceReference(UnhandledExceptionService.class.getName());
             if (ref != null) {
                 UnhandledExceptionService service = (UnhandledExceptionService) context.getService(ref);
@@ -45,11 +62,10 @@ public class Activator extends AbstractUIPlugin {
             }
             ConsoleAppender ca = new ConsoleAppender(console);
             ch.qos.logback.classic.Logger logbackLogger =
-                    (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+                    (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
             logbackLogger.addAppender(ca);
             ca.start();
         }
-
     }
 
 }