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);
}
}
}
}
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());
}
}
}
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);
}
}
}
}
}
}
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);
}
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);
}
}
}
}
}
}
Aggregations