|
1 | 1 | package io.gitlab.arturbosch.detekt.config;
|
2 | 2 |
|
3 |
| -import com.intellij.openapi.fileChooser.*; |
4 |
| -import com.intellij.openapi.ui.*; |
5 |
| -import com.intellij.openapi.util.*; |
6 |
| -import com.intellij.ui.*; |
| 3 | +import com.intellij.openapi.fileChooser.FileChooserDescriptor; |
| 4 | +import com.intellij.openapi.ui.TextComponentAccessor; |
| 5 | +import com.intellij.openapi.ui.TextFieldWithBrowseButton; |
| 6 | +import com.intellij.openapi.util.Comparing; |
| 7 | +import com.intellij.ui.IdeBorderFactory; |
| 8 | +import org.jetbrains.annotations.NotNull; |
| 9 | + |
7 | 10 | import javax.swing.*;
|
8 |
| -import org.jetbrains.annotations.*; |
9 | 11 |
|
10 | 12 | /**
|
11 | 13 | * @author Dmytro Primshyts
|
12 | 14 | */
|
13 | 15 | public class DetektConfigurationForm {
|
14 |
| - private JCheckBox enableDetekt; |
15 |
| - private JCheckBox checkTestSources; |
16 |
| - private JComboBox detektVersion; |
17 |
| - private TextFieldWithBrowseButton configurationFilePath; |
18 |
| - private JPanel myMainPanel; |
19 |
| - |
20 |
| - private DetektConfigStorage detektConfigStorage; |
21 |
| - |
22 |
| - @NotNull |
23 |
| - public JComponent createPanel(@NotNull DetektConfigStorage detektConfigStorage) { |
24 |
| - this.detektConfigStorage = detektConfigStorage; |
25 |
| - |
26 |
| - myMainPanel.setBorder(IdeBorderFactory.createTitledBorder("Detekt settings")); |
| 16 | + private JCheckBox enableDetekt; |
| 17 | + private JCheckBox checkTestSources; |
| 18 | + private TextFieldWithBrowseButton configurationFilePath; |
| 19 | + private JPanel myMainPanel; |
| 20 | + private JCheckBox treatAsErrors; |
27 | 21 |
|
28 |
| - FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor( |
29 |
| - true, |
30 |
| - false, |
31 |
| - false, |
32 |
| - false, |
33 |
| - false, |
34 |
| - false); |
| 22 | + private DetektConfigStorage detektConfigStorage; |
35 | 23 |
|
36 |
| - configurationFilePath.addBrowseFolderListener( |
37 |
| - "", |
38 |
| - "Detekt rules file", |
39 |
| - null, |
40 |
| - fileChooserDescriptor, |
41 |
| - TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT |
42 |
| - ); |
| 24 | + @NotNull |
| 25 | + public JComponent createPanel(@NotNull DetektConfigStorage detektConfigStorage) { |
| 26 | + this.detektConfigStorage = detektConfigStorage; |
43 | 27 |
|
44 |
| - return myMainPanel; |
45 |
| - } |
| 28 | + myMainPanel.setBorder(IdeBorderFactory.createTitledBorder("Detekt settings")); |
46 | 29 |
|
47 |
| - public void apply() { |
48 |
| - detektConfigStorage.setEnableDetekt(enableDetekt.isSelected()); |
49 |
| - detektConfigStorage.setCheckTestFiles(checkTestSources.isSelected()); |
| 30 | + FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor( |
| 31 | + true, |
| 32 | + false, |
| 33 | + false, |
| 34 | + false, |
| 35 | + false, |
| 36 | + false); |
50 | 37 |
|
51 |
| - Object selectedDetektVersion = detektVersion.getSelectedItem(); |
| 38 | + configurationFilePath.addBrowseFolderListener( |
| 39 | + "", |
| 40 | + "Detekt rules file", |
| 41 | + null, |
| 42 | + fileChooserDescriptor, |
| 43 | + TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT |
| 44 | + ); |
52 | 45 |
|
53 |
| - if (selectedDetektVersion != null) { |
54 |
| - detektConfigStorage.setDetektVersion(selectedDetektVersion.toString()); |
55 |
| - } else { |
56 |
| - detektConfigStorage.setDetektVersion(""); |
57 |
| - } |
| 46 | + return myMainPanel; |
| 47 | + } |
58 | 48 |
|
59 |
| - detektConfigStorage.setRulesPath(configurationFilePath.getText()); |
60 |
| - } |
| 49 | + public void apply() { |
| 50 | + detektConfigStorage.setEnableDetekt(enableDetekt.isSelected()); |
| 51 | + detektConfigStorage.setCheckTestFiles(checkTestSources.isSelected()); |
| 52 | + detektConfigStorage.setTreatAsError(treatAsErrors.isSelected()); |
| 53 | + detektConfigStorage.setRulesPath(configurationFilePath.getText()); |
| 54 | + } |
61 | 55 |
|
62 |
| - public void reset() { |
63 |
| - enableDetekt.setSelected(detektConfigStorage.getEnableDetekt()); |
64 |
| - checkTestSources.setSelected(detektConfigStorage.getCheckTestFiles()); |
65 |
| - configurationFilePath.setText(detektConfigStorage.getRulesPath()); |
66 |
| - } |
| 56 | + public void reset() { |
| 57 | + enableDetekt.setSelected(detektConfigStorage.getEnableDetekt()); |
| 58 | + checkTestSources.setSelected(detektConfigStorage.getCheckTestFiles()); |
| 59 | + treatAsErrors.setSelected(detektConfigStorage.getTreatAsError()); |
| 60 | + configurationFilePath.setText(detektConfigStorage.getRulesPath()); |
| 61 | + } |
67 | 62 |
|
68 |
| - public boolean isModified() { |
69 |
| - return !Comparing.equal(detektConfigStorage.getEnableDetekt(), enableDetekt.isSelected()) |
70 |
| - || !Comparing.equal(detektConfigStorage.getCheckTestFiles(), checkTestSources.isSelected()) |
71 |
| - || !Comparing.equal(detektConfigStorage.getDetektVersion(), detektVersion.getSelectedItem()) |
72 |
| - || !Comparing.equal(detektConfigStorage.getRulesPath(), configurationFilePath.getText()); |
73 |
| - } |
| 63 | + public boolean isModified() { |
| 64 | + return !Comparing.equal(detektConfigStorage.getEnableDetekt(), enableDetekt.isSelected()) |
| 65 | + || !Comparing.equal(detektConfigStorage.getCheckTestFiles(), checkTestSources.isSelected()) |
| 66 | + || !Comparing.equal(detektConfigStorage.getTreatAsError(), treatAsErrors.isSelected()) |
| 67 | + || !Comparing.equal(detektConfigStorage.getRulesPath(), configurationFilePath.getText()); |
| 68 | + } |
74 | 69 | }
|
0 commit comments