use of org.eclipse.emf.common.notify.Notification in project openhab1-addons by openhab.
the class TinkerforgeBinding method listen2Model.
/**
* Adds a listener {@link EContentAdapter} to the {@link Ecosystem}. The listener handles updated
* sensor values and posts them to the openhab eventbus by
* {@link #processTFDeviceValues(Notification) processTFDeviceValues}. Furthermore the addition
* and removal of devices is handled by {@link #initializeTFDevices(Notification)
* initializeTFDevices}.
*
* @param tinkerforgeEcosystem The EMF Ecosystem object.
*/
private void listen2Model(Ecosystem tinkerforgeEcosystem) {
EContentAdapter modelAdapter = new EContentAdapter() {
@Override
public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
logger.debug("TinkerforgeNotifier was notified");
if (notification.getEventType() == Notification.ADD || notification.getEventType() == Notification.ADD_MANY || notification.getEventType() == Notification.REMOVE || notification.getEventType() == Notification.REMOVE_MANY) {
initializeTFDevices(notification);
} else {
processTFDeviceValues(notification);
}
}
};
tinkerforgeEcosystem.eAdapters().add(modelAdapter);
}
use of org.eclipse.emf.common.notify.Notification in project xtext-core by eclipse.
the class DerivedStateAwareResourceTest method testInitialization.
@Test
public void testInitialization() throws Exception {
TestedResource resource = new TestedResource();
assertTrue(resource.getContents().isEmpty());
resource.setDerivedStateComputer(new IDerivedStateComputer() {
@Override
public void installDerivedState(DerivedStateAwareResource resource, boolean resolve) {
fail("shouldn't be called after initialization");
}
@Override
public void discardDerivedState(DerivedStateAwareResource resource) {
fail("shouldn't be called after initialization");
}
});
resource.getContents();
resource.setIsLoaded();
resource.eAdapters().add(new AdapterImpl() {
@Override
public void notifyChanged(Notification msg) {
fail("notification received");
super.notifyChanged(msg);
}
});
resource.setDerivedStateComputer(new IDerivedStateComputer() {
@Override
public void installDerivedState(DerivedStateAwareResource resource, boolean resolve) {
resource.getContents().add(EcoreFactory.eINSTANCE.createEObject());
}
@Override
public void discardDerivedState(DerivedStateAwareResource resource) {
resource.getContents().clear();
}
});
assertEquals(1, resource.getContents().size());
}
Aggregations