简体   繁体   English

Eclipse e4应用程序中的自定义错误对话框

[英]Custom error dialog in eclipse e4 application

I'm trying to change the default status handler of our e4 application, because I want to add the full stack trace to it. 我试图更改e4应用程序的默认状态处理程序,因为我想向其添加完整的堆栈跟踪。

So far, I added the following snippet to the plugin xml: 到目前为止,我将以下代码段添加到了插件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>

The class our.test.StatusHandler looks as follows: 类our.test.StatusHandler如下所示:

public class StatusHandler extends AbstractStatusHandler {

    @Override
    public void handle(StatusAdapter statusAdapter, int style) {
        System.out.println("Hello World");
    }
}

But this does not seem to work. 但这似乎不起作用。 The default Error dialog is still shown and there is no output in the console. 默认的“错误”对话框仍然显示,并且控制台中没有输出。

I already looked at this answer and used WorkbenchErrorHandler instead of AbstractStatusHandler, but it does not work either. 我已经看过这个答案,并使用WorkbenchErrorHandler而不是AbstractStatusHandler,但是它也不起作用。

StatusHandler is 3.x compatibility mode and isn't used in a pure e4 application. StatusHandler是3.x兼容模式,在纯e4应用程序中不使用。

You can deal with unhandled exceptions by adding an implementation of IEventLoopAdvisor in the application context. 您可以通过在应用程序上下文中添加IEventLoopAdvisor的实现来处理未处理的异常。 The @PostContextCreate method of the RCP LifeCycle class is a good place to do this: 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
  }
}

Note that the call to display.sleep() in eventLoopIdle is very important. 请注意,对eventLoopIdle display.sleep()的调用非常重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM