use of com.vaadin.flow.dom.PropertyChangeEvent in project flow by vaadin.
the class ElementPropertyMapTest method listenerIsNotified.
private void listenerIsNotified(boolean clientEvent) {
ElementPropertyMap map = createSimplePropertyMap();
StateNode node = map.getNode();
AtomicReference<PropertyChangeEvent> event = new AtomicReference<>();
PropertyChangeListener listener = ev -> {
Assert.assertNull(event.get());
event.set(ev);
};
map.addPropertyChangeListener("foo", listener);
map.setProperty("foo", "bar", !clientEvent);
Assert.assertNull(event.get().getOldValue());
Assert.assertEquals("bar", event.get().getValue());
Assert.assertEquals("foo", event.get().getPropertyName());
Assert.assertEquals(Element.get(node), event.get().getSource());
Assert.assertEquals(clientEvent, event.get().isUserOriginated());
// listener is not called. Otherwise its assertion fails.
map.setProperty("bar", "foo");
}
use of com.vaadin.flow.dom.PropertyChangeEvent in project flow by vaadin.
the class ElementPropertyMap method putWithDeferredChangeEvent.
private PutResult putWithDeferredChangeEvent(String key, Serializable value, boolean emitChange) {
Serializable oldValue = super.put(key, value, emitChange);
boolean valueChanged = !Objects.equals(oldValue, value);
if (valueChanged) {
setFilterIfMapNode(oldValue, () -> null);
setFilterIfMapNode(value, () -> createChildFilter(key));
}
PropertyChangeEvent event;
if (hasElement() && valueChanged) {
event = new PropertyChangeEvent(Element.get(getNode()), key, oldValue, !emitChange);
} else {
event = null;
}
return new PutResult(oldValue, event);
}
Aggregations