Saturday, January 19, 2008

Jump-start Eclipse plug-ins -I - Making your first plugin

Jump-start Eclipse plug-ins -I - Making your first plugin
Recently, a friend of mine approached me with an interesting query. He told me all about the different IDEs he'd seen that were made on top of the Eclipse Platform like Flex Builder and RAD etc. and he was curious to learn how to start - rather jump start with plugin development. I suggested that he read "Contributing to Eclipse" (Gamma et al.) and "Eclipse for the Java Developer".

The following day, I got a phone call from him. He told me that he ha'd given up on that as he thought that the learning curve is too steep. That was surpising, to hear from an experienced Java developer. Upon discussing the matter with other java developers whom I knew, I was surprised to hear them echoing the same sentiment. Now, when I look at it from an unbiased newbie's standpoint, I feel that they were probably right.

An absolute newbie to eclipse development would be bewildered! And if you are impatient, it would be all the more worse. In trying to build Rome in a day, all you would get is another set of acronyms to add to the long list that you already know as a Java developer like SWT, JFace, RCP etc. But the fact is that for the impatient newbie, there isn't an "Eclipse plug-in development in 24 hours". I hope this short introduction jump-starts you into eclipse plugin development.

Without further ado, lets dive right in. Open Eclipse and then create a new Plugin Project. I'll tell you how.


1. Select File>New>Project
2. Select Plug-in Development

From the drop-down that appears, select the Plug-in Project as shown in the figure alongside. If you do not see these options in your eclipse, your version of Eclipse does not incluse the plugins for Plug-In development. You should probably go to eclipse.org and download a version of Eclipse which enables you to devlop plugins.

Ok, now onto the next screen by clicking "Next".









3. Give a name for your project. We are going to make a HTML editor here. So I have named my project as "HTMLEditor".

Dont be afraid seeing abbreviations like OSGi. OSGi is kind of a module system which helps buiding an application out of small, reusable, collaborative components. The eclipse plugin architecture conforms to OSGi, and so does the architecture of WebSphere 6.1, Spring etc. So, you now have a rough idea. It's kind of a platform which enables applicaiotns to be built by assembloing a lot of loosely coupled, reusable modules. For more information on OSGi , you can have a look at http://www.osgi.org
Onward to the next screen...








4. Type in other facny stuff.. like the provider for the plug in..

Here, I'm the provider, so Ive typed in my name. You can type in yours or your company's name. Simple isn't it? Let's click "Next" and march on..

















5. From the "Templates" screen, choose "Plug-in with an editor".

This the screen that the quick and impateint learner should extract a lot of information from. Click on each of the template types and read what they intend to create. To understand that fully, let me give you some basic information. A view is any pane on your eclipse which displays somthing. For example, the "outline", "Package Explorer", "Console", "Errors" are all views. Just try exploring the "Window>Show View" option. That enables you to show up any views which are not shown up in eclipse by default. An editor is right at the center where you edit your java files and XML files. The way Eclipse looks with all it's views and Editors is called a perspective. So, things are arranged in a particular fashin in the "Java development" perspective. The CVS Repository Exploring perspective doesn't need any file edits, so we have a different set of views arranged in anpother way. And don't you see the "Extension Used" haedline on the right hand side of every template description? That just means that this plugin is built on top another already existing plugin using whatever functionality that already exposes. In this context, it is very important to know that Eclipse is just a plug-in runner. It has a very small core program (called the Platform Runtime which is based on OSGi) which keeps executing all the plugins which are built on top of it. I suggest now that you just take a look at the Eclipse Architecture for a better idea. See the picture below for a better idea:


THE ECLIPSE PLUG-IN ARCHITECTURE
The white box right at the bottom is the PlatForm Runtime and the rest are all plug-ins built on top of it. Each plugins carries with it a set of packages and each plug-in extends from Extension Points of the plug-ins which are used to build it. Imagine it like a piece of a jigsaw - it has holes to fit in other pieces and it also has projections which perfectly fit into fissures of the same shape in the adjacent piece. The holes are the extension points of the plug-in which can be used to fit other plug-ins on top. And the projection fits into another already existing hole - that hole is the extension point of some already existing plug-in which was used by our plug-in. So our editor plug-in uses the extension points of the org.eclipse.ui.editors plugin and extends from it. Okay, onto the final screen now.

6. Fill in other details.
Name your Editor Class. I have named it as HTMLEditor. And in the file extension, I have typed in html because our editor is going to be associated with html files. Click finish. And we have our basic HTML Editor ready!



Now that we have some key concepts in the bag. Let's take a breather now. I'll see you in the next part for adding more features into it.