I’ve revamped the pastebin website (http://pbin.oogly.co.uk) – which is based on CakePHP (a model view controller PHP framework) and SyntaxHighlighter (http://alexgorbatchev.com/wiki/SyntaxHighlighter).  I also created an Eclipse plugin to interface with the website.

pbin-sel5

A pastebin allows you to share a patch/code selection/text selection with other people without having to resort to email/instant messenger.  You can either interact with pastebin via the URL or above or install the Eclipse plugin.  If you’ve installed the Eclispe plugin you then right click on the code/text you want to share and select Pastebin->Create Pastebin from the menu.  More instructions and screenshots are available on the website.

The Eclipse architecture is a little strange to start with, the support it provides via the extensions framework is easy enough to understand, although I’m a little confused now that they’ve announced declarative services and their bizarre use of OSGi. The plugin uses the org.eclipse.ui.popupmenus extension.  Dependency wise, I used the Eclipse UI and runtime along with the JFace Textfield components to provide the URL for the created pastebin.  The main plugin itself is made up of an Activator class along with a NewPastebinAction class which implements IObjectActionDelegate which provides a run(IAction action) method.  This obtains the current selection and checks to see whether it is a TextSelection (editor content selection) or a StructuredSelection (a package explorer/navigator file selection).

The selection is then wrapped in a simple domain object and passed to a web client facade that uses the Apache HttpClient (http://hc.apache.org/httpclient-3.x/) framework to provide connectivity with the pastebin website.

Finally, it uses a custom OkInputDialog to present the pastebin URL back to the user.

It’s not perfect at present (I need to unpick the dependency on the JDT plugin for the StructuredSelection), but it serves as a first attempt at creating a Eclipse plugin and understanding the internals of the Eclipse API.  Also, it unfortunately does not autodetect the file type and convert it into the internal pastebin format.

Packaging the plugin was very straightforward.  It involved using the File->Export function provided by Eclipse to package it into an appropriate JAR file.  Alternatively, you can publish an update site, I did this by creating a new feature project (and adding the plugin to it) then exporting the the update site using Eclipse.

I’m going to take the pastebin as a starting point for more collaborative features.