27
27
import java .awt .event .WindowAdapter ;
28
28
import java .awt .event .WindowEvent ;
29
29
import java .util .Objects ;
30
- import javax .swing .JButton ;
31
- import javax .swing .JCheckBox ;
32
- import javax .swing .JComboBox ;
33
- import javax .swing .JComponent ;
34
- import javax .swing .JLabel ;
35
- import javax .swing .JPanel ;
36
- import javax .swing .KeyStroke ;
30
+ import javax .swing .*;
37
31
import org .jetbrains .annotations .NotNull ;
38
32
39
33
@ SuppressWarnings ({"PMD.TooManyFields" , "PMD.ExcessiveImports" })
@@ -44,7 +38,9 @@ public class ConfigurationDialog extends AbstractDialog {
44
38
45
39
private JCheckBox enable ;
46
40
private LabeledComponent <TextFieldWithBrowseButton > modulePath ;
41
+ private LabeledComponent <TextFieldWithBrowseButton > additionalPath ;
47
42
private JCheckBox ignoreCurrentVersion ;
43
+ private JCheckBox hasAdditionalPath ;
48
44
private JComboBox <ComboBoxItemData > currentVersion ;
49
45
private JComboBox <ComboBoxItemData > targetVersion ;
50
46
private JComboBox <ComboBoxItemData > issueSeverityLevel ;
@@ -59,6 +55,8 @@ public class ConfigurationDialog extends AbstractDialog {
59
55
private JLabel modulePathError ;//NOPMD
60
56
private JLabel enableComment ;//NOPMD
61
57
private JLabel enableCommentPath ;//NOPMD
58
+ private JLabel additionalPathLabel ;//NOPMD
59
+ private JLabel additionalPathError ;//NOPMD
62
60
63
61
/**
64
62
* Configuration dialog.
@@ -76,6 +74,7 @@ public ConfigurationDialog(final @NotNull Project project) {
76
74
setTitle (ConfigureUctAction .ACTION_NAME );
77
75
getRootPane ().setDefaultButton (buttonOk );
78
76
77
+ hasAdditionalPath .addActionListener (event -> refreshAdditionalFields (hasAdditionalPath .isSelected ()));
79
78
buttonOk .addActionListener (event -> onOK ());
80
79
buttonCancel .addActionListener (event -> onCancel ());
81
80
@@ -98,9 +97,13 @@ public void windowClosing(final WindowEvent event) {
98
97
modulePathError .setText ("" );
99
98
modulePathError .setFont (UIUtil .getLabelFont (UIUtil .FontSize .SMALL ));
100
99
modulePathError .setForeground (new Color (252 , 119 , 83 ));
100
+ additionalPathError .setText ("" );
101
+ additionalPathError .setFont (UIUtil .getLabelFont (UIUtil .FontSize .SMALL ));
102
+ additionalPathError .setForeground (new Color (252 , 119 , 83 ));
101
103
enableComment .setForeground (JBColor .blue );
102
104
enableCommentPath .setForeground (JBColor .blue );
103
105
setDefaultValues ();
106
+ refreshAdditionalFields (hasAdditionalPath .isSelected ());
104
107
}
105
108
106
109
/**
@@ -120,12 +123,19 @@ public static void open(final @NotNull Project project) {
120
123
*/
121
124
private void onOK () {
122
125
modulePathError .setText ("" );
126
+ additionalPathError .setText ("" );
123
127
124
128
if (modulePath .getComponent ().getText ().isEmpty ()
125
129
|| !UctModulePathValidatorUtil .validate (modulePath .getComponent ().getText ())) {
126
130
modulePathError .setText ("The `Path To Analyse` field is empty or invalid" );
127
131
return ;
128
132
}
133
+ if (hasAdditionalPath .isSelected () && additionalPath .getComponent ().getText ().isEmpty ()
134
+ || hasAdditionalPath .isSelected ()
135
+ && !UctModulePathValidatorUtil .validate (additionalPath .getComponent ().getText ())) {
136
+ additionalPathError .setText ("The `Path To Analyse` field is empty or invalid" );
137
+ return ;
138
+ }
129
139
settingsService .setEnabled (enable .isSelected ());
130
140
131
141
final ComboBoxItemData currentVersionItemData =
@@ -155,7 +165,8 @@ private void onOK() {
155
165
)
156
166
);
157
167
settingsService .setIgnoreCurrentVersion (ignoreCurrentVersion .isSelected ());
158
-
168
+ settingsService .setHasAdditionalPath (hasAdditionalPath .isSelected ());
169
+ settingsService .setAdditionalPath (additionalPath .getComponent ().getText ());
159
170
exit ();
160
171
}
161
172
@@ -221,6 +232,15 @@ private void setDefaultValues() {
221
232
}
222
233
final Boolean shouldIgnore = settingsService .shouldIgnoreCurrentVersion ();
223
234
ignoreCurrentVersion .setSelected (Objects .requireNonNullElse (shouldIgnore , false ));
235
+
236
+ final Boolean isShowAdditionalPath = settingsService .getHasAdditionalPath ();
237
+ hasAdditionalPath .setSelected (
238
+ Objects .requireNonNullElse (isShowAdditionalPath , false )
239
+ );
240
+
241
+ if (settingsService .getAdditionalPath () != null ) {
242
+ additionalPath .getComponent ().setText (settingsService .getAdditionalPath ());
243
+ }
224
244
}
225
245
226
246
/**
@@ -271,5 +291,20 @@ private void createUIComponents() {
271
291
new FileChooserDescriptor (false , true , false , false , false , false )
272
292
)
273
293
);
294
+
295
+ additionalPath = new LabeledComponent <>();
296
+ additionalPath .setComponent (new TextFieldWithBrowseButton ());
297
+ additionalPath .getComponent ().addBrowseFolderListener (
298
+ new TextBrowseFolderListener (
299
+ new FileChooserDescriptor (false , true , false , false , false , false )
300
+ )
301
+ );
302
+ }
303
+
304
+ private void refreshAdditionalFields (final boolean isEnabled ) {
305
+ additionalPath .setEnabled (isEnabled );
306
+ additionalPath .setVisible (isEnabled );
307
+ additionalPathLabel .setVisible (isEnabled );
308
+ additionalPathError .setVisible (isEnabled );
274
309
}
275
310
}
0 commit comments