0

I'd like to determine whether an icon is used based on the value of the "row" value that is in the CellTable (or DataGrid). How do I determine that when building the Cell renderer?

IconCellDecorator<String> icd = new IconCellDecorator<String>(res.search(), new ClickableTextCell()) {
  @Override
  protected boolean isIconUsed(String value) {
    //value may not be unique across rows (column value), I really need the row instance here.
  }
};
Joel
  • 2,601
  • 4
  • 33
  • 44
  • It appears to me that I really want the decorator to take my row type, but then the ClickableTextCell won't know how to get the string value it needs. It appears I have to write a custom IconCellDecorator, but thought there was possibly a cleaner solution. – Joel Jun 26 '12 at 15:35
  • Just realized that render() has a context which gives an index and key... Thinking this might help. – Joel Jun 26 '12 at 16:35

2 Answers2

1

If you need the row object, you'll have to use an IconCellDecorator<RowObject>, and wrap or subclass the ClickableTextCell to extract the String out of the RowObject.

Or you could use a CompositeCell and ImageResourceCell instead of the IconCellDecorator.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Wrapping/subclassing ClickableTextCell looks like the awkward part. It s not really meant to handle non-text. I'll look if CompositeCell makes sense. (I've actually made my own IconDecorator that doesn't show a blank area when the icon isn't used. so might need to refactor) – Joel Jun 26 '12 at 16:27
0

I decided to rewrite IconCellDecorator so that the getImageUsed method passes in the Context object, which gives me the row index and key. This seemed the most straightforward for specifically what I was trying to accomplish, although Thomas' answer should work as well.

Joel
  • 2,601
  • 4
  • 33
  • 44