0

I've a custom image cell in a CellTree. I want to render two different images depending on the row/node selection state, for example if the row/node is selected I want to render image A if not selected image B. The images couple is different for each node.

What is the best way to get the selection state in the render method of the cell?

Fedy2
  • 3,147
  • 4
  • 26
  • 44

1 Answers1

1

CSS solution

If you can work with background images here, the easiest and most efficient solution would be CSS based.

Take a look at /com/google/gwt/user/cellview/client/CellTree.css (in gwt-user.jar). There you see the css classes ".cellTreeItem" and ".cellTreeSelectedItem". The latter one already has an image. You could assign it your own, and for ".cellTreeItem" a different one.

For general information how to adjust CellTable/CellTree/... styles, see e.g. https://stackoverflow.com/a/6387210/291741

Cell solution

You could construct your cell with the SelectionModel like

public MyCell(SelectionModel selectionModel) {
  this.selectionModel = selectionModel;
}

public void render(final Cell.Context context, final Node value,
    final SafeHtmlBuilder sb) {

  if (selectionModel.isSelected(...
}

However, you will probably need to retrigger the cell rendering when the selection changes. It's probably possible, but I've never done that.

Community
  • 1
  • 1
Chris Lercher
  • 37,264
  • 20
  • 99
  • 131
  • Unfortunately the CSS solution is not possible because images couples are different for each node. I will update the question with the constraint. – Fedy2 Dec 04 '13 at 10:51
  • Nice the selection model solution. – Fedy2 Dec 04 '13 at 10:52