use of com.vaadin.flow.dom.Element in project flow by vaadin.
the class SynchronizedPropertyView method addSyncWithInitialValue.
private void addSyncWithInitialValue() {
add(new Text("Synchronized on 'change' event with initial value"));
final Div syncOnChangeInitialValueLabel = new Div();
syncOnChangeInitialValueLabel.setId("syncOnChangeInitialValueLabel");
Element syncOnChangeInitialValue = ElementFactory.createInput();
syncOnChangeInitialValueLabel.setText("Server value on create: " + syncOnChangeInitialValue.getProperty("value"));
syncOnChangeInitialValue.setAttribute("id", "syncOnChangeInitialValue");
syncOnChangeInitialValue.synchronizeProperty("value", "change");
syncOnChangeInitialValue.addEventListener("change", e -> {
syncOnChangeInitialValueLabel.setText("Server value in change listener: " + syncOnChangeInitialValue.getProperty("value"));
});
syncOnChangeInitialValue.setProperty("value", "initial");
getElement().appendChild(syncOnChangeInitialValue);
add(syncOnChangeInitialValueLabel);
}
use of com.vaadin.flow.dom.Element in project flow by vaadin.
the class AttachExistingElementFeatureTest method unregister_dataIsNotAvailaleByNode.
@Test
public void unregister_dataIsNotAvailaleByNode() {
StateNode node = new StateNode();
AttachExistingElementFeature feature = new AttachExistingElementFeature(node);
Element element = Mockito.mock(Element.class);
StateNode child = Mockito.mock(StateNode.class);
ChildElementConsumer callback = Mockito.mock(ChildElementConsumer.class);
Node<?> parent = Mockito.mock(Node.class);
feature.register(parent, element, child, callback);
feature.unregister(child);
Assert.assertNull(feature.getCallback(child));
Assert.assertNull(feature.getParent(child));
Assert.assertNull(feature.getPreviousSibling(child));
}
use of com.vaadin.flow.dom.Element in project flow by vaadin.
the class AttachExistingElementFeatureTest method forEachChild_register_registeredStatNodeIsAChild.
@Test
public void forEachChild_register_registeredStatNodeIsAChild() {
StateNode node = new StateNode();
AttachExistingElementFeature feature = new AttachExistingElementFeature(node);
Element element = Mockito.mock(Element.class);
StateNode child = Mockito.mock(StateNode.class);
ChildElementConsumer callback = Mockito.mock(ChildElementConsumer.class);
Node<?> parent = Mockito.mock(Node.class);
feature.register(parent, element, child, callback);
List<StateNode> children = new ArrayList<>(1);
feature.forEachChild(children::add);
Assert.assertEquals(1, children.size());
Assert.assertEquals(child, children.get(0));
}
use of com.vaadin.flow.dom.Element in project flow by vaadin.
the class ElementListenersTest method testEventDataInEvent.
@Test
public void testEventDataInEvent() {
AtomicReference<JsonObject> eventDataReference = new AtomicReference<>();
ns.add("foo", e -> {
Assert.assertNull(eventDataReference.get());
eventDataReference.set(e.getEventData());
}, new String[0]);
Assert.assertNull(eventDataReference.get());
JsonObject eventData = Json.createObject();
eventData.put("baz", true);
ns.fireEvent(new DomEvent(new Element("element"), "foo", eventData));
JsonObject capturedJson = eventDataReference.get();
Assert.assertNotNull(capturedJson);
Assert.assertEquals(1, capturedJson.keys().length);
Assert.assertEquals("true", capturedJson.get("baz").toJson());
}
use of com.vaadin.flow.dom.Element in project flow by vaadin.
the class EventUtilTest method collectBeforeNavigationObserversFromComponentList_elementHasVirtualChildren.
@Test
public void collectBeforeNavigationObserversFromComponentList_elementHasVirtualChildren() throws Exception {
Foo foo = new Foo();
foo.getElement().getStateProvider().appendVirtualChild(foo.getElement().getNode(), new EnterObserver().getElement(), NodeProperties.INJECT_BY_ID, "id");
Bar bar = new Bar();
Element nested = new Element("nested");
nested.appendVirtualChild(new Element("nested-child"), new EnterObserver().getElement());
bar.getElement().appendChild(new Foo().getElement(), nested);
List<BeforeEnterObserver> beforeNavigationObservers = EventUtil.collectBeforeEnterObservers(Arrays.asList(foo, bar));
Assert.assertEquals("Wrong amount of listener instances found", 2, beforeNavigationObservers.size());
}
Aggregations