Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Custom LabelProvider for table column?
Custom LabelProvider for table column? [message #1748845] Tue, 29 November 2016 09:40 Go to next message
Johan Van Noten is currently offline Johan Van NotenFriend
Messages: 87
Registered: July 2009
Member
I need to change the appearance of one of the columns in my custom table: the element should not only list its name, I want to see also its type.

For the column's header, this can easily be accomplished using the Label Provider Configuration for the Column Label:
https://wiki.eclipse.org/Table_Developer_Documentation#Define_Label_Provider_Configuration_for_Column_Label

For the column's elements, I guess changing the LabelProvider is required.
Unfortunately precisely that section is missing from the table dev documentation.
https://wiki.eclipse.org/Table_Developer_Documentation#How_to_create_your_own_label_provider

Could you point me to an example of such a customization?
Or even better, fill the required section in the doc?
If the example is clear enough, I'm willing to adjust the doc myself.

Thanks,
Johan
Re: Custom LabelProvider for table column? [message #1748860 is a reply to message #1748845] Tue, 29 November 2016 12:37 Go to previous messageGo to next message
vincent lorenzo is currently offline vincent lorenzoFriend
Messages: 125
Registered: June 2010
Location: Paris Saclay, France
Senior Member
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 :

  1. ILabelProviderCellContextElementWrapper : a wrapper owning a reference to the real cell element
  2. IConfigRegistry : the config registry of the table
  3. 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:

  1. accept(Object), the object will be a ILabelProviderCellContextElementWrapper
  2. 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 Go to previous messageGo to next message
Johan Van Noten is currently offline Johan Van NotenFriend
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 Go to previous message
vincent lorenzo is currently offline vincent lorenzoFriend
Messages: 125
Registered: June 2010
Location: Paris Saclay, France
Senior Member
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.
Previous Topic:Can't Add Trace to SysML Requirement
Next Topic:[DSML/Diagram kind]: Forcing stereotype creation on model creation
Goto Forum:
  


Current Time: Sun Jan 26 22:08:08 GMT 2020

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

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

Back to the top