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;
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);
}
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();
}
-
}
}