Skip to content

Commit d4fffe4

Browse files
BananeweizenCalixte
authored andcommitted
Issue #510: Open description hyperlinks in external browser
Also change the new hyperlinks in the preference page to always use the external browser, because people might not even notice the browser tab _behind_ the preference dialog.
1 parent 0ec0bae commit d4fffe4

File tree

3 files changed

+69
-12
lines changed

3 files changed

+69
-12
lines changed

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/CheckConfigurationConfigureDialog.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import net.sf.eclipsecs.ui.CheckstyleUIPluginImages;
4040
import net.sf.eclipsecs.ui.CheckstyleUIPluginPrefs;
4141
import net.sf.eclipsecs.ui.Messages;
42+
import net.sf.eclipsecs.ui.util.InternalBrowser;
4243
import net.sf.eclipsecs.ui.util.SWTUtil;
4344
import net.sf.eclipsecs.ui.util.table.EnhancedCheckBoxTableViewer;
4445
import net.sf.eclipsecs.ui.util.table.ITableComparableProvider;
@@ -73,6 +74,8 @@
7374
import org.eclipse.osgi.util.NLS;
7475
import org.eclipse.swt.SWT;
7576
import org.eclipse.swt.browser.Browser;
77+
import org.eclipse.swt.browser.LocationAdapter;
78+
import org.eclipse.swt.browser.LocationEvent;
7679
import org.eclipse.swt.custom.SashForm;
7780
import org.eclipse.swt.events.KeyEvent;
7881
import org.eclipse.swt.events.KeyListener;
@@ -213,6 +216,17 @@ protected Control createDialogArea(Composite parent) {
213216
gridData = new GridData(GridData.FILL_BOTH);
214217
gridData.heightHint = 100;
215218
mBrowserDescription.setLayoutData(gridData);
219+
mBrowserDescription.addLocationListener(new LocationAdapter() {
220+
@Override
221+
public void changing(LocationEvent event) {
222+
String url = event.location;
223+
if (url == null || !url.startsWith("http")) {
224+
return;
225+
}
226+
InternalBrowser.openLinkInExternalBrowser(url);
227+
event.doit = false;
228+
}
229+
});
216230

217231
// initialize the data
218232
initialize();

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePage.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
package net.sf.eclipsecs.ui.preferences;
2222

23-
import java.net.MalformedURLException;
24-
import java.net.URL;
2523
import java.util.Collection;
2624

2725
import org.eclipse.core.resources.IProject;
@@ -49,9 +47,6 @@
4947
import org.eclipse.swt.widgets.Text;
5048
import org.eclipse.ui.IWorkbench;
5149
import org.eclipse.ui.IWorkbenchPreferencePage;
52-
import org.eclipse.ui.PartInitException;
53-
import org.eclipse.ui.PlatformUI;
54-
import org.eclipse.ui.browser.IWebBrowser;
5550
import org.osgi.service.prefs.BackingStoreException;
5651

5752
import com.puppycrawl.tools.checkstyle.Main;
@@ -61,13 +56,13 @@
6156
import net.sf.eclipsecs.core.builder.CheckstyleBuilder;
6257
import net.sf.eclipsecs.core.config.CheckConfigurationFactory;
6358
import net.sf.eclipsecs.core.config.ICheckConfigurationWorkingSet;
64-
import net.sf.eclipsecs.core.util.CheckstyleLog;
6559
import net.sf.eclipsecs.core.util.CheckstylePluginException;
6660
import net.sf.eclipsecs.ui.CheckstyleUIPlugin;
6761
import net.sf.eclipsecs.ui.CheckstyleUIPluginImages;
6862
import net.sf.eclipsecs.ui.CheckstyleUIPluginPrefs;
6963
import net.sf.eclipsecs.ui.Messages;
7064
import net.sf.eclipsecs.ui.config.CheckConfigurationWorkingSetEditor;
65+
import net.sf.eclipsecs.ui.util.InternalBrowser;
7166
import net.sf.eclipsecs.ui.util.SWTUtil;
7267

7368
/**
@@ -176,12 +171,7 @@ private void linkClicked(Event event) {
176171
if (Character.isDigit(event.text.charAt(0))) {
177172
url = url + "/releasenotes.html#Release_" + getCheckstyleVersion();
178173
}
179-
try {
180-
final IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser(null);
181-
browser.openURL(new URL(url));
182-
} catch (PartInitException | MalformedURLException ex) {
183-
CheckstyleLog.log(ex);
184-
}
174+
InternalBrowser.openLinkInExternalBrowser(url);
185175
}
186176

187177
/**
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//============================================================================
2+
//
3+
// Copyright (C) 2003-2023 the original author or authors.
4+
//
5+
// This library is free software; you can redistribute it and/or
6+
// modify it under the terms of the GNU Lesser General Public
7+
// License as published by the Free Software Foundation; either
8+
// version 2.1 of the License, or (at your option) any later version.
9+
//
10+
// This library is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
// Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public
16+
// License along with this library; if not, write to the Free Software
17+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+
//
19+
//============================================================================
20+
21+
package net.sf.eclipsecs.ui.util;
22+
23+
import java.net.MalformedURLException;
24+
import java.net.URL;
25+
26+
import org.eclipse.ui.PartInitException;
27+
import org.eclipse.ui.PlatformUI;
28+
import org.eclipse.ui.browser.IWebBrowser;
29+
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
30+
31+
import net.sf.eclipsecs.core.util.CheckstyleLog;
32+
33+
/**
34+
* Wrapper of the Eclipse internal browser.
35+
*/
36+
public final class InternalBrowser {
37+
38+
private InternalBrowser() {
39+
// utility class
40+
}
41+
42+
/**
43+
* Open a link in an external browser, independent of the Eclipse browser settings.
44+
*/
45+
public static final void openLinkInExternalBrowser(String url) {
46+
try {
47+
final IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser(IWorkbenchBrowserSupport.AS_EXTERNAL, null, null, null);
48+
browser.openURL(new URL(url));
49+
} catch (PartInitException | MalformedURLException ex) {
50+
CheckstyleLog.log(ex);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)