Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Cast DynamicEObjectImpl to EMF model element
Cast DynamicEObjectImpl to EMF model element [message #1699533] Wed, 24 June 2015 19:50 Go to next message
qwer qwer is currently offline qwer qwerFriend
Messages: 9
Registered: June 2015
Junior Member
Hi everyone,

I'm using a Java service to create a label for a component of my editor. The label consists of many parts. The reference to the java service works properly and I'm calling it in this way: [self.createLabel()/]. The service method looks like this:
public String createLabel(EObject eObject) {
.....
		return ((MyObject)eObject).getSomeProperty();
	}


The problem is that I'm not able to cast eObject to my EMF generated object (MyObject) because eObject is of type DynamicEObjectImpl and I don't know how to get MyObject from DynamicEObjectImpl and if that's possible. Do you have any ideas how to make this work? I need the actual object (MyObject) which is passed to the service method.

Thank you! Smile
Re: Cast DynamicEObjectImpl to EMF model element [message #1699594 is a reply to message #1699533] Thu, 25 June 2015 09:42 Go to previous message
Pierre-Charles David is currently offline Pierre-Charles DavidFriend
Messages: 703
Registered: July 2009
Senior Member
Le 24/06/2015 21:50, qwer qwer a écrit :
> Hi everyone,
>
> I'm using a Java service to create a label for a component of my editor.
> The label consists of many parts. The reference to the java service
> works properly and I'm calling it in this way: [self.createLabel()/].
> The service method looks like this:
> public String createLabel(EObject eObject) {
> ....
> return ((MyObject)eObject).getSomeProperty();
> }
>
> The problem is that I'm not able to cast eObject to my EMF generated
> object (MyObject) because eObject is of type DynamicEObjectImpl and I
> don't know how to get MyObject from DynamicEObjectImpl and if that's
> possible. Do you have any ideas how to make this work? I need the actual
> object (MyObject) which is passed to the service method.

If you use DynamicEObject, you need to use EMF's refective APIs, as the
Java classes and methods do not exist in that case.

somehting like

eObject.eGet(eObject.eClass().getEStructuralFeature("someProperty"))


--
Pierre-Charles David - Obeo

Need professional services for Sirius?
http://www.obeodesigner.com/sirius


Pierre-Charles David - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:Feature org.eclipse.sirius.runtime.acceleo missing in mars update site
Next Topic:How to reset diagram validation errors
Goto Forum:
  


Current Time: Fri Apr 26 23:48:40 GMT 2024

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

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

Back to the top