]> source.dussan.org Git - vaadin-framework.git/commitdiff
Implements #1928 (cellstylegenerator row styling). Fixes #1985 (cell style off-by...
authorMarc Englund <marc.englund@itmill.com>
Fri, 15 Aug 2008 12:51:14 +0000 (12:51 +0000)
committerMarc Englund <marc.englund@itmill.com>
Fri, 15 Aug 2008 12:51:14 +0000 (12:51 +0000)
svn changeset:5194/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java
src/com/itmill/toolkit/ui/Table.java

index af1623c71d23b17ca0e684d2d98cc7ee4d674693..602719ac282409b4043d4132448bd6051f5abbae 100644 (file)
@@ -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 {
index 02d07de22c1fbdb9715b91a05a954aefac05ca6f..940eb21612382cfdac319354a2d4926a3065c480 100644 (file)
@@ -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
-     * <tt>i-table-cell-content-[style name]</tt>
+     * 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 <tt>i-table-cell-content-[style name]</tt>, and
+     * the row style will be <tt>i-table-row-[style name]</tt>.
      */
     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);
     }