Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 419044

Summary: Support markup in tooltip (Control#setToolTipText)
Product: [RT] RAP Reporter: davide dav <teabof>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: dev, gregor.rosenauer, ivan, mknauer, tbuschto
Version: 2.2   
Target Milestone: 2.2 M3   
Hardware: PC   
OS: Linux   
Whiteboard:

Description davide dav CLA 2013-10-09 10:37:47 EDT
Currently (RAP 2.2 M2) tooltip doesn't support markup and text alignment.
Could you add these features?
Comment 1 Tim Buschtoens CLA 2013-10-10 04:02:03 EDT
Are you talking about the ToolTip widget or the property ToolTipText?
Comment 2 davide dav CLA 2013-10-10 04:12:54 EDT
the property ToolTipText.

this is sample code

TableViewerColumn tableViewerColumn = new TableViewerColumn(
				checkboxTableViewer_grantor, SWT.NONE);
TableColumn tblclmnName = tableViewerColumn.getColumn();
tblclmnName.setText("Name");
tableViewerColumn.setLabelProvider(new ColumnLabelProvider() 
{
  public String getText(Object element) 
{
  return Util.getName(element);
}

@Override
public String getToolTipText(Object element) 
{
  String s= "Name:"+Util.getName(element)+"\nType: ";
	s+= Util.getType(element);
  return s;
}});
		
		ColumnViewerToolTipSupport.enableFor(tableViewerColumn.getViewer());
Comment 3 Tim Buschtoens CLA 2013-10-10 04:37:43 EDT
Enabling markup for tooltips is generally a good idea and not too difficult, but we may need some time to come up with an API. We can not simply enable it by default because some some code may use "<"/">" without escaping. 

While we're at it, I think it would also be cool to support links in tooltips, but for that we would need to be able to change the behavior that tooltips disappear when hovered. (Or just turn it of when an "<a>" tag exists.)

Alignment could be a theme property, though it currently could only be enabled globally, not on a per-widget basis. (We have the same issue if we would want to configure other aspects like timeout by theming.)
Comment 4 Ivan Furnadjiev CLA 2013-11-01 08:10:16 EDT
Added markup support with commit 6b95f0afc60fa0e8fbdd35daf6d8c6a7a80cb37f. <a> tag is supported, but currently not clickable as tooltip disappears when you move the mouse - we will look on it in the next days. Currently markup in tooltip is enabled with provisional constant RWT.TOOLTIP_MARKUP_ENABLED like:
button.setData( RWT.TOOLTIP_MARKUP_ENABLED, Boolean.TRUE );
Comment 5 Markus Knauer CLA 2013-11-01 13:17:53 EDT
Great. Can't wait to test it. I hope I find some time next week.
Comment 6 Ivan Furnadjiev CLA 2013-11-04 04:21:09 EST
Added CSS property "text-align" to Widget-ToolTip element with commit  449c53049873204b7627c35449353e6f40ef39a0.
Comment 7 Sebastian Habenicht CLA 2014-02-19 08:58:06 EST
(In reply to Ivan Furnadjiev from comment #6)
> Added CSS property "text-align" to Widget-ToolTip element with commit 
> 449c53049873204b7627c35449353e6f40ef39a0.

(In reply to Ivan Furnadjiev from comment #4)
> Added markup support with commit 6b95f0afc60fa0e8fbdd35daf6d8c6a7a80cb37f.
> <a> tag is supported, but currently not clickable as tooltip disappears when
> you move the mouse - we will look on it in the next days. Currently markup
> in tooltip is enabled with provisional constant RWT.TOOLTIP_MARKUP_ENABLED
> like:
> button.setData( RWT.TOOLTIP_MARKUP_ENABLED, Boolean.TRUE );

Hi Ivan,

I wonder if this feature is also supported for tool tips created by ColumnViewerToolTipSupport (as can be seen in the sample code from comment 2).

Using this feature for widgets which have the property ToolTipText works (e.g. buttons or texts), but it does not seem to work when providing tool tip text with markup from CellLabelProvider.getToolTipText. 
I tried setting RWT.TOOLTIP_MARKUP_ENABLED to the viewer and to the underlying control after creating the viewer, both ways failed. Am I doing something wrong?

Thanks for a short comment on this!

Regards,
Sebastian
Comment 8 Gregor Rosenauer CLA 2015-04-01 10:16:12 EDT
same problem here, I'd need to format tooltips in my TableViewerColumn's getToolTipText() method, but the text is presented as is, with formatting tags unparsed.
Can we please have this feature fully implemented, not just for simple (widget.setToolTipText()) cases?
Comment 9 Ivan Furnadjiev CLA 2015-04-01 10:38:26 EDT
(In reply to Gregor Rosenauer from comment #8)
> same problem here, I'd need to format tooltips in my TableViewerColumn's
> getToolTipText() method, but the text is presented as is, with formatting
> tags unparsed.
> Can we please have this feature fully implemented, not just for simple
> (widget.setToolTipText()) cases?

Markup in Table column tooltip is supported in RAP. You must set RWT.TOOLTIP_MARKUP_ENABLED to the column like:
column.setData( RWT.TOOLTIP_MARKUP_ENABLED, Boolean.TRUE );
Comment 10 Gregor Rosenauer CLA 2015-04-01 11:00:02 EDT
no, sadly does not work, try the sample code from comment #2 or this one:

TableViewerColumn nameColumn = new TableViewerColumn(myTableViewer, SWT.NONE);
nameColumn.setLabelProvider(new ColumnLabelProvider() {
    ...
    @Override
    public String getToolTipText(Object element) {
        return "<b>bold</b> tooltips yey!";
    }

will just open a normal tooltip with the literal text <b>bold</b>...
Comment 11 Ivan Furnadjiev CLA 2015-04-01 11:47:50 EDT
(In reply to comment #10)
> no, sadly does not work, try the sample code from comment #2 or this one:
> 
> TableViewerColumn nameColumn = new TableViewerColumn(myTableViewer, SWT.NONE);
> nameColumn.setLabelProvider(new ColumnLabelProvider() {
> ...
> @Override
> public String getToolTipText(Object element) {
> return "<b>bold</b> tooltips yey!";
> }
> 
> will just open a normal tooltip with the literal text <b>bold</b>...
If you want markup in cell tooltips you have to enable it on the table like:
tableViewer.getTable().setData( RWT.TOOLTIP_MARKUP_ENABLED, Boolean.TRUE );

For markup in column header tooltip, enable it on table column:
tableColumnViewer.getColumn().setData( RWT.TOOLTIP_MARKUP_ENABLED, Boolean.TRUE );

Just tested it with our Controls Demo -> TableViewer Tab and both are working fine in RAP 3.0M6.