use of com.vaadin.client.flow.StateNode in project flow by vaadin.
the class SimpleElementBindingStrategy method getClosestStateNodeIdToEventTarget.
// This method could be moved somewhere to be reusable
private int getClosestStateNodeIdToEventTarget(StateNode topNode, EventTarget target) {
if (target == null) {
return -1;
}
try {
DomNode targetNode = DomApi.wrap(WidgetUtil.crazyJsCast(target));
JsArray<StateNode> stack = JsCollections.array();
stack.push(topNode);
// collect children and test eagerly for direct match
for (int i = 0; i < stack.length(); i++) {
final StateNode stateNode = stack.get(i);
if (targetNode.isSameNode(stateNode.getDomNode())) {
return stateNode.getId();
}
// NOTE: for now not looking at virtual children on purpose.
// If needed (?), those can be included here to the search stack
stateNode.getList(NodeFeatures.ELEMENT_CHILDREN).forEach(child -> stack.push((StateNode) child));
}
// no direct match, all child element state nodes collected.
// bottom-up search elements until matching state node found
targetNode = DomApi.wrap(targetNode.getParentNode());
return getStateNodeForElement(stack, targetNode);
} catch (Exception e) {
// not going to let event handling fail; just report nothing found
Console.debug("An error occurred when Flow tried to find a state node matching the element " + target + ", which was the event.target. Error: " + e.getMessage());
}
// no match / error;
return -1;
}
use of com.vaadin.client.flow.StateNode in project flow by vaadin.
the class GwtExecuteJavaScriptElementUtilsTest method addChild.
private StateNode addChild(Element child, int index) {
StateNode childNode = new StateNode(nextId, tree);
nextId++;
childNode.setDomNode(child);
node.getList(NodeFeatures.ELEMENT_CHILDREN).add(index, childNode);
return childNode;
}
use of com.vaadin.client.flow.StateNode in project flow by vaadin.
the class GwtExecuteJavaScriptElementUtilsTest method setupShadowRoot.
private void setupShadowRoot() {
setupParent(element);
NodeMap map = node.getMap(NodeFeatures.SHADOW_ROOT_DATA);
map.getProperty(NodeProperties.SHADOW_ROOT).setValue(new StateNode(34, tree));
}
use of com.vaadin.client.flow.StateNode in project flow by vaadin.
the class SimpleElementBindingStrategy method doBind.
private void doBind(StateNode node, BinderContext nodeFactory) {
Node domNode = node.getDomNode();
// this will fire an event which gives a chance to run logic which
// needs to know when the element is completely initialized
node.setDomNode(null);
node.setDomNode(domNode);
nodeFactory.createAndBind(node);
}
use of com.vaadin.client.flow.StateNode in project flow by vaadin.
the class SimpleElementBindingStrategy method handlePropertyChange.
private void handlePropertyChange(String fullPropertyName, Supplier<Object> valueProvider, StateNode node) {
UpdatableModelProperties updatableProperties = node.getNodeData(UpdatableModelProperties.class);
if (updatableProperties == null || !updatableProperties.isUpdatableProperty(fullPropertyName)) {
// collection of updatable properties
return;
}
// This is not the property value itself, its a parent node of the
// property
String[] subProperties = fullPropertyName.split("\\.");
StateNode model = node;
MapProperty mapProperty = null;
int i = 0;
int size = subProperties.length;
for (String subProperty : subProperties) {
NodeMap elementProperties = model.getMap(NodeFeatures.ELEMENT_PROPERTIES);
if (!elementProperties.hasPropertyValue(subProperty) && i < size - 1) {
Console.debug("Ignoring property change for property '" + fullPropertyName + "' which isn't defined from server");
return;
}
mapProperty = elementProperties.getProperty(subProperty);
if (mapProperty.getValue() instanceof StateNode) {
model = (StateNode) mapProperty.getValue();
}
i++;
}
if (mapProperty.getValue() instanceof StateNode) {
// Don't send to the server updates for list nodes
StateNode nodeValue = (StateNode) mapProperty.getValue();
JsonObject obj = WidgetUtil.crazyJsCast(valueProvider.get());
if (!obj.hasKey("nodeId") || nodeValue.hasFeature(NodeFeatures.TEMPLATE_MODELLIST)) {
return;
}
}
mapProperty.syncToServer(valueProvider.get());
}
Aggregations