最近在做一个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上:
基本思路用两种:一种是自己的多页编辑器继承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上:
- <extension
- point="org.eclipse.ui.editors">
- <editor
- class="com.test.MyMultiEditorPart"
- id="com.test.MyMultiEditorPart"
- name="%editor.name.1"
- icon="resources/icons/runner.gif"
- extensions="arl">
- <contentTypeBinding
- contentTypeId="com.test.MyMultiEditorPart.contenttype.arl"/>
- </editor>
- </extension>
- <extension
- point="org.eclipse.core.contenttype.contentTypes">
- <content-type
- id="com.test.MyMultiEditorPart.contenttype.arl"
- name="%content-type.name.1"
- base-type="org.eclipse.core.runtime.xml"
- file-extensions="arl">
- <property name="charset" default="UTF-8"/>
- </content-type>
- </extension>