|
Re: Custom LabelProvider for table column? [message #1748860 is a reply to message #1748845] |
Tue, 29 November 2016 12:37 |
|
Hi Johan,
so you want to customize the text displayed in the cells of the Body.
If you just want to display the type in addition of the name, maybe extending the class org.eclipse.papyrus.uml.nattable.provider.UMLTypedElementCellLabelProvider to cancel its behavior could help you. Nevertheless, I will give you the full informations here;
1. Some informations
The text displayed in the cells is returned by the method org.eclipse.papyrus.infra.nattable.provider.NattableTopLabelProvider.getBodyLabel(ILabelProviderCellContextElementWrapper, IConfigRegistry) which call this one: org.eclipse.papyrus.infra.nattable.provider.NattableTopLabelProvider.getLabel(ILabelProviderCellContextElementWrapper, IConfigRegistry, String), with these parameters :
- ILabelProviderCellContextElementWrapper : a wrapper owning a reference to the real cell element
- IConfigRegistry : the config registry of the table
- String : the context to use to get your label, in your case, it will be org.eclipse.papyrus.infra.nattable.utils.Constants.BODY_LABEL_PROVIDER_CONTEXT
2. How to change this text
You need to create a new class extending [b]AbstractNattableCellLabelProvider:
- accept(Object), the object will be a ILabelProviderCellContextElementWrapper
- getElementText(LabelProviderService, Object), here, it is your object
You can use as example the classes:
org.eclipse.papyrus.infra.nattable.provider.GenericCellLabelProvider and
org.eclipse.papyrus.uml.nattable.provider.UMLTypedElementCellLabelProvider
You need to register your class with the extension point called org.eclipse.papyrus.infra.services.labelprovider.labelProvider, with the context : org.eclipse.papyrus.infra.nattable.body.labelprovider and the good priority.
3. It should work.
Regards,
/Vincent Lorenzo
|
|
|
Re: Custom LabelProvider for table column? [message #1749676 is a reply to message #1748860] |
Fri, 09 December 2016 12:12 |
Johan Van Noten Messages: 87 Registered: July 2009 |
Member |
|
|
Hi Vincent,
Thanks for your very fast feedback. I was unfortunately not able to try your suggestions sooner...
Current status/observations:
* It doesn't work yet.
* When I debug, I see that my own LabelProvider is not in the providers list which is considered by the getText method. Instead, I see the UMLTypedElementCellLabelProvider still being used.
* I see that my plugin.xml has a warning on the context attribute org.eclipse.papyrus.infra.nattable.body.labelprovider that you suggested.
I fail to understand some part of your suggestion:
* I do contribute a new extension point for my custom label provider. I don't see how this one gets "tied" to my table. Of course it is not my purpose that suddenly this custom provider would be used for all tables that have 'accepted' elements. Shouldn't I then refer to the desired labelprovider from within my nattableconfiguration?
* The "good priority" feels like a guess... I can't Judge the current list of priorities, nor do I know whether there is a best practice to select a sensible priority. Moreover I find it tricky to go and invent "global scope priorities" (see previous bullet) or am I misjudging the scope of these priorities?
Sincerely,
Johan
[Updated on: Fri, 09 December 2016 12:14] Report message to a moderator
|
|
|
Re: Custom LabelProvider for table column? [message #1750153 is a reply to message #1749676] |
Fri, 16 December 2016 13:46 |
|
Hello Johan,
please found in attachment a sample plugin to override the label of the cell for a TypedElement. In addition, I set a snapshot of the result.
FYI, you can show all registered contribution for an extension point (it required toknow which plugin provides it), thank to the Plug-in Registry view (as snapshot too).
I hope it will allow you to fix your problem.
The warning in the plugin.xml for org.eclipse.papyrus.infra.nattable.body.labelprovider is 'normal'.
To avoid to impact all the tables, you need to override the accept method to check the type of the table (see example in attachment).
Regards,
--
Vincent.
|
|
|
Powered by
FUDForum. Page generated in 0.04210 seconds