Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to access certain EStructuralFeatures?
How to access certain EStructuralFeatures? [message #1177138] Fri, 08 November 2013 20:01 Go to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Hello there!

I know that there are ways to access an EAttribute of an Eclipse EMF model by its featureID or by its name via different indirect approaches. For that I found the following from StackOverflow: http://stackoverflow.com/questions/13370773/eclipse-emf-how-to-get-access-eattribute-by-name/19861549#19861549

But what if I don't know the name of the attribute I want to get? Let's say, based on the design, the model has some fixed attributes by the developer, along with the features that can be set dynamically by the user.

So, for the time being I use the getEAllStructuralFeatures() and use indexes via get() to reach to the by-the-user-created attributes, since I know that the list I get will have the fixed attributes of the model as its first elements beginning with the index 0. But I find this solution unclear and inefficient. Also in some cases, that I want to work, not suitable.

E.g:
IEMFEditProperty prop = EMFEditProperties.list(editingDomain, EMFMODELPackage.Literals.EMFMODEL.getEAllStructuralFeatures().get(X));


Do you know a solution or a workaround for this problem? As far as I can see, there are no direct methods to get such dynamically created features of the model.

Every help will be appreciated.
Re: How to access certain EStructuralFeatures? [message #1178468 is a reply to message #1177138] Sat, 09 November 2013 17:34 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1199
Registered: July 2009
Location: Canada
Senior Member

Hi,

See some comments in-line, below.

HTH,

Christian

On 2013-11-08 20:01:54 +0000, Emre T said:

> Hello there!
>
> I know that there are ways to access an EAttribute of an Eclipse EMF
> model by its featureID or by its name via different indirect
> approaches. For that I found the following from StackOverflow:
> http://stackoverflow.com/questions/13370773/eclipse-emf-how-to-get-access-eattribute-by-name/19861549#19861549
>
>
> But what if I don't know the name of the attribute I want to get? Let's
> say, based on the design, the model

How do you know that you even want to get the attribute if you don't
know which one it is? Somehow, you have to know which attribute you
need to access, otherwise its value will be of no use. Something in
the application, whether it be the UI interacting with the user or
something else, will know the name of the feature.

Or, I'm missing something.


> has some fixed attributes by the developer, along with the features
> that can be set dynamically by the user.

Ecore models don't support dynamic addition of attributes, AFAIK. Once
defined, an EClass is "frozen", immutable. There are mechanisms by
which additional data can be attached to objects using a flexible
schema like name/value pairs, annotations, even UML stereotypes. But,
the access patterns for these mechanisms are all different.


> So, for the time being I use the getEAllStructuralFeatures() and use
> indexes via get() to reach to the by-the-user-created attributes, since
> I know that the list I get will have the fixed attributes of the model
> as its first elements beginning with the index 0. But I find this
> solution unclear and inefficient. Also in some cases, that I want to
> work, not suitable.

In what cases is it unsuitable for your application? I think in all
cases it would break EMF's assumptions about the structure of EClasses.

In any case, wouldn't you at least know the name of the attribute that
you want to access? EClass::getEStructuralFeature(String) will supply
it.


> E.g: IEMFEditProperty prop = EMFEditProperties.list(editingDomain,
> EMFMODELPackage.Literals.EMFMODEL.getEAllStructuralFeatures().get(X));

How do data bindings fit into the picture? So far, it has been an
Ecore model problem.


> Do you know a solution or a workaround for this problem? As far as I
> can see, there are no direct methods to get such dynamically created
> features of the model.

I think there isn't enough information yet about the context of your
problem, for example why it is that the application doesn't know how to
identify a feature that it needs to access.


> Every help will be appreciated.
Re: How to access certain EStructuralFeatures? [message #1179444 is a reply to message #1178468] Sun, 10 November 2013 09:16 Go to previous messageGo to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Thanks for the reply.

Well, the perfect example for situation would be the Papyrus. With it, it is also possible that the user identifies new features for the models as stereotypes. And the integrated properties view of Eclipse still manages to show the new identified attributes of the models. Even though that it does not know how the new attributes called.

And yes, funny that it sounds, my UI application doesn't know at the compile time which attributes of a chosen model instance should be shown. Since for every different model instance, there can be different features, beside the ones that are hard-designed/-coded in the model (There are three of them.).

By the way the data binding was just an example. I just need to access these features and bid them to my view.

You have mentioned that there are different access patterns for name/value schemes, annotations or UML Stereotypes. Where can I get some more information regarding these? It might be helpful I guess.

Again, thanks a lot.
Re: How to access certain EStructuralFeatures? [message #1179798 is a reply to message #1179444] Sun, 10 November 2013 14:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30688
Registered: July 2009
Senior Member
Emre,

Comments below.

On 10/11/2013 10:16 AM, Emre T wrote:
> Thanks for the reply.
> Well, the perfect example for situation would be the Papyrus. With it,
> it is also possible that the user identifies new features for the
> models as stereotypes.
Yes, but that's not the same as adding features dynamically to an EClass.
> And the integrated properties view of Eclipse still manages to show
> the new identified attributes of the models.
It's using dynamic Ecore for that. A whole new model is created...
> Even though that it does not know how the new attributes called.
But it knows the EClass and can use EClass.getEAllStructuralFeatures,
but again, that's not the same as you've added structural features to an
existing EClass.
>
> And yes, funny that it sounds, my UI application doesn't know at the
> compile time which attributes of a chosen model instance should be shown.
How does it know what should be shown and is that a subset of all the
features?
> Since for every different model instance, there can be different
> features, beside the ones that are hard-designed/-coded in the model
> (There are three of them.).
No, that I don't understand. The features of a generated EClass are
fixed and cannot change. There might be a dynamic subclass that
introduces new features. But for your generated class
XyzPackage.ABC__COUNT will give you the number of features in your
generated class.
>
> By the way the data binding was just an example. I just need to access
> these features and bid them to my view.
>
> You have mentioned that there are different access patterns for
> name/value schemes, annotations or UML Stereotypes. Where can I get
> some more information regarding these? It might be helpful I guess.
What you find on EMF's documentation page and the EMF book itself is
pretty much all there is.
>
> Again, thanks a lot.
Re: How to access certain EStructuralFeatures? [message #1180005 is a reply to message #1179444] Sun, 10 November 2013 18:11 Go to previous message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1199
Registered: July 2009
Location: Canada
Senior Member

Hi,

In addition to Ed's reply, there is something special about how
stereotypes work in UML (as you observed them in Papyrus). Not only
are stereotypes implemented by entirely distinct (from the base UML
elements) EClasses, but there is the question of how the tooling knows
*which* stereotypes are applied to any given element, in order to show
its attributes.

In the case of UML and stereotypes, this is accomplished by a very
particular convention: the stereotype instances attached to an element
are found by:

- searching the cross-references inbound to the UML model element
- filtering those inbound references for those that modeled with
property names beginning with "base_" (as is conventional for
metaclass extension ends)
- filtering further only those in which the referring element's EClass
traces to a Stereotype in a UML Profile

So, this happens to be one of the more complex (though quite robust)
ways to dynamically add properties to model elements that are
completely unknown at design/compile time. An important characteristic
of this design is that different stereotypes may be applied to
(decorating) distinct instances of the same UML metaclass (Ecore
EClass).

HTH,

Christian


On 2013-11-10 09:16:30 +0000, Emre T said:

> Thanks for the reply.
> Well, the perfect example for situation would be the Papyrus. With it,
> it is also possible that the user identifies new features for the
> models as stereotypes. And the integrated properties view of Eclipse
> still manages to show the new identified attributes of the models. Even
> though that it does not know how the new attributes called.
>
> And yes, funny that it sounds, my UI application doesn't know at the
> compile time which attributes of a chosen model instance should be
> shown. Since for every different model instance, there can be different
> features, beside the ones that are hard-designed/-coded in the model
> (There are three of them.).
>
> By the way the data binding was just an example. I just need to access
> these features and bid them to my view.
>
> You have mentioned that there are different access patterns for
> name/value schemes, annotations or UML Stereotypes. Where can I get
> some more information regarding these? It might be helpful I guess.
>
> Again, thanks a lot.
Previous Topic:TreeViewer collapsing after saving
Next Topic:Saving model in a resource causes IOWrappedException
Goto Forum:
  


Current Time: Wed Dec 11 00:34:20 GMT 2019

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

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

Back to the top