Eclipse plug-in development

1. Eclipse Architecture

Eclipse is an IDE (Integrated Development Environment) for java.

Essentially, Eclipse is just a platform (Runtime (OSGi)) on which plug-ins (Plugin) can be integrated, and plug-ins provide development functions. Plugins can then integrate plugins. Such as:

Runtime(OSGi)->SWT->JFace->UI

Runtime(OSGi)->Resources

Each plug-in can extend the plug-in of the previous layer, and at the same time can expose its own extension point (Extension Point) for the plug-in of the lower layer to extend itself.

 

2. How to extend existing extension points

1> Write plugin.xml

<plugin>
<extension point="extension point id">
</extension>
</plugin>

Just write the extension point id you want to extend, and you can extend its function according to the format (Schema) required by the extension point.

For example, if you want to add a function key, you need to extend the extension point org.eclipse.ui.actionSets exposed by Eclipse, and write plugin.xml according to its specified format (Schema):

<plugin>
<extension point=" org.eclipse.ui.actionSets "> // declare extension point
<actionSet label="Sample Action Set" visible="true" id="HelloPlugIn.actionSet"> // declare function key group
<menu label="Sample &Menu" id="sampleMenu"> // Declare the menu for the function key group
<separator name="sampleGroup"/>
</menu>
<action label="&Sample Action"icon=" icons/sample.gif" tooltip="Hello, Eclipse world" // declare the function key

toolbarPath="sampleGroup"menubarPath="sampleMenu/sampleGroup"

id="helloplugin.actions.SampleAction"class="helloplugin.actions.SampleAction" //声明按下该功能键的响应类,需要编写

/>
</actionSet>
</extension>
</plugin>

接下来我们只需要编写响应类即可。

 

2>编写扩展点需要的类。

编写扩展点需要的类,如上面,我们想为Eclipse添加一个功能键,当然需要编写一个当按下功能键后,用于响应的类。

该类通常需要实现扩展点提供的接口,或继承扩展点提供的父类,我们只需要实现(implement)接口的方法即可。

如功能键的响应类,我们只需要实现IWorkbenchWindowActionDelegate接口,实现run()方法即可。

public void run(IAction action) {
MessageDialog.openInformation(window.getShell(),"Hello Plug In","Hello Plug In");
}

当按下该功能键后,会弹出框,上写"Hello Plug In"。

 

3. 扩展点介绍。

既然我们已经知道,编写插件,就是扩展已知扩展点,那如果想写一定功能的插件(Plug In),就需要了解,都有那些扩展点(Extension Point)供我们扩展(Extension)。

Eclipse已经给我们暴露出了足够多的扩展点(Extension Point),以便我们写出功能。大概分为两类:

一是UI,用于扩展Eclipse的用户界面的操作

一是Resource,用于扩展Eclipse的文件资源的操作。

 

1>UI扩展点

 

IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IEditorPart part = page.getActiveEditor();

 

 

2> Resource扩展点

 

IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = wsroot.getProjects();

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326747167&siteId=291194637