List of usage examples for com.google.gwt.dom.client NodeList getItem
public T getItem(int index)
From source file:org.kaaproject.avro.ui.gwt.client.widget.grid.AvroUiDataGrid.java
License:Apache License
@Override protected boolean resetFocusOnCell() { boolean focused = false; if (hasFilterHeaders() && filterFocusedCellColumn > -1 && filterFocusedCellRow > -1) { TableSectionElement thead = getTableHeadElement(); NodeList<TableRowElement> rows = thead.getRows(); if (filterFocusedCellRow < rows.getLength()) { TableRowElement row = rows.getItem(filterFocusedCellRow); NodeList<TableCellElement> cells = row.getCells(); if (filterFocusedCellColumn < cells.getLength()) { TableCellElement cell = cells.getItem(filterFocusedCellColumn); if (getHeaderBuilder().isHeader(cell)) { Header<?> header = getHeaderBuilder().getHeader(cell); Context context = new Context(0, 0, header.getKey()); focused = resetFocusOnFilterCellImpl(context, header, cell); }//ww w . jav a2 s. c om } } } if (!focused) { focused = super.resetFocusOnCell(); } return focused; }
From source file:org.kuali.student.common.ui.client.widgets.KSLightBox.java
License:Educational Community License
private void grabFocus() { Widget mainContent = contentPanel.getWidget(); NodeList<Element> nodeList = mainContent.getElement().getElementsByTagName("*"); for (int i = 0; i < nodeList.getLength(); i++) { Element e = nodeList.getItem(i); if (FOCUSABLE_TAGS.contains(e.getTagName().toUpperCase())) { e.focus();//from ww w . j a va 2 s. co m return; } } }
From source file:org.lightframe.components.client.ui.VWindowManager.java
License:Apache License
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { // This call should be made first. Ensure correct implementation, // and let the containing layout manage caption, etc. if (client.updateComponent(this, uidl, true)) { return;/*from www . j ava 2 s. c o m*/ } // Save reference to server connection object to be able to send // user interaction later this.client = client; // Save the UIDL identifier for the component uidlId = uidl.getId(); if (uidl.hasAttribute(ATTRIBUTE_SC_WINDOW_NAMES)) { // ugly way to clear all elements. getElement().setInnerHTML(""); final String[] names = uidl.getStringArrayAttribute(ATTRIBUTE_SC_WINDOW_NAMES); for (final String name : names) { final Element windowBox = DOM.createDiv(); windowBox.setInnerHTML(name); windowBox.setClassName(WINDOWBOX_CLASSNAME); DOM.sinkEvents(windowBox, Event.ONCLICK | Event.ONCONTEXTMENU); DOM.appendChild(getElement(), windowBox); } windowCount = names.length; } if (uidl.hasAttribute(ATTRIBUTE_SC_WINDOW_MINIMZED)) { final int[] minimized = uidl.getIntArrayAttribute(ATTRIBUTE_SC_WINDOW_MINIMZED); final NodeList<Node> windowBoxes = getElement().getChildNodes(); for (int i = 0; i < windowBoxes.getLength(); i++) { final Element windowBox = (Element) windowBoxes.getItem(i); windowBox.setClassName(minimized[i] == 1 ? WINDOWBOX_CLASSNAME_MINIMIZED : WINDOWBOX_CLASSNAME); } } }
From source file:org.lightframe.components.client.ui.VWindowManager.java
License:Apache License
private int getWindowBoxIndex(Element windowBox) { final NodeList<Node> siblings = windowBox.getParentNode().getChildNodes(); for (int i = 0; i < siblings.getLength(); i++) { final Node sibling = siblings.getItem(i); if (sibling.equals(windowBox)) { return i; }/*from ww w. j ava2s . c o m*/ } return -1; }
From source file:org.nsesa.editor.gwt.core.client.ui.document.sourcefile.content.ContentController.java
License:EUPL
/** * Get the root element node(s) that is/are set on the * {@link org.nsesa.editor.gwt.core.client.ui.document.sourcefile.content.ContentView#getContentElement()} * * @return the root element//from w w w . j a v a 2 s.co m */ public Element[] getContentElements() { if (!contentLoaded) { throw new RuntimeException("Content not yet available."); } final List<Element> elements = new ArrayList<Element>(); final NodeList<Node> childNodes = view.getContentElement().getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.getItem(i); if (node.getNodeType() == Node.ELEMENT_NODE) { elements.add(Element.as(node)); } } return elements.toArray(new Element[elements.size()]); }
From source file:org.nsesa.editor.gwt.core.client.ui.overlay.DefaultFormatter.java
License:EUPL
/** * This method is in facto responsible with the xml generation. For each child of the given * overlay widget ({@link org.nsesa.editor.gwt.core.client.ui.overlay.document.OverlayWidget#getChildOverlayWidgets()}) * it tries to find out the corresponding browser element node and to extract from there the text content and the * css attributes values. The process continue then recursively for all descendants of the original overlay widget. * * @param widget The overlay widget that will be processed * @param namespaces The map of all namespaces used in overlay widget and its descendants * @param rootNode True if the//from w ww . j av a 2s . c om * @param depth * @return Xml representation of overlay widget as String */ public String toXMLElement(final OverlayWidget widget, final Map<String, String> namespaces, final boolean rootNode, int depth) { final StringBuilder sb = new StringBuilder(); final String indent = withIndentation ? TextUtils.repeat(depth, " ") : ""; sb.append(indent).append("<"); if (rootNode) { sb.append(widget.getType()); for (final Map.Entry<String, String> entry : namespaces.entrySet()) { if (DEFAULT_NAMESPACE.equals(entry.getValue())) { // this is the default namespace sb.append(" xmlns=\"").append(widget.getNamespaceURI()).append("\""); } else { // prefixed namespace sb.append(" xmlns:").append(entry.getValue()).append("=\"").append(entry.getKey()).append("\""); } } } else { final String prefix = namespaces.get(widget.getNamespaceURI()); if (!DEFAULT_NAMESPACE.equals(prefix)) { sb.append(prefix).append(":"); } sb.append(widget.getType()); } //get the attributes final LinkedHashMap<String, String> attrs = widget.getAttributes(); if (!attrs.isEmpty()) { for (final Map.Entry<String, String> entry : attrs.entrySet()) { // do not add the class attribute if (!"class".equalsIgnoreCase(entry.getKey())) { if (entry.getValue() != null && entry.getValue().length() > 0) { sb.append(" ").append(entry.getKey()).append("=").append("\"").append(entry.getValue()) .append("\""); } } } } sb.append(">"); Element element = widget.getOverlayElement(); NodeList<Node> nodes = element.getChildNodes(); int length = nodes.getLength(); if (length == 0) { // the root is all the time a new one // apply xml transformation for children for (final OverlayWidget child : widget.getChildOverlayWidgets()) { sb.append(toXMLElement(child, namespaces, false, depth + 1).trim()); } } else { for (int i = 0; i < length; i++) { final short nodeType = nodes.getItem(i).getNodeType(); Element childElement = nodes.getItem(i).cast(); switch (nodeType) { case Node.ELEMENT_NODE: // get the amendable widget corresponding to this child and apply xml transformation // hopefully there is one amendable widget linked to this node OverlayWidget child = null; // try to find out a amendable widget linked to childElement for (OverlayWidget aw : widget.getChildOverlayWidgets()) { if (aw.getOverlayElement().equals(childElement)) { child = aw; break; } } if (child != null) { sb.append(toXMLElement(child, namespaces, false, depth + 1)); } else { LOG.warning("No amendable child widget found for element " + childElement.getInnerHTML()); } break; case Node.TEXT_NODE: sb.append(TextUtils.escapeXML(nodes.getItem(i).getNodeValue())); //sb.append(nodes.getItem(i).getNodeValue().trim()); break; case Node.DOCUMENT_NODE: LOG.log(Level.WARNING, "There should be no document node here for " + element.getInnerHTML()); break; } } } sb.append("</"); final String prefix = namespaces.get(widget.getNamespaceURI()); if (!DEFAULT_NAMESPACE.equals(prefix)) { sb.append(prefix).append(":"); } sb.append(widget.getType()).append(">"); return sb.toString(); }
From source file:org.nsesa.editor.gwt.core.client.ui.overlay.document.OverlayStrategySupport.java
License:EUPL
/** * Returns a list of all the amendable elements under this element by * enumerating the elements under the 'children' element of this element. * <p/>//from w ww .ja v a2 s .c o m * If there is no children element, an empty list will be returned. * * @return the list of children. */ public final List<Element> getChildren(Element element) { NodeList<Node> nodes = element.getChildNodes(); List<Element> amendableElements = new ArrayList<Element>(); int length = 0; try { length = nodes.getLength(); } catch (Exception e) { LOG.log(Level.WARNING, "Caught exception (probably under Chrome): " + e, e); } for (int i = 0; i < length; i++) { if (nodes.getItem(i).getNodeType() == Node.ELEMENT_NODE) { Element el = nodes.getItem(i).cast(); // do not include any of the 'property' tags // these elements are not included in our tree, but can be searched by their parent later on, to // get certain properties such as content, num, ... if (!asProperties.contains(el.getAttribute("type").toUpperCase())) { amendableElements.add(el); } } } return amendableElements; }
From source file:org.nsesa.editor.gwt.core.client.ui.overlay.HTMLFormatter.java
License:EUPL
/** * This method is in facto responsible with the xml generation. For each child of the given * overlay widget ({@link org.nsesa.editor.gwt.core.client.ui.overlay.document.OverlayWidget#getChildOverlayWidgets()}) * it tries to find out the corresponding browser element node and to extract from there the text content and the * css attributes values. The process continue then recursively for all descendants of the original overlay widget. * * @param widget The overlay widget that will be processed * @param depth/* www . j av a 2 s. c o m*/ * @return Xml representation of overlay widget as String */ public String toHTMLElement(final OverlayWidget widget, boolean withIndentation, int depth) { final StringBuilder sb = new StringBuilder(); final String indent = withIndentation ? TextUtils.repeat(depth, " ") : ""; if (!widget.getOverlayElement().getClassName().contains(widget.getType())) widget.getOverlayElement().addClassName(widget.getType()); sb.append(indent).append("<span class=\"").append(widget.getOverlayElement().getClassName()) .append("\" data-type=\"").append(widget.getType()).append("\"").append(" data-ns=\"") .append(widget.getNamespaceURI()).append("\""); //get the attributes final LinkedHashMap<String, String> attrs = widget.getAttributes(); if (!attrs.isEmpty()) { for (final Map.Entry<String, String> entry : attrs.entrySet()) { // do not add the class attribute if (!"class".equalsIgnoreCase(entry.getKey())) { if (entry.getValue() != null && entry.getValue().length() > 0) { sb.append(" ").append(entry.getKey()).append("=").append("\"").append(entry.getValue()) .append("\""); } } } } // add class names sb.append(">"); Element element = widget.getOverlayElement(); NodeList<Node> nodes = element.getChildNodes(); int length = nodes.getLength(); if (length == 0) { // the root is all the time a new one // apply xml transformation for children for (final OverlayWidget child : widget.getChildOverlayWidgets()) { sb.append(toHTMLElement(child, false, depth + 1).trim()); } } else { for (int i = 0; i < length; i++) { final short nodeType = nodes.getItem(i).getNodeType(); Element childElement = nodes.getItem(i).cast(); switch (nodeType) { case Node.ELEMENT_NODE: // get the amendable widget corresponding to this child and apply xml transformation // hopefully there is one amendable widget linked to this node OverlayWidget child = null; // try to find out a amendable widget linked to childElement for (OverlayWidget aw : widget.getChildOverlayWidgets()) { if (aw.getOverlayElement().equals(childElement)) { child = aw; break; } } if (child != null) { sb.append(toHTMLElement(child, false, depth + 1).trim()); } else { LOG.warning("No amendable child widget found for element " + childElement.getNodeName()); sb.append(DOM.toString((com.google.gwt.user.client.Element) childElement.cast())); } break; case Node.TEXT_NODE: sb.append(TextUtils.escapeXML(nodes.getItem(i).getNodeValue().trim())); //sb.append(nodes.getItem(i).getNodeValue().trim()); break; case Node.DOCUMENT_NODE: LOG.log(Level.WARNING, "There should be no document node here for " + element.getInnerHTML()); break; } } } sb.append("</span>"); return sb.toString(); }
From source file:org.nsesa.editor.gwt.core.client.util.NodeUtil.java
License:EUPL
public static Text getText(final Node node, boolean includeChildren) { final NodeList<Node> childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.getItem(i); if (child.getNodeType() == Node.TEXT_NODE) { return (Text) child; } else if (child.getNodeType() == Node.ELEMENT_NODE) { return getText(child, includeChildren); }/*from ww w . jav a 2s . c o m*/ } return null; }
From source file:org.nsesa.editor.gwt.core.client.util.NodeUtil.java
License:EUPL
public static void walk(final Node node, final NodeVisitor visitor) { visitor.visit(node);// w w w . ja v a 2s. c o m final NodeList<Node> childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.getItem(i); walk(child, visitor); } }