A U-Bend In The Tubes

Thursday, July 17, 2008

The “selected” variable in eclipse Core Expressions

A couple of days ago I posted a little something about Contexts in the eclipse Core expressions framework. What I said was the only thing you were probably interesting in the standard ISource was the “activeContexts” variable. ThatĀ  was a little misleading of me. ThereĀ  are several that are potentially useful, but I’ve not been using them, since what I’ve been working on doesn’t really lend itself to most of them.

The “selected” variable lets you access whatever is “globally selected” under your mouse. Depending on the view you’re acting on it can consist of 0 or more entries of type “Whatever”.

As I have written previously, if you’re working on a View whose selection can affect the whole application, then you’re going to need to add:

getSite().setSelectionProvider(viewer);

Somewhere in the ViewPart class. All this does is register that viewer as a SelectionProvider with eclipse in its ISelectionService. That Viewer can now make its selections known to the UI itself.

To make use of this, you’ve got to delve into the Core expressions. The easiest thing to do is to create a “definitions” extension point and create the expression in there – that way you’ll be able to reuse it. One I’ve used is:

<definition
  id="category.definition">
  <iterate ifEmpty="false" operator="or">
    <instanceof value="TreeNode"></instanceof>
  </iterate>
</definition>

This one basically says “If anything out of what I have selected is of type “TreeNode” then this expression evaluates to true. In order to use this with a Handler, you’d use the following…

<activeWhen>
  <reference definitionId="category.definition"></reference>
</activeWhen>

Makes sense, no?

posted by Bradshaw at 09:19  

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress