Search in sources :

Example 1 with PropertyChangeEvent

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");
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) BasicElementStateProvider(com.vaadin.flow.dom.impl.BasicElementStateProvider) PropertyChangeListener(com.vaadin.flow.dom.PropertyChangeListener) Registration(com.vaadin.flow.shared.Registration) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Serializable(java.io.Serializable) HashSet(java.util.HashSet) Element(com.vaadin.flow.dom.Element) PropertyChangeEvent(com.vaadin.flow.dom.PropertyChangeEvent) Assert(org.junit.Assert) PropertyChangeEvent(com.vaadin.flow.dom.PropertyChangeEvent) PropertyChangeListener(com.vaadin.flow.dom.PropertyChangeListener) StateNode(com.vaadin.flow.internal.StateNode) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 2 with PropertyChangeEvent

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);
}
Also used : Serializable(java.io.Serializable) PropertyChangeEvent(com.vaadin.flow.dom.PropertyChangeEvent)

Aggregations

PropertyChangeEvent (com.vaadin.flow.dom.PropertyChangeEvent)2 Serializable (java.io.Serializable)2 Element (com.vaadin.flow.dom.Element)1 PropertyChangeListener (com.vaadin.flow.dom.PropertyChangeListener)1 BasicElementStateProvider (com.vaadin.flow.dom.impl.BasicElementStateProvider)1 StateNode (com.vaadin.flow.internal.StateNode)1 Registration (com.vaadin.flow.shared.Registration)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1