List of usage examples for com.google.gwt.dom.client NodeList getLength
public int getLength()
From source file:com.vaadin.client.ui.embedded.EmbeddedConnector.java
License:Apache License
@Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { if (!isRealUpdate(uidl)) { return;/*from ww w . j a va 2s . com*/ } // Save details getWidget().client = client; boolean clearBrowserElement = true; clickEventHandler.handleEventHandlerRegistration(); if (uidl.hasAttribute("type")) { // remove old style name related to type if (getWidget().type != null) { getWidget().removeStyleName(VEmbedded.CLASSNAME + "-" + getWidget().type); } // remove old style name related to mime type if (getWidget().mimetype != null) { getWidget().removeStyleName(VEmbedded.CLASSNAME + "-" + getWidget().mimetype); } getWidget().type = uidl.getStringAttribute("type"); if (getWidget().type.equals("image")) { getWidget().addStyleName(VEmbedded.CLASSNAME + "-image"); Element el = null; boolean created = false; NodeList<Node> nodes = getWidget().getElement().getChildNodes(); if (nodes != null && nodes.getLength() == 1) { Node n = nodes.getItem(0); if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; if (e.getTagName().equals("IMG")) { el = e; } } } if (el == null) { getWidget().setHTML(""); el = DOM.createImg(); created = true; DOM.sinkEvents(el, Event.ONLOAD); } // Set attributes Style style = el.getStyle(); style.setProperty("width", getState().width); style.setProperty("height", getState().height); resourceElement = el; objectElement = null; setResourceUrl(getResourceUrl("src")); if (uidl.hasAttribute(EmbeddedConstants.ALTERNATE_TEXT)) { el.setPropertyString(EmbeddedConstants.ALTERNATE_TEXT, uidl.getStringAttribute(EmbeddedConstants.ALTERNATE_TEXT)); } if (created) { // insert in dom late getWidget().getElement().appendChild(el); } /* * Sink tooltip events so tooltip is displayed when hovering the * image. */ getWidget().sinkEvents(VTooltip.TOOLTIP_EVENTS); } else if (getWidget().type.equals("browser")) { getWidget().addStyleName(VEmbedded.CLASSNAME + "-browser"); if (getWidget().browserElement == null) { getWidget().setHTML("<iframe width=\"100%\" height=\"100%\" frameborder=\"0\"" + " allowTransparency=\"true\" src=\"\"" + " name=\"" + uidl.getId() + "\"></iframe>"); getWidget().browserElement = DOM.getFirstChild(getWidget().getElement()); } resourceElement = getWidget().browserElement; objectElement = null; setResourceUrl(getResourceUrl("src")); clearBrowserElement = false; } else { VConsole.error("Unknown Embedded type '" + getWidget().type + "'"); } } else if (uidl.hasAttribute("mimetype")) { // remove old style name related to type if (getWidget().type != null) { getWidget().removeStyleName(VEmbedded.CLASSNAME + "-" + getWidget().type); } // remove old style name related to mime type if (getWidget().mimetype != null) { getWidget().removeStyleName(VEmbedded.CLASSNAME + "-" + getWidget().mimetype); } final String mime = uidl.getStringAttribute("mimetype"); if (mime.equals("application/x-shockwave-flash")) { getWidget().mimetype = "flash"; // Handle embedding of Flash getWidget().addStyleName(VEmbedded.CLASSNAME + "-flash"); getWidget().setHTML(getWidget().createFlashEmbed(uidl)); } else if (mime.equals("image/svg+xml")) { getWidget().mimetype = "svg"; getWidget().addStyleName(VEmbedded.CLASSNAME + "-svg"); String data; Map<String, String> parameters = VEmbedded.getParameters(uidl); ObjectElement obj = Document.get().createObjectElement(); resourceElement = null; if (parameters.get("data") == null) { objectElement = obj; data = getResourceUrl("src"); setResourceUrl(data); } else { objectElement = null; data = "data:image/svg+xml," + parameters.get("data"); obj.setData(data); } getWidget().setHTML(""); obj.setType(mime); if (!isUndefinedWidth()) { obj.getStyle().setProperty("width", "100%"); } if (!isUndefinedHeight()) { obj.getStyle().setProperty("height", "100%"); } if (uidl.hasAttribute("classid")) { obj.setAttribute("classid", uidl.getStringAttribute("classid")); } if (uidl.hasAttribute("codebase")) { obj.setAttribute("codebase", uidl.getStringAttribute("codebase")); } if (uidl.hasAttribute("codetype")) { obj.setAttribute("codetype", uidl.getStringAttribute("codetype")); } if (uidl.hasAttribute("archive")) { obj.setAttribute("archive", uidl.getStringAttribute("archive")); } if (uidl.hasAttribute("standby")) { obj.setAttribute("standby", uidl.getStringAttribute("standby")); } getWidget().getElement().appendChild(obj); if (uidl.hasAttribute(EmbeddedConstants.ALTERNATE_TEXT)) { obj.setInnerText(uidl.getStringAttribute(EmbeddedConstants.ALTERNATE_TEXT)); } } else { VConsole.error("Unknown Embedded mimetype '" + mime + "'"); } } else { VConsole.error("Unknown Embedded; no type or mimetype attribute"); } if (clearBrowserElement) { getWidget().browserElement = null; } }
From source file:com.vaadin.client.ui.TouchScrollDelegate.java
License:Apache License
public static ArrayList<Element> getElements(Element scrolledElement2) { NodeList<Node> childNodes = scrolledElement2.getChildNodes(); ArrayList<Element> l = new ArrayList<Element>(); for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.getItem(i); if (item.getNodeType() == Node.ELEMENT_NODE) { l.add((Element) item); }//from w w w . j ava 2s .com } return l; }
From source file:com.vaadin.client.ui.ui.UIConnector.java
License:Apache License
/** * Internal helper for removing any stylesheet with the given URL * //from w ww .j av a 2 s .c om * @since 7.3 * @param url * the url to match with existing stylesheets */ private void removeStylesheet(String url) { NodeList<Element> linkTags = getHead().getElementsByTagName(LinkElement.TAG); for (int i = 0; i < linkTags.getLength(); i++) { LinkElement link = LinkElement.as(linkTags.getItem(i)); if (!"stylesheet".equals(link.getRel())) { continue; } if (!"text/css".equals(link.getType())) { continue; } if (url.equals(link.getHref())) { getHead().removeChild(link); } } }
From source file:com.vaadin.client.ui.ui.UIConnector.java
License:Apache License
private void updateVaadinFavicon(String newTheme) { NodeList<Element> iconElements = querySelectorAll("link[rel~=\"icon\"]"); for (int i = 0; i < iconElements.getLength(); i++) { Element iconElement = iconElements.getItem(i); String href = iconElement.getAttribute("href"); if (href != null && href.contains("VAADIN/themes") && href.endsWith("/favicon.ico")) { href = href.replaceFirst("VAADIN/themes/.+?/favicon.ico", "VAADIN/themes/" + newTheme + "/favicon.ico"); iconElement.setAttribute("href", href); }/* ww w . j av a 2 s. c om*/ } }
From source file:com.vaadin.client.ui.ui.UIConnector.java
License:Apache License
/** * Finds a link tag for a style sheet with the given URL * //from w w w. j av a 2 s . c om * @since 7.3 * @param url * the URL of the style sheet * @return the link tag or null if no matching link tag was found */ private LinkElement findStylesheetTag(String url) { NodeList<Element> linkTags = getHead().getElementsByTagName(LinkElement.TAG); for (int i = 0; i < linkTags.getLength(); i++) { final LinkElement link = LinkElement.as(linkTags.getItem(i)); if ("stylesheet".equals(link.getRel()) && "text/css".equals(link.getType()) && url.equals(link.getHref())) { return link; } } return null; }
From source file:com.vaadin.client.ui.VContextMenu.java
License:Apache License
@Override public String getSubPartName(com.google.gwt.user.client.Element subElement) { if (getElement().isOrHasChild(subElement)) { com.google.gwt.dom.client.Element e = subElement; {// ww w. ja v a 2 s. com while (e != null && !e.getTagName().toLowerCase().equals("tr")) { e = e.getParentElement(); // ApplicationConnection.getConsole().log("Found row"); } } com.google.gwt.dom.client.TableSectionElement parentElement = (TableSectionElement) e .getParentElement(); NodeList<TableRowElement> rows = parentElement.getRows(); for (int i = 0; i < rows.getLength(); i++) { if (rows.getItem(i) == e) { // ApplicationConnection.getConsole().log( // "Found index for row" + 1); return "option" + i; } } return null; } else { return null; } }
From source file:com.vaadin.client.ui.VCustomLayout.java
License:Apache License
/** * Img elements needs some special handling in custom layout. Img elements * will get their onload events sunk. This way custom layout can notify * parent about possible size change.//from w ww .j a v a2 s .co m */ private void initImgElements() { NodeList<Element> nodeList = getElement().getElementsByTagName("IMG"); for (int i = 0; i < nodeList.getLength(); i++) { ImageElement img = ImageElement.as(nodeList.getItem(i)); DOM.sinkEvents(img, Event.ONLOAD); } }
From source file:com.vaadin.client.ui.VMediaBase.java
License:Apache License
public void removeAllSources() { NodeList<com.google.gwt.dom.client.Element> l = media.getElementsByTagName(SourceElement.TAG); for (int i = l.getLength() - 1; i >= 0; i--) { media.removeChild(l.getItem(i)); }//from ww w . jav a 2 s . co m }
From source file:com.vaadin.client.ui.window.WindowConnector.java
License:Apache License
private Node cloneNodeFilteringMedia(Node node) { if (node instanceof Element) { Element old = (Element) node; if ("audio".equalsIgnoreCase(old.getTagName()) || "video".equalsIgnoreCase(old.getTagName())) { if (!old.hasAttribute("controls") && "audio".equalsIgnoreCase(old.getTagName())) { return null; // nothing to animate, so we won't add this to // the clone }//from ww w .j a va 2 s .co m Element newEl = DOM.createElement(old.getTagName()); if (old.hasAttribute("controls")) { newEl.setAttribute("controls", old.getAttribute("controls")); } if (old.hasAttribute("style")) { newEl.setAttribute("style", old.getAttribute("style")); } if (old.hasAttribute("class")) { newEl.setAttribute("class", old.getAttribute("class")); } return newEl; } } Node res = node.cloneNode(false); if (node.hasChildNodes()) { NodeList<Node> nl = node.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node clone = cloneNodeFilteringMedia(nl.getItem(i)); if (clone != null) { res.appendChild(clone); } } } return res; }
From source file:com.vaadin.client.WidgetUtil.java
License:Apache License
public static void sinkOnloadForImages(Element element) { NodeList<com.google.gwt.dom.client.Element> imgElements = element.getElementsByTagName("img"); for (int i = 0; i < imgElements.getLength(); i++) { DOM.sinkEvents(imgElements.getItem(i), Event.ONLOAD); }/*from w ww. j a va2 s . co m*/ }