Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Editing a generic attribute in the property sheet pane
Editing a generic attribute in the property sheet pane [message #519573] Tue, 09 March 2010 11:07 Go to next message
Ronald is currently offline RonaldFriend
Messages: 5
Registered: March 2010
Junior Member
I have an ecore model which is going to be used to model cpp threads. These threads have several properties, among others a priority.

I want the user to give the ability to define constraints for the propiority using the editor of this ecore model. To achieve this I created an class called BoundedPriority which has fields lower and upper bound wich are of the type integer just like the value of priority.

However I want to create such a datastructure for some more datatypes and therefor I started investigating if generics are usable for this. So I wanted to be able to define a generic model for a property in which all values are of type E which exteds Type. Type is my own typing system which currently only exists of integers.

The goal is to automatically adopt the types of lower and upper bound to the type of the value chosen. I have been able to define all of this in the ecore model and it seems to generate appropriate java code.

However when I use the generated editor, I click on the upper/lower bound cells to change their value and it is blank, a value will automatically appear, something address-like as "ACED000570". If I put a value in, it disappears after I set it.

My question is, is it possible what I want to achieve?

From http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg3 5219.html I learned that it might be necessary to define my own serialization method, but can anyone point me to some documentation about how to do that?

Re: Editing a generic attribute in the property sheet pane [message #519594 is a reply to message #519573] Tue, 09 March 2010 12:04 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Ronald,

Comments below.

Ronald wrote:
> I have an ecore model which is going to be used to model cpp threads.
> These threads have several properties, among others a priority.
> I want the user to give the ability to define constraints for the
> propiority using the editor of this ecore model. To achieve this I
> created an class called BoundedPriority which has fields lower and
> upper bound wich are of the type integer just like the value of priority.
>
> However I want to create such a datastructure for some more datatypes
> and therefor I started investigating if generics are usable for this.
> So I wanted to be able to define a generic model for a property in
> which all values are of type E which exteds Type. Type is my own
> typing system which currently only exists of integers.
>
> The goal is to automatically adopt the types of lower and upper bound
> to the type of the value chosen. I have been able to define all of
> this in the ecore model and it seems to generate appropriate java code.
Keep in mind that XML Schema lets you define simple types with these
types of bounds, and EMF can capture those with extended meta data
annotations; maybe you can just reuse that.
>
> However when I use the generated editor, I click on the upper/lower
> bound cells to change their value and it is blank, a value will
> automatically appear, something address-like as "ACED000570". If I put
> a value in, it disappears after I set it.
It sounds like you've not specialized the
createAbcFromString/convertAbcToString in the generated XyzFactoryImpl
for your data type Abc so it's just using java.io.Serializable which
isn't human readable.
>
> My question is, is it possible what I want to achieve?
> From
> http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg3 5219.html
> I learned that it might be necessary to define my own serialization
> method, but can anyone point me to some documentation about how to do
> that?
The first introductory overview talks about data types and specializing
the factory. I'm sure you'll find the method with the hint above.
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Editing a generic attribute in the property sheet pane [message #519647 is a reply to message #519594] Tue, 09 March 2010 15:14 Go to previous messageGo to next message
Ronald is currently offline RonaldFriend
Messages: 5
Registered: March 2010
Junior Member
Thanks for your fast answer. I have had a look at the documentation regarding the convert methods. It is however not exactly what I'm look for since a DataType cannot extend my own class.

Let me try to write down the class I have. The hierarchy is basically about 3 'separate' parts. These parts are:

Type hierarchy
This consists of an abstract class type with is extended by Integer. This will later on be extended with addition types.

Property hierarchy
This consists of the top class Property which is extended by MutableProperty. MutableProperty is on its turn extended by LowerBoundProperty (next to the LowerBoundProperty a UpperBoundProperty will be created). The top class (Property) has a generic attribute value of type E. The class LowerBoundProperty adds a lowerbound of type E. Throught the property hierarchy the E generic parameter extends the Type hierarchy and is passed on to the higher level classes.

Thread hierarchy
The thread hierarchy binds the two hierarchies together. The thread hierarchy has among others a APeriodicThread class. This class has a reference (containment) to the abstract class Priority. MutablePriority extends the Priority class and uses a EClassifier to specify that the Integer type is needed (this is the Integer type from my own type hierarchy). MutablePriority also extends MutableProperty. This MutableProperty is an abstract class which is extended by LowerBoundProperty which adds a lowerboud of the type Integer at this moment.

The expected behavior is that when I add a MutablePriority to the thread I would like to be able to create multiple children in the priority in order to set the value and the lowerbound. At this moment the result is that I see the lowerbound attribute of LowerBoundProperty as an attribute with an memory address instead of the ability to add my own new Integer object.

So am I able to use the generics with the DataType structure provided by EMF? So I should drop the Type hierarchy and create the DataTypes using the DataType construct and let them point to java classes which represent the datatypes? and by doing it in that way being able to create complex datatypes?
Re: Editing a generic attribute in the property sheet pane [message #519808 is a reply to message #519647] Tue, 09 March 2010 21:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Ronald,

Comments below.

Ronald wrote:
> Thanks for your fast answer.
I'm slower now because of traveling to Vancouver.
> I have had a look at the documentation regarding the convert methods.
> It is however not exactly what I'm look for since a DataType cannot
> extend my own class.
>
> Let me try to write down the class I have. The hierarchy is basically
> about 3 'separate' parts. These parts are:
>
> Type hierarchy
> This consists of an abstract class type with is extended by Integer.
> This will later on be extended with addition types.
How can a class be extended by Integer? I don't get that.
>
> Property hierarchy
> This consists of the top class Property which is extended by
> MutableProperty. MutableProperty is on its turn extended by
> LowerBoundProperty (next to the LowerBoundProperty a
> UpperBoundProperty will be created). The top class (Property) has a
> generic attribute value of type E. The class LowerBoundProperty adds a
> lowerbound of type E. Throught the property hierarchy the E generic
> parameter extends the Type hierarchy and is passed on to the higher
> level classes.
My brain is hurting a little. :-P
>
> Thread hierarchy
> The thread hierarchy binds the two hierarchies together. The thread
> hierarchy has among others a APeriodicThread class. This class has a
> reference (containment) to the abstract class Priority.
> MutablePriority extends the Priority class and uses a EClassifier to
> specify that the Integer type is needed (this is the Integer type from
> my own type hierarchy). MutablePriority also extends MutableProperty.
> This MutableProperty is an abstract class which is extended by
> LowerBoundProperty which adds a lowerboud of the type Integer at this
> moment.
>
> The expected behavior is that when I add a MutablePriority to the
> thread I would like to be able to create multiple children in the
> priority in order to set the value and the lowerbound. At this moment
> the result is that I see the lowerbound attribute of
> LowerBoundProperty as an attribute with an memory address instead of
> the ability to add my own new Integer object.
Yep, my brain is definitely sore now...
>
> So am I able to use the generics with the DataType structure provided
> by EMF?
Yes, Ecore supports generics in the same way as does Java itself....
> So I should drop the Type hierarchy and create the DataTypes using the
> DataType construct and let them point to java classes which represent
> the datatypes?
Maybe. That's what they're for....
> and by doing it in that way being able to create complex datatypes?
XML Schema has complex type and simple types. EMF has EClass and
EDataType. They're analogous. I'm not sure I know what a complex data
type is though...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Editing a generic attribute in the property sheet pane [message #519951 is a reply to message #519808] Wed, 10 March 2010 15:46 Go to previous messageGo to next message
Ronald is currently offline RonaldFriend
Messages: 5
Registered: March 2010
Junior Member
Hmm I don't think I was very clear last time. I have made a small test case of this problem. I created my own abstract Property class. This class has a attribute value of the type EString and an attribute called value of the generic type E. The abstract Property<E> class is generic. I have two classes which extend Property they are called IntegerProperty and StringProperty and they extend the Property class by using the appropriate generic parameters. If this explanation is unclear or you want to know more details, the files can be found on the following urls:

http:// mediaservert.student.utwente.nl/ontwerpproject/genericsSampl e.ecore
http:// mediaservert.student.utwente.nl/ontwerpproject/genericsSampl e.ecorediag
http:// mediaservert.student.utwente.nl/ontwerpproject/genericsSampl e.genmodel

What I would expect is that when I use the generated editor and I add a IntegerProperty to my System that the type of the value attribute is EIntegerObject and that I can put Integers into this object or that the editor provides a add child menu which provides the ability to add a child to this IntegerProperty of the specified type within the generics.

I have also tried this some example but then using my own datatype instead of the provided datatypes (EIntegeRObject, EString etc) this has the same result.

With a complex datatype I mean an object which has several properties. For example within a model regarding threads an interval datatype with has the attributes nanoseconds and seconds to specify the interval

[Updated on: Wed, 10 March 2010 15:49]

Report message to a moderator

Re: Editing a generic attribute in the property sheet pane [message #519969 is a reply to message #519951] Wed, 10 March 2010 16:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Ronald,

If E has no bounds then an EAttribute of type E is effectively an
attribute of type EJavaObject. So while you can instantiate it with all
manner of serializeable types, there's only one EAttribute and its type
is effectively unbounded. Maybe your issue is also related to
https://bugs.eclipse.org/bugs/show_bug.cgi?id=289859 but I've not had
time to look into the effect of type binding to allowable children.


Ronald wrote:
> Hmm I don't think I was very clear last time. I have made a small test
> case of this problem. I created my own abstract Property class. This
> class has a attribute value of the type EString and an attribute
> called value of the generic type E. The abstract Property<E> class is
> generic. I have two classes which extend Property they are called
> IntegerProperty and StringProperty and they extend the Property class
> by using the appropriate generic parameters. If this explanation is
> unclear or you want to know more details, the files can be found on
> the following urls:
>
> http://mediaservert.student.utwente.nl/ontwerpproject/generi csSample.ecore
>
> http://mediaservert.student.utwente.nl/ontwerpproject/generi csSample.ecorediag
>
> http://mediaservert.student.utwente.nl/ontwerpproject/generi csSample.genmodel
>
>
> What I would expect is that when I use the generated editor and I add
> a IntegerProperty to my System that the type of the value attribute is
> EIntegerObject and that I can put Integers into this object or that
> the editor provides a add child menu which provides the ability to add
> a child to this IntegerProperty of the specified type within the
> generics.
>
> I have also tried this some example but then using my own datatype
> instead of the provided datatypes (EIntegeRObject, EString etc) this
> has the same result.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Editing a generic attribute in the property sheet pane [message #519977 is a reply to message #519969] Wed, 10 March 2010 16:54 Go to previous messageGo to next message
Ronald is currently offline RonaldFriend
Messages: 5
Registered: March 2010
Junior Member
Hmm, I would expect that when I create a object of the type StringProperty that the generic type (which is indeed unbound in the example) would be bound to String (as I specified in the model that StringProperty extends property with EString as a generic parameter type (Property<EString>). The generated code from StringProperty looks like:

public interface StringProperty extends Property<String> {
} // StringProperty


So I would expect the generated editor to know that it is a string and to ask the string how to represent itself? Or in a more general approach provide the ability to add an object of the bounded type (String in this case)

I don't have time at the moment to read the bug/feature report in detail, I'll have some time that reserved tomorrow

ps really thanks for the fast and good, constructive replies!
Re: Editing a generic attribute in the property sheet pane [message #520005 is a reply to message #519977] Wed, 10 March 2010 18:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Ronald,

Comments below.

Ronald wrote:
> Hmm, I would expect that when I create a object of the type
> StringProperty that the generic type (which is indeed unbound in the
> example) would be bound to String (as I specified in the model that
> StringProperty extends property with EString as a generic parameter
> type (Property<EString>). The generated code from StringProperty looks
> like:
>
> public interface StringProperty extends Property<String> {
> } // StringProperty
Yes, but note that nothing from the base class is regenerated.
>
> So I would expect the generated editor to know that it is a string and
> to ask the string how to represent itself?
Seems reasonable, but keep in mind that EMF like Java defines generics
in a way where it's generally erased at runtime. So someone can use an
instance of Property<String> without subclassing it to create a derived
EClass; such an instance at runtime would have no idea it was
instantiated with <String>.
> Or in a more general approach provide the ability to add an object of
> the bounded type (String in this case)
>
> I don't have time at the moment to read the bug/feature report in
> detail, I'll have some time that reserved tomorrow
>
> ps really thanks for the fast and good, constructive replies!
You're welcome.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Editing a generic attribute in the property sheet pane [message #520117 is a reply to message #520005] Thu, 11 March 2010 08:51 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Ed Merks wrote:
>
> Seems reasonable, but keep in mind that EMF like Java defines generics
> in a way where it's generally erased at runtime.

I've encountered a problem which I think is similar. I had an abstract
container class with a type parameter limiting its allowed children:
Container<T extends Component> with a containment reference children
having T as its eType. Specific containers then could limit their
children, e.g. TabFolder<Tab>. This works well when you use the specific
type names like TabFolder in your code, since calls like
getChildren().add/remove can be checked statically. When you instead
write generic code against the Container class, nothing prevents you
from adding other kinds of Components.

I handled this myself by implementing a special constraint that used the
Container's EClass (e.g. TabFolder), navigated to the type parameter
(e.g. Tab) and used this for checking the type of the children. I think
this technique can be used for other problems, perhaps also specializing
property editing, but I don't think EMF can do this on its own. In my
case, I knew that this specific type parameter limited that specific
reference, but I suspect (but please correct me if I'm wrong) that in
general the analysis that would be required is too complex for EMF to do
it automatically.

Hallvard
Re: Editing a generic attribute in the property sheet pane [message #520192 is a reply to message #520117] Thu, 11 March 2010 14:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Hallvard,

An instance of Container's eClass() will simply return the EClass for
Container. There's no information at that point which EClass or
EDataType is bound to T. Certainly there are cases like the one
described in this chain, where someone subclasses Container with a new
EClass and the EGenericSuperTypes do end up specifying the EClass or
EDataType bound to T as part of defining Container to be the super type
where it would be possible to do more. I imagine there are other cases
where the object is known to be referenced by a feature and the type of
the feature helps further specify the bounds. There are likely places in
the code where checking for this type of situation could provide type
information that's otherwise erased, but that's certainly a complication
and an expense. Not only that, but you might well require more context,
the original most derived class of the instance owning the feature, or
the type of the feature referring to the instance, than you actually
have available locally.


Hallvard Trætteberg wrote:
> Ed Merks wrote:
>>
>> Seems reasonable, but keep in mind that EMF like Java defines
>> generics in a way where it's generally erased at runtime.
>
> I've encountered a problem which I think is similar. I had an abstract
> container class with a type parameter limiting its allowed children:
> Container<T extends Component> with a containment reference children
> having T as its eType. Specific containers then could limit their
> children, e.g. TabFolder<Tab>. This works well when you use the
> specific type names like TabFolder in your code, since calls like
> getChildren().add/remove can be checked statically. When you instead
> write generic code against the Container class, nothing prevents you
> from adding other kinds of Components.
>
> I handled this myself by implementing a special constraint that used
> the Container's EClass (e.g. TabFolder), navigated to the type
> parameter (e.g. Tab) and used this for checking the type of the
> children. I think this technique can be used for other problems,
> perhaps also specializing property editing, but I don't think EMF can
> do this on its own. In my case, I knew that this specific type
> parameter limited that specific reference, but I suspect (but please
> correct me if I'm wrong) that in general the analysis that would be
> required is too complex for EMF to do it automatically.
>
> Hallvard


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Editing a generic attribute in the property sheet pane [message #520223 is a reply to message #520192] Thu, 11 March 2010 15:25 Go to previous message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Ed,

I think we agree. I just wanted to point out that in specific cases,
like mine, it's possible to use the meta-information (oops, I just said
the m-word) to discover relevant constraints. In general, it may be very
complicated and maybe impossible, and EMF can certainly not do it
automagically.

Hallvard

Ed Merks wrote:
> Hallvard,
>
> An instance of Container's eClass() will simply return the EClass for
> Container. There's no information at that point which EClass or
> EDataType is bound to T. Certainly there are cases like the one
> described in this chain, where someone subclasses Container with a new
> EClass and the EGenericSuperTypes do end up specifying the EClass or
> EDataType bound to T as part of defining Container to be the super type
> where it would be possible to do more. I imagine there are other cases
> where the object is known to be referenced by a feature and the type of
> the feature helps further specify the bounds. There are likely places in
> the code where checking for this type of situation could provide type
> information that's otherwise erased, but that's certainly a complication
> and an expense. Not only that, but you might well require more context,
> the original most derived class of the instance owning the feature, or
> the type of the feature referring to the instance, than you actually
> have available locally.
>
>
> Hallvard Trætteberg wrote:
>> Ed Merks wrote:
>>>
>>> Seems reasonable, but keep in mind that EMF like Java defines
>>> generics in a way where it's generally erased at runtime.
>>
>> I've encountered a problem which I think is similar. I had an abstract
>> container class with a type parameter limiting its allowed children:
>> Container<T extends Component> with a containment reference children
>> having T as its eType. Specific containers then could limit their
>> children, e.g. TabFolder<Tab>. This works well when you use the
>> specific type names like TabFolder in your code, since calls like
>> getChildren().add/remove can be checked statically. When you instead
>> write generic code against the Container class, nothing prevents you
>> from adding other kinds of Components.
>>
>> I handled this myself by implementing a special constraint that used
>> the Container's EClass (e.g. TabFolder), navigated to the type
>> parameter (e.g. Tab) and used this for checking the type of the
>> children. I think this technique can be used for other problems,
>> perhaps also specializing property editing, but I don't think EMF can
>> do this on its own. In my case, I knew that this specific type
>> parameter limited that specific reference, but I suspect (but please
>> correct me if I'm wrong) that in general the analysis that would be
>> required is too complex for EMF to do it automatically.
>>
>> Hallvard
Previous Topic:[CDO] Exception in CDORevisionDelta.compare
Next Topic:[CDO] Error at first commit to an CDO server instance
Goto Forum:
  


Current Time: Fri Sep 20 13:18:36 GMT 2024

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

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

Back to the top