Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF Edit] Accessing attributes of children containment references
[EMF Edit] Accessing attributes of children containment references [message #1009490] Fri, 15 February 2013 03:24 Go to next message
Cedric Moonen is currently offline Cedric Moonen
Messages: 269
Registered: August 2009
Senior Member
Hello,

Let me first explain what I'm trying to achieve on an example, it will be easier Smile.
In my meta-model, I have elements that have a dimension (width, height and length), so for this I created an EClass called "Dimension". Objects having a dimension always have one and only one dimension, so, the EReference from the element to the "Dimensions" EClass has a cardinality of [1]. I also set the "Changeable" property to false, since you can modify the properties of the dimension but you can't set a new dimension object.

I have a couple of questions:
1) Is there a way to specify in the EMF model that the dimension reference has to be instanciated with a new Dimension object in the constructor of my element ? I know that I can edit the generated code and add a @generated not annotation above the constructor but I would like to avoid this as much as possible.
2) In the edit generated code, is there a way to specify that the attributes of the dimension field should be editable from the parent element ? I would like to have a "Dimension" category in the property sheet of the parent element that allows me to directly edit the dimension of the element, without having to add a "Dimension" to the element and having to select the dimension.

The reason for this is that I am creating a GMF editor and I would like to avoid having to create Dimension objects on my elements and having to select those in order to edit the dimensions of an element.

Of course, I could drop the dimension concept and always have the 3 dimensions attributes in all elements with a dimension but I would like to avoid this solution too. I don't want to adapt my abstract syntax because my concrete syntax doesn't allow certain things Smile

Thanks,
Cédric
Re: [EMF Edit] Accessing attributes of children containment references [message #1009500 is a reply to message #1009490] Fri, 15 February 2013 03:34 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 25931
Registered: July 2009
Senior Member
Cedric,

Comments below.

On 15/02/2013 9:24 AM, Cedric Moonen wrote:
> Hello,
>
> Let me first explain what I'm trying to achieve on an example, it will
> be easier :).
> In my meta-model, I have elements that have a dimension (width, height
> and length), so for this I created an EClass called "Dimension".
> Objects having a dimension always have one and only one dimension, so,
> the EReference from the element to the "Dimensions" EClass has a
> cardinality of [1]. I also set the "Changeable" property to false,
> since you can modify the properties of the dimension but you can't set
> a new dimension object.
It seems to me such a thing should be an EDataType that you hand
implement to produce something with minimal footprint. You might even
provide only a factory method so it's possible to intern them...
>
> I have a couple of questions:
> 1) Is there a way to specify in the EMF model that the dimension
> reference has to be instanciated with a new Dimension object in the
> constructor of my element ?
No, you should not attempt to do that. If you made it an EDataType, you
could specify a default value, which would be a constant.
> I know that I can edit the generated code and add a @generated not
> annotation above the constructor but I would like to avoid this as
> much as possible.
Yes, and it's generally a bad idea because when you deserialize you'd
always create such a thing only to have it replaced with the proper
value that was serialized.
> 2) In the edit generated code, is there a way to specify that the
> attributes of the dimension field should be editable from the parent
> element ? I would like to have a "Dimension" category in the property
> sheet of the parent element that allows me to directly edit the
> dimension of the element, without having to add a "Dimension" to the
> element and having to select the dimension.
Again, if you have an EDataType, you'd have a string representation you
could edit, and you could provide a specialized cell editor to bring up
a small dialog. Or you could specialize the parent's property
descriptors so that you create several property descriptors for the same
value, each of which would create a new Dimension instance and set the
one actual EAttribute.
>
> The reason for this is that I am creating a GMF editor and I would
> like to avoid having to create Dimension objects on my elements and
> having to select those in order to edit the dimensions of an element.
>
> Of course, I could drop the dimension concept and always have the 3
> dimensions attributes in all elements with a dimension but I would
> like to avoid this solution too. I don't want to adapt my abstract
> syntax because my concrete syntax doesn't allow certain things :)
I strongly advise you rethink this approach. Design an EDataType and
specialize the property descriptors to produce three of them or to
specialize a cell editor for editing a dimension (which wouldn't
actually modify the Dimension but rather create a new one. Dimensions
should be immutable data objects, like strings or EMF's URI.
> Thanks,
> Cédric
Previous Topic:[CDO] BufferUnderflowException when trying to connect with Java 7 (64bit)
Next Topic:Empty Combo when EMF databinding to a combo in a table viewer
Goto Forum:
  


Current Time: Mon Jul 28 18:41:24 EDT 2014

Powered by FUDForum. Page generated in 0.04652 seconds