Example usage for com.google.gwt.dom.client NodeList getLength

List of usage examples for com.google.gwt.dom.client NodeList getLength

Introduction

In this page you can find the example usage for com.google.gwt.dom.client NodeList getLength.

Prototype

public int getLength() 

Source Link

Usage

From source file:org.openremote.modeler.client.gxtextends.CheckBoxListViewExt.java

License:Open Source License

public List<M> getChecked() {
    List<M> l = new ArrayList<M>();
    NodeList<Element> nodes = el().select(checkBoxSelector);
    for (int i = 0; i < nodes.getLength(); i++) {
        InputElement e = nodes.getItem(i).cast();
        if (e.isChecked()) {
            l.add(getStore().getAt(i));//from   w w w .ja  v  a 2 s  .  c  om
        }
    }
    return l;
}

From source file:org.openxdata.sharedlib.client.util.FormUtil.java

public static String getDivValue(String id) {
    com.google.gwt.dom.client.Element p = com.google.gwt.dom.client.Document.get().getElementById(id);
    if (p != null) {
        NodeList<Node> nodes = p.getChildNodes();
        if (nodes != null && nodes.getLength() > 0) {
            Node node = nodes.getItem(0);
            String s = node.getNodeValue();
            p.removeChild(node);//from w  ww. j  av a  2  s  . c o m
            return s;
        }
    }

    return null;
}

From source file:org.otalo.ao.client.widget.chlist.client.ChosenImpl.java

License:Apache License

private void setDefaultValues() {
    clickTestAction = new Function() {
        @Override/*from  www . j a v  a  2s  .  co  m*/
        public boolean f(Event e) {
            return testActiveClick(e);
        }
    };

    activateAction = new Function() {
        @Override
        public boolean f(Event e) {
            return activateField(e);
        }
    };

    activeField = false;
    mouseOnContainer = false;
    resultsShowing = false;

    NodeList<OptionElement> optionsList = selectElement.getOptions();
    allowSingleDeselect = options.isAllowSingleDeselect() && optionsList.getLength() > 0
            && "".equals(optionsList.getItem(0).getText());

    choices = 0;

    if (options.getResources() != null) {
        css = options.getResources().css();
    } else {
        css = GWT.<Resources>create(Resources.class).css();
    }

    // Force the injection the first time only
    // If you want to use different css file for different GwtChosen component
    // please register your css files (css.ensureInject()) before the first call of the plugin
    if (!cssInjected) {
        StyleInjector.inject(css.getText(), true);
        cssInjected = true;
    }

}

From source file:org.otalo.ao.client.widget.chlist.gwt.ChosenListBox.java

License:Apache License

/**
 * Return the values of all selected options in an array.
 * Usefull to know which options are selected in case of multiple ChosenListBox
 * @return//from  w w  w. j a  v a2 s  . c o  m
 */
public String[] getValues() {
    if (!isMultipleSelect()) {
        return new String[] { getValue() };
    }

    JsArrayString values = JsArrayString.createArray().cast();
    NodeList<OptionElement> options = SelectElement.as(getElement()).getOptions();
    for (int i = 0; i < options.getLength(); i++) {
        OptionElement option = options.getItem(i);
        if (option.isSelected()) {
            values.push(option.getValue());
        }
    }

    String[] result = new String[values.length()];
    for (int i = 0; i < values.length(); i++) {
        result[i] = values.get(i);
    }

    return result;
}

From source file:org.overlord.commons.gwt.client.local.widgets.SortableTemplatedWidgetTable.java

License:Apache License

/**
 * Sets a column in the table to be sortable.  This will convert the content in the
 * "th" to be something the user can click on.  When the user clicks on it, the
 * internal state of the table will be altered *and* an event will be fired.
 * @param columnIndex/*from w w w  . j a va 2 s  . co  m*/
 * @param columnId
 */
public void setColumnSortable(int columnIndex, final String columnId) {
    Element thElement = null;
    NodeList<com.google.gwt.dom.client.Element> elementsByTagName = this.thead.getElementsByTagName("th"); //$NON-NLS-1$
    if (columnIndex <= elementsByTagName.getLength()) {
        thElement = elementsByTagName.getItem(columnIndex).cast();
    }
    if (thElement == null) {
        return;
    }

    String columnLabel = thElement.getInnerText();
    thElement.setInnerText(""); //$NON-NLS-1$

    SortableTableHeader widget = new SortableTableHeader(columnLabel, columnId);
    widget.removeFromParent();
    DOM.appendChild(thElement, widget.getElement());
    adopt(widget);
    widget.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            onColumnHeaderClick(columnId);
        }
    });
    columnIdMap.put(columnId, widget);
}

From source file:org.overlord.commons.gwt.client.local.widgets.TemplatedWidgetTable.java

License:Apache License

/**
 * Called when the table is attached.  This is here to better support the WidgetTable
 * in an Errai UI template.  This method will grab the thead and tbody from the
 * template.  In addition, it will remove all of the tr children from the tbody.
 *//*  w  w w.  ja va2 s  . c o  m*/
protected void doAttachInit() {
    NodeList<Node> nodes = getElement().getChildNodes();
    for (int j = 0; j < nodes.getLength(); j++) {
        Node item = nodes.getItem(j);
        if ("thead".equalsIgnoreCase(item.getNodeName())) { //$NON-NLS-1$
            this.thead = item.cast();
            NodeList<Node> childNodes = this.thead.getChildNodes();
            for (int i = 0; i < childNodes.getLength(); i++) {
                Node theadtr = childNodes.getItem(i);
                if ("tr".equalsIgnoreCase(theadtr.getNodeName())) { //$NON-NLS-1$
                    int thcount = 0;
                    NodeList<Node> nodeList = theadtr.getChildNodes();
                    for (int k = 0; k < nodeList.getLength(); k++) {
                        if ("th".equalsIgnoreCase(nodeList.getItem(k).getNodeName())) { //$NON-NLS-1$
                            thcount++;
                        }
                    }
                    this.columnCount = thcount;
                }
            }
        } else if ("tbody".equalsIgnoreCase(item.getNodeName())) { //$NON-NLS-1$
            this.tbody = item.cast();
            removeAllChildNodes(this.tbody);
        }
    }
}

From source file:org.overlord.commons.gwt.client.local.widgets.TemplatedWidgetTable.java

License:Apache License

/**
 * Removes all child nodes from the given element.
 *//*  w w w.j a  v a  2s.  c  o m*/
protected void removeAllChildNodes(Node elem) {
    NodeList<Node> childNodes = elem.getChildNodes();
    for (int i = childNodes.getLength() - 1; i >= 0; i--) {
        elem.removeChild(childNodes.getItem(i));
    }
}

From source file:org.overlord.commons.gwt.client.local.widgets.WidgetTable.java

License:Apache License

/**
 * Remove a single row and all its widgets from the table
 *
 * @param rowIndex which row to add to (0 based, excluding thead)
 *//*from w  w w.  ja va2 s .co m*/
public void deleteRow(int rowIndex) {
    Element rowElem = rowElements.get(rowIndex);
    NodeList<Node> tds = rowElem.getChildNodes();
    for (int i = 0; i < tds.getLength(); i++) {
        Element td = tds.getItem(i).cast();
        for (Widget widget : wrapperMap.keySet()) {
            if (wrapperMap.get(widget).equals(td)) {
                remove(widget);
                break;
            }
        }
    }
    this.tbody.removeChild(rowElem);
    rowElements.remove(rowIndex);
}

From source file:org.overlord.commons.gwt.client.local.widgets.WidgetTable.java

License:Apache License

/**
 * Ensures that a row at the given index exists.
 * @param rowIndex//w ww.  j  a  v a 2  s  .  co m
 */
private Element ensureRow(int rowIndex) {
    NodeList<Node> childNodes = this.tbody.getChildNodes();
    int numTRs = childNodes.getLength();
    if (rowIndex < numTRs) {
        return childNodes.getItem(rowIndex).cast();
    }
    Element tr = null;
    for (int r = numTRs; r <= rowIndex; r++) {
        tr = Document.get().createTRElement().cast();
        DOM.appendChild(this.tbody, tr);
        this.rowElements.add(tr);
    }
    return tr;
}

From source file:org.overlord.commons.gwt.client.local.widgets.WidgetTable.java

License:Apache License

/**
 * Ensure that a td cell exists for the row at the given column
 * index.// ww w  . j  a  va  2  s  . c o  m
 * @param tr the row
 * @param colIndex the column index (0 based)
 * @return the new or already existing td
 */
private Element ensureCell(Element tr, int colIndex) {
    NodeList<Node> tds = tr.getChildNodes();
    int numTDs = tds.getLength();
    if (colIndex < numTDs) {
        return tds.getItem(colIndex).cast();
    }
    Element td = null;
    for (int c = numTDs; c <= colIndex; c++) {
        td = Document.get().createTDElement().cast();
        if (this.columnClasses.containsKey(colIndex)) {
            td.setAttribute("class", this.columnClasses.get(colIndex)); //$NON-NLS-1$
        }
        DOM.appendChild(tr, td);
    }
    return td;
}