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
I’ve finally made some changes to the look of the site. These are:
- I’ve moved the Wordpress installation up a level, and stuck a 301 redirect in the .htaccess. Watch Google b0rk like a muthafucka.
- Replaced an h1 header with my awesome logo, that was awesome when I made it, but is of too low a resolution. Annoyingly I can’t remember how I made it and I’m shit with photoshop. This will probably get redesigned soon enough…
- Fiddled with the Wordpress theme. It now defaults to a width of 800, not 660. Anyone still running their monitor at 800×600 can shove it up their arse.
Now I guess it’s Wordpress upgrade time…
posted by Bradshaw at 08:49
I’ve just spent an hour and half on this one…
If you want the eclipse UI to know what you’ve got selected under your sticky little mouse, for the purposes of Core Command checking, then you need to include something akin to this in your View class:
getSite().setSelectionProvider(viewer);
Where viewer is the name you’ve given to the viewer class (Either TreeViewer or TableViewer in most cases), otherwise eclipse won’t register your viewer with its SelectionService, and won’t know when you’ve got something selected.
Just a little something to show that I love you. Kiss kiss.
posted by Bradshaw at 13:08
One of the things that has pissed me off more than anything else throughout my odyssey with eclipse RCP has been the utterly, UTTERLY awful documentation for the declarative Commands framework. I’m sure you know the basics…
- You define “Command”s as xml entities through your plugin.xml / extensions browser. They shouldn’t contain anything more than presentation information. They are then included on menus and Tool/Coolbars.
- Unless there’s some behaviour associated with that “Command” that is Always available – where you provide a link to the class that implements that behaviour as a “Default Handler”
- A Handler is the implementation that is associated with a given Command. If they’re not always available, then they should be defined in the “Handlers” extenstion point.
Now, this is where it got me… Most of the time you need to stop idiot bastard users from clicking on the “Commit” button when there isn’t a Database connection, or whatever. So you need to ghost the menu / toolbar items, right?
However, in eclipse, you don’t get hold of the widget itself and set it to a “ghost” state, you actually need to disable the implementation, so that there are no active handlers for that Command. The Command itself is still there, but since eclipse hasn’t got anything for it to do, it’s disabled, right?
OK – so here’s the thing. There’s an arcane language for logical assessment, all part of the Core Expression Framework. Just so you don’t think I’m being mean for the sake of it, this is the eclipse wiki page for it:
http://wiki.eclipse.org/Command_Core_Expressions
Clear as dogpiss? Hmmm?
(more…)
posted by Bradshaw at 09:59
OK, so the last post I made wasn’t quite what I mean to say. It’s not custom contexts, that’s something else. What I was talking about was custom ISources (When you’re defining core expressions, these are the Variables that you want to stick in the “with” elements and such.)
Well, rather than explain it all away, I’ll just post a link to the eclipse news posting that turned me on to how to use it. You see, when you write functionality, it’s REALLY important to make sure that potential users have to root about in newsgroups for getting on for a week before they get half of an idea (Which is normally all I end up getting, since I’m obviously fuckin’ thick…) and that when posting on newsgroup you get a “upgrade to 3.4″ or plain ignored.
For the record – “I’m stuck with 3.3 until I get a finished product. Then I can *think* about upgrading, this isn’t an answer, it’s you grabbing your nuts and making obscene gestures in my direction.”
Anyway, minor rant over.
For custom ISources, check out http://dev.eclipse.org/newslists/news.eclipse.platform/msg66913.html. Bear in mind that the EvaluationService is a restricted package in 3.3, since it’s internal. If you’re using 3.4. I suppose you should use the IEvaluationService interface. Can’t remember which package it’s in, though…
Right, NOW for contexts…
posted by Bradshaw at 08:33
I’ve just spent about three weeks looking for a way to enable / disable handlers (Read “ghost menu items / Commands”). In eclipse 3.3., when the Standard ones just won’t cut it. Like when stuff gets turned on / off depending on something slightly more complicated than having a ViewPart selected, or an Editor in use.
It’s a cockache and a half…
Full instructions will follow once I’ve managed to implement it all, but basically you need to write your own Context and ContextSourceProvider, then add the new SourceProvider to the Platform IHandlerService and IEvaluationServices.
Actually, I still don’t really understand the example it’s taken me a thousand years to find, since there are no decent explanations of how the Core Expressions language fucking works.
Eclipse Developers, SORT IT FUCKING OUT.
posted by Bradshaw at 12:07
When you run eclipse or an eclipse based application it runs, by default, in javaw – so there’s no console and it seems to be a bit funny about what exceptions it logs, and which it catches itself. Unless you’re explicitly writing possible exceptions to log files, surrounded by great big “Look here” statements, you may never, ever see them. The solution is to have eclipse (or RCP) running as a standard java app with a console.
This is a piece of piss
%eclipse -vm {LOCATION OF YOUR JAVA.EXE}
Oh, and I’ve not forgotten about the RCP config files, but they’re taking up a bit of writing and I’ve got other things to do with my life.
posted by Bradshaw at 09:04