Scripting Eclipse RCP with JavaScript?!?

Ward and I have been talking about mashups a lot lately. We both think that Eclipse RCP is a great vehicle for building mashups on the desktop (we don’t think that mashups should be exclusive to the web). I’ve managed to invoke a few web services and do some interesting things from within Eclipse, but thus far, everything has required a lot of Java programming.

Then I thought of Eclipse Monkey (Dash Project). Eclipse Monkey is the result of some work done by Bjorn and Ward to bring scripting to Eclipse. You can use Eclipse Monkey to do all sorts of things provided you have a rich enough set of DOMs. DOMs basically contribute functionality that manifest as variables you can access in your scripts. The DOMs themselves are pretty easy to create; making them do interesting things is the challenge. But if you build reasonably good DOMs, you can reuse the heck out of them.

Anyway, it occurred to me that Eclipse Monkey can be used to invoke web services and create views and just about anything else you can imagine if you provide the right set of DOMs. Why not use Eclipse Monkey to drive a mashup?

I spent the afternoon coding up a couple of DOMs:

The first DOM contributes a variable named “Flickr”. You can use this variable to search for photos on by providing a search phrase. The method returns a bunch of objects containing data about the photos, including a title and enough information to find the actual image itself.

The second DOM contributes a “TableView”. This is an Eclipse view that contains a table. You can tell the table to add and remove columns (columns are moveable and resizeable). When you add a column, you provide a label for the column, what to display, and an initial width. The “what to display” is either the name of a JavaScript function or the name of a property. The function or property is used on each object in the table to compute what will be displayed for that object in the column.

You can create any number of these “TableViews”. When you “get” the TableView, you provide an id. If you ask for a TableView with the same id twice, you get the same instance back. Use a different id, and you get a different TableView.

The third DOM contributes an “ImageViewer”. It listens to the workbench’s selection service and when the selection changes, it asks the selected object for an image to display. Currently, if the selected object has a “getImageUrl” method, it is invoked, and the resulting URL is used to download the image which is displayed. At some point, I’ll probably add the ability to provide the view with a JavaScript function to invoke on the object to get the image. I leveraged the Image View plugin I wrote about a few days ago for this so it displays a scaled version that gets enlarged when you hover over it.

Each of these DOMs is completely decoupled from the others. Everything is completely reusable.

Here’s a script that I wrote to test this out:

* Menu: Fun
* DOM: http://needanupdatesite/
* DOM: http://needanupdatesite/org.eclipse.monkey.console
* DOM: http://needanupdatesite/org.eclipse.monkey.table
* DOM: http://needanupdatesite/org.eclipse.monkey.image

function main() {;
table = Table.getTable("photos");
table.setName("Photos of Wayne");
table.addColumn("Id", "id", 100);
table.addColumn("Title", getTitle, 200);
table.addColumn("URL", "imageUrl", 200);
images ="Wayne");

function getTitle(object) {
return object.title;

and here’s what it produces:

This is running in Eclipse 3.2M4. You can see the TableView open in the bottom right corner, displaying the results of searching Flickr. The image view (bottom left) displays the image corresponding to the object selected in the table. When you change your selection, the image changes.

There’s still a lot of work to do to make this really useful. Each of the DOMs is pretty simple and each basically does what I need it to do and little more. I’m going to spend some time making a little more useful (like make the table sortable on all columns). Also, this isn’t really much of a mashup yet since I’m only using one service. Now that I’ve proven that this works, I need to make DOMs for more services and work out how to actually mash things together…

And then, of course, I have to sort out how to package this all up in an Eclipse RCP application. I have some thoughts about this that I’m going to explore over the next couple of days. When I get this sorted out, it will be possible to create an Eclipse RCP using JavaScript. Maybe that will open the doors for other scripting languages…

This entry was posted in Uncategorized. Bookmark the permalink.

8 Responses to Scripting Eclipse RCP with JavaScript?!?

  1. murphee says:

    Wayne, if you’d like to use an interactive shell for prototyping or creating Eclipse Monkey scripts: I created the EclipseShell project: supports JavaScript (Rhino), but also JRuby and Beanshell.If you look at the Screencastspage: can see some demos, whereI build a simple View (a ClassBrowser) using JRuby.The EclipseMonkey DOMs will be very useful for that too; in the long run I hope that Eclipse can become even more like Smalltalk, ie. write most of an RCP app in some dynamic language…

  2. Henrique says:

    “in the long run I hope that Eclipse can become even more like Smalltalk, ie. write most of an RCP app in some dynamic language…”this is my dream…+1 !Henrique

  3. Dominique Boucher says:

    The SchemeScript plug-in ( can also be used to script Eclipse. It provides a Kawa Scheme console that can be used to inspect editors, the JDT, etc. Some of its features have been implemented by dynamically evaluating code.And I wonder whether the Eclipse Shell’s ScratchPadView has been modelled on the Kawa Scratchpad view that comes with SchemeScript…

  4. murphee says:

    @Dominique Boucher:Wow, SchemeScript looks nice, I’ll have to check that out. But: The EclipseShell ScratchpadView was not taken from/inspired by it; I just needed something to experiment with Draw2D graphs, and that’s easier in an interactive environment.

  5. Evan says:

    This looks really great. I’ve installed the samples, and the eclipsemonkey code from eclipse – I’d like to start experimenting with my own doms as well.I’m struggling with getting my own dom to load: I’ve created the plugin, the feature, and an update site.Is it possible to load a dom from an eclipse “local update” site (as opposed to remote). I tested loading my feature this way and all was well. But I can’t seem to get monkey to recognise a local URL … specifying it as file:///c:/ … etc,I see you used the “ineedanupdatesite” placeholder. Do you have any hints ?thanks,Evan

  6. Wayne says:

    Hey Evan. To be honest, I haven’t had a chance yet to try building an update site for Eclipse Monkey. My focus has been elsewhere. Ward recently announced “Dash Time”, where you can dial in and discuss EclipseMonkey/Dash…

  7. Ricky Clarkson says:

    I’d like to see a Beanshell or JavaScript script/dom/both that gives me a programmatic view of all the source files in my project, so that I can write Java-sensitive scripts.The scripts I’ve seen so far have all been simple outputting or a regex search for System.out.println – my requirements are more Java-based than that.Specifically, see for what I’m aiming to do with Eclipse Monkey (and probably cannot do with pmd).

  8. Thomas says:

    Are the mentioned DOM plugins availabe somehow (for download)?We’re currently investigating possibilities for Eclipse Scripting (using MonkeyScript) and are especially looking for samples and people who already have (successfully) used MonkeyScript…best regardsThomas Koch

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s