11
11
import com .intellij .ui .DocumentAdapter ;
12
12
import com .magento .idea .magento2plugin .actions .generation .InjectAViewModelAction ;
13
13
import com .magento .idea .magento2plugin .actions .generation .data .ViewModelFileData ;
14
- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .InjectAViewModelDialogValidator ;
14
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
15
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
16
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .AlphanumericRule ;
17
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .DirectoryRule ;
18
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
19
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .PhpClassRule ;
15
20
import com .magento .idea .magento2plugin .actions .generation .generator .ModuleViewModelClassGenerator ;
16
21
import com .magento .idea .magento2plugin .actions .generation .generator .code .ClassArgumentInXmlConfigGenerator ;
17
22
import com .magento .idea .magento2plugin .actions .generation .generator .util .NamespaceBuilder ;
21
26
import com .magento .idea .magento2plugin .util .FirstLetterToLowercaseUtil ;
22
27
import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
23
28
import java .awt .event .ActionEvent ;
24
- import java .awt .event .ActionListener ;
25
29
import java .awt .event .KeyEvent ;
26
30
import java .awt .event .WindowAdapter ;
27
31
import java .awt .event .WindowEvent ;
35
39
import javax .swing .event .DocumentEvent ;
36
40
import org .jetbrains .annotations .NotNull ;
37
41
42
+ @ SuppressWarnings ({
43
+ "PMD.ExcessiveImports"
44
+ })
38
45
public class InjectAViewModelDialog extends AbstractDialog {
39
46
@ NotNull
40
47
private final Project project ;
41
- @ NotNull
42
- private final InjectAViewModelDialogValidator validator ;
43
48
private final XmlTag targetBlockTag ;
44
49
private JPanel contentPane ;
45
50
private JButton buttonOK ;
46
51
private JButton buttonCancel ;
47
- private JTextField viewModelClassName ;
48
- private JTextField viewModelDirectory ;
49
52
private final CommonBundle commonBundle ;
50
53
private final ValidatorBundle validatorBundle ;
51
- private JTextField viewModelArgumentName ;
52
54
private JLabel inheritClassLabel ;//NOPMD
53
55
private JLabel viewModelDirectoryLabel ;//NOPMD
54
56
private JLabel viewModelClassNameLabel ;//NOPMD
55
57
private JLabel viewModelArgumentNameLabel ;//NOPMD
58
+ private static final String CLASS_NAME = "class name" ;
59
+ private static final String DIRECTORY = "directory" ;
60
+ private static final String ARGUMENT_NAME = "argument name" ;
61
+
62
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
63
+ message = {NotEmptyRule .MESSAGE , CLASS_NAME })
64
+ @ FieldValidation (rule = RuleRegistry .PHP_CLASS ,
65
+ message = {PhpClassRule .MESSAGE , CLASS_NAME })
66
+ private JTextField viewModelClassName ;
67
+
68
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
69
+ message = {NotEmptyRule .MESSAGE , DIRECTORY })
70
+ @ FieldValidation (rule = RuleRegistry .DIRECTORY ,
71
+ message = {DirectoryRule .MESSAGE , DIRECTORY })
72
+ private JTextField viewModelDirectory ;
73
+
74
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
75
+ message = {NotEmptyRule .MESSAGE , ARGUMENT_NAME })
76
+ @ FieldValidation (rule = RuleRegistry .ALPHANUMERIC ,
77
+ message = {AlphanumericRule .MESSAGE , ARGUMENT_NAME })
78
+ private JTextField viewModelArgumentName ;
56
79
57
80
/**
58
81
* Constructor.
@@ -68,7 +91,6 @@ public InjectAViewModelDialog(
68
91
69
92
this .project = project ;
70
93
this .targetBlockTag = targetBlockTag ;
71
- this .validator = new InjectAViewModelDialogValidator (this );
72
94
this .validatorBundle = new ValidatorBundle ();
73
95
this .commonBundle = new CommonBundle ();
74
96
@@ -84,19 +106,8 @@ protected void textChanged(final @NotNull DocumentEvent event) {
84
106
setModal (true );
85
107
getRootPane ().setDefaultButton (buttonOK );
86
108
87
- buttonOK .addActionListener (new ActionListener () {
88
- @ Override
89
- public void actionPerformed (final ActionEvent event ) {
90
- onOK ();
91
- }
92
- });
93
-
94
- buttonCancel .addActionListener (new ActionListener () {
95
- @ Override
96
- public void actionPerformed (final ActionEvent event ) {
97
- onCancel ();
98
- }
99
- });
109
+ buttonOK .addActionListener ((final ActionEvent event ) -> onOK ());
110
+ buttonCancel .addActionListener ((final ActionEvent event ) -> onCancel ());
100
111
101
112
setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
102
113
addWindowListener (new WindowAdapter () {
@@ -106,13 +117,11 @@ public void windowClosing(final WindowEvent event) {
106
117
}
107
118
});
108
119
109
- contentPane .registerKeyboardAction (new ActionListener () {
110
- @ Override
111
- public void actionPerformed (final ActionEvent event ) {
112
- onCancel ();
113
- }
114
- }, KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
115
- JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
120
+ contentPane .registerKeyboardAction (
121
+ (final ActionEvent event ) -> onCancel (),
122
+ KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
123
+ JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
124
+ );
116
125
}
117
126
118
127
protected void updateArgumentText () {
@@ -123,7 +132,7 @@ protected void updateArgumentText() {
123
132
}
124
133
125
134
protected void onOK () {
126
- if (!validator . validate ( project )) {
135
+ if (!validateFormFields ( )) {
127
136
return ;
128
137
}
129
138
final String moduleName = GetModuleNameByDirectoryUtil .execute (
0 commit comments