我在简单的TextCell()中有一个包含多列的CellTable.其中两列是通过ClickableTextCell()类"可点击"的,但我想改变它们的外观.什么是使单元格内容类似于锚标记的最简单方法,同时仍然使用表格中的单元格?
我尝试了以下内容:1.实现自定义渲染器以添加锚标签2.搜索Google寻找提示3.忽略'我的库做它你只需要更改整个框架'链接4.滚动我的头他们的键盘
有趣的是这个简单的改变是多么令人讨厌.
我目前的想法是实现一个自定义的AnchorCell类型,它放入一个Anchor小部件,而不是它在其他小部件中做的任何事情,但我不确定所有需要做的事情.
任何帮助表示赞赏.
举个例子:
public class MyClickableCellText extends ClickableTextCell {
String style;
public MyClickableCellText()
{
super();
style = "myClickableCellTestStyle";
}
@Override
protected void render(Context context, SafeHtml value, SafeHtmlBuilder sb) {
if (value != null) {
sb.appendHtmlConstant("<div class=\""+style+"\">");
sb.append(value);
sb.appendHtmlConstant("</div>");
}
}
public void addStyleName(String style)
{
this.style = style;
}
}
Run Code Online (Sandbox Code Playgroud)
风格(没有div,因为你正在硬编码它的风格):
.myClickableCellTestStyle{
text-decoration:underline;
}
Run Code Online (Sandbox Code Playgroud)
您甚至可以通过不扩展ClickableTextCell但扩展AbstractCell来创建自己的单元格(更强大但需要更多解释).问你是否需要它!
小智 5
提到的解决方案有问题,这些没有链接和样式表与:悬停等等不起作用.
这是我的解决方案:
private class SellerName {
private final String sellerName;
private final Command cmd;
private SellerName(String displayName, Command cmd) {
this.sellerName = displayName;
this.cmd = cmd;
}
public String getDisplayName() {
return sellerName;
}
public Command getCommand() {
return cmd;
}
};
private class SellerNameCell extends AbstractCell<SellerName> {
public SellerNameCell() {
super("click", "keydown");
}
@Override
public void render(com.google.gwt.cell.client.Cell.Context context, SellerName value, SafeHtmlBuilder sb) {
if (value != null) {
sb.appendHtmlConstant("<a href='javascript:;'>");
sb.appendEscaped(value.getDisplayName());
sb.appendHtmlConstant("</a>");
}
}
@Override
public void onBrowserEvent(Context context, Element parent, SellerName value, NativeEvent event, ValueUpdater<SellerName> valueUpdater) {
if (value == null)
return;
super.onBrowserEvent(context, parent, value, event, valueUpdater);
if ("click".equals(event.getType())) {
if (value.getCommand() != null)
value.getCommand().execute();
}
}
};
Run Code Online (Sandbox Code Playgroud)
它创建了一个可点击的真正的锚单元:)