简体   繁体   中英

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.

So far, I added the following snippet to the plugin 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:

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.

StatusHandler is 3.x compatibility mode and isn't used in a pure e4 application.

You can deal with unhandled exceptions by adding an implementation of IEventLoopAdvisor in the application context. The @PostContextCreate method of the RCP LifeCycle class is a good place to do this:

@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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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