Friday, May 24, 2019

Step towards Eclipse Plugin Development -Series 1

Step towards Eclipse Plugin Development - Series 1

Few days back, I had an opportunity to write an Eclipse plugin. I had written one before as well, but  I found it very hard to recollect. I will try my best to to capture the concept of plugin development rather than implementation detail. 

Eclipse plugin is hard for first timers, but once you have some basics it is easier to develop. Thanks for eclipse plugin wizard, which comes with sample code & configuration. With some basic knowledge and inbuilt sample code we should be able to penetrate through the Eclipse PDE


Hang a picture on wall:

Consider Eclipse PDE as like hanging a picture on wall. To achieve that we need three things
  1. Picture
  2. Wall position (where to hang)
  3. Nail/ substance to hold picture & wall

In the same way, in eclipse plugin development, we have three things at high level
  1. Plugin - core logic / plugin (picture)
  2. Extension point - where to display the plugin (wall)
  3. Extension - holds the plugin and extension point (nail)


Extension point:


Extension point can be menu, or new wizard (file > new), from where we can host/invoke our plugin

Most used menu types:
Context menu – menu invoked by a mouse right click. Sometimes called also popup menu.
Main menu – menu always visible on the top of GUI.
Main toolbar – always visible toolbar available under the main menu

Plugin:

There are two framework available for menu plugin
1. Handler - depreciated
2. Command

The command/handler class will get the control when user clicks on our plugin menu, from where we can do the logic of our wish.

With this, now lets get our hands into plugin development.

Installation

Ensure Plugin Development Tools and RCP component are installed

Help > install new software >> Choose Eclipse project updates in drop down
choose Eclipse plugin development and RCP





First Plugin Project


Page 1:
File >> New > Eclipse Plugin Project

Enter project name
Target platform - eclipse version the plugin to support. It is always better to develop the plugin on version you target

Page 2:
Check Generate Activator
Rich Client Application: No

Page 3:
Choose Hello world command - will generate sample code, there are also many other sample available, which we may choose as when required


This will create a helloworld plugin, which will be hosted on tool bar, on click of it will print a dialog "Hello, Eclipse world"


Execution:

Right click the plugin project, run as eclipse application
will open a new eclipse instance,where you will be able to find the new plugin


Source Analysis:

Below are the auto generated files in the new project, lets look at it:

Activator class - Take care of eclipse life cycle

*Handler class -  Receives control on click of plugin, and prompt the dialog message

MANIFEST.MF- holds on bundle/target information, like dependencies, target environment, etc
 
build.properties -  holds information about the folders/files needs to considered for packaging

plugin.xml   -      Most important file for plugin, onclick on it will open the  wizard in eclipse editor with multiple tabs. Click on extensions tab, where you will see all the extension used for the plugin. Drill down on menus to see the places where the plugin is configured





With this we have successfully developed our first plugin, in the subsequent series we will look into real time scenarios