Eclipse插件开发自定义扩展点_chuannaoxuan4674的博客-程序员秘密

技术标签: java  开发工具  

  • 介绍
如果你的插件写的有特色,想拿来用,但是还不能或者不适合直接修改你的代码,怎么办呢?解决方案当然是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

转载于:https://my.oschina.net/surenpi/blog/481920

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/chuannaoxuan4674/article/details/101047698

智能推荐

在一台服务器建立多个web站点的方法,在一台WEB服务器上实现建立多个Web网站站点的几种方法..._weixin_39761696的博客-程序员秘密

我们知道,网络上的每一个Web站点都有一个惟一的身份标识,从而使客户机能够准确地访问。这一标识由三部分组成,即TCP端口号、IP地址和主机头名,要实现“一机多站”就需要在这三个方面下工夫。现在我们有一台服务器,在这台服务器上要建立默认站点“余志国网站设计工作室”和新增站点“中国鄱阳网”(建立更多网站原理相同),下面我们分别探讨三种不同的实现途径。途径一、TCP端口法我们知道Web站点的默认端口一般...

值得推荐的C/C++开源框架和库_weixin_30364147的博客-程序员秘密

原文链接:http://coolshell.info/c/c++/2014/12/13/c-open-project.htm留档备查,非常强大的C/C++开源项目总结文档~值得学习的C语言开源项目- 1. WebbenchLinux下使用的非常简单的网站压测工具。它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万...

uc浏览器下载的视频怎么导出来?导出方法分享_虎观~艺的博客-程序员秘密

很多时候用户都会使用浏览器下载视频和文件,那么用户已经下载的视频要如何导出呢,这时候如果不知道怎么操作,那么就往下看下去吧,今天小编会与大家一起来分享一下如何将uc浏览器下载的视频导出的方法,其实操作下来还是非常方便的,有兴趣的用户就来马上学习使用吧,下面有详细的文字和图片,在操作的时候只要按照要求和步骤就可以了,任何一个步骤都有详细解说,马上就让用户将自己下载的视频导出来,方便用户更好的使用。uc浏览器下载的视频怎么导出来首先,我们要打开已经安装好 UC浏览器软件,在浏览器窗口右侧找到“菜单栏”图标的

【HTML5播放器】DPlayer播放器使用指引(支持m3u8等多格式)-程序员秘密

文章目录DPlayerDPlayerGithub项目地址官方说明文档镜像引用地址参考示例代码更多内容

Docker数据管理及实例_docker 实例数_Zmac111的博客-程序员秘密

docker数据管理一、管理方式1.数据卷2.数据卷容器二、容器互联(使用centos镜像)三、docker镜像创建1.基于已有镜像创建2.基于本地模板创建3.基于 Dockerfile创建(1)联合文件系统(UnionFS)(2)镜像加载原理(3)Docker里的centos的大小为200M的原因(4)Dockerfile概述四、Docker 镜像结构的分层五、Dockerfile 操作常用指令1.FROM 镜像2.MAINTAINER 名字3.RUN 命令4.ENTRYPOINT ["要运行的程

垃圾回收机制之标记清除算法_Leon_Jinhai_Sun的博客-程序员秘密

这个时候我来讲一下垃圾回收策略,主要分为这几种1. 标记清除算法就相当于给一个对象做一个标记,怎么做标记呢,其实是这样做标记的,比如举个例子,这个地方假如是堆内存,比如你创建一个对象的时候,User user = new User();你拿到user对象的时候,这个时候是存活的,会起一个标记,那这边怎么做标记呢,0标识为存活,1标识为没有存活的,比如这个时候我的垃圾回收机制回收的...

随便推点

Elasticsearch 6.3 发布,支持SQL搜索_狮子头儿的博客-程序员秘密

如题目所言,SQL模块作为C-Pack的一部分发布于Elasticsearch 6.3。但是官方文档也明确写明下面一段话:大致意思就是:“这个功能是实验性的,以后没准儿改变或者完全移除(人家先打个预防针儿,以后发生什么都没准儿,所以期待不要太高……)”。不过,这个东西已经发布出来了,应该也不会说放弃就放弃吧。今天做了一下实验,简单分享一下。安装因为是简单测试,所以直接在windows下安装的单机。...

鸿蒙gradle,build.gradle_老王理财经的博客-程序员秘密

// Top-level build file where you can add configuration options common to all sub-projects/modules.apply plugin: 'com.huawei.ohos.app'apply plugin: 'kotlin'ohos {compileSdkVersion 3defaultConfig {comp...

【bzoj3689】异或之 trie+堆_qingdaobaibai的博客-程序员秘密

好多种解法,自己YY了一种二分答案+trie的做法,不过貌似还是O(nlog^2n)的,看了一下PoPoQQQ大神的题解,发现可以用堆来做,先把每个位置的最小值放入堆里,每次弹出一个元素,假设这个元素是对应位置的第k小,那么把对应位置的第k+1小放入堆中。一个巧妙的处理,因为会重复,所以取2*k次,只取奇数次的就可以了。一开始要考虑自己的问题,所以每个位置的第二小值放入堆中。#

计算机网络 什么是帧头部,帧头是什么意思_weixin_39965102的博客-程序员秘密

1. 本发明公开了一种超3代(B3G)移动通信系统下的媒体接入控制层帧结构。包括9个字段,其顺序及每个字段的位数依次为:用户标识字段;业务标识字段,位数为3比特;分段标识字段,位数为3比特;标志字段,位数为1比特;偏移量字段,位数为6比特;长度字段,位数为8比特;保留字段,位数为3比特;帧头校验字段,位数根据采用的前向纠错编码算法而定;数据字段。This invention discloses a...

重新定义高端存储架构,华为Dorado V6树立全闪存新标杆_大数据在线的博客-程序员秘密

企业级存储正在迎来它真正的全闪存时代。由于闪存介质在成本上的不断下降,闪存容量的不断攀升,以及软件功能的不断完善,全闪存存储逐渐成为市场的主流。根据IDC的统计数据,全闪存存储的营收规模已经与传统基于机械硬盘和混合介质的存储系统相接近,甚至在某些地区,全闪存存储的份额已经实现了超越。可以说,全闪存存储是企业级存储市场最大的未来。作为全球全闪存市场增速第一的厂商,华为近日发布了其全新一代智能...

Linux Or Ubuntu动态磁盘 挂载(带区卷)Win10 Ubuntu 双系统 ldmtool_linux能做带区吗_dendysan的博客-程序员秘密

Linux Or Ubuntu动态磁盘 挂载(带区卷) Win10 Ubuntu 双系统 ldmtool环境介绍系统win10ubuntu 20.4 Desktop LTS磁盘/sda 与 /sdb win10 带区卷 (动态磁盘)/sdc Win10 系统盘/sdd Ubuntu 系统盘 sudo lsblk --------sda 8:0 0 465.8G 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2