在E4

2017-05-05 50 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還沒有完全定案,所以給出這個警告。 –