Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to add dynamic Hyperlink in SWT shell with eclipse(Hyperlink in SWT TableViewer)
How to add dynamic Hyperlink in SWT shell with eclipse [message #1830400] Fri, 24 July 2020 21:44 Go to next message
Eric Zuo is currently offline Eric ZuoFriend
Messages: 14
Registered: October 2014
Junior Member
Dear Experts,
I have SWT window, and it will launch another SWT shell with TableViewer containing a list of information from Oracle database, each row will have a hyperlink in TableColumn for details of this row.
The second shell is launched, The columns are correctly loaded with data from Oracle, but the link "https://..." does not clickable. I guess the https may be a issue.
I attached the function for the initialization..

One the web, all examples show link with hard coded URL, and actually those samples do not work for me either, links did not launch.
Could you please forward me example for dynamic composed hyperlink?
Thank you very much.

Eric

[Updated on: Fri, 24 July 2020 23:29]

Report message to a moderator

Re: How to add dynamic Hyperlink in SWT shell with eclipse [message #1830408 is a reply to message #1830400] Sat, 25 July 2020 06:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
If you want to open a browser, perhaps use IWorkbenchBrowserSupport instead:

https://git.eclipse.org/c/oomph/org.eclipse.oomph.git/tree/plugins/org.eclipse.oomph.ui/src/org/eclipse/oomph/internal/ui/EarlyStart.java#n140

You could use IWorkbenchBrowserSupport.AS_EXTERNAL to always launch an external browser if that's what you want.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to add dynamic Hyperlink in SWT shell with eclipse [message #1830418 is a reply to message #1830408] Sat, 25 July 2020 16:29 Go to previous messageGo to next message
Rolf Theunissen is currently offline Rolf TheunissenFriend
Messages: 260
Registered: April 2012
Senior Member
When using plain SWT, have a look at the snippets [1], it links to the git sources. Snippet182 and snippet183 (in the link category seem relevant), also Snippet137, Snippet327 and Snippet356 might help you. (search for 'link' on the snippet overview page)

[1] https://www.eclipse.org/swt/snippets/
Re: How to add dynamic Hyperlink in SWT shell with eclipse [message #1830544 is a reply to message #1830418] Tue, 28 July 2020 23:03 Go to previous messageGo to next message
Eric Zuo is currently offline Eric ZuoFriend
Messages: 14
Registered: October 2014
Junior Member
Thank Ed and Rolf for your response. For OOMPH, it is new environment, I installed it, will try late. The Snippets are good, I learned a lot from them. I modified the Snippet148 to my page displaying my web page. the problem is how to launch it.
The link still not reflect to click. I tried both in (TableItem) cell.getItem():
Link: link.addListener (SWT.Selection, event ->{
System.out.println(url); // url printed.
// sn148.open(); // does not work, crashed.
});

button: public void mouseDoubleClick(MouseEvent e) {
Snippet148 sn148 = new Snippet148();
sn148.setUrl(url);
sn148.open();
}
in both cases , it crashed. But Snippet148 runs well if I run it alone.

Experts please take a look, and kindly forward instruction.
My Eclipse : Oxygen.3a (4.7.3a), Window 64. Project: WindowBuilder/SWT Desiner/SWT/JFace Java Project
Thank you in advance.
Eric

public void initializeQui() {
TableViewer viewer = new TableViewer(HYSHOPWORKORDER);
viewer.getTable().setHeaderVisible(true);
viewer.getTable().setLinesVisible(true);
viewer.setContentProvider(new ArrayContentProvider());
loadWorkOrder lWO = new loadWorkOrder();
ArrayList<WorkOrder> workOrders = lWO.mxWorkOrderOf1Asset(carNo);
TableColumn column = null;
column = new TableColumn(viewer.getTable(), SWT.NONE);
column.setText("wonum");
column.setWidth(100);
TableViewerColumn Col1 = new TableViewerColumn(viewer, column);
Col1.setLabelProvider(new ColumnLabelProvider(){
String url= "";
String wonum ="";
@Override
public String getText(Object element) {
WorkOrder wo = (WorkOrder)element;
url=wo.getUrl();
wonum= wo.getWonum();
return wonum;
}
@Override
public void update(ViewerCell cell) {
TableItem item = (TableItem) cell.getItem();
Hyperlink hyperlink;
wonum = getText(cell.getElement());

Link link = new Link((Composite) cell.getControl(), SWT.NONE);
String text = "<a>" + wonum + "</a>";
link.setText(text);
Snippet148 sn148 = new Snippet148();
sn148.setUrl(url);
link.addListener (SWT.Selection, event ->{
System.out.println(url); // url printed.
// sn148.open(); // does not work, crashed.
}); // How to bring up Snippet148?

TableEditor editor = new TableEditor(item.getParent());
editor.grabHorizontal = true;
editor.grabVertical = true;
editor.setEditor(link , item, cell.getColumnIndex());
editor.layout();
}
});
// column2, colukmn3, column4
}
//Instead use Link, I used Button, still not worked:
Button aWorkOrder = new Button((Composite) cell.getControl(), SWT.NONE);
String text = wonum ;
aWorkOrder.setText(text);
aWorkOrder.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
Snippet148 sn148 = new Snippet148();
sn148.setUrl(url);
sn148.open(); // Does not work, crashed. How to bring up Snippet148?

}
});
Re: How to add dynamic Hyperlink in SWT shell with eclipse [message #1830545 is a reply to message #1830544] Tue, 28 July 2020 23:41 Go to previous message
Eric Zuo is currently offline Eric ZuoFriend
Messages: 14
Registered: October 2014
Junior Member
Hi All, my problem resolved. it is the first step. I have other question, will post in different topic.
The error is
final Display display = new Display (); changed to Display.getDefault() problem resolved.
Thank you. Thank Ed, thank Rolf .

Eric
Previous Topic:Why does F5 seem to do nothing, but "Refresh" does?
Next Topic:Changing preferences of Project Explorer in RCP
Goto Forum:
  


Current Time: Fri Apr 19 08:13:30 GMT 2024

Powered by FUDForum. Page generated in 0.01859 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top