Reviewers: jlabanca,
Description:
Add support for additional header styles for CellTable.
Please review this at http://gwt-code-reviews.appspot.com/1538803/
Affected files:
M
user/src/com/google/gwt/user/cellview/client/DefaultHeaderOrFooterBuilder.java
M user/src/com/google/gwt/user/cellview/client/Header.java
Index:
user/src/com/google/gwt/user/cellview/client/DefaultHeaderOrFooterBuilder.java
===================================================================
---
user/src/com/google/gwt/user/cellview/client/DefaultHeaderOrFooterBuilder.java
(revision 10598)
+++
user/src/com/google/gwt/user/cellview/client/DefaultHeaderOrFooterBuilder.java
(working copy)
@@ -20,6 +20,8 @@
import com.google.gwt.dom.builder.shared.TableRowBuilder;
import com.google.gwt.user.cellview.client.AbstractCellTable.Style;
import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo;
+import
com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant;
+import
com.google.gwt.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant;
/**
* Default implementation of {@link HeaderBuilder} that renders columns.
@@ -102,10 +104,11 @@
if (isSorted) {
classesBuilder.append(sortedStyle);
}
-
+
// Render the header.
TableCellBuilder th =
-
tr.startTH().colSpan(prevColspan).className(classesBuilder.toString());
+
tr.startTH().colSpan(prevColspan).className(classesBuilder.toString()
+ + getExtraStyles(prevHeader));
enableColumnHandlers(th, column);
if (prevHeader != null) {
// Build the header.
@@ -144,9 +147,10 @@
// The first and last columns could be the same column.
classesBuilder.append(" ").append(
isFooter ? style.lastColumnFooter() : style.lastColumnHeader());
-
+
// Render the last header.
- TableCellBuilder th =
tr.startTH().colSpan(prevColspan).className(classesBuilder.toString());
+ TableCellBuilder th =
tr.startTH().colSpan(prevColspan).className(classesBuilder.toString()
+ + getExtraStyles(prevHeader));
enableColumnHandlers(th, column);
if (prevHeader != null) {
Context context = new Context(0, curColumn - prevColspan,
prevHeader.getKey());
@@ -159,4 +163,20 @@
return true;
}
+
+ /**
+ * Return the extra style names for the header.
+ */
+ private <H> String getExtraStyles(Header<H> header) {
+ if (header == null) {
+ return "";
+ }
+ H headerValue = header.getValue();
+ String headerStyleNames = header.getHeaderStyleNames(headerValue);
+ if (headerStyleNames != null) {
+ return " " + headerStyleNames;
+ } else {
+ return "";
+ }
+ }
}
Index: user/src/com/google/gwt/user/cellview/client/Header.java
===================================================================
--- user/src/com/google/gwt/user/cellview/client/Header.java (revision
10598)
+++ user/src/com/google/gwt/user/cellview/client/Header.java (working copy)
@@ -31,6 +31,7 @@
private final Cell<H> cell;
+ private String headerStyleNames = null;
private ValueUpdater<H> updater;
/**
@@ -52,6 +53,18 @@
}
/**
+ * Get extra style names that should be applied to a cell in this header.
+ *
+ * @param value the value of the header that needs to be updated
+ * @return the extra styles of the given row in a space-separated list,
or
+ * {@code null} if there are no extra styles for the cells in
this
+ * header
+ */
+ public String getHeaderStyleNames(H object) {
+ return headerStyleNames;
+ }
+
+ /**
* Get the key for the header value. By default, the key is the same as
the
* value. Override this method to return a custom key.
*
@@ -67,7 +80,7 @@
* @return the header value
*/
public abstract H getValue();
-
+
/**
* Handle a browser event that took place within the header.
*
@@ -90,6 +103,21 @@
}
/**
+ * Set extra style names that should be applied to every cell in this
header.
+ *
+ * <p>
+ * If you want to apply style names based on the header value, override
+ * {@link #getHeaderStyleNames(Object)} directly.
+ * </p>
+ *
+ * @param styleNames the extra style names to applyin a space-separated
list,
+ * or {@code null} if there are no extra styles for this cell
+ */
+ public void setHeaderStyleNames(String styleNames) {
+ this.headerStyleNames = styleNames;
+ }
+
+ /**
* Set the {@link ValueUpdater}.
*
* @param updater the value updater to use
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors