Eclipse插件开发自定义扩展点
来源:互联网 发布:淘宝的导航条 编辑:程序博客网 时间:2024/05/22 14:20
- 介绍
如果你的插件写的有特色,想拿来用,但是还不能或者不适合直接修改你的代码,怎么办呢?解决方案当然是Eclipse插件系统最推荐的了——增加扩展点。
- 概念
一个扩展点(Extension Point)包括ID、Name及Schema文件,shema文件以ID命名,后缀为.exsd,存放在插件schema目录下。
- 定义
[codesyntax lang="xml"]
<?xml version='1.0' encoding='UTF-8'?><!-- Schema file written by PDE --><schema targetNamespace="org.suren.littlebird" xmlns="http://www.w3.org/2001/XMLSchema"><annotation> <appinfo> <meta.schema plugin="org.suren.littlebird" id="org.suren.littlebird.bundles.list" name="BundlesList"/> </appinfo> <documentation> 对bundle列表的扩展 </documentation> </annotation> <element name="extension"> <annotation> <appinfo> <meta.element /> </appinfo> </annotation> <complexType> <attribute name="id" type="string"> <annotation> <documentation> </documentation> </annotation> </attribute> <attribute name="point" type="string" use="required"> <annotation> <documentation> 测试啊 </documentation> </annotation> </attribute> <attribute name="name" type="string"> <annotation> <documentation> </documentation> </annotation> </attribute> </complexType> </element> <element name="column"> <annotation> <documentation> 新增一列 </documentation> </annotation> <complexType> <attribute name="text" type="string" use="required"> <annotation> <documentation> 列名 </documentation> </annotation> </attribute> <attribute name="sorter" type="string"> <annotation> <documentation> </documentation> <appinfo> <meta.attribute kind="java" basedOn="org.suren.littlebird.views.listener.SorterAdapter:"/> </appinfo> </annotation> </attribute> </complexType> </element> <element name="action"> <annotation> <documentation> 对列表操作的扩展 </documentation> </annotation> <complexType> <attribute name="reload" type="string"> <annotation> <documentation> </documentation> <appinfo> <meta.attribute kind="java" basedOn="org.suren.littlebird.actions.bundle.SuRenBundleReload:"/> </appinfo> </annotation> </attribute> <attribute name="install" type="string"> <annotation> <documentation> </documentation> <appinfo> <meta.attribute kind="java" basedOn="org.suren.littlebird.actions.bundle.SuRenBundleInstallAction:"/> </appinfo> </annotation> </attribute> <attribute name="uninstall" type="string"> <annotation> <documentation> </documentation> <appinfo> <meta.attribute kind="java" basedOn="org.suren.littlebird.actions.bundle.SuRenBundleUninstallAction:"/> </appinfo> </annotation> </attribute> <attribute name="update" type="string"> <annotation> <documentation> </documentation> <appinfo> <meta.attribute kind="java" basedOn="org.suren.littlebird.actions.bundle.SuRenBundleUpdateAction:"/> </appinfo> </annotation> </attribute> <attribute name="start" type="string"> <annotation> <documentation> </documentation> <appinfo> <meta.attribute kind="java" basedOn="org.suren.littlebird.actions.bundle.SuRenBundleStartAction:"/> </appinfo> </annotation> </attribute> <attribute name="stop" type="string"> <annotation> <documentation> 停止bundle </documentation> <appinfo> <meta.attribute kind="java" basedOn="org.suren.littlebird.actions.bundle.SuRenBundleStopAction:"/> </appinfo> </annotation> </attribute> </complexType> </element> <annotation> <appinfo> <meta.section type="since"/> </appinfo> <documentation> [Enter the first release in which this extension point appears.] </documentation> </annotation> <annotation> <appinfo> <meta.section type="examples"/> </appinfo> <documentation> [Enter extension point usage example here.] </documentation> </annotation> <annotation> <appinfo> <meta.section type="apiinfo"/> </appinfo> <documentation> [Enter API information here.] </documentation> </annotation> <annotation> <appinfo> <meta.section type="implementation"/> </appinfo> <documentation> [Enter information about supplied implementation of this extension point.] </documentation> </annotation> <annotation> <appinfo> <meta.section type="copyright"/> </appinfo> <documentation> http://surenpi.com </documentation> </annotation></schema>
[/codesyntax]
上面的定义文件org.suren.littlebird.bundles.list.exsd,放在schema目录中。
- 注册
[codesyntax lang="xml"]
<?xml version="1.0" encoding="UTF-8"?><?eclipse version="3.4"?><plugin> <extension-point id="org.suren.littlebird.bundles.list" name="BundlesList" schema="schema/org.suren.littlebird.bundles.list.exsd"/></plugin>
[/codesyntax]
上面的文件是plugin.xml
- 挂载扩展点
[codesyntax lang="java"]
private void regExtension(){IExtensionRegistry reg = Platform.getExtensionRegistry();IConfigurationElement[] extensions = reg.getConfigurationElementsFor("org.suren.littlebird.bundles.list");if(extensions != null){for(IConfigurationElement ele : extensions){if("column".equals(ele.getName())){String textAttr = ele.getAttribute("text");String sorterCls = ele.getAttribute("sorter");TableColumn col = new TableColumn(table, SWT.None);col.setText(textAttr);try {SorterAdapter ext = (SorterAdapter) WorkbenchPlugin.createExtension(ele, "sorter");ext.setViewer(viewer);col.addSelectionListener(ext);} catch (CoreException e) {e.printStackTrace();}}}}}
[/codesyntax]
- 使用扩展点
这时候,你需要新建一个插件工程,不知道怎么新建插件工程?这里有入门教程。
[codesyntax lang="xml"]
<?xml version="1.0" encoding="UTF-8"?><?eclipse version="3.4"?><plugin> <extension point="org.suren.littlebird.bundles.list"> <column text="test" sorter="test.extension.TestSorter"/> <column text="two" /> </extension></plugin>
[/codesyntax]
上面的类test.extension.TestSorter是对列排序的扩展,然后增加了两列——test、two。
- 参考
http://www.cnblogs.com/maxupeng/archive/2011/07/27/2118975.html
查看原文:http://surenpi.com/2015/07/10/eclipse%e6%8f%92%e4%bb%b6%e5%bc%80%e5%8f%91%e8%87%aa%e5%ae%9a%e4%b9%89%e6%89%a9%e5%b1%95%e7%82%b9/
0 0
- Eclipse插件开发自定义扩展点
- eclipse 自定义扩展点
- Eclipse自定义扩展点
- eclipse 自定义扩展点
- 自定义eclipse扩展点
- eclipse自定义扩展点
- 【eclipse插件开发实战】Eclipse插件开发1——eclipse内核结构、扩展点机制
- Eclipse plugins 插件开发学习 - 扩展点介绍
- eclipse RCP 开发中删除插件扩展点
- eclipse插件开发--popMenu扩展点--找不到菜单项
- Eclipse plugins 插件开发学习 - 扩展点介绍
- eclipse扩展点介绍 插件
- Eclipse插件扩展点清单
- Eclipse插件扩展点清单
- Eclipse插件开发tomcat扩展
- Eclipse插件入门:创建扩展点
- Eclipse 插件开发 -- 深入理解菜单(Menu)功能及其扩展点
- Eclipse 插件开发 -- 深入理解菜单(Menu)功能及其扩展点
- Android 中 Handler 引起的内存泄露
- eclipse使用
- hdu 1061 Rightmost Digit 快速幂
- Android中的Intent详解
- 关于singleTask做的测试
- Eclipse插件开发自定义扩展点
- Oracle初探(六)
- SWT/JFace常用组件
- 删除文件及文件夹
- 常用Eclipse插件
- XML与JSON的区别?各自有哪些优缺点?
- SWT开发常见异常
- 哪三样东西永远不能放进数据库里
- tmux(cp:https://wiki.freebsdchina.org/software/t/tmux)