2

I want to use GWT-Bootstrap Tooltip for cells of a column in the CellTable. Each Tooltip will show description of a cell which is a field in the "MyCustomObject" class used for generating the table.

One of the quick solutions I found in one of the answers on this question is the following.

CellTable<MyCustomObject> table = new CellTable<MyCustomObject>();

table.addCellPreviewHandler(new Handler<MyCustomObject>() {
    @Override
    public void onCellPreview(CellPreviewEvent<MyCustomObject> event) {
        if (event.getNativeEvent().getType().equals("mouseover")){
            table.getRowElement(event.getIndex()).getCells()
                .getItem(event.getColumn()).setTitle(event.getValue().getDescription());
            }
        }
    }
);

It makes a little sense but I don't see anything when I hover the cursor over the table cells and nothing is attached to the DOM. Can anyone explain how this even works? I want to attach the Tooltip to table cell similar to the following.

Tooltip tt = new Tooltip("Here goes the description");
tt.setAnimation(true);
tt.setWidget(tableColumn);
tt.reconfigure();

The problem is that a CellTable cell is not a widget so it can't be attached in that way.

So is there any workaround for this?

Community
  • 1
  • 1
CobaltBabyBear
  • 2,188
  • 6
  • 26
  • 47

1 Answers1

0

I've faced this issue once and I created my own cell that displays a tooltip, here's how I did it: Note: My cell was displaying an image with a tooltip so I quickly changed the code to display String text... So I did not test it with text.

private class TooltipCell extends AbstractCell<String> {
      private String tooltipText = "";

      @Override
      public void render(Context context, String value, SafeHtmlBuilder sb) {
        if (value != null) {
            sb.appendHtmlConstant("<div title=\"" + tooltipText + "\">");
          sb.append(SafeHtmlUtils.fromString(value));
        }
      }

      public void setTooltip(String tootltipTextToSet){
          tooltipText = tootltipTextToSet;
      }
    }

And in your table use method setTooltip("tooltip text") in method getValue just before returning the cell text.

Hope this helps

Youssef Lahoud
  • 529
  • 3
  • 8