Home » Modeling » EMF » EMF Databinding to Inherited Attribute(How to get EStructuralFeature of inherited attribute.)
| |
Re: EMF Databinding to Inherited Attribute [message #487608 is a reply to message #487494] |
Wed, 23 September 2009 17:28 |
Andy Condon 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.
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 |
Ed Merks 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 |
Thomas Schindl 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 |
Andy Condon 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
|
|
|
Goto Forum:
Current Time: Fri Apr 26 02:47:39 GMT 2024
Powered by FUDForum. Page generated in 0.03409 seconds
|