在E3中,每个类都可以处理如下状态:
IStatus status = new Status(IStatus.WARNING, TestPlugin.PLUGIN_ID, "Hello World");
StatusManager.getManager().handle(status, StatusManager.SHOW);
现在看起来有点棘手。 This documentation猜测这应该适用于支持注入的类:
@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());
}
}
然而,它没有。由于示例中没有导入(为什么会出现?普通java中只有4个Provider
类),我猜测它们意味着javax.inject.Provider
并试图注入org.eclipse.jface.util.StatusHandler
:
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)
所以也许这不是正确的StatusHandler
?如何在E4中使用StatusHandler
?
答案 0 :(得分:2)
看起来这从未实现过。相反,可以注入org.eclipse.e4.core.services.statusreporter.StatusReporter
类并用于记录或显示错误。
@Inject
StatusReporter statusReporter;
statusReporter.report(status, StatusReporter.SHOW | StatusReporter.LOG);