基本的に、 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
を my のコンストラクターに渡すことAbstractCell
です。もっとエレガントな方法はありませんか(すでにCellTableに渡しています)。
主な質問は、
「Cell または Column から CellTable 変数にアクセスするにはどうすればよいですか?」ということだと思います。