Example usage for com.google.gwt.dom.client TableElement insertRow

List of usage examples for com.google.gwt.dom.client TableElement insertRow

Introduction

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

Prototype

public final native TableRowElement insertRow(int index) ;

Source Link

Document

Insert a new empty row in the table.

Usage

From source file:org.xwiki.gwt.wysiwyg.client.plugin.table.util.TableUtils.java

License:Open Source License

/**
 * Insert a row in the currently edited table.
 * //from w w w.  jav  a2  s.com
 * @param doc the Document to get the selection from.
 * @param insertBefore indicates the creation position relatively to the currently edited row.
 * @return the newly created TableRowElement.
 */
public TableRowElement insertRow(Document doc, boolean insertBefore) {
    TableRowElement row = getRow(getCaretNode(doc));
    TableElement table = getTable(row);
    int index = row.getRowIndex();

    if (!insertBefore) {
        index++;
    }

    TableRowElement newRow = table.insertRow(index);
    // Populate the row
    int cellCount = row.getCells().getLength();
    for (int i = 0; i < cellCount; i++) {
        TableCellElement cell = newRow.insertCell(i);
        cell.setInnerHTML(CELL_DEFAULTHTML);
    }

    return newRow;
}