Nested features in TableViewer, any updates ? [message #1827292] |
Tue, 12 May 2020 10:53 |
Samuel BADION Messages: 2 Registered: May 2020 |
Junior Member |
|
|
Hello Parlsey team,
First, thank you for your awesome work.
Related topics
I have read a few topics related to my interest but they are 4 or 5 years old. Maybe things have evolved.
Related topics :
- https://www.eclipse.org/forums/index.php/t/1075375/
- https://www.eclipse.org/forums/index.php/t/1065425/
Issue
I would like to show a nested feature using a TableView, however I do not want to declare a derived feature in my metamodel for this sole purpose.
Here is an example :
,--------------.
| Child |
|--------------|
|+name : String|
|--------------|
`--------------'
|
|
V parent
,--------------.
| Adult |
|--------------|
|+name : String|
|--------------|
`--------------'
Let each row of my TableView respresent a child instance, I would like to display a column containing parent's name (child.parent.name). No containment here.
Using your DSL, the usage of a '.' is invalid :
featuresProvider{
features{
Child -> name, parent.name
}
}
Is there any way of doing this using your DSL ?
Should I provide my own Java class extending your FeaturesProvider ?
If so, what should my implementation put in the provided stringMap ?
public void buildStringMap(final EClassToEStructuralFeatureAsStringsMap stringMap);
|
|
|
Re: Nested features in TableViewer, any updates ? [message #1827314 is a reply to message #1827292] |
Tue, 12 May 2020 23:26 |
|
Hi Samuel,
if your goal is to show an additional column showing parent.name and you have a specific Parsley plugin for handling the table, then you could simply specify via DSL (with tableLabelProvider) how to represent Child.parent, like this:
tableLabelProvider {
text {
Child:parent -> { it.parent.name }
}
}
|
|
|
|
|
Re: Nested features in TableViewer, any updates ? [message #1827515 is a reply to message #1827418] |
Sat, 16 May 2020 13:06 |
|
Hi Samuel,
you're right: my previous suggestion only works if you have just one attribute to show in the referenced object.
Indeed the idea behind Parsley is that the EMF Model should be strongly tied to the UI, rather than to the domain model (even at the cost of having two different models).
Usually your goal is obtained by adding to the main model class a set of 'calculated' EAttributes (e.g. parentName, parentAge) with:
- Changeable = false (no setter will be generated)
- Volatile = true (no attribute will be generated)
then, after re-generating the model source you will see tha *Impl classes contains methods like getParentName()
getParentAge() whose body is throwing an exception.
Notice that no new attributes are being generated and that no correspondent setter method is present.
At this point you can implement their body as you wish, e.g.:
public String getParentName() {
return parent.getName();
}
Note: remember to delete or change the * @generated annotation in comment, otherwise at next re-generation your code will be overwritten.
In case you are not allowed to change the original EMF model you can create a derived model that depends and extends the original one.
HTH
Vincenzo
|
|
|
Powered by
FUDForum. Page generated in 0.03445 seconds