在多页编辑器中加入xml编辑功能

 

最近在做一个GEF多页编辑器,图形用xml格式保存。为了简单,在source标签页应用了eclipse已经存在xml编辑器。 

基本思路用两种:一种是自己的多页编辑器继承XMLMultiPageEditorPart,这样就会继承来design、source两个标签页,然后再加入自己的编辑器页,JBPM designer插件就是用这种思路实现的。 
另一种是直接引入source编辑页到自己的MultiPageEditorPart中,也就是StructuredTextEditor。项目中采用了后一种思路。 

eclipse.org上有一篇文章对引入StructuredTextEditor有详细的介绍: 
http://www.eclipse.org/webtools/wst/components/sse/tutorials/multipage-editor-tutorial.html 

在实现过程中发现,如果设置编辑文件的扩展名为.xml是没有问题的,如果默认扩展名不是.xml,则显示的xml文档是黑白的,非常难看。 
这是因为我们的editor没有绑定content type。解决方法:需要实现org.eclipse.core.contenttype.contentTypes扩展点,然后绑定到editor上: 
Java代码    收藏代码
  1. <extension  
  2.          point="org.eclipse.ui.editors">  
  3.       <editor  
  4.             class="com.test.MyMultiEditorPart"  
  5.             id="com.test.MyMultiEditorPart"  
  6.             name="%editor.name.1"  
  7.             icon="resources/icons/runner.gif"  
  8.             extensions="arl">  
  9.             <contentTypeBinding  
  10.                contentTypeId="com.test.MyMultiEditorPart.contenttype.arl"/>  
  11.       </editor>  
  12.    </extension>  
  13.      
  14.     <extension  
  15.         point="org.eclipse.core.contenttype.contentTypes">  
  16.         <content-type   
  17.                 id="com.test.MyMultiEditorPart.contenttype.arl"  
  18.                 name="%content-type.name.1"  
  19.                 base-type="org.eclipse.core.runtime.xml"  
  20.                 file-extensions="arl">  
  21.             <property name="charset" default="UTF-8"/>  
  22.         </content-type>  
  23.     </extension>  
分享到:   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值