In E3, each class could handle a status like this:
IStatus status = new Status(IStatus.WARNING, TestPlugin.PLUGIN_ID, "Hello World");
StatusManager.getManager().handle(status, StatusManager.SHOW);
Now it seems a bit more tricky. This documentation guesses this should work for classes that support injection:
@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());
}
}
However, it doesn't. Since there were no imports in the example (and why would there? There are only 4 Provider
classes in plain java), I guessed they meant javax.inject.Provider
and tried to inject 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)
So maybe that's not the right StatusHandler
? How do I use the StatusHandler
in E4?
It looks like this was never implemented. Instead the org.eclipse.e4.core.services.statusreporter.StatusReporter
class can be injected and used to log or show errors.
@Inject
StatusReporter statusReporter;
statusReporter.report(status, StatusReporter.SHOW | StatusReporter.LOG);