use of org.gwtproject.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant 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();
}
use of org.gwtproject.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant in project gwtproject by treblereel.
the class AbstractCellTable method renderRowValuesLegacy.
/**
* Render all row values into the specified {@link SafeHtmlBuilder}.
*
* <p>This method is here for legacy reasons, to support subclasses that call {@link
* #renderRowValues(SafeHtmlBuilder, List, int, SelectionModel)}.
*
* @param sb the {@link SafeHtmlBuilder} to render into
* @param values the row values
* @param start the absolute start index of the values
* @param selectionModel the {@link SelectionModel}
* @deprecated as of GWT 2.5, use a {@link CellTableBuilder} to customize the table structure
* instead
*/
@Deprecated
protected final void renderRowValuesLegacy(SafeHtmlBuilder sb, List<T> values, int start, SelectionModel<? super T> selectionModel) {
int keyboardSelectedRow = getKeyboardSelectedRow() + getPageStart();
String evenRowStyle = style.evenRow();
String oddRowStyle = style.oddRow();
String cellStyle = style.cell();
String evenCellStyle = " " + style.evenRowCell();
String oddCellStyle = " " + style.oddRowCell();
String firstColumnStyle = " " + style.firstColumn();
String lastColumnStyle = " " + style.lastColumn();
String selectedRowStyle = " " + style.selectedRow();
String selectedCellStyle = " " + style.selectedRowCell();
int columnCount = columns.size();
int length = values.size();
int end = start + length;
for (int i = start; i < end; i++) {
T value = values.get(i - start);
boolean isSelected = (selectionModel == null || value == null) ? false : selectionModel.isSelected(value);
boolean isEven = i % 2 == 0;
String trClasses = isEven ? evenRowStyle : oddRowStyle;
if (isSelected) {
trClasses += selectedRowStyle;
}
if (rowStyles != null) {
String extraRowStyles = rowStyles.getStyleNames(value, i);
if (extraRowStyles != null) {
trClasses += " ";
trClasses += extraRowStyles;
}
}
SafeHtmlBuilder trBuilder = new SafeHtmlBuilder();
int curColumn = 0;
for (Column<T, ?> column : columns) {
String tdClasses = cellStyle;
tdClasses += isEven ? evenCellStyle : oddCellStyle;
if (curColumn == 0) {
tdClasses += firstColumnStyle;
}
if (isSelected) {
tdClasses += selectedCellStyle;
}
// The first and last column could be the same column.
if (curColumn == columnCount - 1) {
tdClasses += lastColumnStyle;
}
// Add class names specific to the cell.
Context context = new Context(i, curColumn, getValueKey(value));
String cellStyles = column.getCellStyleNames(context, value);
if (cellStyles != null) {
tdClasses += " " + cellStyles;
}
SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
if (value != null) {
column.render(context, value, cellBuilder);
}
// Build the contents.
SafeHtml contents = SafeHtmlUtils.EMPTY_SAFE_HTML;
contents = Template.INSTANCE.div(cellBuilder.toSafeHtml());
// Build the cell.
HorizontalAlignmentConstant hAlign = column.getHorizontalAlignment();
VerticalAlignmentConstant vAlign = column.getVerticalAlignment();
if (hAlign != null && vAlign != null) {
trBuilder.append(Template.INSTANCE.tdBothAlign(tdClasses, hAlign.getTextAlignString(), vAlign.getVerticalAlignString(), contents));
} else if (hAlign != null) {
trBuilder.append(Template.INSTANCE.tdHorizontalAlign(tdClasses, hAlign.getTextAlignString(), contents));
} else if (vAlign != null) {
trBuilder.append(Template.INSTANCE.tdVerticalAlign(tdClasses, vAlign.getVerticalAlignString(), contents));
} else {
trBuilder.append(Template.INSTANCE.td(tdClasses, contents));
}
curColumn++;
}
sb.append(Template.INSTANCE.tr(trClasses, trBuilder.toSafeHtml()));
}
}
Aggregations