I have created a custom cell that determines whether to display a SelectionCell
or TextCell
. In the case of a SelectionCell
render, I am unable to get the setFieldUpdater
method to fire.
Code below...
private class CustomTypeCell extends AbstractCell<String>
{
SelectionCell selectCell = new SelectionCell(cardMnemonics);
TextCell textCell = new TextCell();
@Override
public void render(
Context context,
String value, SafeHtmlBuilder sb)
{
if (value != null)
{
textCell.render(context, value, sb);
}
else
{
selectCell.render(context, "", sb);
}
}
}
private class CustomTypeColumn extends Column<Object, String>
{
public CustomTypeColumn(CustomTypeCell cell)
{
super(cell);
}
@Override
public String getValue(Object object)
{
return object.getStringValue();
}
}
Implemented using...
CustomTypeCell cell = new CustomTypeCell();
CustomTypeColumn customCol = new CustomTypeColumn(cell);
customCol.setFieldUpdater(new FieldUpdater<Object, String>()
{
public void update(int index, Object object, String value)
{
object.setStringValue(value);
// perform action }
});
cellTable.addColumn(customCol, "Custom Column");
This works fine if i use a standard Column with SelectionCell
.
Rendering is not enough, you also want to delegate the event handling to the appropriate cell implementation: add your if/else construct into onBrowserEvent
, and make sure you listen for the appropriate events in getConsumedEvents
.
You should probably also implement resetFocus
.
You'll probably find inspiration in the CompositeCell
code.