Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to get value of an EAttribute?(accessing the instances of eclass)
How to get value of an EAttribute? [message #641340] Thu, 25 November 2010 06:26 Go to next message
Bharani  is currently offline Bharani Friend
Messages: 2
Registered: November 2010
Junior Member
Hi,

I'm very new to EMF. I've created my model code using the generate options. I've also created the diagram editor using GMF to create the diagrams.

I want to create my own custom java code using JET by accessing the instances of eclasses. I don't know how to traverse through the created objects to retrieve the value of eattributes that are set in the diagram.
For eg, I've access to PurhcaseOrderFactory and PurchaseOrderPackage. How to retrieve the details of purchase order. I want to get the instance of purchase order rather than the eclass instance. Can yoy post the sample code to achieve this.

regards,
Bharani
Re: How to get value of an EAttribute? [message #641346 is a reply to message #641340] Thu, 25 November 2010 07:00 Go to previous messageGo to next message
Animesh Kumar is currently offline Animesh KumarFriend
Messages: 79
Registered: September 2010
Location: Bangalore
Member
Hi Bharani,

By the question, do u mean that you wanted to retrieve all the Attributes within a class????

You can do that as follows:-

EList<EClassifier> eClassifiers = PurchaseOrderPackage.eINSTANCE.getEClassifiers();

The above code will retrieve you all the EClasses. Then you can retrieve the attributes from each EClass.

for (EClassifier eclass : eClassifiers) {
EList<EAttribute> eAllAttributes = ((EClass) eclass).getEAllAttributes();
EList<EAttribute> eLocalAttributesofTheClass = ((EClass) eclass).getEAttributes();
}




Regards,
Animesh
Re: How to get value of an EAttribute? [message #641347 is a reply to message #641346] Thu, 25 November 2010 07:05 Go to previous messageGo to next message
Bharani  is currently offline Bharani Friend
Messages: 2
Registered: November 2010
Junior Member
Hi Animesh,

I'm able to retrieve eattributes. what i want to get is the value of the attribute that is set through the editor(developed using GMF). For eg, the value of quantity, price from item object etc.

regards,
Bharani
Re: How to get value of an EAttribute? [message #641363 is a reply to message #641347] Thu, 25 November 2010 08:25 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 699
Registered: July 2009
Senior Member
Hi,

eGet(eAttribute)

Cheers
Jonas

On 25.11.10 08:05, Bharani wrote:
> Hi Animesh,
>
> I'm able to retrieve eattributes. what i want to get is the value of the
> attribute that is set through the editor(developed using GMF). For eg,
> the value of quantity, price from item object etc.
>
> regards,
> Bharani
Re: How to get value of an EAttribute? [message #641461 is a reply to message #641340] Thu, 25 November 2010 15:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Bharani,

Generally you'd load the resource and use getContents() to get at the
objects in the root of the resource. Is your model instance stored in
the same resource as the diagram (instances of the Notation model) or
are they in separate resources?


Bharani wrote:
> Hi,
>
> I'm very new to EMF. I've created my model code using the generate
> options. I've also created the diagram editor using GMF to create the
> diagrams.
> I want to create my own custom java code using JET by accessing the
> instances of eclasses. I don't know how to traverse through the
> created objects to retrieve the value of eattributes that are set in
> the diagram. For eg, I've access to PurhcaseOrderFactory and
> PurchaseOrderPackage. How to retrieve the details of purchase order. I
> want to get the instance of purchase order rather than the eclass
> instance. Can yoy post the sample code to achieve this.
>
> regards,
> Bharani


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to get value of an EAttribute? [message #641462 is a reply to message #641347] Thu, 25 November 2010 15:06 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Bharani,

Try to maintain a single thread for your one question. Given that you
have a generated API and are talking about wanting to use instances in a
template language, I imagine you should just be casting to your
generated API's instances and using the API methods to access all the
data. Using EObject.eGet is fine when writing purely generic code, but
my guess is that's not what you're doing...


Bharani wrote:
> Hi Animesh,
>
> I'm able to retrieve eattributes. what i want to get is the value of
> the attribute that is set through the editor(developed using GMF). For
> eg, the value of quantity, price from item object etc.
>
> regards,
> Bharani


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Teneo] UsageCrossReferencer(EObject, EObject)
Next Topic:Loading EMF Model from plugin-directory
Goto Forum:
  


Current Time: Thu Apr 25 22:44:48 GMT 2024

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

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

Back to the top