Search in sources :

Example 6 with EventListenerList

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

Example 7 with EventListenerList

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));
}
Also used : EventListenerList(org.eclipse.scout.rt.platform.util.EventListenerList) EventListener(java.util.EventListener) Test(org.junit.Test)

Example 8 with EventListenerList

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));
}
Also used : EventListenerList(org.eclipse.scout.rt.platform.util.EventListenerList) EventListener(java.util.EventListener) Test(org.junit.Test)

Example 9 with EventListenerList

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));
}
Also used : EventListenerList(org.eclipse.scout.rt.platform.util.EventListenerList) EventListener(java.util.EventListener) Test(org.junit.Test)

Example 10 with EventListenerList

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

Aggregations

EventListenerList (org.eclipse.scout.rt.platform.util.EventListenerList)16 DataChangeListener (org.eclipse.scout.rt.client.ui.DataChangeListener)4 EventListener (java.util.EventListener)3 Test (org.junit.Test)3 PropertyChangeListener (java.beans.PropertyChangeListener)2 ArrayList (java.util.ArrayList)2 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)2 OrderedCollection (org.eclipse.scout.rt.platform.util.collection.OrderedCollection)2 INotificationListener (org.eclipse.scout.rt.shared.notification.INotificationListener)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1 IClientSession (org.eclipse.scout.rt.client.IClientSession)1 IPlannerContextMenu (org.eclipse.scout.rt.client.ui.action.menu.root.IPlannerContextMenu)1 IValueFieldContextMenu (org.eclipse.scout.rt.client.ui.action.menu.root.IValueFieldContextMenu)1 PlannerContextMenu (org.eclipse.scout.rt.client.ui.action.menu.root.internal.PlannerContextMenu)1 DesktopListener (org.eclipse.scout.rt.client.ui.desktop.DesktopListener)1 PropertyMap (org.eclipse.scout.rt.platform.context.PropertyMap)1 ExceptionHandler (org.eclipse.scout.rt.platform.exception.ExceptionHandler)1