Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EContentAdapter
EContentAdapter [message #416919] Wed, 20 February 2008 14:00 Go to next message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

Hi,

Using EContentAdapter I receive no notification if objects are changed.
super is included.

I followed the following descriptions:

http://www.eclipsezone.com/eclipse/forums/m92062667.html
http://www.eclipsepowered.com/eclipse/forums/t94946.html

Any advice?

Best regards, Lars

-----------------

Example:

The model is very simple:

package model;

import org.eclipse.emf.common.util.EList;
import java.util.List;

import org.eclipse.emf.ecore.EObject;

/**
* @model
*/
public interface IPersonList extends EObject {
/**
* @model
*/
public EList<IPerson> getPersons();

}


package model;

import org.eclipse.emf.ecore.EObject;

/**
* @model
*/
public interface IPerson extends EObject {
/**
* @model
*/
public String getFirstName();

/**
* Sets the value of the '{@link model.IPerson#getFirstName <em>First
Name</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>First Name</em>' attribute.
* @see #getFirstName()
* @generated
*/
void setFirstName(String value);
}


This class should attach itself as an observer:

package observers;

import model.IPerson;
import model.IPersonList;
import model.ModelFactory;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.util.EContentAdapter;

public class TotalObserver {
private IPersonList persons;

public TotalObserver() {
ModelFactory factory = ModelFactory.eINSTANCE;
persons = factory.createIPersonList();

EContentAdapter adapter = new EContentAdapter() {
public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
System.out
.println("Notfication received from the data model. Data model has
changed!!!");
}
};
persons.eAdapters().add(adapter);
}

public void doStuff() {
ModelFactory factory = ModelFactory.eINSTANCE;
IPerson person = factory.createIPerson();
person.setFirstName("Lars");
System.out.println("I'm adding a person.");
persons.getPersons().add(person);
System.out.println("I'm changing a entry");
IPerson person2 = persons.getPersons().get(0);
person2.setFirstName("Lars2");

}
}


A main class to test it:

package main;

import observers.TotalObserver;

public class Main {

/**
* @param args
*/
public static void main(String[] args) {
TotalObserver observ2 = new TotalObserver();
observ2.doStuff();
}
}
Re: EContentAdapter [message #416928 is a reply to message #416919] Wed, 20 February 2008 15:11 Go to previous messageGo to next message
Marcelo Paternostro is currently offline Marcelo PaternostroFriend
Messages: 602
Registered: July 2009
Senior Member
Hi Lars,

Based on the @model annotation of IPersonList.getPersons(), I believe
that the reference is not a containment. This would explain why the
EContentAdapter is not adding itself to the IPersons.

Cheers,
Marcelo

Lars Vogel wrote:
> Hi,
>
> Using EContentAdapter I receive no notification if objects are changed.
> super is included.
>
> I followed the following descriptions:
>
> http://www.eclipsezone.com/eclipse/forums/m92062667.html
> http://www.eclipsepowered.com/eclipse/forums/t94946.html
>
> Any advice?
>
> Best regards, Lars
>
> -----------------
>
> Example:
> The model is very simple:
> package model;
>
> import org.eclipse.emf.common.util.EList;
> import java.util.List;
>
> import org.eclipse.emf.ecore.EObject;
>
> /**
> * @model
> */
> public interface IPersonList extends EObject {
> /**
> * @model
> */
> public EList<IPerson> getPersons();
>
> }
>
>
> package model;
>
> import org.eclipse.emf.ecore.EObject;
>
> /**
> * @model
> */
> public interface IPerson extends EObject {
> /**
> * @model
> */
> public String getFirstName();
>
> /**
> * Sets the value of the '{@link model.IPerson#getFirstName
> <em>First Name</em>}' attribute.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @param value the new value of the '<em>First Name</em>' attribute.
> * @see #getFirstName()
> * @generated
> */
> void setFirstName(String value);
> }
>
>
> This class should attach itself as an observer:
>
> package observers;
>
> import model.IPerson;
> import model.IPersonList;
> import model.ModelFactory;
>
> import org.eclipse.emf.common.notify.Notification;
> import org.eclipse.emf.ecore.util.EContentAdapter;
>
> public class TotalObserver {
> private IPersonList persons;
>
> public TotalObserver() {
> ModelFactory factory = ModelFactory.eINSTANCE;
> persons = factory.createIPersonList();
>
> EContentAdapter adapter = new EContentAdapter() {
> public void notifyChanged(Notification notification) {
> super.notifyChanged(notification);
> System.out
> .println("Notfication received from the data
> model. Data model has changed!!!");
> }
> };
> persons.eAdapters().add(adapter);
> }
>
> public void doStuff() {
> ModelFactory factory = ModelFactory.eINSTANCE;
> IPerson person = factory.createIPerson();
> person.setFirstName("Lars");
> System.out.println("I'm adding a person.");
> persons.getPersons().add(person);
> System.out.println("I'm changing a entry");
> IPerson person2 = persons.getPersons().get(0);
> person2.setFirstName("Lars2");
>
> }
> }
>
>
> A main class to test it:
>
> package main;
>
> import observers.TotalObserver;
>
> public class Main {
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> TotalObserver observ2 = new TotalObserver();
> observ2.doStuff();
> }
> }
>
>
>
>
>
>
>
Re: EContentAdapter [message #416930 is a reply to message #416928] Wed, 20 February 2008 15:31 Go to previous messageGo to next message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

Hello Marcelo,

thank you, stupid error from my side. It works now.

Best regards, Lars
Re: EContentAdapter [message #416933 is a reply to message #416930] Wed, 20 February 2008 17:35 Go to previous messageGo to next message
Marcelo Paternostro is currently offline Marcelo PaternostroFriend
Messages: 602
Registered: July 2009
Senior Member
My pleasure!

Lars Vogel wrote:
> Hello Marcelo,
>
> thank you, stupid error from my side. It works now.
>
> Best regards, Lars
>
Re: EContentAdapter [message #416949 is a reply to message #416933] Wed, 20 February 2008 20:55 Go to previous messageGo to next message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

Hi,

for future reference I uploaded a working example here:

http://www.vogella.de/articles/EclipseEMF/article.html#emfno tifcation

Best regards, Lars

"Marcelo Paternostro" <marcelop@ca.ibm.com> wrote in message
news:fphocn$gai$1@build.eclipse.org...
> My pleasure!
>
> Lars Vogel wrote:
>> Hello Marcelo,
>>
>> thank you, stupid error from my side. It works now.
>>
>> Best regards, Lars
>>
Re: EContentAdapter [message #531002 is a reply to message #416949] Mon, 03 May 2010 10:24 Go to previous message
Kris Missing name is currently offline Kris Missing nameFriend
Messages: 47
Registered: July 2009
Member
apparently the article has moved to:
http://www.vogella.de/articles/EclipseEMFNotification/articl e.html

Am 2/20/08 9:55 PM, schrieb Lars Vogel:
> Hi,
>
> for future reference I uploaded a working example here:
>
> http://www.vogella.de/articles/EclipseEMF/article.html#emfno tifcation
>
> Best regards, Lars
>
> "Marcelo Paternostro"<marcelop@ca.ibm.com> wrote in message
> news:fphocn$gai$1@build.eclipse.org...
>> My pleasure!
>>
>> Lars Vogel wrote:
>>> Hello Marcelo,
>>>
>>> thank you, stupid error from my side. It works now.
>>>
>>> Best regards, Lars
>>>
>
>
Previous Topic:ID Attribute Name
Next Topic:Looking for examples of EContentAdapter usage
Goto Forum:
  


Current Time: Thu Apr 25 07:19:43 GMT 2024

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

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

Back to the top