List of usage examples for com.google.gwt.dom.client NodeList getItem
public T getItem(int index)
From source file:com.smartgwt.mobile.client.util.Page.java
License:Open Source License
@SGWTInternal public static void _updateViewport(Float scale, String width, String height, Boolean scalable, String extraViewportParams) { final StringBuilder sb = new StringBuilder(); if (scale != null) { sb.append("initial-scale=").append(scale.floatValue()); }//ww w.ja v a2s . co m if (width != null) { if (sb.length() != 0) sb.append(", "); sb.append("width=").append(width); } if (height != null) { if (sb.length() != 0) sb.append(", "); sb.append("height=").append(height); } if (scalable != null) { if (sb.length() != 0) sb.append(", "); sb.append("user-scalable=").append(scalable.booleanValue() ? "yes" : "no"); // setting user-scalable to 'no' seems to reliably disable pinch zooming // However on pivot the iPhone zooms by default and this seems to still occur // with user-scalable set to 'no'. If a desired 'scale' was specified, // setting the min/max scale to it appears to really disable scale on pivot if (scalable == false && scale != null) { sb.append(", minimum-scale=").append(scale.floatValue()).append(", maximum-scale=") .append(scale.floatValue()); } } if (extraViewportParams != null && !extraViewportParams.isEmpty()) { if (sb.length() > 0) sb.append(", "); sb.append(extraViewportParams); } final NodeList<Element> metaTags = Document.get().getElementsByTagName("meta"); MetaElement vpTag = null; // remove all but the last viewport <meta> tag and select the last one for (int i = 0; i < metaTags.getLength(); /*empty*/) { if ("viewport".equals(metaTags.getItem(i).<MetaElement>cast().getName())) { if (vpTag != null) { vpTag.getParentNode().removeChild(vpTag); vpTag = metaTags.getItem(i - 1).cast(); } else { vpTag = metaTags.getItem(i).cast(); ++i; } } else ++i; } if (vpTag != null) { vpTag.setContent(sb.toString()); } else { vpTag = Document.get().createMetaElement(); vpTag.setName("viewport"); vpTag.setContent(sb.toString()); Document.get().getElementsByTagName("head").getItem(0).appendChild(vpTag); } }
From source file:com.smartgwt.mobile.client.widgets.tableview.TableView.java
License:Open Source License
private Element findLoadMoreRecordsElement() { if (_ul != null) { final NodeList<Node> children = _ul.getChildNodes(); for (int ri = children.getLength(); ri > 0; --ri) { final Node child = children.getItem(ri - 1); if (child.getNodeType() != Node.ELEMENT_NODE) continue; final Element childElem = (Element) child; if (childElem.hasAttribute(IS_LOAD_MORE_RECORDS_ATTRIBUTE_NAME)) { return childElem; }/*from w ww.j av a 2s . c o m*/ } } return null; }
From source file:com.smartgwt.mobile.client.widgets.tableview.TableView.java
License:Open Source License
@SGWTInternal protected Integer _findRecordIndex(Element element) { if (element == null) { return null; }/*from ww w. j a v a2 s .c om*/ while (!element.hasAttribute(RECORD_INDEX_ATTRIBUTE_NAME)) { element = element.getParentElement(); if (element == null) { break; } } boolean found = false; if (element != null) { if (element.getTagName().equalsIgnoreCase("li")) { Element parent = element.getParentElement(); Element thisElement = this.getElement(); while (parent != null) { if (parent == thisElement) { found = true; break; } parent = parent.getParentElement(); } } else { NodeList<Node> nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); ++i) { Node node = nodes.getItem(i); if (element == node) { found = true; break; } } } } if (found) { assert element != null; return Integer.valueOf(element.getAttribute(RECORD_INDEX_ATTRIBUTE_NAME)); } return null; }
From source file:com.smartgwt.mobile.client.widgets.tableview.TableView.java
License:Open Source License
@Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); if (!isEnabled()) return;/*w ww.ja v a 2 s . co m*/ final Element targetElem = EventUtil.getTargetElem(event); if (targetElem != null) { final Element element; final JsArray<Touch> touches; final int clientX, clientY; final boolean wasContextClickFired; switch (event.getTypeInt()) { case Event.ONMOUSEDOWN: onStart(event, null); break; case Event.ONTOUCHSTART: touches = event.getTouches(); if (touches.length() == 1 && touchIdentifier == null) { onStart(event, touches.get(0)); } else { // Another finger is touching the screen. onEnd(event); } break; case Event.ONMOUSEMOVE: if (touchActive) { clientX = event.getClientX(); clientY = event.getClientY(); if (Math.abs(touchPointX - clientX) >= 10 || Math.abs(touchPointY - clientY) >= 10) { onEnd(event); } } break; case Event.ONTOUCHMOVE: if (touchActive) { touches = event.getTouches(); if (touches.length() == 1 && touchIdentifier != null) { final Touch touch = touches.get(0); if (touch.getIdentifier() == touchIdentifier.intValue()) { clientX = touch.getClientX(); clientY = touch.getClientY(); if (Math.abs(touchPointX - clientX) >= 10 || Math.abs(touchPointY - clientY) >= 10) { onEnd(event); } } } } break; case Event.ONMOUSEUP: case Event.ONMOUSEOUT: case Event.ONTOUCHEND: case Event.ONTOUCHCANCEL: element = activeElement; wasContextClickFired = contextClickFired; onEnd(event); if (element != null && wasContextClickFired) { onClick(element, null); } break; case Event.ONCLICK: if (!isEnabled()) return; element = _findElement(event); onClick(element, targetElem); break; case Event.ONCONTEXTMENU: if (!isEnabled()) return; element = _findElement(event); if (element != null) { // Find the "context clickable element". // The context clickable element is the title element, unless there // is no title element, in which case it is the <li>. Element contextClickableElement = element; final NodeList<Node> children = element.getChildNodes(); final int children_length = children.getLength(); for (int i = 0; i < children_length; ++i) { final Node child = children.getItem(i); if (child.getNodeType() != Node.ELEMENT_NODE) continue; final Element childElem = (Element) child; if (ElementUtil.hasClassName(childElem, TableView.RECORD_TITLE_CLASS_NAME)) { contextClickableElement = childElem; if (touchActive) contextClickFired = true; break; } } if (contextClickableElement.isOrHasChild(targetElem)) { final Integer recordIndex = _findRecordIndex(element); if (recordIndex != null) { final Record record = _getData().get(recordIndex.intValue()); final boolean cancelled = RowContextClickEvent._fire(this, -1, record, recordIndex.intValue()); if (!cancelled) { final Menu contextMenu = getContextMenu(); if (contextMenu != null) { contextClickableElement.addClassName(_CSS.contextClickedElementClass()); final Object recordID = getRecordId(record); final Element li = elementMap.get(recordID); assert li != null; final Element finalContextClickableElement = contextClickableElement; new BeforeMenuHiddenHandler() { private HandlerRegistration beforeMenuHiddenRegistration = contextMenu ._addBeforeMenuHiddenHandler(this); @Override public void _onBeforeMenuHidden(BeforeMenuHiddenEvent event) { beforeMenuHiddenRegistration.removeHandler(); finalContextClickableElement .removeClassName(_CSS.contextClickedElementClass()); } }; contextMenu._showAt(this, event.getClientX(), event.getClientY(), contextClickableElement.getAbsoluteLeft(), contextClickableElement.getAbsoluteRight(), contextClickableElement.getAbsoluteTop(), contextClickableElement.getAbsoluteBottom()); if (touchActive) contextClickFired = true; break; } } } } } break; } } }
From source file:com.smartgwt.mobile.client.widgets.tableview.TableView.java
License:Open Source License
@SGWTInternal protected void _setSelected(Element element) { final SelectionStyle selectionType = getSelectionType(); assert selectionType != null && selectionType != SelectionStyle.NONE; if (!hasClassName(element, _CSS.selectedTableViewRowClass()) && !hasClassName(element, _CSS.selectedTableViewRowHasIconClass())) { if (showSelectedIcon) { element.addClassName(_CSS.selectedTableViewRowHasIconClass()); if (selectionType == SelectionStyle.SINGLE || selectedIcon != null) { SpanElement span = Document.get().createSpanElement(); span.addClassName(_CSS.selectedClass()); Image image = selectedIcon != null ? new Image(selectedIcon) : impl.getDefaultSingleSelectionIcon(); image.getElement().addClassName(_CSS.selectedClass()); span.setInnerHTML(image.toString()); element.insertFirst(span); } else { assert selectionType != SelectionStyle.SINGLE; assert selectionType == SelectionStyle.MULTIPLE; // Find the .selection-disclosure element and add class `CSS.checkedSelectionOrDeleteDisclosureClass()'. NodeList<Node> children = element.getChildNodes(); final int children_length = children.getLength(); int i = 0; for (; i < children_length; ++i) { final Node n = children.getItem(i); if (n.getNodeType() != Node.ELEMENT_NODE) { continue; }//from w w w . j a v a 2 s . com final Element child = Element.as(n); if (hasClassName(child, _CSS.recordSelectionDisclosureClass())) { child.addClassName(_CSS.checkedSelectionOrDeleteDisclosureClass()); break; } } assert i < children_length; } } else { element.removeClassName(_CSS.clearingTemporaryTableViewRowSelectionClass()); element.addClassName(_CSS.selectedTableViewRowClass()); } } }
From source file:com.smartgwt.mobile.client.widgets.tableview.TableView.java
License:Open Source License
@SGWTInternal protected void _clearSelected(Element element) { if (element == null) return;/*from www. j a v a 2s . com*/ element.removeClassName(_CSS.selectedTableViewRowClass()); element.removeClassName(_CSS.selectedTableViewRowHasIconClass()); if (showSelectedIcon) { final SelectionStyle selectionType = getSelectionType(); if (selectionType == SelectionStyle.SINGLE) { NodeList<Node> children = element.getChildNodes(); final int children_length = children.getLength(); for (int i = 0; i < children_length; ++i) { final Node n = children.getItem(i); if (n.getNodeType() != Node.ELEMENT_NODE) { continue; } final Element child = Element.as(n); if (hasClassName(child, _CSS.selectedClass())) { element.removeChild(child); break; } } } else if (selectionType == SelectionStyle.MULTIPLE) { NodeList<Node> children = element.getChildNodes(); final int children_length = children.getLength(); for (int i = 0; i < children_length; ++i) { final Node n = children.getItem(i); if (n.getNodeType() != Node.ELEMENT_NODE) { continue; } final Element child = Element.as(n); if (hasClassName(child, _CSS.recordSelectionDisclosureClass())) { child.removeClassName(_CSS.checkedSelectionOrDeleteDisclosureClass()); } } } } }
From source file:com.tasktop.c2c.server.common.profile.web.client.TextBoxCell.java
License:Open Source License
private InputElement findFirstInputElement(Element parent) { NodeList<Element> inputChildren = parent.getElementsByTagName("input"); if (inputChildren == null || inputChildren.getLength() == 0) { return null; } else {// w w w . j a va 2 s . com // Return the first tag in the list. return (InputElement) inputChildren.getItem(0); } }
From source file:com.tasktop.c2c.server.tasks.client.widgets.wiki.WikiHTMLPanel.java
License:Open Source License
public void setWikiHTML(String wikiHtml) { // First, clear out previous contents. super.clear(); // Add all of our HTML to our element so that it gets converted to DOM format. HTML html = new HTML(wikiHtml); super.add(html); // Then, find all of our anchors and see if they are task links NodeList<Element> anchors = this.getElement().getElementsByTagName("a"); for (int i = 0; i < anchors.getLength(); i++) { Element curElem = anchors.getItem(i); // Grab out our href String href = curElem.getAttribute("href"); if (isTaskAnchor(href)) { String internalUrl = href.substring(href.indexOf("#")); // We need to do some fancy footwork here in order to inject a TaskAnchor into the body of this page - // hold on tight, it's going to get a bit bumpy. // First, grab the text inside the anchor - we'll use this and the href to construct our TaskAnchor. String label = curElem.getInnerText(); // Next, replace our existing anchor with a <span>-based HTMLPanel - we do this to ensure we are // preserving our location within the DOM tree (i.e. inserting our TaskAnchor at the right point in the // Document) HTMLPanel panel = new HTMLPanel("span", "") { @Override/* w w w. ja v a 2 s. com*/ public void add(Widget widget) { // Very ugly hack - need to call onAttach(), but it's a protected method. Sooo, we insert that // call in the add() method, which we'll call one time further inside this method, to ensure // that the widget is attached (otherwise it won't bind, and we won't get the normal Widget // behaviour, which is required for our TaskAnchor hovers to work). // If you are reading this comment and you know of a better way to handle this, you are // honour-bound to implement it and remove this hack. onAttach(); super.add(widget); } }; curElem.getParentElement().replaceChild(panel.getElement(), curElem); // Next, wrap that span in an HTML widget - this is done so that we can then inject our TaskAnchor as a // widget. panel.add(createTaskAnchor(label, internalUrl)); } } }
From source file:com.uni.hs13.visupoll.client.OptGroupListBox.java
License:Apache License
/** * Adds a new OPTGROUP item to the ListBox. If the name of the group already exists, the group * item will <strong>not</strong> be created. * //from w w w .j ava 2 s. c o m * @param groupName The name of the group. * @return {@code true}, if the name does not already exist, otherwise {@code false}. */ public boolean addGroup(final String groupName) { // check if this group already exists SelectElement selectElement = this.getElement().cast(); NodeList<Element> elementsByTagName = selectElement.getElementsByTagName("*"); for (int i = 0; i < elementsByTagName.getLength(); i++) { Element item = elementsByTagName.getItem(i); if (OptGroupListBoxItemType.GROUP.getItemNodeName().equals(item.getNodeName())) { OptGroupElement castedElement = (OptGroupElement) item; if (castedElement.getLabel().equals(groupName)) { return false; } } } // okay, it does not already exist... create it OptGroupElement groupElement = Document.get().createOptGroupElement(); groupElement.setLabel(groupName); SelectElement select = this.getElement().cast(); select.appendChild(groupElement); latestOptGroupElement = groupElement; return true; }
From source file:com.uni.hs13.visupoll.client.OptGroupListBox.java
License:Apache License
/** * Adds a new OPTION item to the ListBox. If the <em>key</em> of this item already exists, the * item will <strong>not</strong> be created (existing <em>label</em> is fine, though). Otherwise * it will be added to the last created OPTGROUP item. If no OPTGROUP item exists, the OPTION item * will be created without a OPTGROUP parent item. * //w w w .ja v a2s . c o m * @param key the key of the OPTION item * @param label the label of the OPTION item * @return {@code true}, if the key of the item does not already exist, otherwise {@code false}. */ public boolean addGroupItem(final String key, final String label) { // check if this item already exists SelectElement selectElement = this.getElement().cast(); NodeList<Element> elementsByTagName = selectElement.getElementsByTagName("*"); for (int i = 0; i < elementsByTagName.getLength(); i++) { Element item = elementsByTagName.getItem(i); if (OptGroupListBoxItemType.OPTION.getItemNodeName().equals(item.getNodeName())) { OptionElement castedElement = (OptionElement) item; if (castedElement.getValue().equals(key)) { return false; } } } // okay, it does not already exist... create it if (latestOptGroupElement == null) { this.addItem(label, key); } else { OptionElement optElement = Document.get().createOptionElement(); optElement.setInnerText(label); optElement.setValue(key); latestOptGroupElement.appendChild(optElement); } return true; }