List of usage examples for com.google.gwt.dom.client NodeList getItem
public T getItem(int index)
From source file:com.goodow.wave.client.wavepanel.blip.SetColor.java
License:Apache License
private void putColor(final NodeList<Node> childNodes) { Iterator<Entry<String, String>> iterator = colorMap.entrySet().iterator(); int i = 1;/*from w w w.jav a 2s . c o m*/ while (iterator.hasNext()) { Entry<String, String> color = iterator.next(); Element elm = Element.as(childNodes.getItem(i)); elm.setTitle(color.getKey()); elm.getStyle().setBackgroundColor(color.getValue()); addEvent(elm); i = i + 2; } }
From source file:com.google.gwt.site.demo.AbstractDemos.java
License:Apache License
@Override public void onContentLoaded() { GQuery demos = $("//div[@id='content']//div[starts-with(@id, '" + prefix + "')]"); NodeList<Element> nodeList = demos.get(); for (int i = 0; i < nodeList.getLength(); i++) { Element item = nodeList.getItem(i); Widget demo = getDemoToLoad(item.getId().replace(prefix, "")); if (demo != null) { HTMLPanel panel = HTMLPanel.wrap(item); panel.add(demo);/*from w w w. j a va 2 s.co m*/ } } }
From source file:com.google.livingstories.client.contentmanager.ObjectElementProofreader.java
License:Apache License
public String proofread(String incomingHtml) { HTML asHTML = new HTML(incomingHtml); Element element = asHTML.getElement(); boolean changed = false; NodeList<Element> embeds = element.getElementsByTagName("embed"); // since we will be removing embeds, iterate from len-1 to 0: for (int i = embeds.getLength() - 1; i >= 0; i--) { changed = true;//from w w w .j ava 2 s.c o m Element embed = embeds.getItem(i); Element embedParent = embed.getParentElement(); if (embedParent.getTagName().equalsIgnoreCase("object")) { // The wrapped object idiom: shouldn't be necessary at all. embedParent.removeChild(embed); } else { Element objectElement = document.createObjectElement(); for (String attribute : EMBED_ATTRIBUTES) { String value = embed.getAttribute(attribute); if (!value.isEmpty()) { TranslatedAttributeRecord record = TranslatedAttributeRecord .getFromEmbedAttribute(attribute); if (record == null) { addParam(objectElement, attribute, value); } else { record.setAttributeForObject(objectElement, value); if (record == TranslatedAttributeRecord.SRC) { addParam(objectElement, "movie", value); } } } } embedParent.replaceChild(objectElement /* new */, embed /* old */); } } // now iterate over objects, looking for places where the "data" value is not replicated as // a "movie" param. NodeList<Element> objectElements = element.getElementsByTagName("object"); // again, iterate from len-1 to 0: for (int i = objectElements.getLength() - 1; i >= 0; i--) { Element objectElement = objectElements.getItem(i); Element objectParent = objectElement.getParentElement(); if (objectParent.getTagName().equalsIgnoreCase("object")) { // nested object idiom. Unnecessary. changed = true; objectParent.removeChild(objectElement); } else { boolean foundMovieParam = false; for (Element child = objectElement.getFirstChildElement(); !foundMovieParam && child != null; child = child.getNextSiblingElement()) { foundMovieParam = child.getNodeName().equalsIgnoreCase("param") && child.getAttribute("name").equalsIgnoreCase("movie"); } if (!foundMovieParam) { // duplicate it from the data attribute of the object itself. changed = true; addParam(objectElement, "movie", objectElement.getAttribute("data")); } } } return (changed // so that we don't worry about embedded comment indicators in the original html: ? (element.getInnerHTML() + "\n<!--\n" + incomingHtml.replaceAll("-+", "-") + "\n-->\n") : null); }
From source file:com.google.livingstories.client.lsp.ContentRenderer.java
License:Apache License
/** * Find the custom tags in the HTML and process them. *//*from w w w .ja v a2s .c om*/ private HTMLPanel processTagsInChunk(String chunk) { HTMLPanel contentPanel = new HTMLPanel(chunk); try { // Process each type of tag for (ContentTag tag : contentTags) { NodeList<Element> tagNodeList = contentPanel.getElement().getElementsByTagName(tag.getTagName()); List<Element> tagElements = new ArrayList<Element>(); for (int i = 0; i < tagNodeList.getLength(); i++) { // First iterate over the node list and copy all the elements into a new list. Can't // iterate and modify them at the same time because the list changes dynamically. tagElements.add(tagNodeList.getItem(i)); } for (Element tagElement : tagElements) { Widget widget = tag.createWidgetToReplaceTag(tagElement); if (widget != null) { // To replace the existing tag with the widget created above, the HTMLPanel needs // to have the id of the element being replaced. Since we can't expect users to assign // unique ids in every tag, we do this here automatically. String uniqueId = HTMLPanel.createUniqueId(); tagElement.setId(uniqueId); contentPanel.addAndReplaceElement(widget, uniqueId); } } } } catch (Exception e) { // Just return the panel with the original content } return contentPanel; }
From source file:com.google.livingstories.client.lsp.views.contentitems.BaseAssetPopupView.java
License:Apache License
protected Widget getContent(AssetContentItem contentItem) { // Add the content HTML contentHTML = new HTML(contentItem.getContent()); // So that lightbox centering in firefox works, enclose each sized <object> // with a div styled to exactly that size. NodeList<Element> objectElements = contentHTML.getElement().getElementsByTagName("object"); Document document = Document.get(); for (int i = 0, len = objectElements.getLength(); i < len; i++) { Element objectElement = objectElements.getItem(i); String width = objectElement.getAttribute("width"); String height = objectElement.getAttribute("height"); if (width.matches("[0-9]+%?") && height.matches("[0-9]+%?")) { DivElement div = document.createDivElement(); div.getStyle().setProperty("width", width + (width.endsWith("%") ? "" : "px")); div.getStyle().setProperty("height", height + (height.endsWith("%") ? "" : "px")); objectElement.getParentElement().replaceChild(div, objectElement); div.appendChild(objectElement); }/*from ww w. j ava 2s .c o m*/ } // In case there are images within the content, we should fire a PopupImageLoadedEvent // so that any popup window displaying this view has a chance to reposition itself. NodeList<Element> imageElements = contentHTML.getElement().getElementsByTagName("img"); for (int i = 0; i < imageElements.getLength(); i++) { ImageElement image = imageElements.getItem(i).cast(); addImageLoadHandler(image); } return contentHTML; }
From source file:com.google.livingstories.client.ui.AutoHidePopupPanel.java
License:Apache License
@Override public void hide(boolean autoClosed) { if (skipHide) { skipHide = false;//from w ww . j a va 2 s . c o m return; } if (getWidget() != null) { // clear the "data" attribute of all HTML objects within the widget, so that no playback // persists. NodeList<Element> objects = getWidget().getElement().getElementsByTagName("object"); for (int i = 0, len = objects.getLength(); i < len; i++) { scrubber.scrub(objects.getItem(i)); scrubbed = true; // in point of fact, we're safe in FF, but this indicates an implementation problem where // a popup is reused that shouldn't be, and we want to catch this on _all_ browsers. } } super.hide(autoClosed); }
From source file:com.google.livingstories.client.util.dom.GwtNodeAdapter.java
License:Apache License
@Override public List<NodeAdapter> getChildNodes() { NodeList<Node> childNodes = node.getChildNodes(); List<NodeAdapter> nodes = new ArrayList<NodeAdapter>(childNodes.getLength()); for (int i = 0; i < childNodes.getLength(); i++) { nodes.add(new GwtNodeAdapter(childNodes.getItem(i))); }//from w ww . ja v a2 s .c o m return nodes; }
From source file:com.google.speedtracer.client.SourceViewer.java
License:Apache License
/** * Getter for the <code>tr</code> element wrapping the line of code. * /*w w w. j a v a 2 s . c om*/ * @param lineNumber the 1 based index for the row. * @return the {@link TableRowElement} wrapping the line of code. */ TableRowElement getTableRowElement(int lineNumber) { NodeList<TableElement> tables = sourceFrame.getContentDocument().getElementsByTagName("table").cast(); TableElement sourceTable = tables.getItem(0); assert (lineNumber > 0); assert (sourceTable != null) : "No table loaded in source frame."; return sourceTable.getRows().getItem(lineNumber - 1); }
From source file:com.google.speedtracer.client.SourceViewer.java
License:Apache License
/** * Returns the cell that contains the line contents for a row. */// ww w .ja v a 2 s .co m private TableCellElement getRowContentCell(TableRowElement row) { NodeList<TableCellElement> cells = row.getElementsByTagName("td").cast(); for (int i = 0, n = cells.getLength(); i < n; i++) { TableCellElement cell = cells.getItem(i); if (cell.getClassName().indexOf(LINE_CONTENT) >= 0) { return cell; } } return null; }
From source file:com.googlecode.mgwt.css.client.updater.CssUpdater.java
License:Apache License
private Element getHead() { NodeList<Element> nodeList = Document.get().getElementsByTagName("head"); if (nodeList.getLength() != 1) { throw new RuntimeException("can not find head element, does your html include a head section?"); }/*from www .j a v a 2 s .com*/ return nodeList.getItem(0); }