簡體   English   中英

Eclipse e4應用程序中的自定義錯誤對話框

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM