站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Eclipse 专题集成Log4j到Eclipse中—《Eclipse IN ACTION》第9章 (2-1)

集成Log4j到Eclipse中—《Eclipse IN ACTION》第9章 (2-1)

摘要: 集成Log4j到Eclipse中—《Eclipse IN ACTION》第9章 (2-1)

1)编辑器类<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

l 提供一个编辑器用于log4j.properties的编辑

l 由于log4j.properties基于文本,所以可以扩展TextEditor(是EditorPart的子类)

l 创建编辑器类PropertiesEditor,扩展org.eclipse.ui.editors.text.TextEditor,框架代码下:

package org.xqtu.log4j.editor;
 
import org.eclipse.ui.editors.text.TextEditor;
 
public class PropertiesEditor extends TextEditor {
 
}

l 由于依赖于org.eclipse.ui.editors和org.eclipse.ui.workbench.texteditor插件,需要指定这些需求的插件:

Ø 打开plugin.xml清单编辑器

Ø 在Dependencies页中,点击Add按钮,添加上述的插件

2)定义编辑器扩展

l 在plugin.xml清单编辑器中选择Extensions页

l 点击Add按钮,添加org.eclipse.ui.editors

l 右击列表中的org.eclipse.ui.editors,New > editor

l 在右边的Extension Element Details部分设置编辑器属性:

Ø id:指定编辑器唯一ID org.xqtu.log4j.editor.PropertiesEditor

Ø name:指定编辑器名称Log4J Properties Editor

Ø icon:选择编辑器图标(要先将图标文件导入工程)

Ø class:指定编辑器类org.xqtu.log4j.editor.PropertiesEditor

Ø default:设置为true,将本编辑器作为缺省编辑器

Ø filenames:由于编辑器只编辑log4j.properties,所以设置为log4j.properties

l 该扩展在plugin.xml中对应的代码如下:

   
         point="org.eclipse.ui.editors">
      
            filenames="log4j.properties"
            icon="icons/file_obj.gif"
            class="org.xqtu.log4j.editor.PropertiesEditor"
            default="true"
            name="Log4J Properties Editor"
            id="org.xqtu.log4j.editor.PropertiesEditor"/>
   

3)测试编辑器

l Run > Run

l 在左边列表中选择Run-time Workbench,点击Add按钮创建一个新的运行配置

l 点击Run按钮,启动运行环境的Workbench窗口

l 创建一个Java工程,在工程中创建log4j.properties文件

l 右击log4j.properties文件,选择Open With,可以看到Log4J Properties Editor是缺省的编辑器

l 选择Log4J Properties Editor打开log4j.properties,发现和TextEditor是一样的,因为扩展了TextEditor,所以具有TextEditor的基本功能,但还没有添加特性功能,如语法颜色和代码辅助



↑返回目录
前一篇: 这篇cvsnt-eclipse文档写得不错!
后一篇: 集成Log4j到Eclipse中—《Eclipse IN ACTION》第9章 (1)