我正在學習如何開發RCP應用程序。我需要做的一項任務是創建一個控制檯視圖。我已經做了一些搜索,我發現下面的代碼段,理應創建一個控制檯視圖:在Eclipse-Kepler(RCP)中創建控制檯視圖
@PostConstruct
public void createComposite(Composite parent) {
MessageConsole myConsole = findConsole("abc");// CONSOLE_NAME);
MessageConsoleStream out = myConsole.newMessageStream();
out.println("Hello from Generic console sample action");
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
String id = IConsoleConstants.ID_CONSOLE_VIEW;
IConsoleView view = null;
try {
view = (IConsoleView) page.showView(id);
} catch (PartInitException e) {
e.printStackTrace();
}
view.display(myConsole);
}
private MessageConsole findConsole(String name) {
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
IConsole[] existing = conMan.getConsoles();
for (int i = 0; i < existing.length; i++)
if (name.equals(existing[i].getName()))
return (MessageConsole) existing[i];
// no console found, so create a new one
MessageConsole myConsole = new MessageConsole(name, null);
conMan.addConsoles(new IConsole[] { myConsole });
return myConsole;
}
但我保留收到以下錯誤:
org.eclipse.e4.core.di.InjectionException :java.lang.IllegalStateException:工作臺尚未創建。
我試圖按照這篇文章中發佈的建議(http://waheedtechblog.blogspot.com/2011/11/javalangillegalstateexception-workbench.html),但無濟於事。
我的問題如下。
1)爲了解決上述錯誤,應該做些什麼?
2)鑑於Eclipse開發環境的豐富性,是否有更好的方式來用較少的編程工作實現同樣的事情(例如Toggle the view of the Console in a RCP application)?
對此的任何幫助將不勝感激。
你在哪裏包括所有這些代碼?從錯誤中,你可以告訴它不是它應該在的地方。你在使用e4嗎?你應該嘗試其他教程,順便說一句。 – GGrec
例如:http://www.eclipsezone.com/eclipse/forums/t49690.html – GGrec