com.vaadin.v7.data.util.AbstractContainer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vaadin-compatibility-server Show documentation
Show all versions of vaadin-compatibility-server Show documentation
Vaadin 7 compatibility package for Vaadin 8
The newest version!
/*
* Copyright (C) 2000-2024 Vaadin Ltd
*
* This program is available under Vaadin Commercial License and Service Terms.
*
* See for the full
* license.
*/
package com.vaadin.v7.data.util;
import java.util.Collection;
import java.util.Collections;
import java.util.EventObject;
import java.util.LinkedList;
import com.vaadin.data.provider.DataProvider;
import com.vaadin.v7.data.Container;
/**
* Abstract container class that manages event listeners and sending events to
* them ({@link PropertySetChangeNotifier}, {@link ItemSetChangeNotifier}).
*
* Note that this class provides the internal implementations for both types of
* events and notifiers as protected methods, but does not implement the
* {@link PropertySetChangeNotifier} and {@link ItemSetChangeNotifier}
* interfaces directly. This way, subclasses can choose not to implement them.
* Subclasses implementing those interfaces should also override the
* corresponding {@link #addListener(com.vaadin.v7.data.Container.ItemSetChangeListener)}
* and {@link #removeListener(com.vaadin.v7.data.Container.ItemSetChangeListener)}
* methods to make them public.
*
* @since 6.6
*
* @deprecated As of 8.0, replaced by {@link DataProvider}
*/
@Deprecated
public abstract class AbstractContainer implements Container {
/**
* List of all Property set change event listeners.
*/
private Collection propertySetChangeListeners = null;
/**
* List of all container Item set change event listeners.
*/
private Collection itemSetChangeListeners = null;
/**
* An event
object specifying the container whose Property set
* has changed.
*
* This class does not provide information about which properties were
* concerned by the change, but subclasses can provide additional
* information about the changes.
*/
@Deprecated
protected static class BasePropertySetChangeEvent extends EventObject
implements Container.PropertySetChangeEvent {
protected BasePropertySetChangeEvent(Container source) {
super(source);
}
@Override
public Container getContainer() {
return (Container) getSource();
}
}
/**
* An event
object specifying the container whose Item set has
* changed.
*
* This class does not provide information about the exact changes
* performed, but subclasses can add provide additional information about
* the changes.
*/
@Deprecated
protected static class BaseItemSetChangeEvent extends EventObject
implements Container.ItemSetChangeEvent {
protected BaseItemSetChangeEvent(Container source) {
super(source);
}
@Override
public Container getContainer() {
return (Container) getSource();
}
}
// PropertySetChangeNotifier
/**
* Implementation of the corresponding method in
* {@link PropertySetChangeNotifier}, override with the corresponding public
* method and implement the interface to use this.
*
* @see PropertySetChangeNotifier#addListener(Container.PropertySetChangeListener)
*/
protected void addPropertySetChangeListener(
Container.PropertySetChangeListener listener) {
if (getPropertySetChangeListeners() == null) {
setPropertySetChangeListeners(
new LinkedList());
}
getPropertySetChangeListeners().add(listener);
}
/**
* @deprecated As of 7.0, replaced by
* {@link #addPropertySetChangeListener(Container.PropertySetChangeListener)}
*/
@Deprecated
protected void addListener(Container.PropertySetChangeListener listener) {
addPropertySetChangeListener(listener);
}
/**
* Implementation of the corresponding method in
* {@link PropertySetChangeNotifier}, override with the corresponding public
* method and implement the interface to use this.
*
* @see PropertySetChangeNotifier#removeListener(Container.
* PropertySetChangeListener)
*/
protected void removePropertySetChangeListener(
Container.PropertySetChangeListener listener) {
if (getPropertySetChangeListeners() != null) {
getPropertySetChangeListeners().remove(listener);
}
}
/**
* @deprecated As of 7.0, replaced by
* {@link #removePropertySetChangeListener(Container.PropertySetChangeListener)}
*/
@Deprecated
protected void removeListener(
Container.PropertySetChangeListener listener) {
removePropertySetChangeListener(listener);
}
// ItemSetChangeNotifier
/**
* Implementation of the corresponding method in
* {@link ItemSetChangeNotifier}, override with the corresponding public
* method and implement the interface to use this.
*
* @see ItemSetChangeNotifier#addListener(Container.ItemSetChangeListener)
*/
protected void addItemSetChangeListener(
Container.ItemSetChangeListener listener) {
if (getItemSetChangeListeners() == null) {
setItemSetChangeListeners(
new LinkedList());
}
getItemSetChangeListeners().add(listener);
}
/**
* @deprecated As of 7.0, replaced by
* {@link #addItemSetChangeListener(Container.ItemSetChangeListener)}
*/
@Deprecated
protected void addListener(Container.ItemSetChangeListener listener) {
addItemSetChangeListener(listener);
}
/**
* Implementation of the corresponding method in
* {@link ItemSetChangeNotifier}, override with the corresponding public
* method and implement the interface to use this.
*
* @see ItemSetChangeNotifier#removeListener(Container.ItemSetChangeListener)
*/
protected void removeItemSetChangeListener(
Container.ItemSetChangeListener listener) {
if (getItemSetChangeListeners() != null) {
getItemSetChangeListeners().remove(listener);
}
}
/**
* @deprecated As of 7.0, replaced by
* {@link #addItemSetChangeListener(Container.ItemSetChangeListener)}
*/
@Deprecated
protected void removeListener(Container.ItemSetChangeListener listener) {
removeItemSetChangeListener(listener);
}
/**
* Sends a simple Property set change event to all interested listeners.
*/
protected void fireContainerPropertySetChange() {
fireContainerPropertySetChange(new BasePropertySetChangeEvent(this));
}
/**
* Sends a Property set change event to all interested listeners.
*
* Use {@link #fireContainerPropertySetChange()} instead of this method
* unless additional information about the exact changes is available and
* should be included in the event.
*
* @param event
* the property change event to send, optionally with additional
* information
*/
protected void fireContainerPropertySetChange(
Container.PropertySetChangeEvent event) {
if (getPropertySetChangeListeners() != null) {
for (Object l : getPropertySetChangeListeners().toArray()) {
((Container.PropertySetChangeListener) l)
.containerPropertySetChange(event);
}
}
}
/**
* Sends a simple Item set change event to all interested listeners,
* indicating that anything in the contents may have changed (items added,
* removed etc.).
*/
protected void fireItemSetChange() {
fireItemSetChange(new BaseItemSetChangeEvent(this));
}
/**
* Sends an Item set change event to all registered interested listeners.
*
* @param event
* the item set change event to send, optionally with additional
* information
*/
protected void fireItemSetChange(ItemSetChangeEvent event) {
if (getItemSetChangeListeners() != null) {
for (Object l : getItemSetChangeListeners().toArray()) {
((Container.ItemSetChangeListener) l)
.containerItemSetChange(event);
}
}
}
/**
* Sets the property set change listener collection. For internal use only.
*
* @param propertySetChangeListeners
*/
protected void setPropertySetChangeListeners(
Collection propertySetChangeListeners) {
this.propertySetChangeListeners = propertySetChangeListeners;
}
/**
* Returns the property set change listener collection. For internal use
* only.
*/
protected Collection getPropertySetChangeListeners() {
return propertySetChangeListeners;
}
/**
* Sets the item set change listener collection. For internal use only.
*
* @param itemSetChangeListeners
*/
protected void setItemSetChangeListeners(
Collection itemSetChangeListeners) {
this.itemSetChangeListeners = itemSetChangeListeners;
}
/**
* Returns the item set change listener collection. For internal use only.
*/
protected Collection getItemSetChangeListeners() {
return itemSetChangeListeners;
}
public Collection> getListeners(Class> eventType) {
if (Container.PropertySetChangeEvent.class
.isAssignableFrom(eventType)) {
if (propertySetChangeListeners == null) {
return Collections.EMPTY_LIST;
} else {
return Collections
.unmodifiableCollection(propertySetChangeListeners);
}
} else if (Container.ItemSetChangeEvent.class
.isAssignableFrom(eventType)) {
if (itemSetChangeListeners == null) {
return Collections.EMPTY_LIST;
} else {
return Collections
.unmodifiableCollection(itemSetChangeListeners);
}
}
return Collections.EMPTY_LIST;
}
}