From: Joonas Lehtinen Date: Tue, 1 Jul 2008 11:50:13 +0000 (+0000) Subject: Integrated patch from ticket #1857. Closes the ticket. X-Git-Tag: 6.7.0.beta1~4525 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4f44a2f25da63f1f4ce722091e0c66348f17eb98;p=vaadin-framework.git Integrated patch from ticket #1857. Closes the ticket. svn changeset:4996/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java index 231e4e6de1..d15eacc769 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java @@ -1959,7 +1959,8 @@ public class IScrollTable extends Composite implements Table, ScrollListener, int col = 0; // row header if (showRowHeaders) { - addCell(uidl.getStringAttribute("caption"), aligns[col++]); + addCell(uidl.getStringAttribute("caption"), aligns[col++], + ""); } if (uidl.hasAttribute("al")) { @@ -1970,12 +1971,20 @@ public class IScrollTable extends Composite implements Table, ScrollListener, 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()) { @@ -1983,12 +1992,16 @@ public class IScrollTable extends Composite implements Table, ScrollListener, } } - 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) { @@ -2005,11 +2018,14 @@ public class IScrollTable extends Composite implements Table, ScrollListener, 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. diff --git a/src/com/itmill/toolkit/ui/Table.java b/src/com/itmill/toolkit/ui/Table.java index e914584460..510c597e40 100644 --- a/src/com/itmill/toolkit/ui/Table.java +++ b/src/com/itmill/toolkit/ui/Table.java @@ -290,6 +290,11 @@ public class Table extends AbstractSelect implements Action.Container, private boolean containerChangeToBeRendered = false; + /** + * Table cell specific style generator + */ + private CellStyleGenerator cellStyleGenerator = null; + /* Table constructors *************************************************** */ /** @@ -1864,6 +1869,20 @@ public class Table extends AbstractSelect implements Action.Container, 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])) { @@ -2803,4 +2822,44 @@ public class Table extends AbstractSelect implements Action.Container, 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 + * i-table-cell-content-[style name] + */ + 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); + } +}