EContentAdapter [message #416919] |
Wed, 20 February 2008 14:00 |
|
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();
}
}
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02217 seconds