use of elemental.dom.NodeList in project che by eclipse.
the class Tree method rightArrowPressed.
/**
* Handles pressing the Right arrow button.
* Does nothing when user selected a file. Expands a folder if the user has selected one.
* Selects the first child if the folder is already selected and expanded.
*/
public void rightArrowPressed() {
if (getModel().getRoot() == null || getSelectionModel().getSelectedNodes().isEmpty() || getModel().dataAdapter.getChildren(getModel().getRoot()).isEmpty()) {
return;
}
D selected = getSelectionModel().getSelectedNodes().get(0);
TreeNodeElement<D> selectedTreeNodeElement = getModel().dataAdapter.getRenderedTreeNode(selected);
if (selectedTreeNodeElement.hasChildrenContainer()) {
if (selectedTreeNodeElement.isOpen()) {
// Select the first child
NodeList children = selectedTreeNodeElement.getChildrenContainer().getChildNodes();
if (children.getLength() > 0) {
TreeNodeElement<D> firstChild = (TreeNodeElement<D>) children.item(0);
selectSingleNode(firstChild);
}
} else {
// Open the folder
expandNode(selectedTreeNodeElement, true, true);
}
}
}
use of elemental.dom.NodeList in project flow by vaadin.
the class GwtTemplateBinderTest method testNgFor_updateModelValues.
public void testNgFor_updateModelValues() {
TestElementTemplateNode parent = TestElementTemplateNode.create("div");
String textVar = "text";
// create 3 children for the parent: <div/><li
// *ngFor>{{text}}</li><span/>
StateNode modelNode = createNgForModelNode(parent, "div", "li", "span", "items", textVar);
StateNode varNode = new StateNode(2, tree);
varNode.getMap(NodeFeatures.TEMPLATE_MODELMAP).getProperty(textVar).setValue("foo");
com.vaadin.client.flow.nodefeature.NodeList modelList = modelNode.getList(NodeFeatures.TEMPLATE_MODELLIST);
modelList.add(0, varNode);
Element element = createElement(parent);
Reactive.flush();
StateNode varNode1 = new StateNode(3, tree);
varNode1.getMap(NodeFeatures.TEMPLATE_MODELMAP).getProperty(textVar).setValue("bar");
StateNode varNode2 = new StateNode(4, tree);
varNode2.getMap(NodeFeatures.TEMPLATE_MODELMAP).getProperty(textVar).setValue("bar1");
modelList.splice(0, 1);
modelList.add(0, varNode1);
modelList.add(1, varNode2);
Reactive.flush();
assertEquals("DIV", element.getTagName());
NodeList childNodes = element.getChildNodes();
assertTrue(childNodes.getLength() > 1);
assertEquals("DIV", ((Element) childNodes.item(0)).getTagName());
assertEquals("SPAN", ((Element) childNodes.item(childNodes.getLength() - 1)).getTagName());
Element li = ((Element) childNodes.item(childNodes.getLength() - 3));
assertEquals("LI", li.getTagName());
assertEquals(5, childNodes.getLength());
// comment
assertEquals(Node.COMMENT_NODE, childNodes.item(1).getNodeType());
assertEquals("bar", li.getTextContent());
li = ((Element) childNodes.item(childNodes.getLength() - 2));
assertEquals("LI", li.getTagName());
assertEquals("bar1", li.getTextContent());
}
use of elemental.dom.NodeList in project flow by vaadin.
the class GwtTemplateBinderTest method testNgFor_updateModel.
public void testNgFor_updateModel() {
TestElementTemplateNode parent = TestElementTemplateNode.create("div");
String textVar = "text";
String collectionVar = "items";
// create 3 children for the parent: <div/><li
// *ngFor>{{text}}</li><span/>
StateNode modelNode = createNgForModelNode(parent, "div", "li", "span", collectionVar, textVar);
StateNode varNode = new StateNode(2, tree);
varNode.getMap(NodeFeatures.TEMPLATE_MODELMAP).getProperty(textVar).setValue("foo");
modelNode.getList(NodeFeatures.TEMPLATE_MODELLIST).add(0, varNode);
Element element = createElement(parent);
Reactive.flush();
NodeMap model = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
MapProperty property = model.getProperty(collectionVar);
modelNode = new StateNode(3, tree);
property.setValue(modelNode);
varNode = new StateNode(4, tree);
varNode.getMap(NodeFeatures.TEMPLATE_MODELMAP).getProperty(textVar).setValue("bar");
modelNode.getList(NodeFeatures.TEMPLATE_MODELLIST).add(0, varNode);
Reactive.flush();
assertEquals("DIV", element.getTagName());
NodeList childNodes = element.getChildNodes();
assertTrue(childNodes.getLength() > 1);
assertEquals("DIV", ((Element) childNodes.item(0)).getTagName());
assertEquals("SPAN", ((Element) childNodes.item(childNodes.getLength() - 1)).getTagName());
Element li = ((Element) childNodes.item(childNodes.getLength() - 2));
assertEquals("LI", li.getTagName());
assertEquals(4, childNodes.getLength());
// comment
assertEquals(Node.COMMENT_NODE, childNodes.item(1).getNodeType());
assertEquals("bar", li.getTextContent());
}
use of elemental.dom.NodeList in project che by eclipse.
the class Tree method getVisibleTreeNodes.
/**
* Gathers all visible nodes of subtree.
*
* @param node subtree parent
* @return array containing all visible nodes of subtree
*/
public List<TreeNodeElement<D>> getVisibleTreeNodes(TreeNodeElement<D> node) {
List<TreeNodeElement<D>> nodes = new ArrayList<>();
nodes.add(node);
if (node.isOpen() && node.hasChildNodes()) {
NodeList children = node.getChildrenContainer().getChildNodes();
for (int ci = 0; ci < children.getLength(); ci++) {
TreeNodeElement<D> child = (TreeNodeElement<D>) children.item(ci);
nodes.addAll(getVisibleTreeNodes(child));
}
}
return nodes;
}
use of elemental.dom.NodeList in project flow by vaadin.
the class ResourceLoader method initLoadedResourcesFromDom.
/**
* Populates the resource loader with the scripts currently added to the
* page.
*/
private void initLoadedResourcesFromDom() {
Document document = Browser.getDocument();
// detect already loaded scripts and stylesheets
NodeList scripts = document.getElementsByTagName("script");
for (int i = 0; i < scripts.getLength(); i++) {
ScriptElement element = (ScriptElement) scripts.item(i);
String src = element.getSrc();
if (src != null && src.length() != 0) {
loadedResources.add(src);
}
}
NodeList links = document.getElementsByTagName("link");
for (int i = 0; i < links.getLength(); i++) {
LinkElement linkElement = (LinkElement) links.item(i);
String rel = linkElement.getRel();
String href = linkElement.getHref();
if (("stylesheet".equalsIgnoreCase(rel) || "import".equalsIgnoreCase(rel)) && href != null && href.length() != 0) {
loadedResources.add(href);
}
}
}
Aggregations