Eclipse plugin 在E4中使用StatusHandler

Eclipse plugin 在E4中使用StatusHandler,eclipse-plugin,e4,Eclipse Plugin,E4,在E3中,每个类都可以处理如下状态: IStatus status = new Status(IStatus.WARNING, TestPlugin.PLUGIN_ID, "Hello World"); StatusManager.getManager().handle(status, StatusManager.SHOW); 现在看起来有点棘手。猜测这对于支持注入的类应该有效: @Inject Provider<StatusHandler> statusHandler; @Inj

在E3中,每个类都可以处理如下状态:

IStatus status = new Status(IStatus.WARNING, TestPlugin.PLUGIN_ID, "Hello World");
StatusManager.getManager().handle(status, StatusManager.SHOW);
现在看起来有点棘手。猜测这对于支持注入的类应该有效:

@Inject Provider<StatusHandler> statusHandler;
@Inject Provider<StatusReportingService> statusReportingService;

public void foo() {
  try {
    // some operation
  } catch (SomeException ex) {
     statusHandler.get().handle(ex, IStatus.ERROR, "Error Message", statusReportingService.get());
  }
}

所以这可能不是正确的
状态处理程序
?如何在E4中使用
StatusHandler

这似乎从未实现过。相反,
org.eclipse.e4.core.services.statusreporter.statusreporter
类可以被注入并用于记录或显示错误

@Inject
StatusReporter StatusReporter;
statusReporter.report(status,statusReporter.SHOW | statusReporter.LOG);

我遇到了类似的问题。然而,当遵循您的建议时,我得到了一个编译器警告:“不鼓励访问:类型'StatusReporter'不是API”。我应该关心这个问题吗?还有其他选择吗?@Pyves通常这是一个问题,但对于e4api来说没关系。很多E4API还没有完全定稿,所以请给出此警告。
org.eclipse.e4.core.di.InjectionException: Unable to instantiate public org.eclipse.jface.util.StatusHandler()
    at org.eclipse.e4.core.internal.di.ConstructorRequestor.execute(ConstructorRequestor.java:44)
    at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:373)
    at org.eclipse.e4.core.internal.di.InjectorImpl.makeFromProvider(InjectorImpl.java:325)
    at org.eclipse.e4.core.internal.di.ProviderImpl.get(ProviderImpl.java:34)
    at org.acme.project.Main.createStatusHandler(StatusUtil.java:26)