|Re: Support for StyledLabelProvider or how to use StyledStrings in LabelProviders [message #1746771 is a reply to message #1746766]
||Fri, 04 November 2016 12:11
| Roman Zimmer
Registered: November 2010
I saw that it is already possible to change the color/font for the whole label. This But I needed something, where I can have different styled fragments for one label (something similiar to that what is described here: http://eclipsesource.com/blogs/2009/03/10/tip-styling-label-providers/ - last screenshot: the number of new mails is displayed in Blue color, while the email address defaults to black). For this you need StyledStrings. EMF generates corresponding getStyledText(Object)methods in for your *ItemProviders, if you set Style Providers to true in your genmodel (your *ItemProviders will then also implement IItemStyledLabelProvider).
So far, so good, let's recap my debugging session:
From my findings, JFace will only call getStyledText(Object) if the label provider is an instance of CellLabelProvider (CellLabelProvider.java:58). If not, it will wrap the label provider using WrappedViewerLabelProvider, which does *not* implement IStyledLabelProvider but extends CellLabelProvider. As Parsley's default ViewerLabelProvider does not extend CellLabelProvider, it will get wrapped by JFace into a WrappedViewerLabelProvider. ViewerColumn then calls labelProvider.update(cell) (ViewerColumn.java:141), but WrappedViewerLabelProvider.update(ViewerCell) calls getText(object) and not getStyledText(Object). So somehow using Parsley's injection mechanism I had to pass in a CellLabelProvider which calls getStyledText(Object) in it's update(ViewerCell). So DelegatingStyledCellLabelProvider joined the party, which works similar to Parsley's ViewerLabelProvider as it also delegates to another ILabelProvider. But it implements IStyledLabelProvider and calls getStyledText(Object) in it's update(ViewerCell). I introduced StyledViewerLabelProvider as ILabelProvider. It needs a AdapterFactoryLabelProvider.StyledLabelProvider to work and so I created InjectableStyledLabelProvider as AdapterFactoryLabelProvider. With these overridden Parsley bindings, JFace found everything how it expects it to finally call getStyledText(Object) on the *ItemProviders
This was a slightly complex abstract, but I hope you could see what I tried to achieve and how it is working now. Feel free to ask further details, if interested!
PS: This is on Eclipse 4.6.1 (Neon.1.a) using EMF Parsley 1.0.1.
[Updated on: Fri, 04 November 2016 13:35]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.01954 seconds