use of org.eclipse.scout.rt.platform.util.EventListenerList in project scout.rt by eclipse.
the class AbstractObservableNotificationHandler method addListener.
/**
* Add a notification listener for notifications of type T. Upon receipt of a notification,
* {@link INotificationListener#handleNotification(Serializable)} is called within a model job with the given
* {@link IClientSession}.
*
* @param listener
* {@link INotificationListener}
* @param session
* {@link IClientSession}
*/
public void addListener(IClientSession session, INotificationListener<T> listener) {
Assertions.assertNotNull(session, "client session can not be null");
Assertions.assertNotNull(listener, "listener can not be null");
synchronized (m_listeners) {
EventListenerList listeners = m_listeners.get(Assertions.assertNotNull(session));
if (listeners == null) {
listeners = new EventListenerList();
m_listeners.put(session, listeners);
}
listeners.add(INotificationListener.class, listener);
}
}
use of org.eclipse.scout.rt.platform.util.EventListenerList in project scout.rt by eclipse.
the class EventListenerListTest method testAdd.
/**
* Test for {@link EventListenerList#add(Class, java.util.EventListener)}
*/
@Test
public void testAdd() {
EventListenerList listenerList = new EventListenerList();
EventListener listener = new EventListener() {
};
listenerList.add(EventListener.class, listener);
listenerList.add(EventListener.class, listener);
Assert.assertEquals(2, listenerList.getListenerCount(EventListener.class));
}
use of org.eclipse.scout.rt.platform.util.EventListenerList in project scout.rt by eclipse.
the class EventListenerListTest method testRemove.
/**
* Test for {@link EventListenerList#add(Class, java.util.EventListener)}
*/
@Test
public void testRemove() {
EventListenerList listenerList = new EventListenerList();
EventListener listener = new EventListener() {
};
listenerList.add(EventListener.class, listener);
listenerList.add(EventListener.class, listener);
listenerList.remove(EventListener.class, listener);
Assert.assertEquals(1, listenerList.getListenerCount(EventListener.class));
}
use of org.eclipse.scout.rt.platform.util.EventListenerList in project scout.rt by eclipse.
the class EventListenerListTest method testRemoveAll.
/**
* Test for {@link EventListenerList#removeAll(Class, java.util.EventListener)}
*/
@Test
public void testRemoveAll() {
EventListenerList listenerList = new EventListenerList();
EventListener listener = new EventListener() {
};
listenerList.add(EventListener.class, listener);
listenerList.add(EventListener.class, listener);
listenerList.removeAll(EventListener.class, listener);
Assert.assertEquals(0, listenerList.getListenerCount(EventListener.class));
}
use of org.eclipse.scout.rt.platform.util.EventListenerList in project scout.rt by eclipse.
the class AbstractObservableNotificationHandler method removeListener.
/**
* Removes the given listener for the given session.
*
* @see #addListener(IClientSession, INotificationListener)
*/
public void removeListener(IClientSession session, INotificationListener<T> listener) {
Assertions.assertNotNull(session, "client session can not be null");
Assertions.assertNotNull(listener, "listener can not be null");
synchronized (m_listeners) {
EventListenerList listeners = m_listeners.get(session);
if (listeners != null) {
listeners.remove(INotificationListener.class, listener);
if (listeners.getListenerCount(INotificationListener.class) == 0) {
m_listeners.remove(session);
}
}
}
}
Aggregations