10
10
import com .intellij .psi .PsiFile ;
11
11
import com .magento .idea .magento2plugin .actions .generation .NewControllerAction ;
12
12
import com .magento .idea .magento2plugin .actions .generation .data .ControllerFileData ;
13
- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .NewControllerValidator ;
13
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
14
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
15
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
16
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .PhpClassRule ;
17
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .PhpDirectoryRule ;
14
18
import com .magento .idea .magento2plugin .actions .generation .generator .ModuleControllerClassGenerator ;
15
19
import com .magento .idea .magento2plugin .magento .files .ControllerBackendPhp ;
16
20
import com .magento .idea .magento2plugin .magento .files .ControllerFrontendPhp ;
21
25
import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
22
26
import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
23
27
import java .awt .event .ActionEvent ;
24
- import java .awt .event .ActionListener ;
25
28
import java .awt .event .KeyEvent ;
26
29
import java .awt .event .WindowAdapter ;
27
30
import java .awt .event .WindowEvent ;
37
40
38
41
@ SuppressWarnings ({
39
42
"PMD.TooManyFields" ,
40
- "PMD.ConstructorCallsOverridableMethod"
43
+ "PMD.ConstructorCallsOverridableMethod" ,
44
+ "PMD.ExcessiveImports"
41
45
})
42
46
public class NewControllerDialog extends AbstractDialog {
43
- private final NewControllerValidator validator ;
44
47
private final String moduleName ;
45
48
private final Project project ;
46
49
private JPanel contentPane ;
47
50
private JButton buttonOK ;
48
51
private JButton buttonCancel ;
49
52
private FilteredComboBox controllerAreaSelect ;
50
53
private FilteredComboBox httpMethodSelect ;
51
- private JTextField controllerName ;
52
54
private JTextField controllerParentDir ;
53
55
private JCheckBox inheritClass ;
54
56
private JPanel adminPanel ;
55
57
private JTextField acl ;
58
+
59
+ private static final String CONTROLLER_NAME = "controller name" ;
60
+ private static final String ACTION_NAME = "action name" ;
61
+
62
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
63
+ message = {NotEmptyRule .MESSAGE , CONTROLLER_NAME })
64
+ @ FieldValidation (rule = RuleRegistry .PHP_DIRECTORY ,
65
+ message = {PhpDirectoryRule .MESSAGE , CONTROLLER_NAME })
66
+ private JTextField controllerName ;
67
+
68
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
69
+ message = {NotEmptyRule .MESSAGE , ACTION_NAME })
70
+ @ FieldValidation (rule = RuleRegistry .PHP_CLASS ,
71
+ message = {PhpClassRule .MESSAGE , ACTION_NAME })
56
72
private JTextField actionName ;
57
73
58
74
/**
@@ -65,7 +81,6 @@ public NewControllerDialog(final Project project, final PsiDirectory directory)
65
81
super ();
66
82
this .project = project ;
67
83
this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
68
- this .validator = NewControllerValidator .getInstance (this );
69
84
70
85
setContentPane (contentPane );
71
86
setModal (true );
@@ -87,11 +102,7 @@ public void windowClosing(final WindowEvent event) {
87
102
88
103
// call onCancel() on ESCAPE
89
104
contentPane .registerKeyboardAction (
90
- new ActionListener () {
91
- public void actionPerformed (final ActionEvent event ) {
92
- onCancel ();
93
- }
94
- },
105
+ (final ActionEvent event ) -> onCancel (),
95
106
KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
96
107
JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
97
108
);
@@ -178,7 +189,7 @@ public static void open(final Project project, final PsiDirectory directory) {
178
189
}
179
190
180
191
private void onOK () {
181
- if (!validator . validate ()) {
192
+ if (!validateFormFields ()) {
182
193
return ;
183
194
}
184
195
@@ -243,6 +254,7 @@ private Boolean getIsInheritClass() {
243
254
return inheritClass .isSelected ();
244
255
}
245
256
257
+ @ Override
246
258
protected void onCancel () {
247
259
dispose ();
248
260
}
0 commit comments