use of com.vaadin.flow.internal.NodeOwner in project flow by vaadin.
the class AbstractComponentDataGenerator method registerRenderedComponent.
/**
* Appends the component to the container and registers it for future use
* during the lifecycle of the generator.
*
* @param itemKey
* the key of the model item
* @param component
* the component to be attached to the container
*/
protected void registerRenderedComponent(String itemKey, Component component) {
Element element = component.getElement();
getContainer().appendChild(element);
NodeOwner owner = getContainer().getNode().getOwner();
UI containerUi = null;
if (owner instanceof StateTree) {
containerUi = ((StateTree) owner).getUI();
}
if (containerUi != null && component.getUI().isPresent() && containerUi != component.getUI().get()) {
throw new IllegalStateException("The component '" + component.getClass() + "' is already attached to a UI instance which differs " + "from the conainer's UI instance. It means that the component instance is " + "reused instead being produced every time on 'createComponent' call." + " Check whether the component instance is a singleton or has inappropriate Spring scope.");
}
renderedComponents.put(itemKey, component);
}
use of com.vaadin.flow.internal.NodeOwner in project flow by vaadin.
the class DomEvent method extractElement.
static Element extractElement(JsonObject eventData, Element source, String key, boolean lookUnderUI) {
assert key.startsWith(JsonConstants.MAP_STATE_NODE_EVENT_DATA);
if (!eventData.hasKey(key)) {
return null;
}
final JsonValue reportedStateNodeId = eventData.get(key);
if (reportedStateNodeId == null) {
return null;
}
int id = (int) reportedStateNodeId.asNumber();
if (id == -1) {
return null;
}
AtomicReference<Element> matchingNode = new AtomicReference<>();
final Consumer<StateNode> visitor = node -> {
if (node.getId() == id) {
matchingNode.set(Element.get(node));
}
};
// first look under event source
source.getNode().visitNodeTree(visitor);
if (lookUnderUI && matchingNode.get() == null) {
// widen search to look under UI too
final NodeOwner owner = source.getNode().getOwner();
if (owner instanceof StateTree) {
((StateTree) owner).getRootNode().visitNodeTree(visitor);
}
}
final Element mappedElementOrNull = matchingNode.get();
// prevent spoofing invisible elements by sending bad state node ids
if (mappedElementOrNull != null && !mappedElementOrNull.isVisible()) {
return null;
}
return mappedElementOrNull;
}
use of com.vaadin.flow.internal.NodeOwner in project flow by vaadin.
the class DefaultBindingExceptionHandler method getUI.
private UI getUI(Element element) {
NodeOwner owner = element.getNode().getOwner();
UI ui = null;
if (element.getNode().isAttached()) {
ui = ((StateTree) owner).getUI();
}
if (ui == null) {
ui = UI.getCurrent();
}
return ui;
}
Aggregations