September 26, 2007

Switching between languages at runtime

One of the requirements we have in our project is to support switching between different languages at runtime. To make this work in the RCP runtime, we decided to close the workbench window and open a new one when the language changes. This works quite well, especially since we have put all state data of the gui in separate models.
Another thing was how to handle data lazily loaded by the platform. For example, a view tab may be visible before the view is actually instanciated. The platform then uses the data (name) given in the extension definition of the view. But this is static, so it won't change if the language changes. We solved this by providing what we call ViewLocalizations via a custom extension point. The ViewLocalization resides in the same bundle as the view it belongs to and knows how to translate the view name. Our Presentation then uses the view localization to determine the right name for the view. Of course, a bundle should not be activated only because one of its ViewLocalizations is needed. Therefore, we put all the ViewLocalizations of a bundle in a separate package which we excluded from the lazyStart-mechanism.
This solution works quite well, but generates a considerable overhead. Especially since beside views, also perspectives, actions, etc. have to be handled this way. So if you have any ideas for improvements, please let me know.

July 23, 2007

An extension is not an extension point

I'm currently working for a customer in an RCP project. There is a lot of work to be done and we are around a dozen of programmers actively contributing. A couple of weeks ago we had a strange problem.
One of the core plugins of the app defines an extension point which is actively used by other components. At some point these extensions were not loaded anymore. After quite some time of guessing we found that there was a new plugin using the extension point. But instead of defining an extension the developer (not really familiar with the Eclipse extension mechanism) had defined an extension point. He named it exactly as the existing one and used the original schema file by referencing it from the original core plugin. I was somewhat surprised that the framework did not complain about this duplication, but the main lesson to learn is certainly that there is some basic RCP mechanisms every developer should be familiar with before contributing.

July 22, 2007

Actions with text in EclipseRCP

I'm using EclipseRCP for more than three years now, and I must say they've come a long way. I still really enjoy it, and with all the upcoming projects there's always new things to discover.
Standard functionality (like hooking buttons into the GUI) is next to trivial (as it should be) but sometimes things get a little bit more complicated when you want your application to look different than the Eclipse IDE.
A simple example, I like toolbar buttons to have a text next to the image. A little read shows that you can achieve this by setting the toolbar style in your actionbar advisor, and then defining your (global) actions there. Things get a bit more involved when you start using editors, and you want your editor actions (contributed via the IEditorActionBarContributor interface) to look the same as the global ones. You can still set the ActionContributionItem.MODE_FORCE_TEXT mode on your toolbar item, but there is no way to change the text alignment (I like the text to be below the image). Digging into the eclipse code I found that the toolbar used for the editor actions is created using the IActionBarPresentationFactory interface. A default one is used if you don't define your own presentation factory (extending AbstractPresentationFactory) which implements IActionBarPresentationFactory. So I created my own presentation (basically delegating to WorkbenchPresentationFactory) and let it extend IActionBarPresentationFactory.
It works, but uses internal API. So if anybody knows a better way to do that, drop me a line.

July 20, 2007

Ten minutes time

It really only takes ten minutes to hook up a blog. Don't know why it took me so long to get here.
Anyway, I finally made it. I'll start blogging about my daily coding experiences here, probably more or less for myself. But, hey, might be something in it for you too.

About Me

codes for a living and also in his freetime, probably for lack of a real hobby. ;-)