From: Marc Englund Date: Fri, 15 Aug 2008 12:51:14 +0000 (+0000) Subject: Implements #1928 (cellstylegenerator row styling). Fixes #1985 (cell style off-by... X-Git-Tag: 6.7.0.beta1~4349 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=732ea8590ed634ddf4f298746a8a9236ec8203b5;p=vaadin-framework.git Implements #1928 (cellstylegenerator row styling). Fixes #1985 (cell style off-by-one w/ rowheaders) svn changeset:5194/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 af1623c71d..602719ac28 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java @@ -1762,7 +1762,9 @@ public class IScrollTable extends Composite implements Table, ScrollListener, first = (IScrollTableRow) renderedRows.get(0); } if (first != null && first.getStyleName().indexOf("-odd") == -1) { - row.setStyleName(CLASSNAME + "-row-odd"); + row.addStyleName(CLASSNAME + "-row-odd"); + } else { + row.addStyleName(CLASSNAME + "-row"); } if (row.isSelected()) { row.addStyleName("i-selected"); @@ -1779,7 +1781,9 @@ public class IScrollTable extends Composite implements Table, ScrollListener, .get(renderedRows.size() - 1); } if (last != null && last.getStyleName().indexOf("-odd") == -1) { - row.setStyleName(CLASSNAME + "-row-odd"); + row.addStyleName(CLASSNAME + "-row-odd"); + } else { + row.addStyleName(CLASSNAME + "-row"); } if (row.isSelected()) { row.addStyleName("i-selected"); @@ -1923,7 +1927,6 @@ public class IScrollTable extends Composite implements Table, ScrollListener, setElement(DOM.createElement("tr")); DOM.sinkEvents(getElement(), Event.ONCLICK); attachContextMenuEvent(getElement()); - setStyleName(CLASSNAME + "-row"); } protected void onDetach() { @@ -1956,6 +1959,11 @@ public class IScrollTable extends Composite implements Table, ScrollListener, public IScrollTableRow(UIDL uidl, char[] aligns) { this(uidl.getIntAttribute("key")); + String rowStyle = uidl.getStringAttribute("rowstyle"); + if (rowStyle != null) { + addStyleName(CLASSNAME + "-row-" + rowStyle); + } + tHead.getColumnAlignments(); int col = 0; // row header @@ -1972,8 +1980,10 @@ public class IScrollTable extends Composite implements Table, ScrollListener, final Object cell = cells.next(); if (cell instanceof String) { String style = ""; - if (uidl.hasAttribute("style-" + col)) { - style = uidl.getStringAttribute("style-" + col); + if (uidl.hasAttribute("style-" + + (showRowHeaders ? col - 1 : col))) { + style = uidl.getStringAttribute("style-" + + (showRowHeaders ? col - 1 : col)); } addCell(cell.toString(), aligns[col++], style); } else { diff --git a/src/com/itmill/toolkit/ui/Table.java b/src/com/itmill/toolkit/ui/Table.java index 02d07de22c..940eb21612 100644 --- a/src/com/itmill/toolkit/ui/Table.java +++ b/src/com/itmill/toolkit/ui/Table.java @@ -1889,6 +1889,18 @@ public class Table extends AbstractSelect implements Action.Container, target.addAttribute("al", keys.toArray()); } + /* + * For each row, if a cellStyleGenerator is specified, get the + * specific style for the cell, using null as propertyId. If there + * is any, add it to the target. + */ + if (cellStyleGenerator != null) { + String rowStyle = cellStyleGenerator.getStyle(itemId, null); + if (rowStyle != null && !rowStyle.equals("")) { + target.addAttribute("rowstyle", rowStyle); + } + } + // cells int currentColumn = 0; for (final Iterator it = visibleColumns.iterator(); it.hasNext(); currentColumn++) { @@ -2871,22 +2883,25 @@ public class Table extends AbstractSelect implements Action.Container, } /** - * 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] + * Allow to define specific style on cells (and rows) contents. Implements + * this interface and pass it to Table.setCellStyleGenerator. Row styles are + * generated when porpertyId is null. The CSS class name that will be added + * to the cell content is i-table-cell-content-[style name], and + * the row style will be i-table-row-[style name]. */ public interface CellStyleGenerator { /** - * Called by Table when a cell is painted. + * Called by Table when a cell (and row) 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] ) + * The propertyId of the cell, null when getting row + * style + * @return The style name to add to this cell or row. (the CSS class + * name will be i-table-cell-content-[style name], or + * i-table-row-[style name] for rows) */ public abstract String getStyle(Object itemId, Object propertyId); }