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 (No Comments »)

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.