use of com.revolsys.beans.WeakPropertyChangeListener in project com.revolsys.open by revolsys.
the class Property method removeListener.
static void removeListener(final Object source, final String propertyName, final Object listener) {
if (listener instanceof PropertyChangeListener) {
final PropertyChangeListener propertyChangeListener = (PropertyChangeListener) listener;
final PropertyChangeSupport propertyChangeSupport = propertyChangeSupport(source);
if (propertyChangeSupport != null) {
for (final PropertyChangeListener otherListener : propertyChangeSupport.getPropertyChangeListeners()) {
if (otherListener instanceof PropertyChangeListenerProxy) {
final PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy) otherListener;
final PropertyChangeListener proxyListener = proxy.getListener();
final String proxyPropertyName = proxy.getPropertyName();
if (proxyListener instanceof WeakPropertyChangeListener) {
final WeakPropertyChangeListener weakListener = (WeakPropertyChangeListener) proxyListener;
final PropertyChangeListener listenerReference = weakListener.getPropertyChangeListener();
if (listenerReference == null) {
propertyChangeSupport.removePropertyChangeListener(proxyPropertyName, weakListener);
} else if (proxyPropertyName.equals(propertyName)) {
if (listenerReference == propertyChangeListener) {
propertyChangeSupport.removePropertyChangeListener(propertyName, weakListener);
}
}
} else if (propertyChangeListener.equals(proxyListener)) {
if (proxyPropertyName.equals(propertyName)) {
propertyChangeSupport.removePropertyChangeListener(propertyName, propertyChangeListener);
}
}
} else if (otherListener instanceof WeakPropertyChangeListener) {
final WeakPropertyChangeListener weakListener = (WeakPropertyChangeListener) otherListener;
final PropertyChangeListener listenerReference = weakListener.getPropertyChangeListener();
if (listenerReference == null) {
propertyChangeSupport.removePropertyChangeListener(weakListener);
}
}
}
}
if (source instanceof Component) {
final Component component = (Component) source;
for (final PropertyChangeListener otherListener : component.getPropertyChangeListeners()) {
if (otherListener.equals(propertyChangeListener)) {
component.removePropertyChangeListener(propertyName, propertyChangeListener);
} else if (otherListener instanceof WeakPropertyChangeListener) {
final WeakPropertyChangeListener weakListener = (WeakPropertyChangeListener) otherListener;
final PropertyChangeListener listenerReference = weakListener.getPropertyChangeListener();
if (listenerReference == null || listenerReference.equals(propertyChangeListener)) {
component.removePropertyChangeListener(propertyName, propertyChangeListener);
}
}
}
}
}
}
use of com.revolsys.beans.WeakPropertyChangeListener in project com.revolsys.open by revolsys.
the class Property method getPropertyChangeListener.
@SuppressWarnings("unchecked")
static PropertyChangeListener getPropertyChangeListener(final Object listener) {
if (listener instanceof PropertyChangeListener) {
final PropertyChangeListener propertyChangeListener = (PropertyChangeListener) listener;
if (propertyChangeListener instanceof NonWeakListener) {
return propertyChangeListener;
} else {
final WeakPropertyChangeListener weakListener = new WeakPropertyChangeListener(propertyChangeListener);
return weakListener;
}
} else if (listener instanceof Consumer) {
final Consumer<Object> consumer = (Consumer<Object>) listener;
return (e) -> {
final Object object = e.getNewValue();
consumer.accept(object);
};
} else {
return null;
}
}
Aggregations