[英]Custom error dialog in eclipse e4 application
我试图更改e4应用程序的默认状态处理程序,因为我想向其添加完整的堆栈跟踪。
到目前为止,我将以下代码段添加到了插件xml:
<extension
point="org.eclipse.ui.statusHandlers">
<statusHandler
class="our.test.StatusHandler"
id="custom_status_handler"/>
<statusHandlerProductBinding
handlerId="custom_status_handler"
productId="my_product.product">
</statusHandlerProductBinding>
</extension>
类our.test.StatusHandler如下所示:
public class StatusHandler extends AbstractStatusHandler {
@Override
public void handle(StatusAdapter statusAdapter, int style) {
System.out.println("Hello World");
}
}
但这似乎不起作用。 默认的“错误”对话框仍然显示,并且控制台中没有输出。
我已经看过这个答案,并使用WorkbenchErrorHandler而不是AbstractStatusHandler,但是它也不起作用。
StatusHandler是3.x兼容模式,在纯e4应用程序中不使用。
您可以通过在应用程序上下文中添加IEventLoopAdvisor
的实现来处理未处理的异常。 RCP LifeCycle类的@PostContextCreate
方法是执行此操作的好地方:
@PostContextCreate
public void postContextCreate(IEclipseContext context)
{
context.set(IEventLoopAdvisor.class, new EventLoopAdvisor(context));
...
}
class EventLoopAdvisor implements IEventLoopAdvisor
{
private final IEclipseContext _appContext;
EventLoopAdvisor(IEclipseContext appContext)
{
super();
_appContext = appContext;
}
@Override
public void eventLoopIdle(final Display display)
{
display.sleep();
}
@Override
public void eventLoopException(final Throwable exception)
{
// Report error
}
}
请注意,对eventLoopIdle
display.sleep()
的调用非常重要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.