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

1)编辑器类

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.editorsorg.eclipse.ui.workbench.texteditor插件,需要指定这些需求的插件:

Ø         打开plugin.xml清单编辑器

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

2)定义编辑器扩展

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

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

l         右击列表中的org.eclipse.ui.editorsNew > 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中对应的代码如下:

   <extension
    
    
         point="org.eclipse.ui.editors">
    
    
      <editor
    
    
            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"/>
    
    
   </extension>
    
    

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的基本功能,但还没有添加特性功能,如语法颜色和代码辅助

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值