在开发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; }
|
阅读(2819) | 评论(0) | 转发(0) |