List of usage examples for com.google.gwt.dom.client NodeList getItem
public T getItem(int index)
From source file:org.nuxeo.ecm.platform.annotations.gwt.client.util.GwtTestXPathUtil.java
License:Apache License
@SuppressWarnings("static-access") public void testGetGetXPath() { createDocument();/* w ww . j a v a 2s. c o m*/ NodeList<Element> el = RootPanel.get().getBodyElement().getElementsByTagName("span"); assertNotNull(el); Node node = el.getItem(0); assertNotNull(node); String xpath = xPathUtil.getXPath(node); assertNotNull(xpath); assertEquals("/html[0]/body[0]/div[0]/div[0]/div[0]/nobr[0]/span[0]", xpath.toLowerCase()); }
From source file:org.nuxeo.ecm.platform.annotations.gwt.client.util.Visitor.java
License:Apache License
public void visit(Node node) { if (startNode == node) { processing = true;//from ww w . j av a2 s . c o m } else if (endNode == node) { processing = false; } if (processor.doBreak()) { return; } NodeList list = node.getChildNodes(); if (list == null || list.getLength() == 0) { processIf(node); } else { int length = list.getLength(); Node[] nodes = new Node[list.getLength()]; for (int x = 0; x < length; x++) { nodes[x] = list.getItem(x); } processIf(node); for (int x = 0; x < length; x++) { visit(nodes[x]); } } }
From source file:org.nuxeo.ecm.platform.annotations.gwt.client.util.XPathUtil.java
License:Apache License
public List<Node> getNode(String xpath, Document document) { List<Node> nodes = new ArrayList<Node>(); if (xpath.startsWith("//")) { xpath = xpath.substring(2);//w w w . j ava 2s .c o m NodeList<Element> n = document.getElementsByTagName(xpath); for (int x = 0; x < n.getLength(); x++) { nodes.add(n.getItem(x)); } return nodes; } Log.debug("XPathUtil#getNode -- xpath: " + xpath); String[] paths = xpath.split("/"); Node result = document; for (String path : paths) { if ("".equals(path)) { continue; } NodeList<Node> nodeList = result.getChildNodes(); String name = path.substring(0, path.indexOf("[")); int index = Integer.parseInt(path.substring(path.indexOf("[") + 1, path.indexOf("]"))); int counter = 1; for (int x = 0; x < nodeList.getLength(); x++) { Node node = nodeList.getItem(x); if (node.getNodeName().equalsIgnoreCase(name)) { if (isIgnored(node)) {// considered as text node continue; } if (counter == index) { result = node; break; } counter++; } } } nodes.add(result); Log.debug("XPathUtil#getNode -- end function: "); return nodes; }
From source file:org.nuxeo.ecm.platform.annotations.gwt.client.view.AnnotatedDocument.java
License:Apache License
private static void preDecorateDocument(Document document) { Log.debug("Predecorate document !"); NodeList<Element> elements = document.getElementsByTagName("img"); for (int x = 0; x < elements.getLength(); x++) { Element element = elements.getItem(x); DivElement divElement = document.createDivElement(); divElement.getStyle().setProperty("position", "relative"); divElement.setClassName(AnnotationConstant.IGNORED_ELEMENT); String path = xPathUtil.getXPath(element); path = XPathUtil.toIdableName(path); divElement.setId(path);/*w w w .j a v a2 s .co m*/ Element nextSibling = element.getNextSiblingElement(); Element parent = element.getParentElement(); if (nextSibling == null) { parent.appendChild(divElement); } else { parent.insertBefore(divElement, nextSibling); } divElement.appendChild(element); } }
From source file:org.nuxeo.ecm.platform.annotations.gwt.client.view.AnnotatedDocument.java
License:Apache License
public void updateSelectedAnnotation(int index) { Annotation annotation = annotations.get(index); BodyElement bodyElement = Document.get().getBody(); if (!(annotation.getXpointer() instanceof NullRangeXPointer)) { NodeList<Element> spans = bodyElement.getElementsByTagName("span"); NodeList<Element> as = bodyElement.getElementsByTagName("div"); int scrollTop = Integer.MAX_VALUE; int scrollLeft = Integer.MAX_VALUE; for (int x = 0; x < spans.getLength(); x++) { Element element = spans.getItem(x); if (processElement(annotation, element)) { int[] absTopLeft = Utils.getAbsoluteTopLeft(element, Document.get()); if (absTopLeft[0] < scrollTop) { scrollTop = absTopLeft[0]; }//from w w w . j a v a2 s.c om if (absTopLeft[1] < scrollLeft) { scrollLeft = absTopLeft[1]; } } } for (int x = 0; x < as.getLength(); x++) { Element element = as.getItem(x); if (processElement(annotation, element)) { int[] absTopLeft = Utils.getAbsoluteTopLeft(element, Document.get()); if (absTopLeft[0] < scrollTop) { scrollTop = absTopLeft[0]; } if (absTopLeft[1] < scrollLeft) { scrollLeft = absTopLeft[1]; } } } scrollLeft = scrollLeft == Integer.MAX_VALUE ? 0 : scrollLeft; scrollTop = scrollTop == Integer.MAX_VALUE ? 0 : scrollTop; Window.scrollTo(scrollLeft, scrollTop); } }
From source file:org.nuxeo.ecm.platform.annotations.gwt.client.view.AnnotatedDocument.java
License:Apache License
public void hideAnnotations() { BodyElement bodyElement = Document.get().getBody(); NodeList<Element> spans = bodyElement.getElementsByTagName("span"); NodeList<Element> divs = bodyElement.getElementsByTagName("div"); for (int x = 0; x < spans.getLength(); x++) { Element element = spans.getItem(x); CSSClassManager manager = new CSSClassManager(element); if (manager.isClassPresent(AnnotationConstant.DECORATE_CLASS_NAME)) { manager.removeClass(AnnotationConstant.DECORATE_CLASS_NAME); manager.addClass(AnnotationConstant.DECORATE_NOT_CLASS_NAME); }/*from ww w .jav a 2s . co m*/ } for (int x = 0; x < divs.getLength(); x++) { Element element = divs.getItem(x); CSSClassManager manager = new CSSClassManager(element); if (manager.isClassPresent(AnnotationConstant.DECORATE_CLASS_NAME)) { manager.removeClass(AnnotationConstant.DECORATE_CLASS_NAME); manager.addClass(AnnotationConstant.DECORATE_NOT_CLASS_NAME); } } setAnnotationsShown(false); }
From source file:org.nuxeo.ecm.platform.annotations.gwt.client.view.AnnotatedDocument.java
License:Apache License
public void showAnnotations() { BodyElement bodyElement = Document.get().getBody(); NodeList<Element> spans = bodyElement.getElementsByTagName("span"); NodeList<Element> divs = bodyElement.getElementsByTagName("div"); for (int x = 0; x < spans.getLength(); x++) { Element element = spans.getItem(x); CSSClassManager manager = new CSSClassManager(element); if (manager.isClassPresent(AnnotationConstant.DECORATE_NOT_CLASS_NAME)) { manager.removeClass(AnnotationConstant.DECORATE_NOT_CLASS_NAME); manager.addClass(AnnotationConstant.DECORATE_CLASS_NAME); }// w ww . j a v a 2 s . c o m if (manager.isClassPresent(AnnotationConstant.SELECTED_NOT_CLASS_NAME)) { manager.removeClass(AnnotationConstant.SELECTED_NOT_CLASS_NAME); manager.addClass(AnnotationConstant.SELECTED_CLASS_NAME); } } for (int x = 0; x < divs.getLength(); x++) { Element element = divs.getItem(x); CSSClassManager manager = new CSSClassManager(element); if (manager.isClassPresent(AnnotationConstant.DECORATE_NOT_CLASS_NAME)) { manager.removeClass(AnnotationConstant.DECORATE_NOT_CLASS_NAME); manager.addClass(AnnotationConstant.DECORATE_CLASS_NAME); } if (manager.isClassPresent(AnnotationConstant.SELECTED_NOT_CLASS_NAME)) { manager.removeClass(AnnotationConstant.SELECTED_NOT_CLASS_NAME); manager.addClass(AnnotationConstant.SELECTED_CLASS_NAME); } } setAnnotationsShown(true); }
From source file:org.nuxeo.ecm.platform.annotations.gwt.client.view.AnnotatedDocument.java
License:Apache License
private List<Element> getElementsToRemove(NodeList<Element> nodes, String className) { List<Element> elementsToRemove = new ArrayList<Element>(); for (int i = 0; i < nodes.getLength(); ++i) { Element element = nodes.getItem(i); CSSClassManager manager = new CSSClassManager(element); if (manager.isClassPresent(className)) { elementsToRemove.add(element); }//www. j av a 2 s . c om } return elementsToRemove; }
From source file:org.opencms.acacia.client.entity.CmsEntityBackend.java
License:Open Source License
/** * Returns a list of DOM elements matching the given selector.<p> * * @param selector the CSS selector//from w ww . j a va 2 s . c o m * @param context the context element * * @return the matching elements */ protected List<Element> select(String selector, Element context) { NodeList<Element> elements = CmsDomUtil.querySelectorAll(selector, context); List<Element> result = new ArrayList<Element>(); for (int i = 0; i < elements.getLength(); i++) { result.add(elements.getItem(i)); } return result; }
From source file:org.opencms.acacia.client.widgets.complex.CmsDataViewValueAccessor.java
License:Open Source License
/** * Replaces the value in the editor with a list of other values.<p> * * @param replacementValues the list of replacement values *//*from w ww . j a v a2 s .co m*/ public void replaceValue(List<CmsDataViewValue> replacementValues) { CmsAttributeHandler handler = (CmsAttributeHandler) m_handler; Element parent = CmsDomUtil .getAncestor(m_widget.getElement(), I_CmsLayoutBundle.INSTANCE.form().attributeValue()) .getParentElement(); NodeList<Node> siblings = parent.getChildNodes(); for (int j = 0; j < siblings.getLength(); j++) { Node node = siblings.getItem(j); if (node instanceof Element) { Element elem = (Element) node; if (elem.isOrHasChild(m_widget.getElement())) { m_index = j; break; } } } Panel container = handler.removeAttributeValueAndReturnPrevParent(m_index, true); int i = m_index; for (CmsDataViewValue value : replacementValues) { CmsEntity entity = CmsEntityBackend.getInstance().createEntity(null, m_entity.getTypeName()); writeValueToEntity(value, entity); // handler.addNewAttributeValue(entity); handler.insertNewAttributeValue(entity, i, container); i += 1; } handler.updateButtonVisisbility(); }