use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.
the class GwtTreeChangeProcessorTest method testPrimitiveSplice.
public void testPrimitiveSplice() {
StateTree tree = new StateTree(null);
StateNode root = tree.getRootNode();
int nsId = 1;
JsonObject change = Json.createObject();
change.put(JsonConstants.CHANGE_TYPE, JsonConstants.CHANGE_TYPE_SPLICE);
change.put(JsonConstants.CHANGE_NODE, root.getId());
change.put(JsonConstants.CHANGE_FEATURE, nsId);
change.put(JsonConstants.CHANGE_SPLICE_INDEX, 0);
JsonArray add = Json.createArray();
add.set(0, "value");
change.put(JsonConstants.CHANGE_SPLICE_ADD, add);
TreeChangeProcessor.processChange(tree, change);
NodeList list = root.getList(nsId);
assertEquals(1, list.length());
assertEquals("value", list.get(0));
}
use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.
the class StateNodeTest method testGetListFeature.
@Test
public void testGetListFeature() {
NodeList list = node.getList(1);
Assert.assertEquals(1, list.getId());
List<NodeFeature> features = collectFeatures();
Assert.assertEquals(Arrays.asList(list), features);
NodeList anotherList = node.getList(1);
Assert.assertSame(anotherList, list);
Assert.assertEquals(features, collectFeatures());
}
use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.
the class SimpleElementBindingStrategy method verifyAttachedElement.
private boolean verifyAttachedElement(Element element, StateNode attachNode, String id, String address, BindingContext context) {
StateNode node = context.node;
String tag = getTag(attachNode);
boolean failure = false;
if (element == null) {
failure = true;
Console.warn(ELEMENT_ATTACH_ERROR_PREFIX + address + " is not found. The requested tag name is '" + tag + "'");
} else if (!ElementUtil.hasTag(element, tag)) {
failure = true;
Console.warn(ELEMENT_ATTACH_ERROR_PREFIX + address + " has the wrong tag name '" + element.getTagName() + "', the requested tag name is '" + tag + "'");
}
if (failure) {
node.getTree().sendExistingElementWithIdAttachToServer(node, attachNode.getId(), -1, id);
return false;
}
if (!node.hasFeature(NodeFeatures.SHADOW_ROOT_DATA)) {
return true;
}
NodeMap map = node.getMap(NodeFeatures.SHADOW_ROOT_DATA);
StateNode shadowRootNode = (StateNode) map.getProperty(NodeProperties.SHADOW_ROOT).getValue();
if (shadowRootNode == null) {
return true;
}
NodeList list = shadowRootNode.getList(NodeFeatures.ELEMENT_CHILDREN);
Integer existingId = null;
for (int i = 0; i < list.length(); i++) {
StateNode stateNode = (StateNode) list.get(i);
Node domNode = stateNode.getDomNode();
if (domNode.equals(element)) {
existingId = stateNode.getId();
break;
}
}
if (existingId != null) {
Console.warn(ELEMENT_ATTACH_ERROR_PREFIX + address + " has been already attached previously via the node id='" + existingId + "'");
node.getTree().sendExistingElementWithIdAttachToServer(node, attachNode.getId(), existingId, id);
return false;
}
return true;
}
use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.
the class SimpleElementBindingStrategy method bindClassList.
private EventRemover bindClassList(Element element, StateNode node) {
NodeList classNodeList = node.getList(NodeFeatures.CLASS_LIST);
for (int i = 0; i < classNodeList.length(); i++) {
DomApi.wrap(element).getClassList().add((String) classNodeList.get(i));
}
return classNodeList.addSpliceListener(e -> {
DomTokenList classList = DomApi.wrap(element).getClassList();
JsArray<?> remove = e.getRemove();
for (int i = 0; i < remove.length(); i++) {
classList.remove((String) remove.get(i));
}
JsArray<?> add = e.getAdd();
for (int i = 0; i < add.length(); i++) {
classList.add((String) add.get(i));
}
});
}
use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.
the class SimpleElementBindingStrategy method getPreviousSibling.
private StateNode getPreviousSibling(int index, BindingContext context) {
NodeList nodeChildren = context.node.getList(NodeFeatures.ELEMENT_CHILDREN);
int count = 0;
StateNode node = null;
for (int i = 0; i < nodeChildren.length(); i++) {
if (count == index) {
return node;
}
StateNode child = (StateNode) nodeChildren.get(i);
if (child.getDomNode() != null) {
node = child;
count++;
}
}
return node;
}
Aggregations