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.

4 comments:

André said...

Hey... if I had known, that you resolve my problem in your blog, I would had saved a few hours of looking for a solution of this problem...

So... next time, I will take a faster look to your blog.

ooooooooooooo said...

Hi,

I want to personalize my toolbars to display text above icon (like you)

I created a class that extends AbstractPresentationFactory and configured plugin.xml. My class is called.

How do you reference your custom class that implements IActionBarPresentationFactory?

Can you post a code snipset ?

Thanks

ooooooooooooo said...

Too late. I succeded.

Thanks for your explanations.

Anonymous said...
This comment has been removed by a blog administrator.

About Me

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