use of com.vaadin.flow.internal.StateNode 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.StateNode in project flow by vaadin.
the class HierarchicalCommunicatorTest method setUp.
@Before
public void setUp() {
ui = Mockito.mock(UI.class);
uiInternals = Mockito.mock(UIInternals.class);
stateTree = Mockito.mock(StateTree.class);
Mockito.when(ui.getInternals()).thenReturn(uiInternals);
Mockito.when(uiInternals.getStateTree()).thenReturn(stateTree);
treeData = new TreeData<>();
treeData.addItems(null, ROOT);
treeData.addItems(ROOT, FOLDER);
treeData.addItems(FOLDER, LEAF);
dataProvider = new TreeDataProvider<>(treeData);
stateNode = Mockito.mock(StateNode.class);
Mockito.when(stateNode.hasFeature(Mockito.any())).thenReturn(true);
ComponentMapping mapping = Mockito.mock(ComponentMapping.class);
Mockito.when(stateNode.getFeatureIfInitialized(ComponentMapping.class)).thenReturn(java.util.Optional.ofNullable(mapping));
Mockito.when(mapping.getComponent()).thenReturn(java.util.Optional.of(new TestComponent()));
communicator = new HierarchicalDataCommunicator<>(Mockito.mock(CompositeDataGenerator.class), arrayUpdater, json -> {
}, stateNode, () -> null);
communicator.setDataProvider(dataProvider, null);
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class BasicElementStateProvider method createStateNode.
/**
* Creates a compatible element state node using the given {@code tag}.
*
* @param tag
* the tag to use for the element
* @return a initialized and compatible state node
*/
public static StateNode createStateNode(String tag) {
assert ElementUtil.isValidTagName(tag) : "Invalid tag name " + tag;
StateNode node = new StateNode(Collections.singletonList(ElementData.class), features);
node.getFeature(ElementData.class).setTag(tag);
return node;
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class ShadowRootStateProvider method createShadowRootNode.
/**
* Create a new shadow root node for the given element {@code node}.
*
* @param node
* the node to create the shadow root for
* @return the shadow root node
*/
public StateNode createShadowRootNode(StateNode node) {
StateNode shadowRoot = new StateNode(getProviderFeatures());
node.getFeature(ShadowRootData.class).setShadowRoot(shadowRoot);
return shadowRoot;
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class MapPutChange method populateJson.
@Override
protected void populateJson(JsonObject json, ConstantPool constantPool) {
// Set the type and key before calling super to make the keys appear in
// a more logical order
json.put(JsonConstants.CHANGE_TYPE, JsonConstants.CHANGE_TYPE_PUT);
json.put(JsonConstants.CHANGE_MAP_KEY, key);
super.populateJson(json, constantPool);
if (value instanceof StateNode) {
StateNode node = (StateNode) value;
json.put(JsonConstants.CHANGE_PUT_NODE_VALUE, Json.create(node.getId()));
} else {
json.put(JsonConstants.CHANGE_PUT_VALUE, JsonCodec.encodeWithConstantPool(value, constantPool));
}
}
Aggregations