在E4

2017-05-05 54 views
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

回答

2

看起来这是从未实现的。相反,org.eclipse.e4.core.services.statusreporter.StatusReporter类可以被注入并用于记录或显示错误。

@Inject 
StatusReporter statusReporter; 

statusReporter.report(status, StatusReporter.SHOW | StatusReporter.LOG); 
+0

我遇到过类似的问题。然而,当遵循你的建议,我得到一个编译器警告:“劝阻访问:'StatusReporter'类型不是API”。我应该关心这一点吗?还有其他的选择吗? – Pyves

+1

@Pyves通常情况下这是一个问题,但对于e4 API来说,它是可以的。很多e4 API还没有完全定案,所以给出这个警告。 –