1
在E3使用StatusHandler,每班可以处理状况是这样的:在E4
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());
}
}
但是,事实并非如此。由于有在例子中,没有进口(以及为什么会出现只有4 Provider
在普通的Java类?),我猜他们的意思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
?
我遇到过类似的问题。然而,当遵循你的建议,我得到一个编译器警告:“劝阻访问:'StatusReporter'类型不是API”。我应该关心这一点吗?还有其他的选择吗? – Pyves
@Pyves通常情况下这是一个问题,但对于e4 API来说,它是可以的。很多e4 API还没有完全定案,所以给出这个警告。 –