List of usage examples for com.google.gwt.dom.client Node setNodeValue
@Override
public void setNodeValue(String nodeValue)
From source file:com.google.livingstories.client.lsp.views.contentitems.QuoteContentItemView.java
License:Apache License
public QuoteContentItemView(QuoteContentItem contentItem) { initWidget(uiBinder.createAndBindUi(this)); // if the rendered HTML content leads with a double-quote character, we replace the underlying // text with 2 non-breaking spaces. HTML detachedHTML = new HTML(contentItem.getContent()); // walk through the content looking for the first text node: Node firstTextNode = getFirstTextNode(detachedHTML.getElement().getFirstChild()); if (firstTextNode != null) { // replace check the first text node to see if there's quotiness to replace. String firstText = firstTextNode.getNodeValue(); // replace leading whitespace plus a quote character with two s. // \u201C is the opening-double-quote codepoint; \u00A0 is a non-breaking space. String replacedText = firstText.replaceFirst("^\\s*[\"\u201C]", "\u00A0\u00A0"); if (!replacedText.equals(firstText)) { firstTextNode.setNodeValue(replacedText); }//from ww w. j ava 2 s . c o m } content.add(new ContentRenderer(detachedHTML.getElement().getInnerHTML(), false)); }
From source file:org.gk.ui.client.com.tree.gkTreePanelIC.java
License:Open Source License
@Override public void bindEvent() { core.subscribe(evtSetBean(), new EventProcess() { @Override/*from w w w . j av a2s .co m*/ public void execute(String eventId, EventObject eo) { setBean(eo.getInfoString()); } }); // ? core.subscribe(evtOnEdit(), new EventProcess() { @Override public void execute(String eventId, EventObject e) { TreeNode tn = (TreeNode) e.getInfoMap() .get((tree.getSelectionModel().getSelectedItem().getProperties().get(PATH) + "")); // ?? final Node nd = tn.getElement().getChild(0); // ?inputelement final Element input = DOM.createElement("input"); // ?????span final Node childnd = nd.getLastChild(); // ?span final String oldString = childnd.getFirstChild().getNodeValue(); // ?input?span input.setAttribute("value", oldString); // inputID?? input.setAttribute("id", "newText"); // ?spanelement final Node oldNode = childnd.getFirstChild().cloneNode(true); // span???input? childnd.replaceChild(input, childnd.getFirstChild()); // ??? tree.disableTextSelection(false); // ??input input.focus(); // ?inputkeydown DOM.sinkEvents(input, com.google.gwt.user.client.Event.ONBLUR | com.google.gwt.user.client.Event.ONKEYDOWN | com.google.gwt.user.client.Event.ONMOUSEOVER | com.google.gwt.user.client.Event.ONMOUSEOUT); // ?inputenter? DOM.setEventListener(input, new EventListener() { // ?inputonblur boolean mouseIn = true; @Override public void onBrowserEvent(com.google.gwt.user.client.Event event) { if (event.getTypeInt() == com.google.gwt.user.client.Event.ONMOUSEOUT) { mouseIn = false; } if (event.getTypeInt() == com.google.gwt.user.client.Event.ONMOUSEOVER) { mouseIn = true; } if (event.getTypeInt() == com.google.gwt.user.client.Event.ONBLUR || event.getKeyCode() == KeyCodeEnter) { if (event.getKeyCode() == KeyCodeEnter || mouseIn == false) { // ?input String newString = getvalue(); // if (newString.equals("")) { input.setAttribute("value", oldString); } // span??input oldNode.setNodeValue(newString); // ?spaninput? childnd.replaceChild(oldNode, input); // ?treemodelDataap??? setModelData(newString, tree); inEdit = false; } } } }); } }); }
From source file:org.xwiki.gwt.dom.client.DOMUtils.java
License:Open Source License
/** * Clones the contents of the given node. If node type is text, CDATA or comment then only the data between * startOffset (including) and endOffset is kept. If node type is element then only the child nodes with indexes * between startOffset (including) and endOffset are included in the document fragment returned. * //www . j a va 2 s .c o m * @param node The DOM node whose contents will be cloned. * @param startOffset the index of the first child to clone or the first character to include in the cloned * contents. * @param endOffset specifies where the cloned contents end. * @return the cloned contents of the given node, between start offset and end offset. */ public DocumentFragment cloneNodeContents(Node node, int startOffset, int endOffset) { DocumentFragment contents = ((Document) node.getOwnerDocument()).createDocumentFragment(); switch (node.getNodeType()) { case CDATA_NODE: case COMMENT_NODE: case Node.TEXT_NODE: if (startOffset < endOffset) { Node clone = node.cloneNode(false); clone.setNodeValue(node.getNodeValue().substring(startOffset, endOffset)); contents.appendChild(clone); } break; case Node.ELEMENT_NODE: for (int i = startOffset; i < endOffset; i++) { contents.appendChild(node.getChildNodes().getItem(i).cloneNode(true)); } break; default: // ignore } return contents; }
From source file:org.xwiki.gwt.dom.client.DOMUtils.java
License:Open Source License
/** * Clones the given DOM node, keeping only the contents between start and end offset. If node type is text, CDATA or * comment then both offsets represent character indexes. Otherwise they represent child indexes. * /*from w ww . j av a 2s . c o m*/ * @param node The DOM node to be cloned. * @param startOffset specifies where to start the cloning. * @param endOffset specifies where to end the cloning. * @return A clone of the given node, containing only the contents between start and end offset. */ public Node cloneNode(Node node, int startOffset, int endOffset) { Node clone = node.cloneNode(false); switch (node.getNodeType()) { case CDATA_NODE: case COMMENT_NODE: case Node.TEXT_NODE: clone.setNodeValue(node.getNodeValue().substring(startOffset, endOffset)); return clone; case Node.ELEMENT_NODE: for (int i = startOffset; i < endOffset; i++) { clone.appendChild(node.getChildNodes().getItem(i).cloneNode(true)); } return clone; default: throw new IllegalArgumentException(UNSUPPORTED_NODE_TYPE); } }
From source file:org.xwiki.gwt.dom.client.DOMUtils.java
License:Open Source License
/** * Deletes the contents of the given node between the specified offsets. If node type is text, CDATA or comment then * only the data between startOffset (including) and endOffset is deleted. If node type is element then only the * child nodes with indexes between startOffset (including) and endOffset are deleted. * //www. j ava2 s . co m * @param node The DOM node whose contents will be deleted. * @param startOffset the index of the first child or the first character to delete, depending on node type. * @param endOffset specifies where to stop deleting content. */ public void deleteNodeContents(Node node, int startOffset, int endOffset) { switch (node.getNodeType()) { case CDATA_NODE: case COMMENT_NODE: case Node.TEXT_NODE: if (startOffset < endOffset) { node.setNodeValue( node.getNodeValue().substring(0, startOffset) + node.getNodeValue().substring(endOffset)); } break; case Node.ELEMENT_NODE: for (int i = startOffset; i < endOffset; i++) { node.removeChild(node.getChildNodes().getItem(startOffset)); } break; default: // ignore } }
From source file:org.xwiki.gwt.dom.client.DOMUtils.java
License:Open Source License
/** * Splits the given DOM node at the specified offset. * //from www. ja va 2s.co m * @param node The node to be split. * @param offset Specifies where to split. It can be either a character index or a child index depending on node * type. * @return The node resulted after the split. It should be the next sibling of the given node. */ public Node splitNode(Node node, int offset) { Node clone = node.cloneNode(false); switch (node.getNodeType()) { case CDATA_NODE: case COMMENT_NODE: case Node.TEXT_NODE: clone.setNodeValue(node.getNodeValue().substring(offset)); node.setNodeValue(node.getNodeValue().substring(0, offset)); break; case Node.ELEMENT_NODE: Element.as(clone).removeAttribute(ID); for (int i = node.getChildNodes().getLength(); i > offset; i--) { clone.appendChild(node.getChildNodes().getItem(offset)); } break; default: throw new IllegalArgumentException(UNSUPPORTED_NODE_TYPE); } insertAfter(clone, node); return clone; }
From source file:org.xwiki.gwt.dom.client.DOMUtils.java
License:Open Source License
/** * Extracts the contents of the given node. If node type is text, CDATA or comment then only the data between * startOffset (including) and endOffset is kept. If node type is element then only the child nodes with indexes * between startOffset (including) and endOffset are included in the document fragment returned. * /* w w w. j a v a2 s .c o m*/ * @param node the DOM node whose contents will be extracted * @param startOffset the index of the first child to extract or the first character to include in the extracted * contents * @param endOffset specifies where the extracted contents end * @return the extracted contents of the given node, between start offset and end offset */ public DocumentFragment extractNodeContents(Node node, int startOffset, int endOffset) { DocumentFragment contents = ((Document) node.getOwnerDocument()).createDocumentFragment(); switch (node.getNodeType()) { case CDATA_NODE: case COMMENT_NODE: case Node.TEXT_NODE: if (startOffset < endOffset) { Node clone = node.cloneNode(false); clone.setNodeValue(node.getNodeValue().substring(startOffset, endOffset)); contents.appendChild(clone); node.setNodeValue( node.getNodeValue().substring(0, startOffset) + node.getNodeValue().substring(endOffset)); } break; case Node.ELEMENT_NODE: for (int i = startOffset; i < endOffset; i++) { contents.appendChild(node.getChildNodes().getItem(startOffset)); } break; default: // ignore } return contents; }
From source file:org.xwiki.gwt.dom.client.DOMUtils.java
License:Open Source License
/** * Extracts the given DOM node, keeping only the contents between start and end offset. If node type is text, CDATA * or comment then both offsets represent character indexes. Otherwise they represent child indexes. * /* w ww . j ava 2 s .c om*/ * @param node the DOM node to be extracted * @param startOffset specifies where to start the extraction * @param endOffset specifies where to end the extraction * @return a shallow clone of the given node, containing only the contents between start and end offset, which have * been extracted from the input node */ public Node extractNode(Node node, int startOffset, int endOffset) { Node clone = node.cloneNode(false); switch (node.getNodeType()) { case CDATA_NODE: case COMMENT_NODE: case Node.TEXT_NODE: clone.setNodeValue(node.getNodeValue().substring(startOffset, endOffset)); node.setNodeValue( node.getNodeValue().substring(0, startOffset) + node.getNodeValue().substring(endOffset)); return clone; case Node.ELEMENT_NODE: for (int i = startOffset; i < endOffset; i++) { clone.appendChild(node.getChildNodes().getItem(startOffset)); } return clone; default: throw new IllegalArgumentException(UNSUPPORTED_NODE_TYPE); } }
From source file:org.xwiki.gwt.dom.client.internal.ie.IEOldSelection.java
License:Open Source License
/** * Adjusts the given range and the DOM tree prior to selecting the range. We have to do this because IE selection * boundaries cannot, in most of the cases, be placed inside empty elements or empty text nodes or at the beginning * of a text node./*from w ww . j a v a 2 s .c om*/ * * @param range the range to be adjusted * @return the adjusted range */ private Range adjustRangeAndDOM(Range range) { Node start = range.getStartContainer(); if (range.isCollapsed() && start.getNodeType() == Node.TEXT_NODE && range.getStartOffset() == 0 && !isTextBefore(start)) { start.setNodeValue("\u00A0" + start.getNodeValue()); Range adjusted = range.cloneRange(); adjusted.setEnd(start, 1); return adjusted; } return range; }