use of org.gwtproject.dom.builder.shared.TableRowBuilder in project gwtproject by treblereel.
the class AbstractCellTableTestBase method testSetHeaderBuilder.
public void testSetHeaderBuilder() {
T table = createAbstractHasData();
HeaderBuilder<String> headerBuilder = new AbstractHeaderOrFooterBuilder<String>(table, false) {
@Override
protected boolean buildHeaderOrFooterImpl() {
TableRowBuilder tr = startRow();
tr.startTH().text("Col 0").endTH();
tr.startTH().text("Col 1").endTH();
tr.startTH().text("Col 2").endTH();
tr.endTR();
return true;
}
};
// Change the header builder.
table.setHeaderBuilder(headerBuilder);
assertEquals(headerBuilder, table.getHeaderBuilder());
table.getPresenter().flush();
// Verify the new header.
NodeList<TableRowElement> rows = table.getTableHeadElement().getRows();
assertEquals(1, rows.getLength());
NodeList<TableCellElement> cells = rows.getItem(0).getCells();
assertEquals(3, cells.getLength());
assertEquals("Col 0", cells.getItem(0).getInnerText());
assertEquals("Col 1", cells.getItem(1).getInnerText());
assertEquals("Col 2", cells.getItem(2).getInnerText());
}
use of org.gwtproject.dom.builder.shared.TableRowBuilder in project gwtproject by treblereel.
the class AbstractCellTableTestBase method testBuildTooManyEnds.
/**
* Test that an error is thrown if the builder ends the table body element
* instead of the table row element.
*/
public void testBuildTooManyEnds() {
final List<Integer> builtRows = new ArrayList<Integer>();
T table = createAbstractHasData(new TextCell());
CellTableBuilder<String> builder = new DefaultCellTableBuilder<String>(table) {
@Override
public void buildRowImpl(String rowValue, int absRowIndex) {
builtRows.add(absRowIndex);
TableRowBuilder tr = startRow(rowValue);
// End the tr.
tr.endTR();
// Accidentally end the table section.
tr.end();
// Try to start another row.
try {
startRow(rowValue);
fail("Expected IllegalStateException: tbody is already ended");
} catch (IllegalStateException e) {
// Expected.
}
}
};
table.setTableBuilder(builder);
table.setVisibleRange(0, 1);
populateData(table);
table.getPresenter().flush();
assertEquals(1, builtRows.size());
assertEquals(0, builtRows.get(0).intValue());
}
use of org.gwtproject.dom.builder.shared.TableRowBuilder in project gwtproject by treblereel.
the class AbstractHeaderOrFooterBuilder method startRow.
/**
* Add a header (or footer) row to the table, below any rows previously added.
*
* @return the row to add
*/
protected final TableRowBuilder startRow() {
// End any dangling rows.
while (section.getDepth() > 1) {
section.end();
}
// Verify the depth.
if (section.getDepth() < 1) {
throw new IllegalStateException("Cannot start a row. Did you call TableRowBuilder.end() too many times?");
}
// Start the next row.
TableRowBuilder row = section.startTR();
row.attribute(ROW_ATTRIBUTE, rowIndex);
rowIndex++;
return row;
}
use of org.gwtproject.dom.builder.shared.TableRowBuilder in project gwtproject by treblereel.
the class AbstractCellTableBuilder method startRow.
/**
* Start a row and return the {@link TableRowBuilder} for this row. The row can be initialized
* according to its corresponding value.
*
* @param rowValue the value for the row corresponding to the element. Can be null.
*/
public final TableRowBuilder startRow(T rowValue) {
// End any dangling rows.
while (tbody.getDepth() > 1) {
tbody.end();
}
// Verify the depth.
if (tbody.getDepth() < 1) {
throw new IllegalStateException("Cannot start a row. Did you call TableRowBuilder.end() too many times?");
}
// Start the next row.
TableRowBuilder row = tbody.startTR();
row.attribute(ROW_ATTRIBUTE, rowIndex);
row.attribute(SUBROW_ATTRIBUTE, subrowIndex);
addRowAttributes(row, rowValue);
subrowIndex++;
return row;
}
use of org.gwtproject.dom.builder.shared.TableRowBuilder in project gwtproject by treblereel.
the class DefaultCellTableBuilder method buildRowImpl.
@Override
public void buildRowImpl(T rowValue, int absRowIndex) {
// Calculate the row styles.
SelectionModel<? super T> selectionModel = cellTable.getSelectionModel();
boolean isSelected = (selectionModel == null || rowValue == null) ? false : selectionModel.isSelected(rowValue);
boolean isEven = absRowIndex % 2 == 0;
StringBuilder trClasses = new StringBuilder(isEven ? evenRowStyle : oddRowStyle);
if (isSelected) {
trClasses.append(selectedRowStyle);
}
// Add custom row styles.
RowStyles<T> rowStyles = cellTable.getRowStyles();
if (rowStyles != null) {
String extraRowStyles = rowStyles.getStyleNames(rowValue, absRowIndex);
if (extraRowStyles != null) {
trClasses.append(" ").append(extraRowStyles);
}
}
// Build the row.
TableRowBuilder tr = startRow(rowValue);
tr.className(trClasses.toString());
// Build the columns.
int columnCount = cellTable.getColumnCount();
for (int curColumn = 0; curColumn < columnCount; curColumn++) {
Column<T, ?> column = cellTable.getColumn(curColumn);
// Create the cell styles.
StringBuilder tdClasses = new StringBuilder(cellStyle);
tdClasses.append(isEven ? evenCellStyle : oddCellStyle);
if (curColumn == 0) {
tdClasses.append(firstColumnStyle);
}
if (isSelected) {
tdClasses.append(selectedCellStyle);
}
// The first and last column could be the same column.
if (curColumn == columnCount - 1) {
tdClasses.append(lastColumnStyle);
}
// Add class names specific to the cell.
Context context = new Context(absRowIndex, curColumn, cellTable.getValueKey(rowValue));
String cellStyles = column.getCellStyleNames(context, rowValue);
if (cellStyles != null) {
tdClasses.append(" " + cellStyles);
}
// Build the cell.
HorizontalAlignmentConstant hAlign = column.getHorizontalAlignment();
VerticalAlignmentConstant vAlign = column.getVerticalAlignment();
TableCellBuilder td = tr.startTD();
td.className(tdClasses.toString());
if (hAlign != null) {
td.align(hAlign.getTextAlignString());
}
if (vAlign != null) {
td.vAlign(vAlign.getVerticalAlignString());
}
addCellAttributes(td);
// Add the inner div.
DivBuilder div = td.startDiv();
div.style().outlineStyle(OutlineStyle.NONE).endStyle();
// Render the cell into the div.
renderCell(div, context, column, rowValue);
// End the cell.
div.endDiv();
td.endTD();
}
// End the row.
tr.endTR();
}
Aggregations