X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.platform.ui%2Fsrc%2Forg%2Fsimantics%2Fplatform%2Fui%2Finternal%2FActivator.java;h=f7047f1a1e18a56c02ad9014f6eb7e7a97943aac;hp=50c4ff590c358e3af690609fd7c78ed5a3d49673;hb=0f2d6b33db9eabe0c1b142f6d0197a5d1446c3b1;hpb=04bf1d8e31c85530bcd47d41051362533997134e diff --git a/bundles/org.simantics.platform.ui/src/org/simantics/platform/ui/internal/Activator.java b/bundles/org.simantics.platform.ui/src/org/simantics/platform/ui/internal/Activator.java index 50c4ff590..f7047f1a1 100644 --- a/bundles/org.simantics.platform.ui/src/org/simantics/platform/ui/internal/Activator.java +++ b/bundles/org.simantics.platform.ui/src/org/simantics/platform/ui/internal/Activator.java @@ -10,9 +10,11 @@ * Semantum Oy - initial API and implementation *******************************************************************************/ 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 +25,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 { + this.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 +63,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(); } - } }