Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to add custom property to EAttribute
How to add custom property to EAttribute [message #1170127] Mon, 04 November 2013 12:26 Go to next message
Thomas Wilhelm is currently offline Thomas WilhelmFriend
Messages: 28
Registered: September 2013
Junior Member
Hey all,

is it possible to add a custom property to an EAttribute? On every EAttribute (e.g. 'firstName', 'lastName', 'age' ) i want to define wether it is searchable or not. The 'searchable' fields are shown in my search UI then. I want to do that so i can just change the underlying EMF Model and the 'searchable' fields of this model will be displayed. Is that possible or is there even a better solution?

Thanks alot for any help.

Thomas
Re: How to add custom property to EAttribute [message #1170184 is a reply to message #1170127] Mon, 04 November 2013 13:06 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1195
Registered: July 2009
Location: Canada
Senior Member

Hi, Thomas,

This is what Ecore's EAnnotation is for. You can annotate any element
in an Ecore model to attach your own metadata.

See numerous examples of annotations in action in the EcoreUtil class.

An alternative is the "decorator model" approach, similar to the design
of the GenModel. You can create a UI model that has some EClass
defining search behaviour that references the EAttributes in your Ecore
model that are searchable. This has the advantage not only of leaving
UI concerns out of your Ecore model (even as annotations) but also of
being separately editable: it is even applicable to Ecore models that
you cannot edit (for example, Ecore.ecore).

HTH,

Christian

On 2013-11-04 12:26:31 +0000, Thomas Wilhelm said:

> Hey all,
>
> is it possible to add a custom property to an EAttribute? On every
> EAttribute (e.g. 'firstName', 'lastName', 'age' ) i want to define
> wether it is searchable or not. The 'searchable' fields are shown in my
> search UI then. I want to do that so i can just change the underlying
> EMF Model and the 'searchable' fields of this model will be displayed.
> Is that possible or is there even a better solution?
>
> Thanks alot for any help.
>
> Thomas
Re: How to add custom property to EAttribute [message #1170214 is a reply to message #1170184] Mon, 04 November 2013 13:35 Go to previous messageGo to next message
Thomas Wilhelm is currently offline Thomas WilhelmFriend
Messages: 28
Registered: September 2013
Junior Member
Hi Christian,

thanks for your tips, i will try that, your second approach sounds very good and flexible to me.

Thanks alot and Greetz
Thomas
Re: How to add custom property to EAttribute [message #1170284 is a reply to message #1170184] Mon, 04 November 2013 14:32 Go to previous messageGo to next message
Thomas Wilhelm is currently offline Thomas WilhelmFriend
Messages: 28
Registered: September 2013
Junior Member
Hey Christian,

one more question Wink How can i make a reference from my "Decorator Model" to the attribute in my "Data Model"? I mean i could create a decorator class having attributes with exactely the same names as the attributes in my "Data model" but maybe i can directley reference them? I didn´t found a way in the diagramm or ecore editor. Maybe you have another hint for me? Wink

Thanks and Greetz
Thomas
Re: How to add custom property to EAttribute [message #1170295 is a reply to message #1170284] Mon, 04 November 2013 14:40 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30372
Registered: July 2009
Senior Member
Thomas,

Use Load Resource... in the outline to load you other Ecore model so you
can make new EReferences to use EClasses from that other model.

On 04/11/2013 3:32 PM, Thomas Wilhelm wrote:
> Hey Christian,
>
> one more question ;) How can i make a reference from my "Decorator
> Model" to the attribute in my "Data Model"? I mean i could create a
> decorator class having attributes with exactely the same names as the
> attributes in my "Data model" but maybe i can directley reference
> them? I didn´t found a way in the diagramm or ecore editor. Maybe you
> have another hint for me? ;)
>
> Thanks and Greetz
> Thomas
Re: How to add custom property to EAttribute [message #1170335 is a reply to message #1170295] Mon, 04 November 2013 15:17 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1195
Registered: July 2009
Location: Canada
Senior Member

Hi, Thomas, Ed,

Right. And not only that, but then an EReference in the decorator
model that has Ecore::EStructuralFeature as its type can be used to
reference the EAttributes and EReferences in the "Data Model" that are
searchable.

cW


On 2013-11-04 14:40:56 +0000, Ed Merks said:

> Thomas,
>
> Use Load Resource... in the outline to load you other Ecore model so
> you can make new EReferences to use EClasses from that other model.
>
> On 04/11/2013 3:32 PM, Thomas Wilhelm wrote:
>> Hey Christian,
>>
>> one more question ;) How can i make a reference from my "Decorator
>> Model" to the attribute in my "Data Model"? I mean i could create a
>> decorator class having attributes with exactely the same names as the
>> attributes in my "Data model" but maybe i can directley reference them?
>> I didn´t found a way in the diagramm or ecore editor. Maybe you have
>> another hint for me? ;)
>>
>> Thanks and Greetz
>> Thomas
Re: How to add custom property to EAttribute [message #1171393 is a reply to message #1170335] Tue, 05 November 2013 07:46 Go to previous messageGo to next message
Thomas Wilhelm is currently offline Thomas WilhelmFriend
Messages: 28
Registered: September 2013
Junior Member
Hi Christian,

sorry but i didn´t get that. What i have done is created a EReference from my decorator model to my data model and then defined all my "searchable" attributes in the "EKeys" property. That works for me but i´m sure your solution is the better one. So i tried to create a EReference to Ecore:EStructuralFeature but i didn´t know how to do that. Do i have to create a class with this type? Sorry for so many questions, if there is a tutorial you can also post a link i will try myself. If there is no tutorial maybe it make sense to create one, i really like your approach and i think more developers should know about that Wink

Many thanks and Greetings

Thomas
Re: How to add custom property to EAttribute [message #1171821 is a reply to message #1171393] Tue, 05 November 2013 14:04 Go to previous message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1195
Registered: July 2009
Location: Canada
Senior Member

Hi, Thomas,

As I understand it, the eKeys property is used by the XMLResource to
construct stable IDREFs for objects.

To reference the Ecore::EStructuralFeature EClass as the type of a
reference in your decorator model, you may need first to load the Ecore
metamodel using the Load Resource... action in the editor. Use the
Browse Registered Packages... button to find Ecore.

So, now you can have an EReference named "searchable" of type
EStructuralFeature in some EClass describing your search capability.
Then, an instance of that EClass can add the "firstName", "lastName",
"age", etc. attributes from your data model to its "searchable"
reference.

The key in this approach is that your decorator model for the UI
describes the semantics that you can attach to your Ecore model, but
you need an *instance* of that decorator model at run-time to actually
make use of it.

As far as tutorials or examples are concerned, the EMF Generator Model
is the classic example of this approach. You have already used this to
generate your model implementation. The GenModel.ecore attaches code
generation metadata to your Ecore model in exactly the same way as this
thread proposes attaching searchable-ness and other concerns.

HTH,

Christian

On 2013-11-05 07:46:22 +0000, Thomas Wilhelm said:

> Hi Christian,
>
> sorry but i didn´t get that. What i have done is created a EReference
> from my decorator model to my data model and then defined all my
> "searchable" attributes in the "EKeys" property. That works for me but
> i´m sure your solution is the better one. So i tried to create a
> EReference to Ecore:EStructuralFeature but i didn´t know how to do
> that. Do i have to create a class with this type? Sorry for so many
> questions, if there is a tutorial you can also post a link i will try
> myself. If there is no tutorial maybe it make sense to create one, i
> really like your approach and i think more developers should know about
> that ;)
>
> Many thanks and Greetings
>
> Thomas
Previous Topic:Use of OCL with CDO
Next Topic:Uniqueness in derived EReferences
Goto Forum:
  


Current Time: Sun Aug 25 20:07:47 GMT 2019

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

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

Back to the top