Wednesday, December 2, 2009

Introduction to Eclipse Plugin Development

更多精彩请到 http://www.139ya.com

From : http://www.eclipsepluginsite.com/index.html

Eclipse Plugin Development TUTORIAL

Eclipse Plugin Development Tutorial website to teach you how to develop eclipse plugins using simple examples to a complex eclipse rcp over time. This chapter will give you a detailed insight into Eclipse Architecture and we will develop a simple but fully functional eclipse plug-in so as to give you a quick start with eclipse plug-in development.

Overview

Eclipse isn’t a huge single java program, but rather a small program which provides the functionality of typical loader called plug-in loader. Eclipse (plug-in loader) is surrounded by hundreds and thousands of plug-ins. Plug-in is nothing but another java program which extends the functionality of Eclipse in some way. Each eclipse plug-in can either consume services provided by other plug-in or can extend its functionality to be consumed by other plug-ins. These plug-in are dynamically loaded by eclipse at run time on demand basis.

An Open Platform

Eclipse is an open platform. It is designed to be easily and infinitely extensible by third parties. At the core is the eclipse SDK, we can build various products/tools around this SDK. These products or tools can further be extended by other products/tools and so on. For example, we can extend simple text editor to create xml editor. Eclipse architecture is truly amazing when it comes to extensibility. This extensibility is achieved by creating these products/tools in form of plug-ins.


Figure 1-1


Inside the Eclipse SDK



Figure 1-2

RCP: On the bottom is RCP which provides the architecture and framework to build any rich client application.

IDE: It is a tools platform and a rich client application itself. We can build various form of tooling by using IDE for example Database tooling.

JDT: It is a complete java IDE and a platform in itself.

PDE: It provides all tools necessary to develop plug-ins and RCP applications. This is what we will concentrate on the course of this tutorial.

Plug-ins everywhere

All the layers in eclipse SDK are made up of plug-ins. If you see all the way, you will notice that everything is a plug-in in eclipse sdk.




Figure 1-3

Plug-in Architecture

A plugin is a small unit of Eclipse Platform that can be developed separately. It must be noted that all of the functionality of eclipse is located in different plugins (except for the kernel)





A plug-in can be delivered as a jar file. A plug-in is self-contained bundle in a sense that it contains the code and resources that it needs to run for ex: code, image files, resource bundles etc. A plug-in is self describing - when I say it is self describing it means that it describes who it is and what it contributes to the world. It also declares what it requires from the world.

A Mechanism For Extensibility

Figure 1-7

We all know that eclipse is extensible. In order to achieve this extensibility eclipse uses the concept of extension points and extension. Think of extension point as Electric socket and think of extension as a plug. Plug-in A exposes a extension point (electric socket) which Plug-in B extends by providing an extension (an electric plug). Plug-in A knows nothing about plug-in B. If we think about it this is very similar to concept of Inheritance – we extend functionality of base class to provide more specific implementation. Think of Plug-in A as a text editor and Plug-in B as xml editor. Text editor declares extension point thereby declaring to the world that it is open for extension and xml editor extends text editor by using its extension point to customize it in its own way. It is important to understand that each extension point essentially declares
a contract. An extension point provider only accepts those extensions which abide by the contract.

These extension points and extensions are declared in plugin.xml (discussed earlier). The runtime is able to wire extensions and extension points and form a registry using markup alone.

Plug-in Example

Now that we have covered good amount of architecture basics, its time to get our hands dirty with some actual plug-in coding. The process for creating a plug-in is best demonstrated by implementing a plug-in on which discussion and examples can be based. Here we will take a step-by-step approach to create a simple but fully operational plug-in. This example will try to give you an feel of eclipse plug-in development. However, don’t try to grab all the details at this point. It is fine if you are not able to understand much of the details in this example. Rest of the tutorial will cover all the topics in great depth.

We will build a simple Resource Manager plug-in. Features of this plug-in are as follows:

  • Ability to add/remove resources (essentially files in workspace) to resource manager.
  • Display list of resources which were added to resource manager.
  • Ability to open up associated editor whenever resource is clicked.



No comments: