- 浏览: 372774 次
- 性别:
- 来自: 上海
最新评论
-
heshifk:
我今天用这个也遇到了一个问题,当焦点在别的组件上面,也添加了快 ...
SWT 添加全局的监听 -
回归蔚蓝:
好文,归纳的太准确了
Groovy闭包深入学习 -
零度弥合:
写的真好,赞赞赞。
Groovy闭包深入学习 -
yuxg:
顶
Java在Eclipse环境下调用Subclipse接口完成SVN操作(附源码) -
zk1878:
不错,好文
Groovy闭包深入学习
一 相关知识
org.eclipse.compare 插件项目,用于进行文本、源码比对的一个插件,提供了一个Editor或Dialog可方便调用。
org.eclipse.compare.CompareEditorInput.CompareEditorInput 是用于给Compare Editor 的EditorInput, 需要自己实现。
org.eclipse.compare.CompareConfiguration 对CompareEditor的配置。是否允许左边内容被修改,或是否允许右边内容被修改;左右两边的label,image等。
org.eclipse.compare.ITypedElement 接口,本意为指代有图片、名称、类型的元素。而在Compare中,为一个基本的对比单元。
org.eclipse.compare.IEditableContent
接口,是否可编辑的元素
org.eclipse.compare.IModificationDate 接口,修改时间
org.eclipse.compare.IStreamContentAccessor 获得内容的接口,内容是以InputStream流的方式获得。
org.eclipse.compare.IContentChangeNotifier 内容变化的通知接口
org.eclipse.compare.BufferedContent 抽象类,实现了 org.eclipse.compare.IStreamContentAccessor 和 org.eclipse.compare.IContentChangeNotifier 2个接口
在BufferedContent中持有了一个byte[], 表示缓存有界面上修改的内容,当然,最后需要你在CompareEditorInupt中将修改后的byte[]内容保存(比如保存至文件等)
二 代码
(1)解决项目依赖
添加对org.eclipse.compare 的依赖
(2)定义一个表示比对的元素
可继承与BufferedContent,并实现ITypeElement 等接口。主要代码如下:
class CompareItem extends BufferedContent implements ITypedElement, IModificationDate, IEditableContent { private String fileName; private long time; CompareItem(String fileName) { this.fileName = fileName; this.time = System.currentTimeMillis(); } /** * @see org.eclipse.compare.BufferedContent#createStream() */ protected InputStream createStream() throws CoreException { try { return new FileInputStream(new File(fileName)); } catch (FileNotFoundException e) { e.printStackTrace(); } return new ByteArrayInputStream(new byte[0]); } /** * @see org.eclipse.compare.IModificationDate#getModificationDate() */ public long getModificationDate() { return time; } /** * @see org.eclipse.compare.ITypedElement#getImage() */ public Image getImage() { return CompareUI.DESC_CTOOL_NEXT.createImage(); } /** * @see org.eclipse.compare.ITypedElement#getName() */ public String getName() { return fileName; } /** * @see org.eclipse.compare.ITypedElement#getType() */ public String getType() { return ITypedElement.TEXT_TYPE; } /** * @see org.eclipse.compare.IEditableContent#isEditable() */ public boolean isEditable() { return true; } /** * @see org.eclipse.compare.IEditableContent#replace(org.eclipse.compare.ITypedElement, org.eclipse.compare.ITypedElement) */ public ITypedElement replace(ITypedElement dest, ITypedElement src) { return null; } public void writeFile() { this.writeFile(this.fileName, this.getContent()); } private void writeFile(String fileName, byte[] newContent) { FileOutputStream fos = null; try { File file = new File(fileName); if (file.exists()) { file.delete(); } file.createNewFile(); fos = new FileOutputStream(file); fos.write(newContent); fos.flush(); } catch (IOException e) { e.printStackTrace(); } finally { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } fos = null; } } }
(3)配置CompareConfiguration
CompareConfiguration config = new CompareConfiguration(); config.setProperty(CompareConfiguration.SHOW_PSEUDO_CONFLICTS, Boolean.FALSE); // left config.setLeftEditable(true); config.setLeftLabel("Left"); // right config.setRightEditable(true); config.setRightLabel("Right");
(4)定义CompareEditorInput
CompareEditorInput editorInput = new CompareEditorInput(config) { CompareItem left = new CompareItem("C:/A.txt"); CompareItem right = new CompareItem("C:/Inject.log"); @Override protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { return new DiffNode(null, Differencer.CONFLICTING, null, left, right); } @Override public void saveChanges(IProgressMonitor pm) throws CoreException { super.saveChanges(pm); left.writeFile(); right.writeFile(); } }; editorInput.setTitle("文件比较");
(5)弹出Compare Editor或Dialog
CompareUI.openCompareEditor(editorInput); // 打开对比Editor CompareUI.openCompareDialog(editorInput); // 弹出对比Dialog
三 效果
(1)Editor效果
(2)Dialog效果
四 其他
(1) 代码是基于Eclipse插件项目的email Template 创建的, 可直接使用附件中的源码替换到默认生成的类。
(2) 代码演示了在Eclipse RCP环境下使用Compare功能。
- MessagePopupAction.zip (1.6 KB)
- 描述: 源码
- 下载次数: 289
评论
我按照您的代码去实现,但左右两边出不来啊.
link就是一个链接文件,比如你在Eclipse里,new一个File,新建向导有个高级选项,链接到文件系统中的文件,这样就好像在工作区间内创建了一个文件,但实际上是在文件系统的其他位置。
这个文件也会在Eclipse的文件树上显示,也可以和工作区间内的其他文件比较。
你指的link是什么意思?
但可以把外面的文件link进来比较。
发表评论
-
SWT的图片叠加效果
2009-09-23 10:58 3883一. 核心类说明 ImageDescr ... -
TreeViewer的ContentProvider详解,以及Lazy载入
2009-08-08 17:30 5951为了实现这样的效果: ... -
SWT多线程
2009-07-15 23:42 4964一:基本概念 在SWT内,有一个UI主线程的概念,自定义的线程 ... -
去掉plugin_customization.ini文件,在代码中实现配置功能
2009-06-03 09:59 1525一. 常规做法 ... -
StyledText 的Traverse,VerifyKey,MouseListener分析
2009-05-06 10:36 2643目标功能: 随便焦点的跳转(键盘的上下左右操作;键盘的 ... -
Java在Eclipse环境下调用Subclipse接口完成SVN操作(附源码)
2009-04-19 19:16 7869Java在Eclipse环境下调用Subclipse接口完成S ... -
JFace的FieldDecoration / DecoratedField 使用详解
2009-04-07 13:01 1346关键代码: IControlCreator cont ... -
RCP异常:The editor class could not be instantiated
2009-03-30 16:26 0Unable to create this part due ... -
NightLabs 开源的swt pdf viewer (Eclipse plugin)
2009-03-26 12:37 1293http://wiki.nightlabs.de/en/PDF ... -
有关于《OSGI进阶》中的org.eclipse.equinox.servlet.api.jar
2009-02-12 09:56 3662具体可以参见JavaEye问答频道: http://www.i ... -
Eclipse在创建Plug-in项目时的Target platform选项的说明
2009-01-15 11:48 6924Target PlatForm 插件的运行平台. Eclip ... -
eclipse中的线程
2009-01-09 19:23 1828见: http://www.eclipseworld.org/ ... -
SWT 如何选中Spinner中所有的数字
2008-12-29 11:30 2433http://dev.eclipse.org/newslist ... -
SWT 添加全局的监听
2008-12-03 12:26 4888Display 有这么一个方法: public void ... -
SWT得到调用ActiveX所需的控件标识符
2008-11-23 16:51 2856怎么使用ole,网上别人的代码已经很多了. 下面是说怎么得到o ... -
Text,Combo添加内容辅助功能[代码提示] [可下载代码]
2008-11-16 23:08 34641. 类 a) ContentProp ... -
SWT byte[]与Image的相互转换
2008-11-06 17:01 45071. 从byte[]得到Image private stat ... -
JFACE 用好StructuredViewer [可下载源代码] - 列表类型的动态控件创建
2008-11-06 10:41 1797功能: 1. 类似一个TableViewer的功能. 2. 可 ... -
AWT, SWING, SWT, JFACE 比较
2008-11-03 10:36 1851AWT Abstract Windows Toolkit(AW ... -
SWT StyledText试用 [可下载项目代码]
2008-10-13 09:57 3728效果图 和 源代码: 效果图 源代码 点击下载. 注: 代 ...
相关推荐
Eclipse rcp 实现文本内容对比功能,可自己选取对比的文件进行比较
41页完全详细方档:Eclipse for ARM是借用开源软件Eclipse的工程管理工具,嵌入GNU工具集,使之能够开发ARM 公司Cortex-A系列的CPU,这里使用Eclipse for ARM作为开发软件。
借用AnyCAD实现C#对3D物体的显示
汉化eclipse全过程,有点乱,开头借用https://blog.csdn.net/weixin_40922936/article/details/80647371 的个人学习笔记(我将他的最后面的汉化做了截图及补充) 强调:1.注意他笔记中的话:点击下载时注意地址是否...
物资借用系统可直接应用到学院及社团部门,方便物资监管,实现高效借用。因此我们可以把握住现在这个还未实现的新领域,创造一个方便学生的新系统。 3.弱势:我们目前面临潜在性威胁如学校可能会实现的系统以及个别...
Matlab实现一维小区定向信道锁定借用(BDCL)仿真,并和FCA(固定信道分配)进行阻塞率的比较。同时也将小区信道数对阻塞率的影响曲线绘制出来!
教室借用软件 VB
delphi+acccess数据库开发的图书借用软件:功能包括:书籍入库、借用书籍、归还书籍、历史明细、超期记录等。数据库可根据情况自己选择sqlserver
调用bing搜索api 本地网站实现搜索功能 并借用fiddler软件 解决跨域问题 伪装服务器 本地实现该搜索功能
管理员身份功能介绍: 1:用户登录:用户通过账号信息进行软件的登录 2:器材管理:管理员可以添加器材信息以及查看用户的借用状态 2:借用公告:管理员可以添加借用公告信息 3:借用信息:可以查看用户的借用信息 4...
SmoSEC资产管理系统包含的功能有:资产列表、借用、归还、领用、退库、维修、报废、调拨、盘点、分类管理,区域管理,部门管理,耗材列表、入库、出库、调拨、盘点等功能。 资产管理开源项目,移动端APP,支持...
笔记本借用登记表.pdf
物品借用管理程序 asp制作
工具借用登记表.doc
软件基于jQuery,MathQuill和CKEditor等组件开发的,基于CKEditor开发了文本编辑功能,实现了文本的输入,基于MathQuill实现公式的输入,它依据LaTex的语法实现,基本满足了日常公式的需求,但一些复杂的公式,如...
主要分成销售采购管理、生产计划管理、物流库存管理、财务结算开票、领导综合查询五个组成部分,系统的实施加强了对经销商的控制和管理力度,提高了渠道的忠诚度,实现了以销售为中心的信息集成,加快了市场反应速度...
笔记本电脑借用规定.doc
最新电脑借用承诺书教职工借用笔记本电脑协议DOC任意编辑版.docx
基于Android的教室查询借用系统