use of com.vaadin.flow.internal.StateTree in project flow by vaadin.
the class ClientDelegteHandlersTest method attach_noFeature.
@Test
public void attach_noFeature() {
StateTree tree = new StateTree(new UI(), ElementChildrenList.class);
StateNode stateNode = new StateNode(ClientDelegateHandlers.class);
tree.getRootNode().getFeature(ElementChildrenList.class).add(stateNode);
Assert.assertEquals(0, stateNode.getFeature(ClientDelegateHandlers.class).size());
}
use of com.vaadin.flow.internal.StateTree in project flow by vaadin.
the class ClientDelegteHandlersTest method attach_noComponent.
@Test
public void attach_noComponent() {
StateTree tree = new StateTree(new UI(), ElementChildrenList.class);
StateNode stateNode = new StateNode(ComponentMapping.class, ClientDelegateHandlers.class);
tree.getRootNode().getFeature(ElementChildrenList.class).add(stateNode);
Assert.assertEquals(0, stateNode.getFeature(ClientDelegateHandlers.class).size());
}
use of com.vaadin.flow.internal.StateTree in project flow by vaadin.
the class AttachExistingElementRpcHandler method handleNode.
@Override
protected Optional<Runnable> handleNode(StateNode node, JsonObject invocationJson) {
assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_REQUESTED_ID);
assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_ASSIGNED_ID);
assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_TAG_NAME);
assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_INDEX);
int requestedId = (int) invocationJson.getNumber(JsonConstants.RPC_ATTACH_REQUESTED_ID);
int assignedId = (int) invocationJson.getNumber(JsonConstants.RPC_ATTACH_ASSIGNED_ID);
String tag = invocationJson.getString(JsonConstants.RPC_ATTACH_TAG_NAME);
int index = (int) invocationJson.getNumber(JsonConstants.RPC_ATTACH_INDEX);
AttachExistingElementFeature feature = node.getFeature(AttachExistingElementFeature.class);
StateTree tree = (StateTree) node.getOwner();
StateNode requestedNode = tree.getNodeById(requestedId);
if (assignedId == -1) {
// handle an error
assert index == -1;
ChildElementConsumer callback = feature.getCallback(requestedNode);
assert callback != null;
callback.onError(feature.getParent(requestedNode), tag, feature.getPreviousSibling(requestedNode));
feature.unregister(requestedNode);
} else {
Element element = Element.get(tree.getNodeById(assignedId));
attachElement(feature, element, index, tree.getNodeById(requestedId), requestedId == assignedId);
}
return Optional.empty();
}
use of com.vaadin.flow.internal.StateTree in project flow by vaadin.
the class MapSyncRpcHandler method tryConvert.
private Serializable tryConvert(Serializable value, StateNode context) {
if (value instanceof JsonObject) {
JsonObject json = (JsonObject) value;
if (json.hasKey("nodeId")) {
StateTree tree = (StateTree) context.getOwner();
double id = json.getNumber("nodeId");
StateNode stateNode = tree.getNodeById((int) id);
return tryCopyStateNode(stateNode, json);
}
}
return value;
}
use of com.vaadin.flow.internal.StateTree in project flow by vaadin.
the class AttachTemplateChildRpcHandler method handleNode.
@Override
protected Optional<Runnable> handleNode(StateNode node, JsonObject invocationJson) {
assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_REQUESTED_ID);
assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_ASSIGNED_ID);
assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_ID);
int requestedId = (int) invocationJson.getNumber(JsonConstants.RPC_ATTACH_REQUESTED_ID);
int assignedId = (int) invocationJson.getNumber(JsonConstants.RPC_ATTACH_ASSIGNED_ID);
StateTree tree = (StateTree) node.getOwner();
StateNode requestedNode = tree.getNodeById(requestedId);
StateNode parent = tree.getNodeById(requestedId).getParent();
JsonValue id = invocationJson.get(JsonConstants.RPC_ATTACH_ID);
String tag = requestedNode.getFeature(ElementData.class).getTag();
Logger logger = LoggerFactory.getLogger(AttachTemplateChildRpcHandler.class.getName());
if (assignedId == -1) {
logger.error("Attach existing element has failed because " + "the client-side element is not found");
if (id instanceof JsonNull) {
throw new IllegalStateException(String.format("The element with the tag name '%s' was " + "not found in the parent with id='%d'", tag, parent.getId()));
} else {
throw new IllegalStateException(String.format("The element with the tag name '%s' and id '%s' was " + "not found in the parent with id='%d'", tag, id.asString(), parent.getId()));
}
} else if (requestedId != assignedId) {
logger.error("Attach existing element has failed because " + "the element has been already attached from the server side");
if (id instanceof JsonNull) {
throw new IllegalStateException(String.format("The element with the tag name '%s' is already " + "attached to the parent with id='%d'", tag, parent.getId()));
} else {
throw new IllegalStateException(String.format("The element with the tag name '%s' and id '%s' is " + "already attached to the parent with id='%d'", tag, id.asString(), parent.getId()));
}
} else {
logger.error("Attach existing element request succeeded. " + "But the response about this is unexpected");
// side should not respond
throw new IllegalArgumentException("Unexpected successful attachment " + "response is received from the client-side. " + "Client side should not respond if everything is fine");
}
}
Aggregations