在RCP程序中使用Eclipse Console View.docx_第1页
在RCP程序中使用Eclipse Console View.docx_第2页
在RCP程序中使用Eclipse Console View.docx_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

在RCP程序中使用Eclipse Conole View作者:Zhang Wei联系方式:关键词:Eclipse RCP LOG4J Console View一、 将Console View 加入自己的程序。在我的RCP项目中,想要给资深用户提供一个运行信息监控的View。就像Eclipse项目中的那个Console View 一样。网上有一些相关的信息,非常有用,不过有些做法不可取,经过验证,其实将Eclipse Console View加入自己的程序非常容易。1、RCP项目的plugin.xml中加入对org.eclipse.ui.console插件引用。2、不用管扩展点(所有的网上例子都要求加入ConsoleFactory的扩展点,其实没有必要),在项目的透视图类perspective中加入占位Viewer,代码如下:IPlaceholderFolderLayout myviews = layout.createPlaceholderFolder(myFoldView, IPageLayout.BOTTOM, 0.2f, layout.getEditorArea();myviews.addPlaceholder(IConsoleConstants.ID_CONSOLE_VIEW);3、因为我不希望调试信息一开始就出现在界面上,所以用的是占位view,其实也可以直接像普通view一样直接打开。就像这样layout.addStandaloneView(IConsoleConstants.ID_CONSOLE_VIEW, false, IPageLayout.BOTTOM, .20f, layout.getEditorArea();4、增加一个工具栏按钮,按钮事件的处理如下:public class ShowDebugConsole static MessageConsole console = new MessageConsole( 监视窗口 , Utils.getimage(trace.bmp); static IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager(); manager.addConsoles( new IConsole console ); /获取本console关联的输入流MessageConsoleStream stream = console .newMessageStream();System.setOut(stream) ;public static MessageConsole getConsole()return console;public static void showConsole() IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager(); manager.showConsoleView(console );/先来显示这个view 那么无论是在按钮Action还是在Command或者其他任何需要的地方,调用showConsole方法都可以出现我们的Eclipse Console View 了。Eclipse Console View出现在你自己的RCP程序中了,是不是很棒呢?下面我们考虑的是如何将Console View 和LOG4J的输出连接上。-二、关于LOG4J的输出注意看到上面的静态代码中,我是将System.out定向输出到console了。但是在我的RCP程序中,根本就没有用System.out打印过任何信息,全部是用的Log4j在做输出。于是很自然想到扩展Log4j的AppenderSkeleton。AppendSkeleton其实很好实现,只需要实现一个Append方法即可,在Append方法里直接将得到的信息向System.out输出,这样就不用修改原来的程序了。但是. 在实现完Append并且成功输出信息之后,我看了看Log4j的api,才发现原来Log4j的WriterAppender完全可以满足需要,没有必要自己去做Append.继续修改后的ShowDebugConsole 代码如下:public class ShowDebugConsole static MessageConsole console = new MessageConsole( 监视窗口 , Utils.getimage(trace.bmp); static IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager(); manager.addConsoles( new IConsole console ); /获取本console关联的输入流MessageConsoleStream stream = console .newMessageStream();/关联到Log4j的输出PrintWriter pr = new PrintWriter( stream);PatternLayout lay = new PatternLayout(%-dyyyy-MM-dd HH:mm:ss,SSS %c-%p %m%n); WriterAppender consoleWriter = new org.apache.log4j.WriterAppender(lay,pr); Logger.getRootLogger().addAppender(consoleWriter);public static MessageConsole getConsole()return console;public static void showConsole() IConsoleManager manager = Con

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论