基本上我想实现类似于GWT 文档中定义的单元格着色的东西
但是,我不想直接在 DIV 元素上指定样式,而是想从我CSSResource
为 CellTable 定义的自定义中分配一个混淆样式名。
这是一些代码:
Resources
我为我的 CellTable定义了一个自定义接口:
public interface CellTableResources extends Resources {
@Source({CellTable.Style.DEFAULT_CSS,CellTableStyle.STYLE})
CellTableStyle cellTableStyle();
public interface CellTableStyle extends Style {
String STYLE = "CellTable.css";
public Sring coloredCell();
}
}
我将它传递给我的 CellTable 的构造函数:
CellTable<XY> table = new CellTable<XY>(15,cellTableResources);
这就是我的自定义单元格的样子。
public class ColorCell extends AbstractCell<String> {
interface Templates extends SafeHtmlTemplates {
@SafeHtmlTemplates.Template("<div class=\"{0}\">{1}</div>")
SafeHtml cell(String classname, SafeHtml value);
}
private static Templates templates = GWT.create(Templates.class);
@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
if (value == null) {
return;
}
// how can I access the CSSResources which I pass to the CellTable
CellTableResources ressources = ?
String className = ressources.cellTableStyle().coloredCell();
SafeHtml safeValue = SafeHtmlUtils.fromString(value);
SafeHtml rendered = templates.cell(className, safeValue);
sb.append(rendered);
}
}
如何访问我CellTableRessources
在自定义单元格中传递给 CellTable 的内容?这是重要的部分:
// how can I access the CSSResources which I pass to the CellTable
CellTableResources ressources = ?
String className = ressources.cellTableStyle().coloredCell();
我想出的唯一解决方案是将 传递CellTableRessources
给我的AbstractCell
. 没有更优雅的方式吗(我已经将它传递给了 CellTable)。
我认为主要问题是:
“如何从单元格或列访问 CellTable 变量?”