List of usage examples for com.google.gwt.dom.client Element setId
@Override
public void setId(String id)
From source file:ca.nanometrics.gflot.client.options.LegendOptions.java
License:Open Source License
/** * Set a custom container to put the legend table into. The "position" and "margin" etc. options will then be * ignored. Note that Flot will overwrite the contents of the container. *//*from ww w .j av a 2 s.co m*/ public LegendOptions setContainer(Element container) { assert null != container : "container can't be null"; String id = container.getId(); if (id == null || id.length() == 0) { id = Document.get().createUniqueId(); container.setId(id); } put(CONTAINER_KEY, "#" + id); return this; }
From source file:ch.bergturbenthal.hs485.frontend.gwtfrontend.client.svg.SVGProcessor.java
License:Open Source License
public static int normalizeIds(final OMSVGElement srcSvg) { docId++;/*from w ww . j a v a 2 s . c om*/ // Collect all the original element ids and replace them with a // normalized id int idIndex = 0; final Map<String, Element> idToElement = new HashMap<String, Element>(); final Map<String, String> idToNormalizedId = new HashMap<String, String>(); final List<Element> queue = new ArrayList<Element>(); queue.add(srcSvg.getElement()); while (queue.size() > 0) { final Element element = queue.remove(0); final String id = element.getId(); if (id != null) { idToElement.put(id, element); final String normalizedId = "d" + docId + "_" + idIndex++; idToNormalizedId.put(id, normalizedId); element.setId(normalizedId); } final NodeList<Node> childNodes = element.getChildNodes(); for (int i = 0, length = childNodes.getLength(); i < length; i++) { final Node childNode = childNodes.getItem(i); if (childNode.getNodeType() == Node.ELEMENT_NODE) queue.add((Element) childNode.cast()); } } // Change all the attributes which are URI references final Set<String> attNames = new HashSet<String>(Arrays.asList(new String[] { "clip-path", "mask", "marker-start", "marker-mid", "marker-end", "fill", "stroke", "filter", "cursor", "style" })); queue.add(srcSvg.getElement()); final IdRefTokenizer tokenizer = GWT.create(IdRefTokenizer.class); while (queue.size() > 0) { final Element element = queue.remove(0); if (DOMHelper.hasAttributeNS(element, SVGConstants.XLINK_NAMESPACE_URI, SVGConstants.XLINK_HREF_ATTRIBUTE)) { final String idRef = DOMHelper.getAttributeNS(element, SVGConstants.XLINK_NAMESPACE_URI, SVGConstants.XLINK_HREF_ATTRIBUTE).substring(1); final String normalizeIdRef = idToNormalizedId.get(idRef); DOMHelper.setAttributeNS(element, SVGConstants.XLINK_NAMESPACE_URI, SVGConstants.XLINK_HREF_ATTRIBUTE, "#" + normalizeIdRef); } final NamedNodeMap<Attr> attrs = DOMHelper.getAttributes(element); for (int i = 0, length = attrs.getLength(); i < length; i++) { final Attr attr = attrs.item(i); if (attNames.contains(attr.getName())) { final StringBuilder builder = new StringBuilder(); tokenizer.tokenize(attr.getValue()); IdRefTokenizer.IdRefToken token; while ((token = tokenizer.nextToken()) != null) { String value = token.getValue(); if (token.getKind() == IdRefTokenizer.IdRefToken.DATA) builder.append(value); else { value = idToNormalizedId.get(value); builder.append(value == null ? token.getValue() : value); } } attr.setValue(builder.toString()); } } final NodeList<Node> childNodes = element.getChildNodes(); for (int i = 0, length = childNodes.getLength(); i < length; i++) { final Node childNode = childNodes.getItem(i); if (childNode.getNodeType() == Node.ELEMENT_NODE) queue.add((Element) childNode.cast()); } } return docId; }
From source file:com.ait.toolkit.core.client.IdGenerator.java
License:Open Source License
public static String getOrCreateId(Element element) { String id = element.getId();//from w w w .j a va2s.c om if (id == null || id.isEmpty()) { id = generateId(); element.setId(id); } return id; }
From source file:com.ait.toolkit.hopscotch.client.TourStep.java
License:Open Source License
protected String getOrCreateId(Element element) { String id = element.getId();/* w w w . j ava2s . com*/ if (id == null || id.isEmpty()) { id = HopScotch.generateId(); element.setId(id); } return id; }
From source file:com.alkacon.acacia.client.widgets.TinyMCEWidget.java
License:Open Source License
/** * Gives an element an id if it doesn't already have an id, and then returns the element's id.<p> * //from www . ja v a 2s . co m * @param element the element for which we want to add the id * * @return the id */ protected String ensureId(Element element) { String id = element.getId(); if ((id == null) || "".equals(id)) { id = Document.get().createUniqueId(); element.setId(id); } return id; }
From source file:com.arcbees.facebook.client.JavaScriptFacebook.java
License:Apache License
@Override public void injectFacebookApi(final FacebookCallback facebookCallback) { String locale = "en_US"; // get the correct locale from meta tag gwt:property facebooklocale final NodeList<Element> metas = Document.get().getElementsByTagName("meta"); for (int i = 0; i < metas.getLength(); i++) { final MetaElement m = MetaElement.as(metas.getItem(i)); if ("gwt:property".equals(m.getName())) { String content = m.getContent(); if (content.contains("facebooklocale")) { locale = content.replaceFirst(".*\\=", "").trim(); }/*from w w w.j av a 2 s . c om*/ } } Element firstElement = Document.get().getBody().getFirstChildElement(); Element fbRoot = Document.get().createDivElement(); fbRoot.setId(FB_ROOT); firstElement.getParentNode().insertBefore(fbRoot, firstElement); ScriptElement fbScript = Document.get().createScriptElement(); fbScript.setSrc(FB_SCRIPT_SRC1 + locale + FB_SCRIPT_SRC2); fbScript.setType(FB_SCRIPT_TYPE); fbRoot.getParentNode().insertAfter(fbScript, fbRoot); Timer ensureFbIsLoaded = new Timer() { @Override public void run() { if (isLoaded()) { facebookCallback.onSuccess(); cancel(); } } }; ensureFbIsLoaded.scheduleRepeating(100); }
From source file:com.cgxlib.xq.client.plugins.widgets.WidgetsUtils.java
License:Apache License
/** * If the <code>oldElement</code> is a td, th, li tags, the new element will replaced its content. * In other cases, the <code>oldElement</code> will be replaced by the <code>newElement</code> * and the old element classes will be copied to the new element. *//* w w w. j a va2s . com*/ private static void replaceOrAppend(Element oldElement, Element newElement) { assert oldElement != null && newElement != null; if (matchesTags(oldElement, appendingTags)) { XQ.$(oldElement).html("").append(newElement); } else { XQ.$(oldElement).replaceWith(newElement); // copy class String c = oldElement.getClassName(); if (!c.isEmpty()) { newElement.addClassName(c); } // copy id newElement.setId(oldElement.getId()); // ensure no duplicate id oldElement.setId(""); } }
From source file:com.eemi.gwt.tour.client.TourStep.java
License:Apache License
protected String getOrCreateId(Element element) { String id = element.getId();//from ww w .j ava 2 s. com if (id == null || id.isEmpty()) { id = GwtTour.generateId(); element.setId(id); } return id; }
From source file:com.ejt.vaadin.loginform.shared.LoginFormConnector.java
License:Apache License
private VTextField configureTextField(Connector connector, String id) { if (connector != null) { VTextField textField = ((TextFieldConnector) connector).getWidget(); textField.addKeyDownHandler(new SubmitKeyHandler()); Element element = textField.getElement(); String externalId = element.getId(); if (externalId == null || externalId.isEmpty() || externalId.startsWith("gwt-")) { element.setId(id); }/*from w w w. j a v a 2 s . c o m*/ element.setAttribute("name", id); element.setAttribute("autocomplete", "on"); return textField; } else { return null; } }
From source file:com.google.gerrit.client.api.HtmlTemplate.java
License:Apache License
private static void attachHandlers(Element e, IdMap ids, ReplacementMap opts, boolean wantElements) { if (e.getId() != null) { String key = ids.get(e.getId()); if (key != null) { ids.remove(e.getId());/*from w ww. j av a 2 s . c o m*/ if (wantElements) { ids.put(key, e); } e.setId(null); opts.map(key).attachHandlers(e); } } for (Element c = e.getFirstChildElement(); c != null;) { attachHandlers(c, ids, opts, wantElements); c = c.getNextSiblingElement(); } }