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

Bug 347436

Summary: Add support for links in table cells
Product: [RT] RAP Reporter: Ivan Motsch <ivan.motsch>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: claudio.guglielmo, ivan, stephan.leichtvogt
Version: 1.5   
Target Milestone: 2.1 M1   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 401305    
Attachments:
Description Flags
example screen
none
patch for org.eclipse.rap.rwt
none
patch for org.eclipse.rap.rwt.q07
none
Patch as stated in comment 6
none
Patch for org.eclipse.rap.rwt
none
Patch for org.eclipse.rap.rwt
none
Patch for org.eclipse.rap.rwt none

Description Ivan Motsch CLA 2011-05-27 07:46:34 EDT
Created attachment 196744 [details]
example screen

This ticket is based on ticket https://bugs.eclipse.org/bugs/show_bug.cgi?id=346768

Based on supporting inline html inside table cells, the last thing missing is hyperlink support.

The attached patch enables this using the ITableExtensionAdapter. Adds a HtmlHyperlinkListener and a corresponding event.

An example on how this will look like is also attached. Note the multiline table header, the multiline table rows as well as the link support.

The attached screenshot was created using:
tableExtensionAdadpter.setItemTextHeight(40);
tableExtensionAdadpter.addHtmlHyperlinkListener(...);

and the cell text is of the form:
<html>... <a href="...>a link</a> ...</html>


Tested on Chrome, Firefox and IE8, IE9.

I marked the ticket as blocker as did Andy in bugzilla 346768 since this is related to the "RWT between SWT and Web2.0" discussions (This ticket adds web2.0 functionality to rwt without the need of changing SWT api or functionality).
Comment 1 Ivan Motsch CLA 2011-05-27 07:47:21 EDT
Created attachment 196745 [details]
patch for org.eclipse.rap.rwt
Comment 2 Ivan Motsch CLA 2011-05-27 07:48:04 EDT
Created attachment 196746 [details]
patch for org.eclipse.rap.rwt.q07
Comment 3 Ivan Furnadjiev CLA 2011-05-30 10:47:15 EDT
I think that you can achieve the same behavior with TableEditor - see SWT snippets:
http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet149.java?view=co
but use Link widget instead of ProgressBar. Does it fit your needs?
Comment 4 Ivan Motsch CLA 2011-05-30 16:14:05 EDT
(In reply to comment #3)
> I think that you can achieve the same behavior with TableEditor - see SWT
> snippets:
> http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet149.java?view=co
> but use Link widget instead of ProgressBar. Does it fit your needs?

Thanks for the hint. I tried the Link field before. For pure swt it does what it can in swt, but for rwt (with focus to web20 and inline html) it lacks the following:
- just one line of text, no multiline support
- missing support for bold, italic and other markups
- missing support for rich alignments (table etc.)

I could create a composite inside the cell and add multiple lables, links etc to it (for my case i needed approx 8 labels, 4 link fields and 3 composites per cell). But when having a table with approx. 1000 such rows, this results in a javascript error on the web page (overflow).

As mentioned above i understand that rwt is sitting between (strict) swt and web20/browser. If it would be possible in any way to add my patch to rwt i would be very grateful, since i see rwt as much more powerful than just "rendering swt". Swt disappointed so many developers with its strict reduced set of capabilities when coompared to swing or modern web technologies.

But with rwt i see light at the end of the tunnel that swt (with rwt as web2.0 extension) can make the race with other major web20 tools. Lets go:)
Comment 5 Ivan Furnadjiev CLA 2011-05-31 03:07:43 EDT
Yes... I see your point. I have some questions in mind about your patch, but Ralf already asked most of them in bug 346768 comment #8. I will change the severity of this bug to "enhancement" as well.
Comment 6 Stephan Leicht Vogt CLA 2011-10-24 08:27:35 EDT
I updated the patch from Ivan Motsch and set the priority to P2. Our products rely on this enhancement.
The patch works for itself. It does not rely on solving bug 346768. I hope you could review this patch and commit it for the 1.5 release.
Comment 7 Stephan Leicht Vogt CLA 2011-10-24 08:29:06 EDT
Created attachment 205806 [details]
Patch as stated in comment 6

Creator Ivan Motsch<ivan.motsch@bsiag.com>
Comment 8 Ralf Sternberg CLA 2011-10-25 07:01:00 EDT
Thanks for the patch, Stephan. I have some comments:

This issue requests hyperlinks that trigger an event, just like in the SWT Link widget. If we go this way, should we limit the feature to links, or should we allow to embed widgets into table cells? As an example, checkboxes in table cells are also a common case. What do you think?

To keep things simple, I would like to have markup to contain only "real" links, not those that trigger events, at least in the first version. 

Resetting priority to default. Please leave the prioritization to the RAP committers. EclipseSource offers professional support in case you need certain fixes urgently.
Comment 9 Ivan Furnadjiev CLA 2012-03-29 05:41:34 EDT
With the bug 346768 fixed, "real" links are now supported in table items.
Comment 10 Stephan Leicht Vogt CLA 2012-04-13 03:40:52 EDT
Created attachment 213960 [details]
Patch for org.eclipse.rap.rwt

I updated the patch. The idea is to write <span tabindex="1" class="link" style="text-decoration:underline;" href="http://local/...">Local link</span> into a table to get an link which calls the server with an HyperLinkEvent.
Comment 11 Claudio Guglielmo CLA 2012-05-16 10:53:33 EDT
Created attachment 215715 [details]
Patch for org.eclipse.rap.rwt

Since the list does now support markup too (https://bugs.eclipse.org/bugs/show_bug.cgi?id=377890) it would be great if links were possible not only for tables but also for lists.

The new patch contains list support as well as some improvements (event synchronization, firing on mouse up instead of mouse down).

It would be great if you consider these requirements if you plan to implement such a feature.
Comment 12 Stephan Leicht Vogt CLA 2012-06-15 10:12:58 EDT
Created attachment 217428 [details]
Patch for org.eclipse.rap.rwt

Works with current git-head. (just after tree->grid change)
Comment 13 Ivan Furnadjiev CLA 2013-02-13 04:25:09 EST
Fixed in master with commit 08f32b9e8af31faa44edede2ae75428233e43346. If the target of the hyperlink is set to "_rwt", default hyperlink behavior will be suppressed and a selection event will be fired on the server-side with event.detail == RWT.HYPERLINK and event.text == <href or text if href is missing>. Snippet:
...
Table table = new Table( parent, SWT.NONE );
table.setData( RWT.MARKUP_ENABLED, Boolean.TRUE );
table.addSelectionListener( new SelectionAdapter() {
  public void widgetSelected( SelectionEvent event ) {
    if( event.detail == RWT.HYPERLINK ) {
      System.out.println( "Hyperlink clicked: " + event.text ); // event text contains "http://www.eclipse.org"
    }
  }
});
TableItem item = new TableItem( table, SWT.NONE );
tem.setText( "<a href=\"http://www.eclipse.org\" target=\"_rwt\">Eclipse.org</a>" );
....
Note: Click on a hyperlink will not select the item. This behavior is similar to a click on the item checkbox. Hyperlinks with target different from "_rwt" will behave as "real" hyperlinks - open page in browser.
Comment 14 Claudio Guglielmo CLA 2013-02-15 03:59:48 EST
Thank you very much for implementing this! It works very well, also with the list.

I think not to select the row if a hyperlink gets clicked was a good decision.  But actually I have to select the row on a hyperlink click. To do so I use the event.item to select the row by my self, which works fine for the table. But it does not for the list because the event.item is always null. Is this done by purpose? Is there another possibility to get the selected list item?
Comment 15 Ivan Furnadjiev CLA 2013-02-15 04:10:17 EST
(In reply to comment #14)
> Thank you very much for implementing this! It works very well, also with the
> list.
> 
> I think not to select the row if a hyperlink gets clicked was a good
> decision.  But actually I have to select the row on a hyperlink click. To do
> so I use the event.item to select the row by my self, which works fine for
> the table. But it does not for the list because the event.item is always
> null. Is this done by purpose? Is there another possibility to get the
> selected list item?

There is no ListItem widget - SelectionEvent#item is a widget.
Comment 16 Claudio Guglielmo CLA 2013-02-15 04:30:59 EST
(In reply to comment #15)
> (In reply to comment #14)
> > Thank you very much for implementing this! It works very well, also with the
> > list.
> > 
> > I think not to select the row if a hyperlink gets clicked was a good
> > decision.  But actually I have to select the row on a hyperlink click. To do
> > so I use the event.item to select the row by my self, which works fine for
> > the table. But it does not for the list because the event.item is always
> > null. Is this done by purpose? Is there another possibility to get the
> > selected list item?
> 
> There is no ListItem widget - SelectionEvent#item is a widget.

Ok, that's why. But how can I select the row which contains the hyperlink? Can I somehow get the position of the click? Event.x and y are always 2.
Comment 17 Ivan Furnadjiev CLA 2013-02-15 05:15:05 EST
One idea that comes to my mind is to encode the the list item data (index or item text) in the link href. As href is not a real link location you could put there whatever you want - id, index etc...
Comment 18 Claudio Guglielmo CLA 2013-02-18 07:31:38 EST
(In reply to comment #17)
> One idea that comes to my mind is to encode the the list item data (index or
> item text) in the link href. As href is not a real link location you could
> put there whatever you want - id, index etc...

Thanks, that works.