Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Setting Value via FeaturePath
Setting Value via FeaturePath [message #964226] Tue, 30 October 2012 06:59 Go to next message
Ludwig Moser is currently offline Ludwig Moser
Messages: 302
Registered: July 2009
Senior Member
Hello!

i'm trying to set a value on one of my EMF objects
so i show this by a simple example

Quote:
Person
name (simple attribute)
Address (another EMF Object)
street


so if i want to set a value by code from a EStructuralFeature
i simply call
Person.eSet(nameFeature, "new Name");


i did not see something for featurePaths, so i googled...

i found a blog entry of Tom Schindl (here)
and hoped this would solve my problem, but actually the value keeps null.

		// create a test object...
		Person p= MyFactory.eINSTANCE.createPerson();
		IEMFValueProperty mProp = EMFProperties.value(featurePath);
		mProp.setValue(p, "newGUID");


is this caused because Address is null when i try it?
as all Classes are EClasses (Person and Address) it should be possible to generate the objects (empty, all with default values).

my final question is:
is there a Class/Feature/Method available to achieve what i need? (could not find anything in the emf book either.

thanks for your help
ludwig
Re: Setting Value via FeaturePath [message #964341 is a reply to message #964226] Tue, 30 October 2012 08:51 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5014
Registered: July 2009
Senior Member
Am 30.10.12 11:59, schrieb Ludwig Moser:
> Hello!
>
> i'm trying to set a value on one of my EMF objects
> so i show this by a simple example
>
> Quote:
>> Person
>> name (simple attribute)
>> Address (another EMF Object)
>> street
>
>
> so if i want to set a value by code from a EStructuralFeature
> i simply call
> Person.eSet(nameFeature, "new Name");
>
> i did not see something for featurePaths, so i googled...
>
> i found a blog entry of Tom Schindl
> (http://tomsondev.bestsolution.at/2011/05/06/interesting-new-feature-in-emf-databinding/)
>
> and hoped this would solve my problem, but actually the value keeps null.
>
> // create a test object...
> Person p= MyFactory.eINSTANCE.createPerson();
> IEMFValueProperty mProp = EMFProperties.value(featurePath);
> mProp.setValue(p, "newGUID");
>
> is this caused because Address is null when i try it?
> as all Classes are EClasses (Person and Address) it should be possible
> to generate the objects (empty, all with default values).
>

That is not true 100% because maybe you want an instance of that is
derived from Address, it might even be that Address is abstract and one
can't even create an instance.

Tom
Re: Setting Value via FeaturePath [message #965349 is a reply to message #964341] Wed, 31 October 2012 02:51 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig Moser
Messages: 302
Registered: July 2009
Senior Member
but is this supposed to work the way i try it or not?

in the meantime i created some code which does exactly what i want, but i have a dirty workaround for getting a new instance of an EClass.

is there a way to get the EClass from an feature? (so i can create a new instance with the factory from it.)
by now i have a static function which creates an Person when i pass the String 'Person' to it (that's what i call dirty...)

btw: in my (special) case i do not have abstract classes
Re: Setting Value via FeaturePath [message #966786 is a reply to message #965349] Thu, 01 November 2012 04:20 Go to previous message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5014
Registered: July 2009
Senior Member
Am 31.10.12 07:51, schrieb Ludwig Moser:
> but is this supposed to work the way i try it or not?
>

Like I said we can't do what you want in a generic way so - yes it is
supposed to NOT work.

> in the meantime i created some code which does exactly what i want, but
> i have a dirty workaround for getting a new instance of an EClass.
>
> is there a way to get the EClass from an feature? (so i can create a new
> instance with the factory from it.)

yes getEType and then use EcoreUtil.create()

> by now i have a static function which creates an Person when i pass the
> String 'Person' to it (that's what i call dirty...)
>
> btw: in my (special) case i do not have abstract classes

in your special case that might be true but it isn't for the generic
case eclipse databinding has to deal with.

Tom
Previous Topic:Creating instance of domain EClass
Next Topic:[CDO] Access to password on the server
Goto Forum:
  


Current Time: Sat Apr 19 16:00:33 EDT 2014

Powered by FUDForum. Page generated in 0.01675 seconds