Search in sources :

Example 1 with Notification

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);
}
Also used : Notification(org.eclipse.emf.common.notify.Notification) EContentAdapter(org.eclipse.emf.ecore.util.EContentAdapter)

Example 2 with Notification

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());
}
Also used : AdapterImpl(org.eclipse.emf.common.notify.impl.AdapterImpl) Notification(org.eclipse.emf.common.notify.Notification) Test(org.junit.Test)

Aggregations

Notification (org.eclipse.emf.common.notify.Notification)2 AdapterImpl (org.eclipse.emf.common.notify.impl.AdapterImpl)1 EContentAdapter (org.eclipse.emf.ecore.util.EContentAdapter)1 Test (org.junit.Test)1