Drawing Hands by M.C. Escher (1948)

Jeff Mesnil

Archive for the ‘eclipse’ Category


JMX Scripts with Eclipse Monkey

On May 23rd, 2007 in eclipse, java, jmx (1 Comment »)

Continuing the series about “writing JMX scripts in a dynamic language”, after Ruby (part I & II), let’s do that in JavaScript.

Aside of the use of a different scripting language, this example differs completely from the Ruby one by its context of execution: it will be integrated into Eclipse and called directly from its user interface (using Eclipse Monkey as the glue).

The example will:

  1. ask graphically the user for a logging level
  2. update all the JVM’s loggers with this level
  3. display all the loggers of the JVM

in 50 lines of code.

This example is simple but it implies several interesting steps:

There are many use cases where you have to perform theses steps in repetition. It’s tedious to do that in a JMX console (e.g. jconsole or eclipse-jmx) and most of the time, it is not worth writing a Java application.

These use cases beg to be scripted.

(more…)

Add a filter to a TreeViewer

On February 26th, 2007 in eclipse, java, jmx (3 Comments »)

In eclipse-jmx, a plug-in to manage Java applications through JMX, I have a view which displays registered MBeans using a TreeViewer.
Since there can be many MBeans to display (e.g. more than 200 just for Tomcat), it is tedious to navigate in the Tree by expanding many nodes before finding the MBeans I want to manage. To make it more usable, I wanted to add a filter text to the view to show only the MBeans which are interesting to me. (more…)

Equinox Resources Monitoring

On August 22nd, 2006 in eclipse, java, jmx, osgi (1 Comment »)

Too much work is done around Eclipse (RCP, Equinox, BIRT, Monkey) that I can’t follow all the things which interests me.

However, by browsing the mailing list of the Equinox (Eclipse’s OSGi implementation), I discovered a cool new project in the Equinox incubator: Resources Monitoring.

Its mission statement?

To provide a framework for monitoring resources that are contributed by bundles installed on the host machine. The term ‘resources’ is used to describe something as specific as a single object or something as abstract as an OSGI bundle.

It seems to use JMX to manage the resources and to provide both the server and the client code to manage the resources.

Definitively worth a look…

An Outliner application based on Eclipse RCP

On July 31st, 2006 in eclipse, java (2 Comments »)

While cleaning up my workpace, I (re) discovered a small application I wrote to familiarize myself with Eclipse editors development.

It is a simple outliner which reads and writes OPML files. Each OPML file is opened in an Eclipse Editor. You can navigate the outliner, indent/outdent the outlines, create new outlines and edit them.
To toggle between the edition and the navigation modes, you can use the ESC key (like in vi).

Eclipse Outliner Screenshot

The code is pre-pre alpha (hence the 0.1.1 version) and a lot of essential features are missing:

The fun part of the application is the OutlinerEditor. Each OutlinerEditor is composed of a TreeViewer which displays the outline. The TreeViewer is not editable but each cell of the tree can be edited in place (a la SWT snippet #111).

I released this project on Google Code’s project hosting under the Apache License 2.0 and created a corresponding web site to complement the project home. You can check it out using Subversion but to make it simpler to check out, you can import in your workspace the Outliner Team Project Set (provided you have a Subversion plug-in like Subclipse). I don’t plan to work extensively on this application but I thought it could be of some interest for new Eclipse RCP developers.

I developped the application on Mac OS X and had the bad surprise to see that the application is not working properly on Linux because I can’t navigate the tree with the arrow keys (see issue #3). It seems to be a “bug” in SWT since I can’t navigate with the arrow keys in SWT snippet #111 either. Though I’m not sure this is a SWT bug or a platform specific behavior…

Eclipse’s ISetSelectionTarget interface

On July 3rd, 2006 in eclipse (4 Comments »)

I just found a new Interface in Eclipse which I found quite handy.

Let’s say that you have an action which creates a new resource and you want to notify views that they have to show this resource.

The key interface is ISetSelectionTarget. If your views respond to this interface (by implementation or adaptation), they can then receive a selectReveal(ISelection selection) message.

For example, one of my view implements ISetSelectionTarget and defines the method:

    public void selectReveal(ISelection selection) {
       StructuredSelection ssel = convertSelection(selection);
       if (!ssel.isEmpty()) {
          viewer.getControl().setRedraw(false);
          viewer.setSelection(ssel, true);
          viewer.getControl().setRedraw(true);
       }
    }

How do you send this selectReveal() message from your action?
An example is found in the JDT, in the org.eclipse.ui.wizards.newresource.BasicNewResourceWizard class:

  public static void selectAndReveal(IResource resource, IWorkbenchWindow window) {
    // validate the input
    if (window == null || resource == null)
        return;
    IWorkbenchPage page = window.getActivePage();
    if (page == null)
        return;

    // get all the view and editor parts
    List parts = new ArrayList();
    IWorkbenchPartReference refs[] = page.getViewReferences();
    for (int i = 0; i < refs.length; i++) {
        IWorkbenchPart part = refs[i].getPart(false);
        if (part != null)
            parts.add(part);
    }
    refs = page.getEditorReferences();
    for (int i = 0; i < refs.length; i++) {
        if (refs[i].getPart(false) != null)
            parts.add(refs[i].getPart(false));
    }

    final ISelection selection = new StructuredSelection(resource);
    Iterator itr = parts.iterator();
    while (itr.hasNext()) {
        IWorkbenchPart part = (IWorkbenchPart) itr.next();

        // get the part's ISetSelectionTarget implementation
        ISetSelectionTarget target = null;
        if (part instanceof ISetSelectionTarget)
            target = (ISetSelectionTarget) part;
        else
            target = (ISetSelectionTarget) part.getAdapter(ISetSelectionTarget.class);

        if (target != null) {
            // select and reveal resource
            final ISetSelectionTarget finalTarget = target;
            window.getShell().getDisplay().asyncExec(new Runnable() {
                public void run() {
                    finalTarget.selectReveal(selection);
                }
            });
        }
    }
  }

However, your code does not need to be that generic. If you already know which view may be interested to be notified, you can use

IViewPart part = page.findView(viewId):

to retrieve the interested IViewPart and after checking that it will respond to ISetSelectionTarget (either by implementation or adaptation), you can send it a selectReveal() message directly.

Eclipse 3.2 and Welcome page on Ubuntu

On July 3rd, 2006 in eclipse (4 Comments »)

Eclipse 3.2 is out and it is a great release. :-)

However, the default Welcome page I had on my Ubuntu desktop is quite broken

Broken Welcome Page in Eclipse 3.2

After a little search on eclipe.org SWT FAQ, it appears that by default, Ubuntu is missing the MOZILLA_FIVE_HOME which is required by SWT to use the web browser internally.

I just added this variable before starting Eclipse:

export MOZILLA_FIVE_HOME=/usr/lib/mozilla-firefox/

and the Welcome page appeared as expected:

Welcome Page in Eclipse 3.2

I really like the new theme (Circles) by the way. )

How to stop SWT Control traversal action

On April 18th, 2006 in eclipse (No Comments »)

Another ah-ha moment with Eclipse

It is quite simple but I stumble upon it before finding how in Eclipse you can stop the traversal of SWT Control from a TraverseListener implementation.

In your listener, handle the TraverseEvent event and then just

event.doit = false;

and the system will stop traversing the Controls.

Everything is well explained in TraverseEvent javadoc (but I’m guilty of not reading javadoc until I need it…). The explanation is worth a read and shows how powerful traversal can be in eclipse using both TraverseEvent detail and doit fields.

Highlights of Greg Stein’s keynote

On March 22nd, 2006 in eclipse (2 Comments »)

Some highlights from Greg Stein’s keynote

The Apache Way

  • Communities first, code second
  • Communities over individuals
  • Apache central to Open Source work but Eclipse is also gravitating to the center
  • The license trend is going to the bottom

 Proprietary
  |
  v
 Restricted
  |
  v
 Copyleft (GPL, EPL)
  |
  v
 Non-copyleft (APL, BSD)   

I found it quite interesting to see how Apache is organized and how Eclipse compares to it.

For now, there is few overlaps between Apache and Eclipse communities but it has already started.
For example, both communities now offer an OSGi implementation:

It it going to be interesting to see where things are going…

Use case for scripting a RCP application

On March 22nd, 2006 in eclipse (No Comments »)

I attended the Scripting Eclipse panel which was quite interesting (see Ed’s transcript.

Scripting Eclipse means a lot of different things to different people.
My own interest is to provide scripting ability to a RCP application so that its users can customize it for their needs and create their own workflow.

For example, imagine that the RCP application is used to manage remote resources. Each resources can be manage individually through a set of methods.
But what if you want to provide a workflow for advanced operations?

One way to do this is through wizards. But with that solution, users lose control like Joel Spolksy explained in his presentation.
Besides it is very difficult to provide wizards which makes simple things simple and complex things possible. They tend to become uncluttered and undecipherable.

Another way is to provide cheatsheets. However, interaction between the cheatsheets and the user interface remains basic. And users are still not in control: they must follow the steps dictated by the cheatsheets.

Now, imagine that we expose a DOM of the managed resources and we let users script their processes. They are in control and they manage the workflow of their resources. They win because they are in control and we (the RCP developpers) win because we can keep our RCP application simple. We just have to expose the simplest useful DOMs to our users to let them handle themselves their more complex and specific processes.

Console DOM for Eclipse Monkey script

On March 21st, 2006 in eclipse (4 Comments »)

I wrote a simple DOM to write message to Eclipse console from a Monkey Script.

I have not yet created an update site for it so you have do download it and install it in your plugins directory manually.
It provides a out variable that you can use to write to a console.

Here is the mandatory “Hello, World” example:

--- Came wiffling through the eclipsey wood ---
/*
 * Menu: Console > Hello
 * Kudos: Jeff Mesnil
 * License: EPL 1.0
 * DOM: http://jmesnil.net/eclipse/updates/net.jmesnil.doms 
 */

function main() {
  out.print("Hello, ").println("World");
 }

--- And burbled as it ran! ---

and its output

Hello, World console screenshot