" <a href=\"http://www.eclipse.org\">http://www.eclipse.org</a>: block link. Context menu \"Open in new Window\" creates a new tab.<br/>" + LS +
" <a href=\"http://www.yahoo.com\" target=\"_blank\">http://www.yahoo.com</a>: link normally opens in a new window but creates a new tab.<br/>" + LS +
" <a href=\"http://www.microsoft.com\">http://www.microsoft.com</a>: link and \"Open in new Window\" are blocked.<br/>" + LS +
" </body>" + LS +
"</html>");
webBrowser.addWebBrowserListener(new WebBrowserAdapter() {
@Override
public void locationChanging(WebBrowserNavigationEvent e) {
final String newResourceLocation = e.getNewResourceLocation();
if(newResourceLocation.startsWith("http://www.google.com/")) {
e.consume();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JWebBrowser webBrowser = new JWebBrowser();
JWebBrowserWindow webBrowserWindow = WebBrowserWindowFactory.create(webBrowser);
webBrowser.navigate(newResourceLocation);
webBrowserWindow.setVisible(true);
}
});
} else if(newResourceLocation.startsWith("http://java.sun.com/")) {
e.consume();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JWebBrowser webBrowser = new JWebBrowser();
webBrowser.navigate(newResourceLocation);
tabbedPane.addTab("java.sun.com", webBrowser);
}
});
} else if(newResourceLocation.startsWith("http://www.eclipse.org/")) {
e.consume();
} else if(newResourceLocation.startsWith("http://www.microsoft.com/")) {
e.consume();
}
}
@Override
public void windowWillOpen(WebBrowserWindowWillOpenEvent e) {
// We let the window to be created, but we will check the first location that is set on it.
e.getNewWebBrowser().addWebBrowserListener(new WebBrowserAdapter() {
@Override
public void locationChanging(WebBrowserNavigationEvent e) {
final JWebBrowser webBrowser = e.getWebBrowser();
webBrowser.removeWebBrowserListener(this);
String newResourceLocation = e.getNewResourceLocation();