Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF Parsley » Support for StyledLabelProvider or how to use StyledStrings in LabelProviders
icon5.gif  Support for StyledLabelProvider or how to use StyledStrings in LabelProviders [message #1746695] Thu, 03 November 2016 10:52 Go to next message
Roman Zimmer is currently offline Roman ZimmerFriend
Messages: 27
Registered: November 2010
Junior Member
Hey @ll,

first thanks a lot for developing EMF Parsley! Really enjoying using it, but I'm still in the very beginning Smile

I've the requirement to show styled labels in a TreeViewer (e.g. the first part of the label should be red, while the second part should have black text color). As of my understanding, since EMF 2.10 StyledStrings or better StyledLabelProviders are used for realizing this.

How would this work out with EMF Parsley? Is this already supported? If not, is there another possibility to realize this?

I'm grateful for all hints, thanks in advance!
Re: Support for StyledLabelProvider or how to use StyledStrings in LabelProviders [message #1746707 is a reply to message #1746695] Thu, 03 November 2016 14:19 Go to previous messageGo to next message
Roman Zimmer is currently offline Roman ZimmerFriend
Messages: 27
Registered: November 2010
Junior Member
After some more time digging through jFace's and EMF.Edit.Ui's code I finally managed to get styled text from my ItemProviders:

In my module.parsley I added the following bindings:

	bindings {
		type ILabelProvider -> StyledViewerLabelProvider
		type AdapterFactoryLabelProvider -> InjectableStyledLabelProvider
	}


Implementation of the style-enabled classes:

import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider.StyledLabelProvider;
import org.eclipse.emf.edit.ui.provider.DelegatingStyledCellLabelProvider;

import com.google.inject.Inject;

public class StyledViewerLabelProvider extends DelegatingStyledCellLabelProvider {

	@Inject
	public StyledViewerLabelProvider(AdapterFactoryLabelProvider delegate) {
		super((StyledLabelProvider) delegate);
	}

}


import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider.StyledLabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;

import com.google.inject.Inject;

public class InjectableStyledLabelProvider extends StyledLabelProvider {

	@Inject
	public InjectableStyledLabelProvider(AdapterFactory adapterFactory) {
		super(adapterFactory, Display.getDefault().getSystemFont(),
				Display.getDefault().getSystemColor(SWT.COLOR_TITLE_FOREGROUND),
				Display.getDefault().getSystemColor(SWT.COLOR_TITLE_BACKGROUND));
	}

}


I'll be more than glad if this gets somehow added to the next EMF Parsley release Smile
Re: Support for StyledLabelProvider or how to use StyledStrings in LabelProviders [message #1746766 is a reply to message #1746707] Fri, 04 November 2016 11:09 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi Roman

I'm glad you're enjoying Parsley Smile

In Parsley, label providers can already specify font and colors (see e.g. https://www.eclipse.org/emf-parsley/documentation.html#par11)

Did you actually mean something else?
Possibly related to what EMF generates in the .edit plugin?

hope to hear from you soon
Lorenzo


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 Go to previous messageGo to next message
Roman Zimmer is currently offline Roman ZimmerFriend
Messages: 27
Registered: November 2010
Junior Member
Thanks, Lorenzo!

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 Smile

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

Re: Support for StyledLabelProvider or how to use StyledStrings in LabelProviders [message #1746828 is a reply to message #1746771] Sat, 05 November 2016 09:26 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Thank you Roman for the explanation! Smile

Please file a bug and we'll try to work on that ASAP!

cheers
Lorenzo


Re: Support for StyledLabelProvider or how to use StyledStrings in LabelProviders [message #1747197 is a reply to message #1746828] Thu, 10 November 2016 15:59 Go to previous message
Roman Zimmer is currently offline Roman ZimmerFriend
Messages: 27
Registered: November 2010
Junior Member
No problem, as suggested I filed a bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=507364
Previous Topic:FeatureCaptionProvider
Next Topic:Drag'n'Drop copies object instead of moving it
Goto Forum:
  


Current Time: Sat Apr 20 00:50:16 GMT 2024

Powered by FUDForum. Page generated in 0.03268 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top