作者TonyQ (沉默是金。)
看板Eclipse
标题[闲聊] How to write a hyperlink in Eclipse Plug-in
时间Sat Mar 19 05:16:03 2011
I mean to write a link to allow user click and
open system browser to view the page.
(Like official help page , reference link ....etc)
Like this image
http://goo.gl/GRAz0
You could use Link widget ( org.eclipse.swt.widgets.Link )
The routine is ,
1. create a link widget
2. set text with <a> tag(just like html)
3. add selection listener , (the e.text will be the herf from tag)
4. open browser.
The following sample code below.
===========
Link link = new Link( parent, style );
link.setText("<a href=\"
http://www.google.com.tw\">hello hyperlink</a>");
link.addSelectionListener(new SelectionListener(){
public void widgetSelected(SelectionEvent e) {
if(e.text!=null && !"".equals(e.text)){
try {
BrowserUtil.openSystemBrowser(null, e.text,false);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
public void widgetDefaultSelected(SelectionEvent e) {
//do nothing
}
});
=============
the browser util class
=============
public class BrowserUtil {
public static IWebBrowser openSystemBrowser(String browserid, String
url,boolean embed) {
try {
IWorkbenchBrowserSupport browserSupport =
PlatformUI.getWorkbench().getBrowserSupport();
IWebBrowser browser = null;
if(embed){
browser = browserSupport.createBrowser(browserid); //$NON-NLS-1$
}else{
browser = browserSupport.getExternalBrowser();
}
browser.openURL(new URL(url));
return browser;
} catch (Exception e) {
return null;
}
}
}
--
网页上拉近距离的帮手 实现 GMail丰富应用的功臣
数也数不清的友善使用者体验 这就是javascript
欢迎同好到 AJAX 板一同讨论。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 198.203.175.175
※ 编辑: TonyQ 来自: 198.203.175.175 (03/25 03:49)