Contributing to Eclipse: Understanding and Writing Plug-ins.

47
Contributing to Eclipse: Understanding and Writing Plug-ins

Transcript of Contributing to Eclipse: Understanding and Writing Plug-ins.

Page 1: Contributing to Eclipse: Understanding and Writing Plug-ins.

Contributing to Eclipse:

Understanding and Writing Plug-ins

Page 2: Contributing to Eclipse: Understanding and Writing Plug-ins.

Tutorial Outline

• Understanding the Contribution Cycle• Introducing the technical side of Eclipse• Using Eclipse to explore Eclipse• Becoming an Extender• Becoming an Enabler

Page 3: Contributing to Eclipse: Understanding and Writing Plug-ins.

Eclipse is an IDE framework

• Is more than a Java IDE– Eclipse + JDT = Java IDE�– Eclipse + CDT = C/C++ IDE– Eclipse + PHP = PHP IDE

• Language Editor/Debugger/Refractor

Page 4: Contributing to Eclipse: Understanding and Writing Plug-ins.

Eclipse is a Tools Framework

• Tools extend the Eclipse platform using plug-ins– Business Intelligence and Reporting Tools (BIRT)– Eclipse Communications Framework (ECF)– Web Tools Project (WTP)– Eclipse Modelling Framework (EMF)– Graphical Editing Framework (GEF)– Test and Performance Tooling Project (TPTP)

Page 5: Contributing to Eclipse: Understanding and Writing Plug-ins.

Eclipse is a Rich Client Platform

Page 6: Contributing to Eclipse: Understanding and Writing Plug-ins.
Page 7: Contributing to Eclipse: Understanding and Writing Plug-ins.
Page 8: Contributing to Eclipse: Understanding and Writing Plug-ins.

Platform vs. Extensible Application

Page 9: Contributing to Eclipse: Understanding and Writing Plug-ins.

Platform Implications

• Everybody can contribute plug-ins– Every programmer can be a tool smith

• Creating opportunities for further extension makes it possible for the tool smith to benefit from the work of others

• It has to be easy to install and manage plug-ins

Page 10: Contributing to Eclipse: Understanding and Writing Plug-ins.

Eclipse Involvements

Page 11: Contributing to Eclipse: Understanding and Writing Plug-ins.

Eclipse Involvements

• Users– Users of Eclipse

• Extenders– Providers of extensions to existing extension

points• Enablers– Providers of extension points others provide

extensions for

Page 12: Contributing to Eclipse: Understanding and Writing Plug-ins.

As an eclipse user

• common user interface paradigm– Workbench– Views – navigation support, properties– Editors – edit files, e.g. Java Editor– Perspectives – arrangement of views and editors– Preference / Property – Global/Local settings

• Hot Keys for Java developer– Ctrl+Shift T Find Type– Ctrl+Shift M Find Import– Ctrl+Shift F Format– Ctrl 1 Quick Fix

Page 13: Contributing to Eclipse: Understanding and Writing Plug-ins.

Tutorial Outline

• Understanding the Contribution Cycle

• Introducing the technical side of Eclipse• Using Eclipse to explore Eclipse• Becoming an Extender• Becoming an Enabler

Page 14: Contributing to Eclipse: Understanding and Writing Plug-ins.

Eclipse Plug-in Architecture

• Plug-in – set of contributions– Smallest unit of Eclipse functionality�– Big example: HTML editor�– Small example: Action to create zip files�

• Extension point - named entity for collecting contributions– Example: extension point for workbench

preference UI

• Extension - a contribution– Example: specific HTML editor

preferences

Page 15: Contributing to Eclipse: Understanding and Writing Plug-ins.

Contribution Rule

• Everything is a contribution.• Each plug-in– Contributes to 1 or more extension points– Optionally declares new extension points– Depends on a set of other plug-ins– Optionally contains Java code libraries and other files– May export Java-based APIs for downstream plug-ins– Lives in its own plug-in subdirectory

• Theoretically unbound number of plug-ins

Page 16: Contributing to Eclipse: Understanding and Writing Plug-ins.

Eclipse Plug-in Architecture

• Allow for loading on demand by separating declaration and implementation:– Declaration of plug-in contributions• Describes plug-in functionality• Describes UI elements to present plug-in functionality• Used by the platform to render parts of the plug-in’s UI• Specifies implementation classes

– Implementation of plug-in contributions• Implemented in Java and provided as Java archive• Is loaded on demand�

Page 17: Contributing to Eclipse: Understanding and Writing Plug-ins.

Tip of the Iceberg

• Startup time: O(#used plug-ins), not O(# installed plug-ins)

Page 18: Contributing to Eclipse: Understanding and Writing Plug-ins.

Eclipse Plug-in Architecture

• Plug-in details spelled out in the plug-in manifest– Manifest declares contributions– Code implements contributions and provides API– plugin.xml file in root of plug-in subdirectory

Page 19: Contributing to Eclipse: Understanding and Writing Plug-ins.

Plug-in Manifest

Page 20: Contributing to Eclipse: Understanding and Writing Plug-ins.
Page 21: Contributing to Eclipse: Understanding and Writing Plug-ins.

Eclipse Platform

• Eclipse Platform is the common base• Consists of several key components

Page 22: Contributing to Eclipse: Understanding and Writing Plug-ins.

Strata Rule

• Separate core functionality from UI functionality.– Workspace Component– Workbench Component

Page 23: Contributing to Eclipse: Understanding and Writing Plug-ins.

Workspace Component

• Project – Folder – Files termed resources• Meta data management:�– Natures (e.g., Web, Java)– Markers

• Incremental builders• Local history

Page 24: Contributing to Eclipse: Understanding and Writing Plug-ins.

Workbench Component

• SWT – generic low-level graphics and widget toolkit• JFace – UI frameworks for common UI tasks• Workbench – UI personality of Eclipse Platform

Page 25: Contributing to Eclipse: Understanding and Writing Plug-ins.

SWT

• A portable widget set– OS-independent API– Uses native widgets where available– Emulates widgets where unavailable

• Supported platforms– Win32, WinCE– Linux/Motif, Solaris/Motif, AIX/Motif, HP-UX/Motif,…– QNX/Photon, Linux/GTK, – Mac OS X/Carbon

Page 26: Contributing to Eclipse: Understanding and Writing Plug-ins.

JFace

• UI framework built on top of SWT– Viewers• Model aware adapters for SWT widgets• Trees, tables, lists, styled text, ..

– Dialog, Preference and Wizard frameworks– Actions• Location-independent user commands• Contribute action to menu, tool bar, or status line

Page 27: Contributing to Eclipse: Understanding and Writing Plug-ins.

Workbench

• Defines common user interface paradigm– Workbench– Views – navigation support, properties– Editors – edit files, e.g. Java Editor– Perspectives – arrangement of views and editors

• Extended by contributing– Views, editors, preference pages, wizards, …

Page 28: Contributing to Eclipse: Understanding and Writing Plug-ins.

Tutorial Outline

• Understanding the Contribution Cycle• Introducing the technical side of Eclipse

• Using Eclipse to explore Eclipse• Becoming an Extender• Becoming an Enabler

Page 29: Contributing to Eclipse: Understanding and Writing Plug-ins.

Explore Eclipse with Eclipse

• The Plug-in Development Environment• Explore a running Eclipse installation• Create a self-hosting workspace

Page 30: Contributing to Eclipse: Understanding and Writing Plug-ins.

Plug-in Development Support

Page 31: Contributing to Eclipse: Understanding and Writing Plug-ins.

Plug-in Development Environment

• Extenders use PDE to implement plug-ins• PDE = Plug-in development environment• Specialized tools for developing Eclipse plug-ins• Built atop Eclipse Platform and JDT• Features– Specialized views to explore a running Eclipse installation– Specialized PDE editor for plug-in manifest files– Templates for new plug-ins– PDE runs and debugs another Eclipse workbench

Page 32: Contributing to Eclipse: Understanding and Writing Plug-ins.

Available and Activated Plug-ins

Page 33: Contributing to Eclipse: Understanding and Writing Plug-ins.

Self-hosting Workspace

• PDE allows to import the plug-ins of a running Eclipse installation into an Eclipse workspace

• Locate implementation class using plugin spy

Page 34: Contributing to Eclipse: Understanding and Writing Plug-ins.

Self-hosting Workspace

• Plug-ins correspond to Java projects�• Source projects “projects you are working on”• Binary projects “projects you are browsing

only”– Source can be inspected

Page 35: Contributing to Eclipse: Understanding and Writing Plug-ins.

Tutorial Outline

• Understanding the Contribution Cycle• Introducing the technical side of Eclipse• Using Eclipse to explore Eclipse

• Becoming an Extender• Becoming an Enabler

Page 36: Contributing to Eclipse: Understanding and Writing Plug-ins.

Becoming an Extender

• Contributions do not– Override existing behavior– Remove or replace existing components– Harm existing or future contributions

Page 37: Contributing to Eclipse: Understanding and Writing Plug-ins.

Becoming an Extender

• Create the Course Explorer plug-in• Import the business layer source to workspace• Declare and sketch the implementation of the

Course Explorer View• Create a PDE launch configuration• Run the Course Explorer• Finalize the implementation

Page 38: Contributing to Eclipse: Understanding and Writing Plug-ins.

Create a PDE launch configuration

Page 39: Contributing to Eclipse: Understanding and Writing Plug-ins.

Viewer Details

• Adapt domain model to a Viewer

Page 40: Contributing to Eclipse: Understanding and Writing Plug-ins.

View Details

Page 41: Contributing to Eclipse: Understanding and Writing Plug-ins.

Becoming an Extender

• Another example:– Popup qualified Java class file Name and show java structure

view• Step:

– Create an eclipse plug-in project– Add dependencies(org.eclipse.jdt.core, org.eclipse.jdt.ui)– Copy qualified name of (org.eclipse.jdt.core.ICompilationUnit)– Add a popup extension.

• Name with ~ShowJavaTreeViewAction~Test the action

– Create a tree view– Reuse JavaElementLabelProvider and

StandardJavaContentProvier

Page 42: Contributing to Eclipse: Understanding and Writing Plug-ins.

Tutorial Outline

• Understanding the Contribution Cycle• Introducing the technical side of Eclipse• Using Eclipse to explore Eclipse• Becoming an Extender

• Becoming an Enabler

Page 43: Contributing to Eclipse: Understanding and Writing Plug-ins.

Tutorial Outline

• Identify the scope of contributions to your plug-in

• Declare the extension points• Implement the extension points• Consume the new extension points

Page 44: Contributing to Eclipse: Understanding and Writing Plug-ins.

作业• 自行实现课堂上讲解的拼写检查的示例– 提示:三个主要的类型:

• SpellChecker/IDictionary/IWordIterator

• 利用上述的组件,实现一个具有以下功能的Eclipse 插件:– 在 PackageExplorer视图中选取一个文件,在右键菜单中增加 OOADSpell Check菜单项。

– 选中后,根据选中文件的类型,选取适当的拼写检查器进行检查,并将检查的结果以表格的形式显示在一个名为 Spell Check Result的视图中。表格包括两栏:错误单词和错误次数。

Page 45: Contributing to Eclipse: Understanding and Writing Plug-ins.

作业• 需要支持对文本文件 (.txt)和 (.xml)文件的检查, XML文件检查时需要简单地忽略掉’ <‘和’ >’之间的内容(不必考虑特殊情况,如 xml文件的格式错误)。

• 可选:– 对于有能力的同学,可以考虑定义扩展点,使得第三方开发者能够提供对其它文件格式的拼写检查的支持。

• 可参考的资料:– 示例– Platform Plug-in Developer Guide(Eclipse Help)– The Official Eclipse FAQs:

http://wiki.eclipse.org/The_Official_Eclipse_FAQs

Page 46: Contributing to Eclipse: Understanding and Writing Plug-ins.

作业讲解

Page 47: Contributing to Eclipse: Understanding and Writing Plug-ins.

主要问题• 包含统计的概念• 有些过度设计的内容–如包含了 Project/Schedule

• 依然有将用例和概念模型混杂在一起的情况–如包含执行任务 /登录系统的概念