Example usage for java.beans PropertyChangeListenerProxy PropertyChangeListenerProxy

List of usage examples for java.beans PropertyChangeListenerProxy PropertyChangeListenerProxy

Introduction

In this page you can find the example usage for java.beans PropertyChangeListenerProxy PropertyChangeListenerProxy.

Prototype

public PropertyChangeListenerProxy(String propertyName, PropertyChangeListener listener) 

Source Link

Document

Constructor which binds the PropertyChangeListener to a specific property.

Usage

From source file:org.rifidi.designer.entities.databinding.ObservableTreeContentProvider.java

/**
 * Helper method to ensure that a given Object is being monitored.
 * //  w  w  w  .  j a va  2s  . c  o m
 * @param element
 */
@SuppressWarnings("unchecked")
private void monitorElement(final Object element) {
    if (!observedElements.containsKey(element)) {
        if (element.getClass().isAnnotationPresent(MonitorThisList.class)) {
            String name = ((MonitorThisList) (element.getClass().getAnnotation(MonitorThisList.class))).name();
            name = name.substring(0, 1).toUpperCase() + name.substring(1);
            try {
                observedElements.put(element, new ObserverHelper(element));
                ((IObservableList) element.getClass().getMethod("get" + name, null).invoke(element))
                        .addListChangeListener(observedElements.get(element));
            } catch (Exception e) {
                logger.error(e);
            }
        }
        if (element.getClass().isAnnotationPresent(MonitoredProperties.class)
                && !monitoredProperties.containsKey(element)) {
            Map<String, PropertyChangeListenerProxy> props = new HashMap<String, PropertyChangeListenerProxy>();
            monitoredProperties.put(element, props);
            for (String name : element.getClass().getAnnotation(MonitoredProperties.class).names()) {
                PropertyChangeListenerProxy proxy = new PropertyChangeListenerProxy(name, this);
                ((Entity) element).addPropertyChangeListener(proxy);
                props.put(name, proxy);
            }
        }
    }
}