use of org.csstudio.display.builder.model.BaseWidgetPropertyListener in project org.csstudio.display.builder by kasemir.
the class PropertyChangeHandler method firePropertyChange.
/**
* Notify listeners of property change.
*
* <p>New value usually matches <code>property.getValue()</code>,
* but in multi-threaded context value might already have changed
* _again_ by the time this executes.
*
* <p>Suppresses notifications where old_value equals new_value,
* unless both values are null, treating that as a "notify anyway"
* case.
*
* @param property Property that changed, or <code>null</code> for "many"
* @param old_value Original value
* @param new_value New value
*/
@SuppressWarnings("unchecked")
protected void firePropertyChange(final WidgetProperty<T> property, final T old_value, final T new_value) {
// Does anybody care?
final List<BaseWidgetPropertyListener> safe_copy = listeners;
if (safe_copy == null)
return;
// Any change at all?
if (new_value != null && old_value != null && new_value.equals(old_value))
return;
// If a property listener changes the property,
// that triggers a recursive listener invocation.
// Not necessarily a problem, but likely better avoided.
final int recursion_level = recursions.incrementAndGet();
if (recursion_level > 1)
logger.log(Level.WARNING, "Recursive update of property " + property.getName() + ", " + recursion_level + " deep");
// Notify listeners
for (BaseWidgetPropertyListener listener : safe_copy) {
try {
if (listener instanceof WidgetPropertyListener)
((WidgetPropertyListener<T>) listener).propertyChanged(property, old_value, new_value);
else
((UntypedWidgetPropertyListener) listener).propertyChanged(property, old_value, new_value);
} catch (Throwable ex) {
// Log error, then continue with next listener
logger.log(Level.WARNING, "Property update error for " + property, ex);
}
}
recursions.decrementAndGet();
}
Aggregations