]> source.dussan.org Git - vaadin-framework.git/commitdiff
Integrated patch from ticket #1857. Closes the ticket.
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Tue, 1 Jul 2008 11:50:13 +0000 (11:50 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Tue, 1 Jul 2008 11:50:13 +0000 (11:50 +0000)
svn changeset:4996/svn branch:trunk

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

index 231e4e6de178280953edb03d190de3a5e57647f1..d15eacc76992ddfa50f48926cf58a5e293f06373 100644 (file)
@@ -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.
index e914584460f2f59503efc23c87bcc81f41b294f7..510c597e409ca620f7f370196eec76bbf7106c89 100644 (file)
@@ -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
+     * <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);
+    }
+}