在開發eclipse擴展時有時需要將信息直接輸出置控制台,比如類似於debug等。同時在RCP應用中可能想最終用戶輸出當前的操作信息等等。那麼我們可以利用如下方法向控制台視圖輸出我們的消息:
//org.eclipse.ui.console
MessageConsoleStream console = this.openLogConsole("RCP",
"Informatiol",
"org.eclipse.workbench.ui.ide");
console.println(new Date(System.currentTimeMillis())
+ ":selected!");
public MessageConsoleStream openLogConsole(String domainName,
String stationId, String applicationId) {
System.err.println("openLogConsole(domain=" + domainName + ",
station="
+ stationId + ", app=" + applicationId + ")");
/*
* get console name and create a new console
*/
StringBuffer consoleName = new StringBuffer(domainName);
if (stationId != null) {
consoleName.append(">" + stationId);
if (applicationId != null) {
consoleName.append(">" + applicationId);
}
}
MessageConsole console = new
MessageConsole(consoleName.toString(),
null);
final MessageConsoleStream consoleStream =
console.newMessageStream();
consoleStream.setColor(Display.getDefault().getSystemColor(
SWT.COLOR_BLUE));
/*
* show view
*/
IConsoleManager manager = (IConsoleManager)
ConsolePlugin.getDefault()
.getConsoleManager();
manager
.addConsoles(new org.eclipse.ui.console.IConsole[] {
(org.eclipse.ui.console.IConsole) console });
manager.showConsoleView (console);
return consoleStream;
}