
net.sf.javagimmicks.collections.event.ObservableEventCollection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of GimmickUtils Show documentation
Show all versions of GimmickUtils Show documentation
Utility classes, APIs and tools for Java
The newest version!
package net.sf.javagimmicks.collections.event;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import net.sf.javagimmicks.collections.event.CollectionEvent.Type;
public class ObservableEventCollection extends AbstractEventCollection
{
private static final long serialVersionUID = -4055919694275882002L;
protected transient List> _listeners;
public ObservableEventCollection(Collection decorated)
{
super(decorated);
}
public void addEventCollectionListener(EventCollectionListener listener)
{
if(_listeners == null)
{
_listeners = new ArrayList>();
}
_listeners.add(listener);
}
public void removeEventCollectionListener(EventCollectionListener listener)
{
if(_listeners != null)
{
_listeners.remove(listener);
}
}
@Override
protected void fireElementsAdded(Collection extends E> elements)
{
fireEvent(new CollectionEvent(this, Type.ADDED, Collections.unmodifiableCollection(new ArrayList(elements))));
}
@Override
protected void fireElementRemoved(E element)
{
fireEvent(new CollectionEvent(this, Type.REMOVED, Collections.singleton(element)));
}
private void fireEvent(CollectionEvent event)
{
if(_listeners == null)
{
return;
}
for(EventCollectionListener listener : _listeners)
{
listener.eventOccured(event);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy