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