Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF Databinding to Inherited Attribute(How to get EStructuralFeature of inherited attribute.)
EMF Databinding to Inherited Attribute [message #487377] Tue, 22 September 2009 23:18 Go to next message
Andy Condon is currently offline Andy CondonFriend
Messages: 18
Registered: July 2009
Junior Member
I using the EMF databinding API in order to bind text fields, etc to elements of my EMF model. I haven't had many issues getting this to work when following Tom Schindl's blog at http://tomsondev.bestsolution.at/2009/06/06/galileo-improved -emf-databinding-support/. In this blog he uses the generated model package to get the EAttributes of classes in his model.

An example of what I'm talking about is this:

final IEMFValueProperty shortProp =
EMFEditProperties.value(editingDomain, ProjectPackage.Literals.PROJECT__SHORTNAME);

This all works fine for me as well so long as I'm using attributes that are specified directly in that class. However, in my design I have some classes that also implement interfaces with attributes of their own.

I would like to create views of my concrete classes that use databinding to the attributes specified in the interface. While there are feature id's generated for those attributes, there are no literals for them generated in <MODEL_NAME>Package.java.

How do I access the EStructuralFeature (EAttribute, etc) of an attribute that is inherited from an interface?

Another question might be is there a way to access the EStructuralFeature of an attribute for a specific class using its feature id?

Thanks for any help,

Andy
Re: EMF Databinding to Inherited Attribute [message #487494 is a reply to message #487377] Wed, 23 September 2009 12:41 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Andy,

The literals are defined directly for each base class. So if a class is
in package Xyz, you'll have
XyzPackage.Literals.<class-name>__<feature-name>.


Andy Condon wrote:
> I using the EMF databinding API in order to bind text fields, etc to
> elements of my EMF model. I haven't had many issues getting this to
> work when following Tom Schindl's blog at
> http://tomsondev.bestsolution.at/2009/06/06/galileo-improved -emf-databinding-support/.
> In this blog he uses the generated model package to get the
> EAttributes of classes in his model.
>
> An example of what I'm talking about is this:
>
> final IEMFValueProperty shortProp =
> EMFEditProperties.value(editingDomain,
> ProjectPackage.Literals.PROJECT__SHORTNAME);
>
> This all works fine for me as well so long as I'm using attributes
> that are specified directly in that class. However, in my design I
> have some classes that also implement interfaces with attributes of
> their own.
>
> I would like to create views of my concrete classes that use
> databinding to the attributes specified in the interface. While there
> are feature id's generated for those attributes, there are no literals
> for them generated in <MODEL_NAME>Package.java.
> How do I access the EStructuralFeature (EAttribute, etc) of an
> attribute that is inherited from an interface?
>
> Another question might be is there a way to access the
> EStructuralFeature of an attribute for a specific class using its
> feature id?
>
> Thanks for any help,
>
> Andy


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Databinding to Inherited Attribute [message #487608 is a reply to message #487494] Wed, 23 September 2009 17:28 Go to previous messageGo to next message
Andy Condon is currently offline Andy CondonFriend
Messages: 18
Registered: July 2009
Junior Member
Thanks for the quick reply Ed, perhaps a little more explanation of my problem is necessary.

In my model I have defined an interface with some attributes and a class that implements that interface with some attributes of its own. For example:

INetworkInterface
ipAddress : EString
...

Computer -> INetworkInterface
name : EString
...

Here is an example of the code I am using to add text widgets to a form and bind the values to the model attributes:

// Create a master observable to listen for changes to the Computer class.
IObservableValue masterObservable = new WritableValue();

// Set the value to an instance of the computer class from the resource.
masterObservable.setValue(computer);

IEMFValueProperty modelValueProperty = EMFProperties.value(ModelPackage.Literals.COMPUTER__NAME);
          
// Create a text widget value property to bind to.
IWidgetValueProperty widgetTextProperty = WidgetProperties.text(SWT.Modify);

toolkit.createLabel(parent, "&Name: ");

// Create the text widget to add to the form.
Text text = toolkit.createText(parent, "", SWT.SINGLE);
text.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 1, 1));

// Bind the value of the text widget to the value of the EAttribute.
dataBindingContext.bindValue(widgetTextProperty.observeDelayed(delay, text), modelValueProperty.observeDetail(masterObservable), null, null);


That code works fine whenever the attribute is directly contained by the class I have set the masterObservable to observe. The problem I am having is when trying to display the inherited attributes i.e. the ipAddress of the computer. I can easily call computer.getIpAddress() to get the value for that attribute but am having trouble getting it to work with the databinding API.

What I have tried so far is to keep the master observable set to the computer just like in the example above. But, since as you said the literals are only generated for attributes of each base class, I try to use this for the EAttribute to bind to:

IEMFValueProperty modelValueProperty = EMFProperties.value(ModelPackage.Literals.NETWORK_INTERFACE__IP_ADDRESS);


This does not work and only shows a seemingly useless string that is the same even between different instance of the Computer class. What should I be doing differently in my code example to bind to the value of an attribute defined in an interface?

Thanks for the help, I'm a bit stumped. Neutral

Andy

[Updated on: Wed, 23 September 2009 17:28]

Report message to a moderator

Re: EMF Databinding to Inherited Attribute [message #487685 is a reply to message #487608] Thu, 24 September 2009 07:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Andy,

Comments below.

Andy Condon wrote:
> Thanks for the quick reply Ed, perhaps a little more explanation of my
> problem is necessary.
>
> In my model I have defined an interface with some attributes and a
> class that implements that interface with some attributes of its own.
> For example:
>
> INetworkInterface
> ipAddress : EString
> ..
>
> Computer -> INetworkInterface
> name : EString
> ..
>
>
> Here is an example of the code I am using to add text widgets to a
> form and bind the values to the model attributes:
>
> // Create a master observable to listen for changes to the Computer
> class.
> IObservableValue masterObservable = new WritableValue();
>
> // Set the value to an instance of the computer class from the resource.
> masterObservable.setValue(computer);
>
> IEMFValueProperty modelValueProperty =
> EMFProperties.value(ModelPackage.Literals.COMPUTER__NAME);
> // Create a text widget value property to bind to.
> IWidgetValueProperty widgetTextProperty =
> WidgetProperties.text(SWT.Modify);
>
> toolkit.createLabel(parent, "&Name: ");
>
> // Create the text widget to add to the form.
> Text text = toolkit.createText(parent, "", SWT.SINGLE);
> text.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 1,
> 1));
>
> // Bind the value of the text widget to the value of the EAttribute.
> dataBindingContext.bindValue(widgetTextProperty.observeDelay ed(delay,
> text), modelValueProperty.observeDetail(masterObservable), null, null);
>
>
> That code works fine whenever the attribute is directly contained by
> the class I have set the masterObservable to observe. The problem I am
> having is when trying to display the inherited attributes i.e. the
> ipAddress of the computer. I can easily call computer.getIpAddress()
> to get the value for that attribute but am having trouble getting it
> to work with the databinding API.
I can't imagine why an inherited attribute would present a different
problem though...
>
> What I have tried so far is to keep the master observable set to the
> computer just like in the example above. But, since as you said the
> literals are only generated for attributes of each base class, I try
> to use this for the EAttribute to bind to:
>
>
> IEMFValueProperty modelValueProperty =
> EMFProperties.value(ModelPackage.Literals.NETWORK_INTERFACE_ _IP_ADDRESS);
>
>
> This does not work and only shows a seemingly useless string that is
> the same even between different instance of the Computer class.
And where does that string value come from? There's no reason I can
imagine why the above wouldn't work.
> What should I be doing differently in my code example to bind to the
> value of an attribute defined in an interface?
>
> Thanks for the help, I'm a bit stumped. :|
I think it should just work. Regardless of which class the feature is
defined in, EObject.eGet will be called to fetch the value for it, so
tracking in the debugger what's happening there should help.
>
> Andy


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Databinding to Inherited Attribute [message #487715 is a reply to message #487685] Thu, 24 September 2009 08:42 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Me neither. If you create a JUnit-Test showing the problem so that we
can reproduce :-) I can take a look. The existing tests (really very few
) in test.databinding and test.databinding.editing will get you started
I hope.

Tom

Ed Merks schrieb:
> Andy,
>
> Comments below.
>
> Andy Condon wrote:
>> Thanks for the quick reply Ed, perhaps a little more explanation of my
>> problem is necessary.
>>
>> In my model I have defined an interface with some attributes and a
>> class that implements that interface with some attributes of its own.
>> For example:
>>
>> INetworkInterface
>> ipAddress : EString
>> ..
>>
>> Computer -> INetworkInterface
>> name : EString
>> ..
>>
>>
>> Here is an example of the code I am using to add text widgets to a
>> form and bind the values to the model attributes:
>>
>> // Create a master observable to listen for changes to the Computer
>> class.
>> IObservableValue masterObservable = new WritableValue();
>>
>> // Set the value to an instance of the computer class from the resource.
>> masterObservable.setValue(computer);
>>
>> IEMFValueProperty modelValueProperty =
>> EMFProperties.value(ModelPackage.Literals.COMPUTER__NAME);
>> // Create a text widget value property to bind to.
>> IWidgetValueProperty widgetTextProperty =
>> WidgetProperties.text(SWT.Modify);
>>
>> toolkit.createLabel(parent, "&Name: ");
>>
>> // Create the text widget to add to the form.
>> Text text = toolkit.createText(parent, "", SWT.SINGLE);
>> text.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 1,
>> 1));
>>
>> // Bind the value of the text widget to the value of the EAttribute.
>> dataBindingContext.bindValue(widgetTextProperty.observeDelay ed(delay,
>> text), modelValueProperty.observeDetail(masterObservable), null, null);
>>
>>
>> That code works fine whenever the attribute is directly contained by
>> the class I have set the masterObservable to observe. The problem I am
>> having is when trying to display the inherited attributes i.e. the
>> ipAddress of the computer. I can easily call computer.getIpAddress()
>> to get the value for that attribute but am having trouble getting it
>> to work with the databinding API.
> I can't imagine why an inherited attribute would present a different
> problem though...
>>
>> What I have tried so far is to keep the master observable set to the
>> computer just like in the example above. But, since as you said the
>> literals are only generated for attributes of each base class, I try
>> to use this for the EAttribute to bind to:
>>
>>
>> IEMFValueProperty modelValueProperty =
>> EMFProperties.value(ModelPackage.Literals.NETWORK_INTERFACE_ _IP_ADDRESS);
>>
>>
>> This does not work and only shows a seemingly useless string that is
>> the same even between different instance of the Computer class.
> And where does that string value come from? There's no reason I can
> imagine why the above wouldn't work.
>> What should I be doing differently in my code example to bind to the
>> value of an attribute defined in an interface?
>>
>> Thanks for the help, I'm a bit stumped. :|
> I think it should just work. Regardless of which class the feature is
> defined in, EObject.eGet will be called to fetch the value for it, so
> tracking in the debugger what's happening there should help.
>>
>> Andy
Re: EMF Databinding to Inherited Attribute [message #487896 is a reply to message #487377] Thu, 24 September 2009 18:07 Go to previous message
Andy Condon is currently offline Andy CondonFriend
Messages: 18
Registered: July 2009
Junior Member
Okay, I made a simple test case to exactly match the theoretical example I posted earlier and it works as expected. I should have done that sooner. My problem seems to be in a more complex interface I have created that uses generics. I'll do more debugging on that one and post results I find. In case anyone's interested, my complex interface looks like this:

IAlarmable<A>
warningBaseline : A
...

IProximityAlarmable<A> -> IAlarmable<A>
warningHysteresis : A
...

Computer -> IProximityAlarmable<EIntegerObject>
name : EString
alarmValue : EIntegerObject
...

[Updated on: Thu, 24 September 2009 18:12]

Report message to a moderator

Previous Topic:how to reorder FeatureMap?
Next Topic:EMF Buch Code
Goto Forum:
  


Current Time: Fri Apr 26 02:47:39 GMT 2024

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

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

Back to the top