int col = 0;
// row header
if (showRowHeaders) {
- addCell(uidl.getStringAttribute("caption"), aligns[col++]);
+ addCell(uidl.getStringAttribute("caption"), aligns[col++],
+ "");
}
if (uidl.hasAttribute("al")) {
while (cells.hasNext()) {
final Object cell = cells.next();
if (cell instanceof String) {
- addCell(cell.toString(), aligns[col++]);
+ String style = "";
+ if (uidl.hasAttribute("style-" + col)) {
+ style = uidl.getStringAttribute("style-" + col);
+ }
+ addCell(cell.toString(), aligns[col++], style);
} else {
final Paintable cellContent = client
.getPaintable((UIDL) cell);
(cellContent).updateFromUIDL((UIDL) cell, client);
- addCell((Widget) cellContent, aligns[col++]);
+ String style = "";
+ if (uidl.hasAttribute("style")) {
+ style = uidl.getStringAttribute("style");
+ }
+ addCell((Widget) cellContent, aligns[col++], style);
}
}
if (uidl.hasAttribute("selected") && !isSelected()) {
}
}
- public void addCell(String text, char align) {
+ public void addCell(String text, char align, String style) {
// String only content is optimized by not using Label widget
final Element td = DOM.createTD();
final Element container = DOM.createDiv();
- DOM.setElementProperty(container, "className", CLASSNAME
- + "-cell-content");
+ String className = CLASSNAME + "-cell-content";
+ if (style != null && !style.equals("")) {
+ className += " " + CLASSNAME + "-cell-content-" + style;
+ }
+
+ DOM.setElementProperty(container, "className", className);
DOM.setInnerHTML(container, text);
if (align != ALIGN_LEFT) {
switch (align) {
DOM.appendChild(getElement(), td);
}
- public void addCell(Widget w, char align) {
+ public void addCell(Widget w, char align, String style) {
final Element td = DOM.createTD();
final Element container = DOM.createDiv();
- DOM.setElementProperty(container, "className", CLASSNAME
- + "-cell-content");
+ String className = CLASSNAME + "-cell-content";
+ if (style != null && !style.equals("")) {
+ className += " " + CLASSNAME + "-cell-content-" + style;
+ }
+ DOM.setElementProperty(container, "className", className);
// TODO most components work with this, but not all (e.g.
// Select)
// Old comment: make widget cells respect align.
private boolean containerChangeToBeRendered = false;
+ /**
+ * Table cell specific style generator
+ */
+ private CellStyleGenerator cellStyleGenerator = null;
+
/* Table constructors *************************************************** */
/**
if (columnId == null || isColumnCollapsed(columnId)) {
continue;
}
+ /*
+ * For each cell, if a cellStyleGenerator is specified, get the
+ * specific style for the cell. If there is any, add it to the
+ * target.
+ */
+ if (cellStyleGenerator != null) {
+ String cellStyle = cellStyleGenerator.getStyle(itemId,
+ columnId);
+ if (cellStyle != null && !cellStyle.equals("")) {
+ target
+ .addAttribute("style-" + currentColumn,
+ cellStyle);
+ }
+ }
if ((iscomponent[currentColumn] || iseditable)
&& Component.class.isInstance(cells[CELL_FIRSTCOL
+ currentColumn][i])) {
public abstract Component generateCell(Table source, Object itemId,
Object columnId);
}
-}
\ No newline at end of file
+
+ /**
+ * Set cell style generator for Table.
+ *
+ * @param cellStyleGenerator
+ * New cell style generator or null to remove generator.
+ */
+ public void setCellStyleGenerator(CellStyleGenerator cellStyleGenerator) {
+ this.cellStyleGenerator = cellStyleGenerator;
+ requestRepaint();
+ }
+
+ /**
+ * Get the current cell style generator.
+ *
+ */
+ public CellStyleGenerator getCellStyleGenerator() {
+ return cellStyleGenerator;
+ }
+
+ /**
+ * Allow to define specific style on cells contents. Implements this
+ * interface and pass it to Table.setCellStyleGenerator. The CSS class name
+ * that will be added to the cell content is
+ * <tt>i-table-cell-content-[style name]</tt>
+ */
+ public interface CellStyleGenerator {
+
+ /**
+ * Called by Table when a cell is painted.
+ *
+ * @param itemId
+ * The itemId of the painted cell
+ * @param propertyId
+ * The propertyId of the
+ * @return The style name to add to this cell (the CSS class name will
+ * be i-table-cell-content-[style name] )
+ */
+ public abstract String getStyle(Object itemId, Object propertyId);
+ }
+}