|
20 | 20 |
|
21 | 21 | package net.sf.eclipsecs.ui.preferences; |
22 | 22 |
|
| 23 | +import java.net.MalformedURLException; |
| 24 | +import java.net.URL; |
23 | 25 | 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; |
36 | 26 |
|
37 | 27 | import org.eclipse.core.resources.IProject; |
38 | 28 | import org.eclipse.jface.dialogs.IDialogConstants; |
39 | 29 | import org.eclipse.jface.dialogs.MessageDialogWithToggle; |
| 30 | +import org.eclipse.jface.layout.RowLayoutFactory; |
40 | 31 | import org.eclipse.jface.preference.PreferencePage; |
41 | 32 | import org.eclipse.osgi.util.NLS; |
42 | 33 | import org.eclipse.swt.SWT; |
|
51 | 42 | import org.eclipse.swt.widgets.Combo; |
52 | 43 | import org.eclipse.swt.widgets.Composite; |
53 | 44 | import org.eclipse.swt.widgets.Control; |
| 45 | +import org.eclipse.swt.widgets.Event; |
54 | 46 | import org.eclipse.swt.widgets.Group; |
55 | 47 | import org.eclipse.swt.widgets.Label; |
| 48 | +import org.eclipse.swt.widgets.Link; |
56 | 49 | import org.eclipse.swt.widgets.Text; |
57 | 50 | import org.eclipse.ui.IWorkbench; |
58 | 51 | import org.eclipse.ui.IWorkbenchPreferencePage; |
| 52 | +import org.eclipse.ui.PartInitException; |
| 53 | +import org.eclipse.ui.PlatformUI; |
| 54 | +import org.eclipse.ui.browser.IWebBrowser; |
59 | 55 | import org.osgi.service.prefs.BackingStoreException; |
60 | 56 |
|
61 | 57 | import com.puppycrawl.tools.checkstyle.Main; |
62 | 58 |
|
| 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 | + |
63 | 73 | /** |
64 | 74 | * This class represents a preference page that is contributed to the Preferences dialog. By |
65 | 75 | * subclassing <samp>FieldEditorPreferencePage </samp>, we can use the field support built into |
@@ -104,30 +114,26 @@ public class CheckstylePreferencePage extends PreferencePage implements IWorkben |
104 | 114 | * Constructor. |
105 | 115 | */ |
106 | 116 | public CheckstylePreferencePage() { |
107 | | - setDescription(NLS.bind(Messages.CheckstylePreferencePage_version, getCheckstyleVersion())); |
108 | 117 | setPreferenceStore(CheckstyleUIPlugin.getDefault().getPreferenceStore()); |
109 | 118 |
|
110 | 119 | mWorkingSet = CheckConfigurationFactory.newWorkingSet(); |
111 | | - initializeDefaults(); |
| 120 | + noDefaultAndApplyButton(); |
112 | 121 | } |
113 | 122 |
|
114 | 123 | private String getCheckstyleVersion() { |
115 | 124 | return Main.class.getPackage().getImplementationVersion(); |
116 | 125 | } |
117 | 126 |
|
118 | | - /** |
119 | | - * Sets the default values of the preferences. |
120 | | - */ |
121 | | - private static void initializeDefaults() { |
122 | | - } |
123 | | - |
124 | 127 | @Override |
125 | 128 | 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); |
128 | 134 |
|
129 | 135 | // |
130 | | - // Build the top level composite with one colume. |
| 136 | + // Build the top level composite with one column. |
131 | 137 | // |
132 | 138 | Composite parentComposite = new Composite(ancestor, SWT.NULL); |
133 | 139 | FormLayout layout = new FormLayout(); |
@@ -157,6 +163,27 @@ public Control createContents(Composite ancestor) { |
157 | 163 | return parentComposite; |
158 | 164 | } |
159 | 165 |
|
| 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 | + |
160 | 187 | /** |
161 | 188 | * Create the area with the general preference settings. |
162 | 189 | * |
|
0 commit comments