Reviewers: jlabanca, rice,
Description:
Added a RowStyles interface that can be used to customize the classes
assigned to <tr> elements in a CellTable.
Please review this at http://gwt-code-reviews.appspot.com/930801/show
Affected files:
M user/src/com/google/gwt/user/cellview/client/CellTable.java
A user/src/com/google/gwt/user/cellview/client/RowStyles.java
Index: user/src/com/google/gwt/user/cellview/client/CellTable.java
===================================================================
--- user/src/com/google/gwt/user/cellview/client/CellTable.java (revision
8835)
+++ user/src/com/google/gwt/user/cellview/client/CellTable.java (working
copy)
@@ -44,6 +44,7 @@
import com.google.gwt.view.client.SelectionModel;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -411,6 +412,7 @@
* Indicates whether or not a redraw is scheduled.
*/
private boolean redrawScheduled;
+ private RowStyles<T> rowStyles;
private final Style style;
private final TableElement table;
private final TableSectionElement tbody;
@@ -767,6 +769,14 @@
return;
}
ensureTableColElement(index).removeClassName(styleName);
+ }
+
+ /**
+ * Sets the object used to determine how a row is styled; the change
will take
+ * effect the next time that the table is rendered.
+ */
+ public void setRowStyles(RowStyles<T> rowStyles) {
+ this.rowStyles = rowStyles;
}
@Override
@@ -791,6 +801,16 @@
String trClasses = i % 2 == 0 ? evenRowStyle : oddRowStyle;
if (isSelected) {
trClasses += selectedRowStyle;
+ }
+
+ if (rowStyles != null) {
+ Collection<String> extraRowStyles = rowStyles.getStyleNames(value);
+ if (extraRowStyles != null) {
+ for (String extraRowStyle : extraRowStyles) {
+ trClasses += " ";
+ trClasses += extraRowStyle;
+ }
+ }
}
SafeHtmlBuilder trBuilder = new SafeHtmlBuilder();
Index: user/src/com/google/gwt/user/cellview/client/RowStyles.java
===================================================================
--- user/src/com/google/gwt/user/cellview/client/RowStyles.java (revision 0)
+++ user/src/com/google/gwt/user/cellview/client/RowStyles.java (revision 0)
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.user.cellview.client;
+
+import java.util.Collection;
+
+/**
+ * A description of how rows are to be styled in a {...@link CellTable}.
+ *
+ * @param <T> the data type of each row
+ */
+public interface RowStyles<T> {
+
+ /**
+ * Get extra style names that should be applied to the given row.
+ *
+ * @return the extra styles of the given row, or {...@code null} if there
are no
+ * extra styles for this row.
+ */
+ public Collection<String> getStyleNames(T row);
+}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors