Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » setting default value of derived propertyi in ecore
setting default value of derived propertyi in ecore [message #1077039] Thu, 01 August 2013 07:02 Go to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Hi,
I have most of my ECLasses extending a common ancestor (Identifiable).
Identifiable defines several common fields, including "name: EString".
I would like to set a default value for this Property *in the derived
EClass*, so I would have different defaults depending if actual
implementation is IdentifiableImpl or something different.
Is this at all possible?
What do I need to do?

Regards
Mauro
Re: setting default value of derived propertyi in ecore [message #1077049 is a reply to message #1077039] Thu, 01 August 2013 07:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mauro,

Comments below.

On 01/08/2013 9:02 AM, Mauro Candarelli wrote:
> Hi,
> I have most of my ECLasses extending a common ancestor (Identifiable).
> Identifiable defines several common fields, including "name: EString".
> I would like to set a default value for this Property *in the derived
> EClass*, so I would have different defaults depending if actual
> implementation is IdentifiableImpl or something different.
> Is this at all possible?
No, the default is defined once and for all in the feature and can't be
specialized anywhere.
> What do I need to do?
I suspect your issue is more of one about initializing newly create
instances in the editor, and there you'll probably want to pick a unique
new name. Is that the case?
>
> Regards
> Mauro


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: setting default value of derived propertyi in ecore [message #1077064 is a reply to message #1077049] Thu, 01 August 2013 07:49 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Thanks Ed.

Oops!
Sorry, I hit the wrong button and I sent this to Your personal account.

On 01/08/2013 09:20, Ed Merks wrote:
> I suspect your issue is more of one about initializing newly create
> instances in the editor, and there you'll probably want to pick a unique
> new name. Is that the case?
Yes.
Name don't need to be unique, "New Machine"/"New Station"/.../"New
Identifiable" are ok.
I would like to also initialize the "id : EInteger" (again in
Identifiable) with some kind of auto-increment (this needs to be unique!).

Mauro
Re: setting default value of derived propertyi in ecore [message #1077067 is a reply to message #1077064] Thu, 01 August 2013 07:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mauro,

Generally you can do initialization by specializing the objects created
for the child descriptors in the each of the generated
org.eclipse.emf.edit.provider.ItemProviderAdapter.collectNewChildDescriptors(Collection<Object>,
Object).

On 01/08/2013 9:49 AM, Mauro Candarelli wrote:
> Thanks Ed.
>
> Oops!
> Sorry, I hit the wrong button and I sent this to Your personal account.
>
> On 01/08/2013 09:20, Ed Merks wrote:
> > I suspect your issue is more of one about initializing newly create
> > instances in the editor, and there you'll probably want to pick a
> unique
> > new name. Is that the case?
> Yes.
> Name don't need to be unique, "New Machine"/"New Station"/.../"New
> Identifiable" are ok.
> I would like to also initialize the "id : EInteger" (again in
> Identifiable) with some kind of auto-increment (this needs to be
> unique!).
>
> Mauro
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: setting default value of derived propertyi in ecore [message #1077228 is a reply to message #1077067] Thu, 01 August 2013 11:58 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Thanks Ed,
comments inline.

On 01/08/2013 09:51, Ed Merks wrote:
> Mauro,
>
> Generally you can do initialization by specializing the objects created
> for the child descriptors in the each of the generated
> org.eclipse.emf.edit.provider.ItemProviderAdapter.collectNewChildDescriptors(Collection<Object>,
> Object).
Uhm, I don't see such a class in my generated code.
NOTE: I'm using only the "Model Code", no edit nor editor.

I was thinking about hand-modifying methods in XxxFactoryImpl, but
perhaps there's a better way?
Maybe using EAnnotations.body ? (examples? "5.7.1 Annotations in EMF"
does not really explain... or I'm being dense?)

>
> On 01/08/2013 9:49 AM, Mauro Candarelli wrote:
>> Thanks Ed.
>>
>> Oops!
>> Sorry, I hit the wrong button and I sent this to Your personal account.
>>
>> On 01/08/2013 09:20, Ed Merks wrote:
>> > I suspect your issue is more of one about initializing newly create
>> > instances in the editor, and there you'll probably want to pick a
>> unique
>> > new name. Is that the case?
>> Yes.
>> Name don't need to be unique, "New Machine"/"New Station"/.../"New
>> Identifiable" are ok.
>> I would like to also initialize the "id : EInteger" (again in
>> Identifiable) with some kind of auto-increment (this needs to be
>> unique!).
>>
>> Mauro
>>
>
Re: setting default value of derived propertyi in ecore [message #1077236 is a reply to message #1077228] Thu, 01 August 2013 12:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mauro,

Comments below.


On 01/08/2013 1:58 PM, Mauro Candarelli wrote:
> Thanks Ed,
> comments inline.
>
> On 01/08/2013 09:51, Ed Merks wrote:
>> Mauro,
>>
>> Generally you can do initialization by specializing the objects created
>> for the child descriptors in the each of the generated
>> org.eclipse.emf.edit.provider.ItemProviderAdapter.collectNewChildDescriptors(Collection<Object>,
>>
>> Object).
> Uhm, I don't see such a class in my generated code.
> NOTE: I'm using only the "Model Code", no edit nor editor.
I specifically asked "I suspect your issue is more of one about
initializing newly create instances in the editor"...
>
> I was thinking about hand-modifying methods in XxxFactoryImpl, but
> perhaps there's a better way?
No, none of such things in the model are a good idea. The base factory
behavior shouldn't be changed. It must create uninitialized instances.
You could add additional factory methods, but I would have expected
that if you're creating things programmatically that you'd populate the
new instances correctly and as desired... E.g., for the Ecore model an
EClassifier must have a name, but it does no good to just initialize one
with "NewClass" in the model, because the name must be populated in a
meaningful way by any and all code that's creating Ecore instances.

So your use case isn't clear to me. I had assumed an editor is involved
and the things you wanted are for the benefit of the user of such an
editor, but now you say that's not the case...
> Maybe using EAnnotations.body ? (examples? "5.7.1 Annotations in EMF"
> does not really explain... or I'm being dense?)
>
>>
>> On 01/08/2013 9:49 AM, Mauro Candarelli wrote:
>>> Thanks Ed.
>>>
>>> Oops!
>>> Sorry, I hit the wrong button and I sent this to Your personal account.
>>>
>>> On 01/08/2013 09:20, Ed Merks wrote:
>>> > I suspect your issue is more of one about initializing newly create
>>> > instances in the editor, and there you'll probably want to pick a
>>> unique
>>> > new name. Is that the case?
>>> Yes.
>>> Name don't need to be unique, "New Machine"/"New Station"/.../"New
>>> Identifiable" are ok.
>>> I would like to also initialize the "id : EInteger" (again in
>>> Identifiable) with some kind of auto-increment (this needs to be
>>> unique!).
>>>
>>> Mauro
>>>
>>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: setting default value of derived propertyi in ecore [message #1077255 is a reply to message #1077236] Thu, 01 August 2013 12:47 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Sorry Ed,
I was not clear.

What I'm writing is, indeed, an editor for this model I'm building.

Application is a native JavaFX application, I am thus using EMF in
"standalone" mode.

Following Tom's advice I am using only the basic "Model Code" EMF code
generator. I am using EMF and JFX Databinding to connect Model with UI.

Question was: I would like to do some basic initialization on EClass
creation, what is the best place to insert it?
Already the basic generated code can insert default values in
attributes, but this doe not work if the value is in an ancestor class
(to be more precise: the default is in the ancestor and seems not
changeable in derived classes).

Is there a good place in EMF/ecore or should I initialize EClasses in my
editor code? Putting defaults in ecore would be very nice.

Thanks again
Mauro

On 01/08/2013 14:12, Ed Merks wrote:
> Mauro,
>
> Comments below.
>
>
> On 01/08/2013 1:58 PM, Mauro Candarelli wrote:
>> Thanks Ed,
>> comments inline.
>>
>> On 01/08/2013 09:51, Ed Merks wrote:
>>> Mauro,
>>>
>>> Generally you can do initialization by specializing the objects created
>>> for the child descriptors in the each of the generated
>>> org.eclipse.emf.edit.provider.ItemProviderAdapter.collectNewChildDescriptors(Collection<Object>,
>>>
>>> Object).
>> Uhm, I don't see such a class in my generated code.
>> NOTE: I'm using only the "Model Code", no edit nor editor.
> I specifically asked "I suspect your issue is more of one about
> initializing newly create instances in the editor"...
>>
>> I was thinking about hand-modifying methods in XxxFactoryImpl, but
>> perhaps there's a better way?
> No, none of such things in the model are a good idea. The base factory
> behavior shouldn't be changed. It must create uninitialized instances.
> You could add additional factory methods, but I would have expected
> that if you're creating things programmatically that you'd populate the
> new instances correctly and as desired... E.g., for the Ecore model an
> EClassifier must have a name, but it does no good to just initialize one
> with "NewClass" in the model, because the name must be populated in a
> meaningful way by any and all code that's creating Ecore instances.
>
> So your use case isn't clear to me. I had assumed an editor is involved
> and the things you wanted are for the benefit of the user of such an
> editor, but now you say that's not the case...
Re: setting default value of derived propertyi in ecore [message #1077272 is a reply to message #1077255] Thu, 01 August 2013 13:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mauro,

Comments below.

On 01/08/2013 2:47 PM, Mauro Candarelli wrote:
> Sorry Ed,
> I was not clear.
>
> What I'm writing is, indeed, an editor for this model I'm building.
>
> Application is a native JavaFX application, I am thus using EMF in
> "standalone" mode.
>
> Following Tom's advice I am using only the basic "Model Code" EMF code
> generator. I am using EMF and JFX Databinding to connect Model with UI.
>
> Question was: I would like to do some basic initialization on EClass
> creation, what is the best place to insert it?
That's more of a data binding question then. I'm not sure how your
editor creates new instances. You might set a breakpoint in the
constructor to determine that...
> Already the basic generated code can insert default values in
> attributes, but this doe not work if the value is in an ancestor class
> (to be more precise: the default is in the ancestor and seems not
> changeable in derived classes).
>
> Is there a good place in EMF/ecore or should I initialize EClasses in
> my editor code?
No.
> Putting defaults in ecore would be very nice.
The Ecore model only supports defaults for features and that's a fixed
constant so not really the place to try to do this. Better you
determine how/where your editor creates new instances and do
initialization there...
>
> Thanks again
> Mauro
>
> On 01/08/2013 14:12, Ed Merks wrote:
>> Mauro,
>>
>> Comments below.
>>
>>
>> On 01/08/2013 1:58 PM, Mauro Candarelli wrote:
>>> Thanks Ed,
>>> comments inline.
>>>
>>> On 01/08/2013 09:51, Ed Merks wrote:
>>>> Mauro,
>>>>
>>>> Generally you can do initialization by specializing the objects
>>>> created
>>>> for the child descriptors in the each of the generated
>>>> org.eclipse.emf.edit.provider.ItemProviderAdapter.collectNewChildDescriptors(Collection<Object>,
>>>>
>>>>
>>>> Object).
>>> Uhm, I don't see such a class in my generated code.
>>> NOTE: I'm using only the "Model Code", no edit nor editor.
>> I specifically asked "I suspect your issue is more of one about
>> initializing newly create instances in the editor"...
>>>
>>> I was thinking about hand-modifying methods in XxxFactoryImpl, but
>>> perhaps there's a better way?
>> No, none of such things in the model are a good idea. The base factory
>> behavior shouldn't be changed. It must create uninitialized instances.
>> You could add additional factory methods, but I would have expected
>> that if you're creating things programmatically that you'd populate the
>> new instances correctly and as desired... E.g., for the Ecore model an
>> EClassifier must have a name, but it does no good to just initialize one
>> with "NewClass" in the model, because the name must be populated in a
>> meaningful way by any and all code that's creating Ecore instances.
>>
>> So your use case isn't clear to me. I had assumed an editor is involved
>> and the things you wanted are for the benefit of the user of such an
>> editor, but now you say that's not the case...
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: setting default value of derived propertyi in ecore [message #1750717 is a reply to message #1077039] Tue, 27 December 2016 09:05 Go to previous messageGo to next message
Shreyas Sangai is currently offline Shreyas SangaiFriend
Messages: 1
Registered: December 2016
Junior Member
Hi ED,

First of all thanks for creating such an amazing framework. Smile

I have a similar but slightly different problem and I would like your advice on the same :
The model is as follows :

interface A{
int length;
}

interface B extends A {

}

Now the requirement is that the value of length should either be 4 when A is instantiated or 8 when B is instantiated. The objects are added to a table as a row. They can be either added through the UI or through a service which creates the list of these objects by reading some information in database which is again shown in the same UI.
My question :
Where should we initialize this value ? Definitely cannot be done in the ecore for sure. So as you have mentioned in the comments above we could do it while adding it in the UI and in the service when we programmatically create those objects.
However, although touching the generated code is not recommended, can we add a if else condition and set the default value in the generated code it self for this variable as an exception. It would have been difficult to do this if an unique value was required every time but since there are only 2 possible values would this be fine ? If not what problems would it cause for the EMF infrastructure.
The reason I would like to have this in the object creation is that anyone else creating these objects should not have to have worry about which value to set after creation or should not forget to set these values on object creation.
Re: setting default value of derived propertyi in ecore [message #1750854 is a reply to message #1750717] Fri, 30 December 2016 08:30 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Should someone be able to change the value for an A instance to be different than 4 or for a B instance to be different than 8? I.e., should someone be able to change a B instance's length to be 4? Could it just be an EOperation? Or just a derived feature in A that's implemented to return 4 in A and is overridden by an operation in B that returns 8?

Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Different item providers for the same EObject in EMF.Edit
Next Topic:Emf cross reference in sphinx
Goto Forum:
  


Current Time: Tue Apr 23 12:58:06 GMT 2024

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

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

Back to the top