How can to open a url on external browser using a relative path from a customized Eclipse Welcome page plugin?
The following code is an example of what I have so far from the intro.xml, which is working OK for Linux but doesn't work for Windows.
<link
label="Documentation"
url="http://org.eclipse.ui.intro/openBrowser?url=file:../documentation/index.html"
id="link-img-documentation"
style-id="content-link">
<text>Read documentation.</text>
</link>
CodePudding user response:
One alternative way is to use http://org.eclipse.ui.intro/runAction
and create a class that implements IIntroAction
Overall, you will need to do two things.
- Add a class that implements
IIntroAction
public class OpenFileInBrowser implements IIntroAction {
@Override
public void run(IIntroSite site, Properties params) {
if (params.containsKey("filePath") ){
String filePath = params.getProperty("filePath");
String workingDir = System.getProperty("user.dir");
String urlString = "file://" workingDir File.separator filePath;
try {
IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
IWebBrowser browser = browserSupport.getExternalBrowser();
URL url = new URL(urlString);
browser.openURL(url);
} catch (Exception e) {
}
}
}
}
- Update url in the link tag as following:
url="http://org.eclipse.ui.intro/runAction?pluginId=x.y.z&class=x.y.z.OpenFileInBrowser&filePath=../documentation/index.html"