How to add custom property to EAttribute [message #1170127] |
Mon, 04 November 2013 07:26  |
Eclipse User |
|
|
|
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 08:06   |
Eclipse User |
|
|
|
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 #1171821 is a reply to message #1171393] |
Tue, 05 November 2013 09:04  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.09216 seconds