Write your custom cell (here an example I wrote based on GWT ActionCell) :
public abstract class ActionTextCell<C> extends AbstractCell<C> {
public static interface Delegate<T> {
void execute(T object);
}
private final Delegate<C> delegate;
public ActionTextCell(Delegate<C> delegate) {
super("click", "keydown");
this.delegate = delegate;
}
@Override
protected void onEnterKeyDown(Context context, Element parent, C value, NativeEvent event,
ValueUpdater<C> valueUpdater) {
delegate.execute(value);
}
@Override
public void onBrowserEvent(Context context, Element parent, C value, NativeEvent event, ValueUpdater<C> valueUpdater) {
super.onBrowserEvent(context, parent, value, event, valueUpdater);
if ("click".equals(event.getType())) {
onEnterKeyDown(context, parent, value, event, valueUpdater);
}
}
@Override
public void render(Context context, C value, SafeHtmlBuilder sb) {
sb.append(new SafeHtmlBuilder().appendHtmlConstant("<span>" + render(value) + "</span>")
.toSafeHtml());
}
public abstract String render(C value);
}
And use it within an IndentityColumn which you add to your CellTable:
final ActionTextCell<MyClass> cell = new ActionTextCell<MyClass>(new ActionTextCell.Delegate<MyClass>() {
@Override
public void execute(MyClass c) {
// do something with c
}
}) {
@Override
public String render(MyClass c) {
// return a string representation of c
}
};
final IdentityColumn<MyClass> column = new IdentityColumn<MyClass>(cell);
ClickableTextCell. A good way to find out of all the cells you can use is to go to the Cell interface and press F4 on it in Eclipse to see the class hierarchy. There are many cells already provided to you, and if none of them suit your needs, you can always write your own. - Strelok