List of usage examples for com.google.gwt.dom.client NodeList getLength
public int getLength()
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;/* ww w .ja v a 2s. c o m*/ 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 {/*from w w w . jav a2 s . c om*/ // 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 ww . ja v a2s. c o m 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 ww w .ja va 2 s. c om * @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. * //www .j a v a 2 s. com * @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; }
From source file:com.uni.hs13.visupoll.client.OptGroupListBox.java
License:Apache License
/** * Removes an item with the given key from the ListBox. * // www . ja v a2 s .c o m * @param type One of the two types defined in {@link OptGroupListBoxItemType}, namely a * <em>group</em> or a <em>group item</em>. * @param key If <em>type</em> is a <em>group item</em>, then <em>key</em> has to be the unique * key of the ListBox element. If <em>type</em> is a <em>group</em>, then <em>key</em> * has to be the label of this group. Pay attention here, as group labels may be present * multiple times (non-unique). This methods only deletes the first occurrence of the * <em>group item</em>. * @return {@code true}, if an item with the given key was found (and removed), otherwise * {@code false}. */ public boolean removeItemWithKey(OptGroupListBoxItemType type, String key) { 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.equals(type) && OptGroupListBoxItemType.OPTION.getItemNodeName().equals(item.getNodeName()) && ((OptionElement) item).getValue().equals(key)) || (OptGroupListBoxItemType.GROUP.equals(type) && OptGroupListBoxItemType.GROUP.getItemNodeName().equals(item.getNodeName()) && ((OptGroupElement) item).getLabel().equals(key))) { item.removeFromParent(); return true; } } return false; }
From source file:com.uni.hs13.visupoll.client.OptGroupListBox.java
License:Apache License
/** * Returns the size of this ListBox, namely the count of elements, including group-elements. * //w ww . j a va2 s. c o m * @return See description. */ public int getSize() { SelectElement selectElement = this.getElement().cast(); NodeList<Element> elementsByTagName = selectElement.getElementsByTagName("*"); return elementsByTagName.getLength(); }
From source file:com.vaadin.client.ResourceLoader.java
License:Apache License
/** * Creates a new resource loader. You should generally not create you own * resource loader, but instead use {@link ResourceLoader#get()} to get an * instance./*from w w w . j a v a 2 s. c om*/ */ protected ResourceLoader() { Document document = Document.get(); head = document.getElementsByTagName("head").getItem(0); // detect already loaded scripts and stylesheets NodeList<Element> scripts = document.getElementsByTagName("script"); for (int i = 0; i < scripts.getLength(); i++) { ScriptElement element = ScriptElement.as(scripts.getItem(i)); String src = element.getSrc(); if (src != null && src.length() != 0) { loadedResources.add(src); } } NodeList<Element> links = document.getElementsByTagName("link"); for (int i = 0; i < links.getLength(); i++) { LinkElement linkElement = LinkElement.as(links.getItem(i)); String rel = linkElement.getRel(); String href = linkElement.getHref(); if ("stylesheet".equalsIgnoreCase(rel) && href != null && href.length() != 0) { loadedResources.add(href); } } }
From source file:com.vaadin.client.ui.calendar.schedule.DateCell.java
License:Apache License
@Override @SuppressWarnings("deprecation") public void onMouseUp(MouseUpEvent event) { if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) { return;/*from w w w. ja va 2 s.c om*/ } Event.releaseCapture(getElement()); setFocus(false); int dragDistance = Math.abs(eventRangeStart - event.getY()); if (dragDistance > 0 && eventRangeStart >= 0) { Element main = getElement(); if (eventRangeStart > eventRangeStop) { if (eventRangeStop <= -1) { eventRangeStop = 0; } int temp = eventRangeStart; eventRangeStart = eventRangeStop; eventRangeStop = temp; } NodeList<Node> nodes = main.getChildNodes(); int slotStart = -1; int slotEnd = -1; // iterate over all child nodes, until we find first the start, // and then the end for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.getItem(i); boolean isRangeElement = element.getClassName().contains("v-daterange"); if (isRangeElement && slotStart == -1) { slotStart = i; slotEnd = i; // to catch one-slot selections } else if (isRangeElement) { slotEnd = i; } else if (slotStart != -1 && slotEnd != -1) { break; } } clearSelectionRange(); int startMinutes = firstHour * 60 + slotStart * 30; int endMinutes = (firstHour * 60) + (slotEnd + 1) * 30; Date currentDate = getDate(); String yr = (currentDate.getYear() + 1900) + "-" + (currentDate.getMonth() + 1) + "-" + currentDate.getDate(); if (weekgrid.getCalendar().getRangeSelectListener() != null) { weekgrid.getCalendar().getRangeSelectListener() .rangeSelected(yr + ":" + startMinutes + ":" + endMinutes); } eventRangeStart = -1; } else { // Click event eventRangeStart = -1; cancelRangeSelect(); } }
From source file:com.vaadin.client.ui.calendar.schedule.DateCell.java
License:Apache License
@Override public void onMouseMove(MouseMoveEvent event) { if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) { return;/*from ww w.j a va 2 s.c o m*/ } if (eventRangeStart >= 0) { int newY = event.getY(); int fromY = 0; int toY = 0; if (newY < eventRangeStart) { fromY = newY; toY = eventRangeStart; } else { fromY = eventRangeStart; toY = newY; } Element main = getElement(); eventRangeStop = newY; NodeList<Node> nodes = main.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Element c = (Element) nodes.getItem(i); if (todaybar != c) { int elemStart = c.getOffsetTop(); int elemStop = elemStart + getSlotHeight(); if (elemStart >= fromY && elemStart <= toY) { c.addClassName("v-daterange"); } else if (elemStop >= fromY && elemStop <= toY) { c.addClassName("v-daterange"); } else if (elemStop >= fromY && elemStart <= toY) { c.addClassName("v-daterange"); } else { c.removeClassName("v-daterange"); } } } } event.preventDefault(); }