Search in sources :

Example 1 with PropertyChangeListener

use of com.vaadin.flow.dom.PropertyChangeListener 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 PropertyChangeListener

use of com.vaadin.flow.dom.PropertyChangeListener in project flow by vaadin.

the class ElementPropertyMapTest method removePropertyChangeListener_fireEvent_listenerIsNotNotified.

@Test
public void removePropertyChangeListener_fireEvent_listenerIsNotNotified() {
    ElementPropertyMap map = createSimplePropertyMap();
    PropertyChangeListener listener = ev -> {
        Assert.fail();
    };
    Registration registration = map.addPropertyChangeListener("foo", listener);
    registration.remove();
    // listener is not called. Otherwise its assertion fails.
    map.setProperty("foo", "bar", true);
}
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) PropertyChangeListener(com.vaadin.flow.dom.PropertyChangeListener) Registration(com.vaadin.flow.shared.Registration) Test(org.junit.Test)

Example 3 with PropertyChangeListener

use of com.vaadin.flow.dom.PropertyChangeListener in project flow by vaadin.

the class ElementPropertyMapTest method addSeveralPropertyChangeListeners_fireEvent_listenersAreNotified.

@Test
public void addSeveralPropertyChangeListeners_fireEvent_listenersAreNotified() {
    ElementPropertyMap map = createSimplePropertyMap();
    AtomicBoolean first = new AtomicBoolean();
    AtomicBoolean second = new AtomicBoolean();
    PropertyChangeListener listener1 = ev -> first.set(!first.get());
    PropertyChangeListener listener2 = ev -> second.set(!second.get());
    map.addPropertyChangeListener("foo", listener1);
    map.addPropertyChangeListener("foo", listener2);
    map.setProperty("foo", "bar", true);
    Assert.assertTrue(first.get());
    Assert.assertTrue(second.get());
}
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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PropertyChangeListener(com.vaadin.flow.dom.PropertyChangeListener) Test(org.junit.Test)

Aggregations

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