本文并非插件开发的最基础教程,推荐2个网站大家可以看一下(国外的,国内资源太少):

eclipse功能点demo:https://wiki.eclipse.org/Eclipse_Corner

eclipse开发API:http://help.eclipse.org/photon/index.jsp

本教程通过开发一系列elipse的插件,为大家讲解elipse插件的使用。本文为大家讲解:org.eclipse.ui.views扩展点、org.eclipse.ui.handlers扩展点、org.eclipse.ui.bindings扩展点。翻译直接使用百度翻译的API,这里不再讲解。

首先需要使用org.eclipse.ui.views,创建自定义的属性视图,该节点使用起来很简单,只需要在plugin.xml中添加:

<extension point="org.eclipse.ui.views"><category name="Msun Category" id="MsunCategory"></category><viewname="Baidu Translate"icon="icons/translate.png"category="MsunCategory"class="com.msun.plug.view.MyTranslateView"id="com.msun.plug.view.MyTranslateView"></view>
</extension>

然后创建MyTranslateView类,该类需要继承org.eclipse.ui.part.ViewPart类:

package com.msun.plug.view;import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import com.msun.plug.util.bdFanyi.TransApi;/**
* @Title:插件开发
* @Description:MyTranslateView业务类
* @Copyright:MSun (c) 2018年9月3日
*
* @author:jiujiya
* @version:1.0
*/
public class MyTranslateView extends ViewPart {public static final String ID = "com.msun.plug.view.MyTranslateView";public static volatile StyledText resultText;@Overridepublic void createPartControl(Composite parent) {resultText = new StyledText(parent, 0);}/*** 翻译*/public static void translate() {// 先获取选中的文本IWorkbenchPartSite activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().getActivePart().getSite();IEditorPart editorPart = activePage.getWorkbenchWindow().getActivePage().getActiveEditor();if (editorPart != null) {ITextOperationTarget target = (ITextOperationTarget)editorPart.getAdapter(ITextOperationTarget.class);if (target instanceof ITextViewer) {ITextViewer textViewer = (ITextViewer)target;String text = textViewer.getTextWidget().getSelectionText();resultText.setText("原文:" + text + "\r\n译文:" + TransApi.getTransResult(text, "auto", "zh"));}}}@Overridepublic void setFocus() {}
}

然后使用org.eclipse.ui.handlers,创建类TranslateHandler:

package com.msun.plug.handlers;import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.PlatformUI;import com.msun.plug.view.MyTranslateView;/** * Title: 插件开发* Description: 翻译入口* Copyright: MSun (c) 2018年9月3日* * @author jiujiya* @version 1.0 */
public class TranslateHandler extends BaseHandler {public Object execute(ExecutionEvent event) throws ExecutionException {try {// 打开MyTranslateViewPlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(MyTranslateView.ID);MyTranslateView.translate();} catch (Exception e) {alert(event, e.getMessage());}return null;}
}

最后绑定快捷键F9:

<extension point="org.eclipse.ui.bindings"> <key sequence="f9" commandId="com.msun.plug.handlers.TranslateHandler" schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"></key>
</extension>

源码下载地址:https://download.csdn.net/download/jiujiya123/10643080

(本教程是从一个项目中抽取出来的,可能会多引用了一些jar,另外Msun是以前项目名称,可自行修改)

跟着实例学eclipse插件开发--第一篇:翻译插件相关推荐

  1. 跟着实例学Go语言(二)

    本教程全面涵盖了Go语言基础的各个方面.一共80个例子,每个例子对应一个语言特性点,既适合新人快速上手,也适合工作中遇到问题速查知识点. 教程代码示例来自go by example,文字部分来自本人自 ...

  2. 架构师成长之旅_第一篇:插件与框架是什么?

    架构师成长之旅_第一篇:c++插件开发 目录 踏入工作前的准备 框架是什么? 多人开发 一.踏入工作前的准备 在即将踏入工作时,最主要的是你的代码量和你编码能力,最重要的是你的代码质量,在编码界代码质 ...

  3. python自学视频-师傅带徒弟学Python:第一篇Python基础视频课程

    ,赠送一本"Python相关图书". 咨询方式:加[51CTO-关老师付费群]523714201 验证消息:咨询赠书 本视频采用Python 3.x版 本篇包括8章内容,系统介绍了 ...

  4. hapi入门简介----净土小沙弥学hapi.js_第一篇

    为什么使用hapi? 做过网站的人都知道,很多网站都是"麻雀虽小五脏俱全".需要设计缓存,验证和身份验证,进行动态数据加载等. 如果每次开发都从头开始,重新编写代码,只会劳时伤财. ...

  5. 大聪明教你学Java设计模式 | 第一篇:单例模式 (懒汉模式和饿汉模式)

    前言 大聪明在写代码的过程中发现设计模式的影子是无处不在,设计模式也是软件开发人员在软件开发过程中面临的一般问题的解决方案.大聪明本着"独乐乐不如众乐乐"的宗旨与大家分享一下设计模 ...

  6. 【跟着项目学CSS】第一期-闪动LOGO

    最近期末比较忙,没有上CSDN,没有回大家私信[非常对不起]. 进阶版JavaScript下周更新. 今天先浅浅学习一下CSS样式. 22 1.body代码 <body><div c ...

  7. C语言学习——从零开始学编程(第一篇:Visual Studio的下载和第一个C语言程序)

    小颖的话: 也许有很多的小伙伴们和小颖一样,曾在玩着马里奥,贪吃蛇,或者打着植物打僵尸的时候想着这些游戏是怎么运作的❓

  8. eclipse插件开发(四) 流程图绘制插件(雏形)

    1.新建一个Plug-in Project, 名为FlowPlugin, Templates选择Multi-page editor, 后缀指定为flow 2.分为2个页签: 源码和设计, 源码使用XM ...

  9. 边打dota边学java 第一篇

    边打dota边学java之开门见山 既然标题是边打dota边学java,那么博客的内容自然离不开dota和java,java的基本常识就不在此做过多介绍避免大家看后有想吐的冲动,网上随便搜一搜便可以, ...

  10. 跟着王进老师学开发之Python篇第一季:基础入门篇-王进-专题视频课程

    跟着王进老师学开发之Python篇第一季:基础入门篇-2859人已学习 课程介绍         本季课程首先对Python简要介绍,然后演示如何搭建Python的开发环境,以及如何在IDE中调试Py ...

最新文章

  1. html产品列表页的设计,产品列表页.html
  2. 业务智能 ETL 设计实施策略(转载)
  3. 【AWS 安全系列】Amazon S3 配置错误(下)
  4. python3.7安装turtle步骤-Python turtle安装和使用教程
  5. 【数据结构与算法】多种语言(VB、C、C#、JavaScript)系列数据结构算法经典案例教程合集目录
  6. 国家可持续发展议程创新示范区创建工作推进会在北京召开
  7. Python基础(12)--模块
  8. 使用 Hasor 从数据库查询显示到页面上
  9. 有向图的强连通分量--Tarjan算法---代码分析
  10. Chrome网页性能分析工具
  11. java 反射 接口_Java 怎么通过反射获取并实现这个类里面的接口,并且实现接口中的方法...
  12. python爬虫实时转发文章新闻;微信机器人使用;
  13. 【接口测试用例设计思路】
  14. 中科院2020计算机sci分区,2020年中科院最新SCI分区表.pdf
  15. 多目标跟踪之数据关联算法——匈牙利算法
  16. 记一次使用verdaccio 搭建本地私有npm服务器
  17. linux temp文件夹在哪_linux基础知识笔记(第一天)
  18. 阵列分组,不足数,补足
  19. Component Xxx is not part of any NgModule or the module has not been imported into your module.
  20. MySQL转账储存过程_mysql中用存储过程实现转账过程

热门文章

  1. ROS基础篇(四)-- 调试时,常用的命令有哪些
  2. HbuilderX 2.6.15 版本说明
  3. 使用kaptcha快速生成验证码
  4. lnmp一键安装包 mysql_mysql - LNMP一键安装包
  5. Dukto 傻瓜安装教程
  6. 仿微信读书APP原型设计
  7. ThreeJS 实现等值线效果
  8. 华为性格测评注意事项
  9. Linux 查看日志文件命令(整合)
  10. 三菱a系列motion软体_三菱各类伺服电机标准参数一览表