Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF with BeanSupport?(how to add an adapter which transforms notifications to pcs...)
EMF with BeanSupport? [message #902135] Thu, 16 August 2012 06:16 Go to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 370
Registered: July 2009
Senior Member
Hi!

i do need java bean support on my model for a component with glazedlists (which does only support javabeans and not emf)

my attempt was to create a class in EMF which is called JavaBeanSupport.
it provides simple functions like


  • propertyChange
  • addPropertyChangeListener
  • removePropertyChangeListener


any EClass in my model which extends this JavaBeanSupport should act as a bean...
so far so good.
i register an adapter on the class so i get an notification for every change.
in this adapter i create an PropertyChangeEvent from the notification and then send the propertyChange

but i have the problem that i cannot gain the name of the property that changed.
how can i do this?

String propertyName = n.getClass().getSimpleName() + "."
					+ n.getEventType();

i need to transform the eventtype to the property name string

PropertyChangeEvent evt = new PropertyChangeEvent(n.getNotifier(), "propertyName", getOldValue(), n.getNewValue());
// notify.getNotifier() or better notify.getFeature()?


PS: or is there already a solution to my problem? (though i did not find one on google nor this forum)
Re: EMF with BeanSupport? [message #902148 is a reply to message #902135] Thu, 16 August 2012 06:49 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
A change notification passes the EStructureFeature so this the name.

Tom

Am 16.08.12 08:16, schrieb Ludwig Moser:
> Hi!
>
> i do need java bean support on my model for a component with glazedlists
> (which does only support javabeans and not emf)
>
> my attempt was to create a class in EMF which is called JavaBeanSupport.
> it provides simple functions like
>
>
> propertyChange
> addPropertyChangeListener
> removePropertyChangeListener
>
>
> any EClass in my model which extends this JavaBeanSupport should act as
> a bean...
> so far so good.
> i register an adapter on the class so i get an notification for every
> change.
> in this adapter i create an PropertyChangeEvent from the notification
> and then send the propertyChange
>
> but i have the problem that i cannot gain the name of the property that
> changed.
> how can i do this?
>
>
> String propertyName = n.getClass().getSimpleName() + "."
> + n.getEventType();
>
> i need to transform the eventtype to the property name string
>
>
> PropertyChangeEvent evt = new PropertyChangeEvent(n.getNotifier(),
> "propertyName", getOldValue(), n.getNewValue());
> // notify.getNotifier() or better notify.getFeature()?
>
>
> PS: or is there already a solution to my problem? (though i did not find
> one on google nor this forum)
Re: EMF with BeanSupport? [message #902150 is a reply to message #902135] Thu, 16 August 2012 07:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Ludwig,

Notification.getFeature for notifications from EObjects should return
you the EStrucutralFeature (except for the REMOVING_ADAPTER event) and
from that you can get the name.

Rather than modeling JavaBeanSupport as an EClass, you might extend
EObjectImpl or MinimalEObjectImpl and specify your extension as the Root
Extends Class of the GenModel to use it for all your implementation
classes. You can specify a Root Extends Interface if you want something
in all your generated interfaces...


On 16/08/2012 8:16 AM, Ludwig Moser wrote:
> Hi!
>
> i do need java bean support on my model for a component with
> glazedlists (which does only support javabeans and not emf)
>
> my attempt was to create a class in EMF which is called JavaBeanSupport.
> it provides simple functions like
>
>
> propertyChange
> addPropertyChangeListener
> removePropertyChangeListener
>
>
> any EClass in my model which extends this JavaBeanSupport should act
> as a bean...
> so far so good.
> i register an adapter on the class so i get an notification for every
> change.
> in this adapter i create an PropertyChangeEvent from the notification
> and then send the propertyChange
>
> but i have the problem that i cannot gain the name of the property
> that changed.
> how can i do this?
>
>
> String propertyName = n.getClass().getSimpleName() + "."
> + n.getEventType();
>
> i need to transform the eventtype to the property name string
>
>
> PropertyChangeEvent evt = new PropertyChangeEvent(n.getNotifier(),
> "propertyName", getOldValue(), n.getNewValue());
> // notify.getNotifier() or better notify.getFeature()?
>
>
> PS: or is there already a solution to my problem? (though i did not
> find one on google nor this forum)
Re: EMF with BeanSupport? [message #902151 is a reply to message #902148] Thu, 16 August 2012 07:04 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 370
Registered: July 2009
Senior Member
thanks tom!
EAttribute attr = (EAttribute) n.getFeature();
String propertyName = attr.getName();
Re: EMF with BeanSupport? [message #902152 is a reply to message #902151] Thu, 16 August 2012 07:11 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 370
Registered: July 2009
Senior Member
i will try the root element too, thanks ed!
Re: EMF with BeanSupport? [message #902155 is a reply to message #902151] Thu, 16 August 2012 07:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Ludwig,

Keep in mind that EReferences produce notifications as well, so better
to cast to EStructuralFeature. And be careful that it will be null for
REMOVING_ADAPTER.

On 16/08/2012 9:04 AM, Ludwig Moser wrote:
> thanks tom!
> EAttribute attr = (EAttribute) n.getFeature();
> String propertyName = attr.getName();
Re: EMF with BeanSupport? [message #902202 is a reply to message #902155] Thu, 16 August 2012 10:30 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 370
Registered: July 2009
Senior Member
so how can i transform a sturcturalfeature to a string like
Quote:
MyObject.Address.street

where MyObject is my Class, Address is my reference and street is the attribute...
because i need to resolve this then...
Re: EMF with BeanSupport? [message #902209 is a reply to message #902202] Thu, 16 August 2012 11:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Ludwig,

You can use EStructuralFeature.getEContainingClass the containing
class. I'm not sure if you want the class that defines the feature of
if you want the actual class of the EObject (i.e., EObject.eClass(). I
don't understand the three part name. What do you mean by Address is
the reference? An EReference?


On 16/08/2012 12:30 PM, Ludwig Moser wrote:
> so how can i transform a sturcturalfeature to a string like
> Quote:
>> MyObject.Address.street
>
> where MyObject is my Class, Address is my reference and street is the
> attribute...
> because i need to resolve this then...
Re: EMF with BeanSupport? [message #902716 is a reply to message #902209] Mon, 20 August 2012 05:39 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 370
Registered: July 2009
Senior Member
let me explain it by a small example

we have ECLasses Person & Address
where Person has Attributes name, adress (an EReference to EClass Address), etc
where Address has Attributes street, city, country

get an notification from an instance of Eclass Person
and i need to access the attribute street of this person...
i usualy do this with an FeaturePath
FeaturePath.fromList(eStructuralFeatureGetAddress, eStructuralFeatureGetStreet)

by using this featurePath i could create the String (which java beans uses to resolve the getter&setter)
btw: the string would be: address.street (which gets resolved to getAddress().getStreet())

how can i do this with only one structuralfeature from the notification?

i hope you understand now what i need, or what my problem is.
thanks for your patience Smile
Re: EMF with BeanSupport? [message #902720 is a reply to message #902716] Mon, 20 August 2012 06:49 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Ludwig,

Comments below.

On 20/08/2012 7:39 AM, Ludwig Moser wrote:
> let me explain it by a small example
>
> we have ECLasses Person & Address
> where Person has Attributes name, adress (an EReference to EClass
> Address), etc
> where Address has Attributes street, city, country
>
> get an notification from an instance of Eclass Person
> and i need to access the attribute street of this person...
For the purpose of producing a bean notification. I would have imagined
that only the Address bean produces notifications for changes to the
street, which is a property of Address not a property of Person.
> i usualy do this with an FeaturePath
> FeaturePath.fromList(eStructuralFeatureGetAddress,
> eStructuralFeatureGetStreet)
> by using this featurePath i could create the String (which java beans
> uses to resolve the getter&setter)
> btw: the string would be: address.street (which gets resolved to
> getAddress().getStreet())
>
> how can i do this with only one structuralfeature from the notification?
Person will only get notifications for changes to its own features.
>
> i hope you understand now what i need, or what my problem is.
No, I just have more questions. Isn't it the case that beans produce
notifications only for changes to their own properties? After all, the
Address bean doesn't know which Person bean refers to it; it might even
be shared among many persons (and you've not mentioned whether it's a
containment reference, which would imply it's only referenced by one
Person).
> thanks for your patience :)
Re: EMF with BeanSupport? [message #902757 is a reply to message #902720] Mon, 20 August 2012 09:44 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 370
Registered: July 2009
Senior Member
you are right notifications for any change in an attribute is only needed the object which contains it.

its true that there might be an situation which makes differences if its a containment or not.

in my case its 'only' for glazedlists, which do not support EMF.

i do bind some objects to my table then the
lists register for property-changes on the properties i display in my table.
if any of the bound data changes, i fire the correlating property change event;
(if the event is not registered by the list it gets dropped, otherwise the table updates the cell which got changed)

btw: this is my current adapter
Adapter adapter = new AdapterImpl() {
		public void notifyChanged(Notification n) {
			EStructuralFeature feature = (EStructuralFeature) n.getFeature();
			if (feature == null) {
				return;
			}
			PropertyChangeEvent evt = new PropertyChangeEvent(n.getNotifier(),
					feature.getName(), n.getOldValue(), n.getNewValue()); 
		}
	};

do you think the way i do it is incorrect?
Re: EMF with BeanSupport? [message #902833 is a reply to message #902757] Mon, 20 August 2012 16:56 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Ludwig,

Comments below.

On 20/08/2012 11:44 AM, Ludwig Moser wrote:
> you are right notifications for any change in an attribute is only
> needed the object which contains it.
>
> its true that there might be an situation which makes differences if
> its a containment or not.
That will affect whether objects are shared. A containment reference
guarantees that the object is contained in at most one place no matter
how much you might try to share it; EMF will automatically remove it
from another container.
>
> in my case its 'only' for glazedlists, which do not support EMF.
>
> i do bind some objects to my table then the
> lists register for property-changes on the properties i display in my
> table.
> if any of the bound data changes, i fire the correlating property
> change event;
> (if the event is not registered by the list it gets dropped, otherwise
> the table updates the cell which got changed)
>
> btw: this is my current adapter
>
> Adapter adapter = new AdapterImpl() {
> public void notifyChanged(Notification n) {
> EStructuralFeature feature = (EStructuralFeature)
> n.getFeature();
> if (feature == null) {
> return;
> }
> PropertyChangeEvent evt = new
> PropertyChangeEvent(n.getNotifier(),
> feature.getName(), n.getOldValue(),
> n.getNewValue()); }
> };
>
> do you think the way i do it is incorrect?
I don't know enough about PropertyChangeEvent to say if this is
correct. OldValue and NewValue mean different things depending on the
type of Notification event...
Previous Topic:[CDO/DAWN] Missing Constraints while trying to reproduce "Getting Started With Dawn Web&
Next Topic:Xcore is really awesome.
Goto Forum:
  


Current Time: Tue Dec 23 03:57:55 GMT 2014

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

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