Skip to content

Commit 0ec0bae

Browse files
BananeweizenCalixte
authored andcommitted
Have hyperlinks in preference page title
Make the project name and version number clickable hyperlinks. They open the homepage respectively release notes, using the default browser settings of Eclipse.
1 parent 4210089 commit 0ec0bae

File tree

2 files changed

+53
-24
lines changed

2 files changed

+53
-24
lines changed

net.sf.eclipsecs.ui/META-INF/MANIFEST.MF

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Bundle-Vendor: Eclipse Checkstyle Project
77
Bundle-Activator: net.sf.eclipsecs.ui.CheckstyleUIPlugin
88
Bundle-ActivationPolicy: lazy
99
Require-Bundle: net.sf.eclipsecs.core,
10-
org.eclipse.core.expressions
10+
org.eclipse.core.expressions,
11+
org.eclipse.ui.workbench,
12+
org.eclipse.jface
1113
Bundle-RequiredExecutionEnvironment: JavaSE-11
1214
Bundle-Localization: plugin
1315
Export-Package: net.sf.eclipsecs.ui,

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

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,14 @@
2020

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

23+
import java.net.MalformedURLException;
24+
import java.net.URL;
2325
import java.util.Collection;
24-
import net.sf.eclipsecs.core.CheckstylePluginPrefs;
25-
import net.sf.eclipsecs.core.builder.CheckerFactory;
26-
import net.sf.eclipsecs.core.builder.CheckstyleBuilder;
27-
import net.sf.eclipsecs.core.config.CheckConfigurationFactory;
28-
import net.sf.eclipsecs.core.config.ICheckConfigurationWorkingSet;
29-
import net.sf.eclipsecs.core.util.CheckstylePluginException;
30-
import net.sf.eclipsecs.ui.CheckstyleUIPlugin;
31-
import net.sf.eclipsecs.ui.CheckstyleUIPluginImages;
32-
import net.sf.eclipsecs.ui.CheckstyleUIPluginPrefs;
33-
import net.sf.eclipsecs.ui.Messages;
34-
import net.sf.eclipsecs.ui.config.CheckConfigurationWorkingSetEditor;
35-
import net.sf.eclipsecs.ui.util.SWTUtil;
3626

3727
import org.eclipse.core.resources.IProject;
3828
import org.eclipse.jface.dialogs.IDialogConstants;
3929
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
30+
import org.eclipse.jface.layout.RowLayoutFactory;
4031
import org.eclipse.jface.preference.PreferencePage;
4132
import org.eclipse.osgi.util.NLS;
4233
import org.eclipse.swt.SWT;
@@ -51,15 +42,34 @@
5142
import org.eclipse.swt.widgets.Combo;
5243
import org.eclipse.swt.widgets.Composite;
5344
import org.eclipse.swt.widgets.Control;
45+
import org.eclipse.swt.widgets.Event;
5446
import org.eclipse.swt.widgets.Group;
5547
import org.eclipse.swt.widgets.Label;
48+
import org.eclipse.swt.widgets.Link;
5649
import org.eclipse.swt.widgets.Text;
5750
import org.eclipse.ui.IWorkbench;
5851
import org.eclipse.ui.IWorkbenchPreferencePage;
52+
import org.eclipse.ui.PartInitException;
53+
import org.eclipse.ui.PlatformUI;
54+
import org.eclipse.ui.browser.IWebBrowser;
5955
import org.osgi.service.prefs.BackingStoreException;
6056

6157
import com.puppycrawl.tools.checkstyle.Main;
6258

59+
import net.sf.eclipsecs.core.CheckstylePluginPrefs;
60+
import net.sf.eclipsecs.core.builder.CheckerFactory;
61+
import net.sf.eclipsecs.core.builder.CheckstyleBuilder;
62+
import net.sf.eclipsecs.core.config.CheckConfigurationFactory;
63+
import net.sf.eclipsecs.core.config.ICheckConfigurationWorkingSet;
64+
import net.sf.eclipsecs.core.util.CheckstyleLog;
65+
import net.sf.eclipsecs.core.util.CheckstylePluginException;
66+
import net.sf.eclipsecs.ui.CheckstyleUIPlugin;
67+
import net.sf.eclipsecs.ui.CheckstyleUIPluginImages;
68+
import net.sf.eclipsecs.ui.CheckstyleUIPluginPrefs;
69+
import net.sf.eclipsecs.ui.Messages;
70+
import net.sf.eclipsecs.ui.config.CheckConfigurationWorkingSetEditor;
71+
import net.sf.eclipsecs.ui.util.SWTUtil;
72+
6373
/**
6474
* This class represents a preference page that is contributed to the Preferences dialog. By
6575
* subclassing <samp>FieldEditorPreferencePage </samp>, we can use the field support built into
@@ -104,30 +114,26 @@ public class CheckstylePreferencePage extends PreferencePage implements IWorkben
104114
* Constructor.
105115
*/
106116
public CheckstylePreferencePage() {
107-
setDescription(NLS.bind(Messages.CheckstylePreferencePage_version, getCheckstyleVersion()));
108117
setPreferenceStore(CheckstyleUIPlugin.getDefault().getPreferenceStore());
109118

110119
mWorkingSet = CheckConfigurationFactory.newWorkingSet();
111-
initializeDefaults();
120+
noDefaultAndApplyButton();
112121
}
113122

114123
private String getCheckstyleVersion() {
115124
return Main.class.getPackage().getImplementationVersion();
116125
}
117126

118-
/**
119-
* Sets the default values of the preferences.
120-
*/
121-
private static void initializeDefaults() {
122-
}
123-
124127
@Override
125128
public Control createContents(Composite ancestor) {
126-
127-
noDefaultAndApplyButton();
129+
// the description with hyperlinks at the top
130+
Composite oneRowComposite = new Composite(ancestor, SWT.NULL);
131+
var oneRowLayout = RowLayoutFactory.fillDefaults().extendedMargins(0, 0, 0, 5).type(SWT.VERTICAL).create();
132+
oneRowComposite.setLayout(oneRowLayout);
133+
createTitleWithLink(oneRowComposite);
128134

129135
//
130-
// Build the top level composite with one colume.
136+
// Build the top level composite with one column.
131137
//
132138
Composite parentComposite = new Composite(ancestor, SWT.NULL);
133139
FormLayout layout = new FormLayout();
@@ -157,6 +163,27 @@ public Control createContents(Composite ancestor) {
157163
return parentComposite;
158164
}
159165

166+
private void createTitleWithLink(Composite parent) {
167+
Link link = new Link(parent, SWT.NONE);
168+
var text = NLS.bind(Messages.CheckstylePreferencePage_version, "<a>" + getCheckstyleVersion() + "</a>");
169+
text = text.replace("Checkstyle", "<a>Checkstyle</a>");
170+
link.setText(text);
171+
link.addListener(SWT.Selection, this::linkClicked);
172+
}
173+
174+
private void linkClicked(Event event) {
175+
String url = "https://checkstyle.org";
176+
if (Character.isDigit(event.text.charAt(0))) {
177+
url = url + "/releasenotes.html#Release_" + getCheckstyleVersion();
178+
}
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+
}
185+
}
186+
160187
/**
161188
* Create the area with the general preference settings.
162189
*

0 commit comments

Comments
 (0)