Search in sources :

Example 1 with INotificationListener

use of org.eclipse.scout.rt.shared.notification.INotificationListener in project scout.rt by eclipse.

the class AbstractObservableNotificationHandler method getListeners.

/**
 * Returns the {@link INotificationListener}s for a given session.
 *
 * @param session
 *          {@link IClientSession}
 * @return {@link INotificationListener}s
 */
public List<INotificationListener<T>> getListeners(IClientSession session) {
    synchronized (m_listeners) {
        List<INotificationListener<T>> res = new ArrayList<>();
        EventListenerList listeners = m_listeners.get(session);
        if (listeners != null) {
            @SuppressWarnings("unchecked") INotificationListener<T>[] notificationListeners = listeners.getListeners(INotificationListener.class);
            if (notificationListeners != null) {
                for (INotificationListener<T> notificationListener : notificationListeners) {
                    res.add(notificationListener);
                }
            }
        }
        return res;
    }
}
Also used : INotificationListener(org.eclipse.scout.rt.shared.notification.INotificationListener) ArrayList(java.util.ArrayList) EventListenerList(org.eclipse.scout.rt.platform.util.EventListenerList)

Example 2 with INotificationListener

use of org.eclipse.scout.rt.shared.notification.INotificationListener 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);
            }
        }
    }
}
Also used : INotificationListener(org.eclipse.scout.rt.shared.notification.INotificationListener) EventListenerList(org.eclipse.scout.rt.platform.util.EventListenerList)

Example 3 with INotificationListener

use of org.eclipse.scout.rt.shared.notification.INotificationListener in project scout.rt by eclipse.

the class AbstractObservableNotificationHandlerTest method testRemoveListeners.

@SuppressWarnings("unchecked")
@Test
public void testRemoveListeners() {
    final AbstractObservableNotificationHandler<Serializable> testHandler = createGlobalHandler();
    INotificationListener l1 = mock(INotificationListener.class);
    INotificationListener l2 = mock(INotificationListener.class);
    testHandler.addListener(m_testSession1, l1);
    testHandler.addListener(m_testSession1, l2);
    testHandler.addListener(m_testSession2, l1);
    testHandler.removeListener(m_testSession1, l1);
    assertEquals(1, testHandler.getListeners(m_testSession1).size());
    assertEquals(1, testHandler.getListeners(m_testSession2).size());
}
Also used : Serializable(java.io.Serializable) INotificationListener(org.eclipse.scout.rt.shared.notification.INotificationListener) Test(org.junit.Test)

Aggregations

INotificationListener (org.eclipse.scout.rt.shared.notification.INotificationListener)3 EventListenerList (org.eclipse.scout.rt.platform.util.EventListenerList)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1