use of com.revolsys.beans.ProxyPropertyChangeListener in project com.revolsys.open by revolsys.
the class Property method removeListener.
static boolean removeListener(final Object source, final Object listener) {
boolean removed = false;
if (source != null && listener instanceof PropertyChangeListener) {
final PropertyChangeListener propertyChangeListener = (PropertyChangeListener) listener;
final PropertyChangeSupport propertyChangeSupport = propertyChangeSupport(source);
if (propertyChangeSupport != null) {
for (final PropertyChangeListener otherListener : propertyChangeSupport.getPropertyChangeListeners()) {
boolean remove = false;
PropertyChangeListener compareListener;
if (otherListener instanceof PropertyChangeListenerProxy) {
final PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy) otherListener;
compareListener = proxy.getListener();
} else {
compareListener = otherListener;
}
if (compareListener == propertyChangeListener) {
remove = true;
} else if (compareListener instanceof ProxyPropertyChangeListener) {
final ProxyPropertyChangeListener proxiedListener = (ProxyPropertyChangeListener) compareListener;
final PropertyChangeListener listenerReference = proxiedListener.getPropertyChangeListener();
if (listenerReference == null || listenerReference == propertyChangeListener) {
remove = true;
}
}
if (remove) {
propertyChangeSupport.removePropertyChangeListener(otherListener);
removed = true;
}
}
}
if (source instanceof Component) {
final Component component = (Component) source;
for (final PropertyChangeListener otherListener : component.getPropertyChangeListeners()) {
if (otherListener.equals(propertyChangeListener)) {
component.removePropertyChangeListener(propertyChangeListener);
removed = true;
} else if (otherListener instanceof ProxyPropertyChangeListener) {
final ProxyPropertyChangeListener proxiedListener = (ProxyPropertyChangeListener) otherListener;
final PropertyChangeListener listenerReference = proxiedListener.getPropertyChangeListener();
if (listenerReference == null || listenerReference.equals(propertyChangeListener)) {
component.removePropertyChangeListener(otherListener);
removed = true;
}
}
}
}
}
return removed;
}
Aggregations