Search in sources :

Example 1 with PropertyChangeSupport

use of com.revolsys.beans.PropertyChangeSupport in project com.revolsys.open by revolsys.

the class AbstractConnectionRegistry method removeConnection.

protected synchronized boolean removeConnection(final String name, final Connection connection) {
    if (connection != null && name != null) {
        final String lowerName = name.toLowerCase();
        final C existingConnection = this.connections.get(lowerName);
        if (existingConnection == connection) {
            final int index = getConnectionIndex(name);
            this.connectionNames.remove(lowerName);
            this.connections.remove(lowerName);
            if (connection instanceof PropertyChangeSupportProxy) {
                final PropertyChangeSupportProxy proxy = (PropertyChangeSupportProxy) connection;
                final PropertyChangeSupport propertyChangeSupport = proxy.getPropertyChangeSupport();
                if (propertyChangeSupport != null) {
                    propertyChangeSupport.removePropertyChangeListener(this);
                }
            }
            this.propertyChangeSupport.fireIndexedPropertyChange("connections", index, connection, null);
            this.propertyChangeSupport.fireIndexedPropertyChange("children", index, connection, null);
            if (this.directory != null && !this.readOnly) {
                final Path file = existingConnection.getConnectionFile();
                Paths.deleteDirectories(file);
            }
            return true;
        }
    }
    return false;
}
Also used : Path(java.nio.file.Path) PropertyChangeSupportProxy(com.revolsys.beans.PropertyChangeSupportProxy) PropertyChangeSupport(com.revolsys.beans.PropertyChangeSupport)

Example 2 with PropertyChangeSupport

use of com.revolsys.beans.PropertyChangeSupport in project com.revolsys.open by revolsys.

the class AbstractConnectionRegistry method addConnection.

protected synchronized void addConnection(final String name, final C connection) {
    if (connection != null && name != null) {
        final String lowerName = name.toLowerCase();
        final C existingConnection = this.connections.get(lowerName);
        removeConnection(existingConnection);
        this.connectionNames.put(lowerName, name);
        this.connections.put(lowerName, connection);
        if (connection instanceof PropertyChangeSupportProxy) {
            final PropertyChangeSupportProxy proxy = (PropertyChangeSupportProxy) connection;
            final PropertyChangeSupport propertyChangeSupport = proxy.getPropertyChangeSupport();
            if (propertyChangeSupport != null) {
                propertyChangeSupport.addPropertyChangeListener(this);
            }
        }
        final int index = getConnectionIndex(name);
        this.propertyChangeSupport.fireIndexedPropertyChange("connections", index, null, connection);
        this.propertyChangeSupport.fireIndexedPropertyChange("children", index, null, connection);
    }
}
Also used : PropertyChangeSupportProxy(com.revolsys.beans.PropertyChangeSupportProxy) PropertyChangeSupport(com.revolsys.beans.PropertyChangeSupport)

Example 3 with PropertyChangeSupport

use of com.revolsys.beans.PropertyChangeSupport in project com.revolsys.open by revolsys.

the class PropertyChangeArrayList method removeListener.

protected void removeListener(final Object object) {
    if (object instanceof PropertyChangeSupportProxy) {
        final PropertyChangeSupportProxy proxy = (PropertyChangeSupportProxy) object;
        final PropertyChangeSupport propertyChangeSupport = proxy.getPropertyChangeSupport();
        if (propertyChangeSupport != null) {
            propertyChangeSupport.removePropertyChangeListener(this);
        }
    }
}
Also used : PropertyChangeSupportProxy(com.revolsys.beans.PropertyChangeSupportProxy) PropertyChangeSupport(com.revolsys.beans.PropertyChangeSupport)

Example 4 with PropertyChangeSupport

use of com.revolsys.beans.PropertyChangeSupport in project com.revolsys.open by revolsys.

the class PropertyChangeArrayList method addListener.

protected void addListener(final Object object) {
    if (object instanceof PropertyChangeSupportProxy) {
        final PropertyChangeSupportProxy proxy = (PropertyChangeSupportProxy) object;
        final PropertyChangeSupport propertyChangeSupport = proxy.getPropertyChangeSupport();
        if (propertyChangeSupport != null) {
            propertyChangeSupport.addPropertyChangeListener(this);
        }
    }
}
Also used : PropertyChangeSupportProxy(com.revolsys.beans.PropertyChangeSupportProxy) PropertyChangeSupport(com.revolsys.beans.PropertyChangeSupport)

Example 5 with PropertyChangeSupport

use of com.revolsys.beans.PropertyChangeSupport 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)12 PropertyChangeSupportProxy (com.revolsys.beans.PropertyChangeSupportProxy)5 ProxyPropertyChangeListener (com.revolsys.beans.ProxyPropertyChangeListener)5 WeakPropertyChangeListener (com.revolsys.beans.WeakPropertyChangeListener)5 PropertyChangeListener (java.beans.PropertyChangeListener)5 JComponent (javax.swing.JComponent)5 Component (java.awt.Component)3 PropertyChangeListenerProxy (java.beans.PropertyChangeListenerProxy)3 BeanPropertyListener (com.revolsys.swing.listener.BeanPropertyListener)1 ProjectFrame (com.revolsys.swing.map.ProjectFrame)1 ThreadBooleanValue (com.revolsys.value.ThreadBooleanValue)1 Path (java.nio.file.Path)1