Integrated log4j to Eclipse - "Eclipse In Action" Chapter 9 (2)

xiaoxiao2021-03-06  78

(1) Editor class

l Provide an editor for log4j.properties

l Since log4j.properties is based on text, you can expand TeXteditor (subclass of EditorPart)

l Create an editor class PropertiesEditor, expand org.eclipse.ui.editors.text.texteditor, frame code under the frame code:

Package org.xqtu.log4j.editor;

Import org.eclipse.ui.editors.text.texteditor;

Public class proffornel eXtends texteditor {

}

l Due to depends on org.eclipse.ui.editors and org.eclipse.ui.Workbench.TextEditor plugins, you need to specify the plugins for these needs:

Ø Open the Plugin.xml list editor

Ø In the Dependencies page, click the Add button to add the above plugin.

(2) Define the editor extension

l Select Extensions page in the Plugin.xml list editor

l Click the Add button, add org.eclipse.ui.editors

l Right click on org.eclipse.ui.editors, New> Editor in the list

l Set the editor properties at the EXTENSION Element Details section on the right:

Ø ID: Specify the editor unique id org.xqtu.log4j.editor.propertiesEditor

Ø name: Specify editor name Log4j Properties Editor

Ø ICON: Select the editor icon (to import the icon file first)

Ø Class: Specify editor class org.xqtu.log4j.editor.propertiesEditor

Ø Default: Set to True, put this editor as the default editor

Ø Filenames: Because the editor only edits Log4j.Properties, set to log4j.properties

l The code corresponding to the Plugin.xml is as follows:

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) Test editor

l Run> run

l Select Run-Time Workbench in the left list, click the Add button to create a new run configuration

l Click the RUN button, start the Workbench window L of the running environment to create a Java project, create a log4j.properties file in the project

l Right-click on the log4j.properties file, select Open with, you can see that log4j profrity editor is the default editor.

l Select Log4j Properties Editor to open log4j.properties, discovery, and TextEditor are the same, because the TextEditor is extended, so there is a basic function of TextEditor, but there is no feature function, such as syntax color and code assistance

转载请注明原文地址:https://www.9cbs.com/read-107444.html

New Post(0)