Search in sources :

Example 1 with ProxyPropertyChangeListener

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;
}
Also used : ProxyPropertyChangeListener(com.revolsys.beans.ProxyPropertyChangeListener) WeakPropertyChangeListener(com.revolsys.beans.WeakPropertyChangeListener) ProxyPropertyChangeListener(com.revolsys.beans.ProxyPropertyChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) PropertyChangeSupport(com.revolsys.beans.PropertyChangeSupport) JComponent(javax.swing.JComponent) Component(java.awt.Component) PropertyChangeListenerProxy(java.beans.PropertyChangeListenerProxy)

Aggregations

PropertyChangeSupport (com.revolsys.beans.PropertyChangeSupport)1 ProxyPropertyChangeListener (com.revolsys.beans.ProxyPropertyChangeListener)1 WeakPropertyChangeListener (com.revolsys.beans.WeakPropertyChangeListener)1 Component (java.awt.Component)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 PropertyChangeListenerProxy (java.beans.PropertyChangeListenerProxy)1 JComponent (javax.swing.JComponent)1