List of usage examples for com.google.gwt.user.client Element getNextSibling
@Override
public Node getNextSibling()
From source file:com.extjs.gxt.ui.client.widget.ListView.java
License:sencha.com license
protected void onAdd(List<M> models, int index) { if (rendered) { if (all.getCount() == 0) { refresh();/*from www.jav a 2 s . c o m*/ return; } NodeList<Element> nodes = bufferRender(models); Element[] elements = Util.toElementArray(nodes); all.insert(elements, index); Element ref = index == 0 ? all.getElement(elements.length) : all.getElement(index - 1); for (int i = elements.length - 1; i >= 0; i--) { Node n = ref.getParentNode(); if (index == 0) { n.insertBefore(elements[i], n.getFirstChild()); } else { Node next = ref == null ? null : ref.getNextSibling(); if (next == null) { n.appendChild(elements[i]); } else { n.insertBefore(elements[i], next); } } if (GXT.isAriaEnabled()) { elements[i].setId(XDOM.getUniqueId()); } } updateIndexes(index, -1); } }
From source file:com.vaadin.client.ComponentLocator.java
License:Apache License
/** * Returns the element passed to the method. Or in case of Firefox 15, * returns the real element that is in the DOM instead of the element passed * to the method (which is the same element but not ==). * //from ww w . j a v a 2s. c o m * @param targetElement * the element to return * @return the element passed to the method */ private Element getElement(Element targetElement) { if (targetElement == null) { return null; } if (!BrowserInfo.get().isFirefox()) { return targetElement; } if (BrowserInfo.get().getBrowserMajorVersion() != 15) { return targetElement; } // Firefox 15, you make me sad if (targetElement.getNextSibling() != null) { return (Element) targetElement.getNextSibling().getPreviousSibling(); } if (targetElement.getPreviousSibling() != null) { return (Element) targetElement.getPreviousSibling().getNextSibling(); } // No siblings so this is the only child return (Element) targetElement.getParentNode().getChild(0); }
From source file:com.vaadin.terminal.gwt.client.Util.java
License:Open Source License
/** * Detaches and re-attaches the element from its parent. The element is * reattached at the same position in the DOM as it was before. * //from w w w. j ava 2s .c o m * Does nothing if the element is not attached to the DOM. * * @param element * The element to detach and re-attach */ public static void detachAttach(Element element) { if (element == null) { return; } Node nextSibling = element.getNextSibling(); Node parent = element.getParentNode(); if (parent == null) { return; } parent.removeChild(element); if (nextSibling == null) { parent.appendChild(element); } else { parent.insertBefore(element, nextSibling); } }
From source file:org.nuxeo.ecm.platform.annotations.gwt.client.view.decorator.NuxeoDecoratorVisitor.java
License:Apache License
protected void decorateText(String textToDecorate) { checkEndNodeFound();/* w w w. ja va2 s. c o m*/ String afterText = getAfterText(); Log.debug("Decorator -- afterText: " + afterText); if (afterText.length() > 0) { textToDecorate = textToDecorate.substring(0, textToDecorate.length() - afterText.length()); } if (currentNode.getParentNode().getNodeName().equalsIgnoreCase("tr")) { // don't add nodes to tr return; } com.google.gwt.dom.client.Element spanElement = decorateTextWithSpan(textToDecorate); if (spanElement == null) { if (afterText.length() > 0) { Document document = currentNode.getOwnerDocument(); Node parent = currentNode.getParentNode(); insertBefore(parent, currentNode, document.createTextNode(afterText)); } } else { Log.debug("Decorator -- span element: " + spanElement.getInnerHTML()); if (afterText.length() > 0) { Document document = currentNode.getOwnerDocument(); Node parent = currentNode.getParentNode(); insertBefore(parent, spanElement.getNextSibling(), document.createTextNode(afterText)); } } }
From source file:org.opencms.ade.containerpage.client.CmsContainerpageUtil.java
License:Open Source License
/** * Transforms all contained elements into {@link CmsContainerPageElementPanel}.<p> * //from w w w . j a va 2s .com * @param container the container */ public void consumeContainerElements(I_CmsDropContainer container) { // the drag element widgets are created from the existing DOM elements, Element child = (Element) container.getElement().getFirstChildElement(); while (child != null) { boolean isContainerElement = CmsDomUtil.hasClass(CLASS_CONTAINER_ELEMENT_START_MARKER, child); boolean isGroupcontainerElement = CmsDomUtil.hasClass(CLASS_GROUP_CONTAINER_ELEMENT_MARKER, child); if (isContainerElement || isGroupcontainerElement) { String clientId = child.getAttribute("clientId"); String sitePath = child.getAttribute("alt"); String noEditReason = child.getAttribute("rel"); String newType = child.getAttribute("newType"); boolean hasProps = Boolean.parseBoolean(child.getAttribute("hasprops")); boolean hasViewPermission = Boolean.parseBoolean(child.getAttribute("hasviewpermission")); boolean releasedAndNotExpired = Boolean.parseBoolean(child.getAttribute("releasedandnotexpired")); if (isContainerElement) { // searching for content element root Element elementRoot = (Element) child.getNextSibling(); while ((elementRoot != null) && (elementRoot.getNodeType() != Node.ELEMENT_NODE)) { Element temp = elementRoot; elementRoot = (Element) elementRoot.getNextSibling(); temp.removeFromParent(); } if (elementRoot == null) { child.removeFromParent(); child = null; continue; } if (CmsDomUtil.hasClass(CLASS_CONTAINER_ELEMENT_START_MARKER, elementRoot)) { // broken element, already at next start marker child.removeFromParent(); child = elementRoot; continue; } if (CmsDomUtil.hasClass(CLASS_CONTAINER_ELEMENT_END_MARKER, elementRoot)) { // broken element, no content element root child.removeFromParent(); child = (Element) elementRoot.getNextSiblingElement(); elementRoot.removeFromParent(); continue; } else { // looking for the next marker that wraps the current element Element endMarker = (Element) elementRoot.getNextSibling(); // only if the end marker node is not null and has neither the end-marker class or start-marker class // remove the current node and check the next sibling while (!((endMarker == null) || ((endMarker.getNodeType() == Node.ELEMENT_NODE) && (CmsDomUtil.hasClass(CLASS_CONTAINER_ELEMENT_END_MARKER, endMarker) || CmsDomUtil .hasClass(CLASS_CONTAINER_ELEMENT_START_MARKER, endMarker))))) { Element temp = endMarker; endMarker = (Element) endMarker.getNextSibling(); temp.removeFromParent(); } if (endMarker == null) { // broken element, end marker missing elementRoot.removeFromParent(); child.removeFromParent(); child = null; continue; } if (CmsDomUtil.hasClass(CLASS_CONTAINER_ELEMENT_START_MARKER, endMarker)) { // broken element, end marker missing elementRoot.removeFromParent(); child.removeFromParent(); child = endMarker; } CmsDomUtil.removeScriptTags(elementRoot); CmsContainerPageElementPanel containerElement = createElement(elementRoot, container, clientId, sitePath, noEditReason, hasProps, hasViewPermission, releasedAndNotExpired); if ((newType != null) && (newType.length() > 0)) { containerElement.setNewType(newType); } container.adoptElement(containerElement); child.removeFromParent(); child = (Element) endMarker.getNextSiblingElement(); // (Element)container.getElement().getFirstChildElement(); endMarker.removeFromParent(); } } else if (isGroupcontainerElement && (container instanceof CmsContainerPageContainer)) { CmsDomUtil.removeScriptTags(child); CmsGroupContainerElementPanel groupContainer = createGroupcontainer(child, container, clientId, sitePath, noEditReason, hasProps, hasViewPermission, releasedAndNotExpired); groupContainer.setContainerId(container.getContainerId()); container.adoptElement(groupContainer); consumeContainerElements(groupContainer); if (groupContainer.getWidgetCount() == 0) { groupContainer .addStyleName(I_CmsLayoutBundle.INSTANCE.containerpageCss().emptyGroupContainer()); } // important: adding the option-bar only after the group-containers have been consumed addOptionBar(groupContainer); child = (Element) child.getNextSiblingElement(); } } else { Element sibling = (Element) child.getNextSiblingElement(); DOM.removeChild((Element) container.getElement(), child); child = sibling; continue; } } }