Search in sources :

Example 1 with DataChangeListener

use of org.eclipse.scout.rt.client.ui.DataChangeListener in project scout.rt by eclipse.

the class AbstractDesktop method addDataChangeListener.

@Override
public void addDataChangeListener(DataChangeListener listener, Object... dataTypes) {
    if (dataTypes == null || dataTypes.length == 0) {
        SimpleEventListenerList<DataChangeListener> list = m_dataChangeListenerList.get(null);
        if (list == null) {
            list = new SimpleEventListenerList<DataChangeListener>();
            m_dataChangeListenerList.put(null, list);
        }
        list.add(listener);
    } else {
        for (Object dataType : dataTypes) {
            if (dataType != null) {
                SimpleEventListenerList<DataChangeListener> list = m_dataChangeListenerList.get(dataType);
                if (list == null) {
                    list = new SimpleEventListenerList<DataChangeListener>();
                    m_dataChangeListenerList.put(dataType, list);
                }
                list.add(listener);
            }
        }
    }
}
Also used : DataChangeListener(org.eclipse.scout.rt.client.ui.DataChangeListener) IExtensibleObject(org.eclipse.scout.rt.shared.extension.IExtensibleObject)

Example 2 with DataChangeListener

use of org.eclipse.scout.rt.client.ui.DataChangeListener in project scout.rt by eclipse.

the class AbstractDesktop method fireDataChangedImpl.

private void fireDataChangedImpl(Object... dataTypes) {
    if (dataTypes != null && dataTypes.length > 0) {
        // Important: Use LinkedHashMaps to make event firing deterministic!
        // (If listeners would be called in random order, bugs may not be reproduced very well.)
        HashMap<DataChangeListener, Set<Object>> map = new LinkedHashMap<>();
        for (Object dataType : dataTypes) {
            if (dataType != null) {
                SimpleEventListenerList<DataChangeListener> listenerList = m_dataChangeListenerList.get(dataType);
                if (listenerList != null) {
                    for (DataChangeListener listener : listenerList.list()) {
                        Set<Object> typeSet = map.get(listener);
                        if (typeSet == null) {
                            typeSet = new LinkedHashSet<Object>();
                            map.put(listener, typeSet);
                        }
                        typeSet.add(dataType);
                    }
                }
            }
        }
        for (Map.Entry<DataChangeListener, Set<Object>> e : map.entrySet()) {
            DataChangeListener listener = e.getKey();
            Set<Object> typeSet = e.getValue();
            listener.dataChanged(typeSet.toArray());
        }
    }
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) DataChangeListener(org.eclipse.scout.rt.client.ui.DataChangeListener) IExtensibleObject(org.eclipse.scout.rt.shared.extension.IExtensibleObject) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) PropertyMap(org.eclipse.scout.rt.platform.context.PropertyMap) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with DataChangeListener

use of org.eclipse.scout.rt.client.ui.DataChangeListener in project scout.rt by eclipse.

the class AbstractDesktop method removeDataChangeListener.

@Override
public void removeDataChangeListener(DataChangeListener listener, Object... dataTypes) {
    if (dataTypes == null || dataTypes.length == 0) {
        for (Iterator<SimpleEventListenerList<DataChangeListener>> it = m_dataChangeListenerList.values().iterator(); it.hasNext(); ) {
            SimpleEventListenerList<DataChangeListener> list = it.next();
            list.remove(listener);
            if (list.isEmpty()) {
                it.remove();
            }
        }
    } else {
        for (Object dataType : dataTypes) {
            if (dataType != null) {
                SimpleEventListenerList<DataChangeListener> list = m_dataChangeListenerList.get(dataType);
                if (list != null) {
                    list.remove(listener);
                    if (list.isEmpty()) {
                        m_dataChangeListenerList.remove(dataType);
                    }
                }
            }
        }
    }
}
Also used : DataChangeListener(org.eclipse.scout.rt.client.ui.DataChangeListener) SimpleEventListenerList(org.eclipse.scout.rt.platform.util.event.SimpleEventListenerList) IExtensibleObject(org.eclipse.scout.rt.shared.extension.IExtensibleObject)

Example 4 with DataChangeListener

use of org.eclipse.scout.rt.client.ui.DataChangeListener in project scout.rt by eclipse.

the class AbstractDesktopTest method testDataChangedSimple.

@Test
public void testDataChangedSimple() {
    TestEnvironmentDesktop desktop = (TestEnvironmentDesktop) IDesktop.CURRENT.get();
    final Holder<Object[]> resultHolder = new Holder<Object[]>(Object[].class);
    desktop.addDataChangeListener(new DataChangeListener() {

        @Override
        public void dataChanged(Object... dataTypes) {
            resultHolder.setValue(dataTypes);
        }
    }, TEST_DATA_TYPE_1, TEST_DATA_TYPE_2);
    desktop.dataChanged(TEST_DATA_TYPE_1, TEST_DATA_TYPE_2);
    verifyDataChanged(resultHolder);
}
Also used : Holder(org.eclipse.scout.rt.platform.holders.Holder) DataChangeListener(org.eclipse.scout.rt.client.ui.DataChangeListener) TestEnvironmentDesktop(org.eclipse.scout.rt.client.testenvironment.ui.desktop.TestEnvironmentDesktop) Test(org.junit.Test)

Example 5 with DataChangeListener

use of org.eclipse.scout.rt.client.ui.DataChangeListener in project scout.rt by eclipse.

the class VirtualDesktop method removeDataChangeListener.

@Override
public void removeDataChangeListener(DataChangeListener listener, Object... dataTypes) {
    if (dataTypes == null || dataTypes.length == 0) {
        for (Iterator<EventListenerList> it = m_dataChangeListenerMap.values().iterator(); it.hasNext(); ) {
            EventListenerList list = it.next();
            list.removeAll(DataChangeListener.class, listener);
            if (list.getListenerCount(DataChangeListener.class) == 0) {
                it.remove();
            }
        }
    } else {
        for (Object dataType : dataTypes) {
            if (dataType != null) {
                EventListenerList list = m_dataChangeListenerMap.get(dataType);
                if (list != null) {
                    list.remove(DataChangeListener.class, listener);
                    if (list.getListenerCount(DataChangeListener.class) == 0) {
                        m_dataChangeListenerMap.remove(dataType);
                    }
                }
            }
        }
    }
}
Also used : EventListenerList(org.eclipse.scout.rt.platform.util.EventListenerList) DataChangeListener(org.eclipse.scout.rt.client.ui.DataChangeListener)

Aggregations

DataChangeListener (org.eclipse.scout.rt.client.ui.DataChangeListener)7 IExtensibleObject (org.eclipse.scout.rt.shared.extension.IExtensibleObject)4 Map (java.util.Map)2 TestEnvironmentDesktop (org.eclipse.scout.rt.client.testenvironment.ui.desktop.TestEnvironmentDesktop)2 PropertyMap (org.eclipse.scout.rt.platform.context.PropertyMap)2 Holder (org.eclipse.scout.rt.platform.holders.Holder)2 EventListenerList (org.eclipse.scout.rt.platform.util.EventListenerList)2 Test (org.junit.Test)2 PropertyChangeListener (java.beans.PropertyChangeListener)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 DesktopListener (org.eclipse.scout.rt.client.ui.desktop.DesktopListener)1 SimpleEventListenerList (org.eclipse.scout.rt.platform.util.event.SimpleEventListenerList)1 SharedVariableMap (org.eclipse.scout.rt.shared.services.common.context.SharedVariableMap)1