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 ;
38
42
public class InjectAViewModelDialog extends AbstractDialog {
39
43
@ NotNull
40
44
private final Project project ;
41
- @ NotNull
42
- private final InjectAViewModelDialogValidator validator ;
43
45
private final XmlTag targetBlockTag ;
44
46
private JPanel contentPane ;
45
47
private JButton buttonOK ;
46
48
private JButton buttonCancel ;
47
- private JTextField viewModelClassName ;
48
- private JTextField viewModelDirectory ;
49
49
private final CommonBundle commonBundle ;
50
50
private final ValidatorBundle validatorBundle ;
51
- private JTextField viewModelArgumentName ;
52
51
private JLabel inheritClassLabel ;//NOPMD
53
52
private JLabel viewModelDirectoryLabel ;//NOPMD
54
53
private JLabel viewModelClassNameLabel ;//NOPMD
55
54
private JLabel viewModelArgumentNameLabel ;//NOPMD
55
+ private static final String CLASS_NAME = "class name" ;
56
+ private static final String DIRECTORY = "directory" ;
57
+ private static final String ARGUMENT_NAME = "argument name" ;
58
+
59
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
60
+ message = {NotEmptyRule .MESSAGE , CLASS_NAME })
61
+ @ FieldValidation (rule = RuleRegistry .PHP_CLASS ,
62
+ message = {PhpClassRule .MESSAGE , CLASS_NAME })
63
+ private JTextField viewModelClassName ;
64
+
65
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
66
+ message = {NotEmptyRule .MESSAGE , DIRECTORY })
67
+ @ FieldValidation (rule = RuleRegistry .DIRECTORY ,
68
+ message = {DirectoryRule .MESSAGE , DIRECTORY })
69
+ private JTextField viewModelDirectory ;
70
+
71
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
72
+ message = {NotEmptyRule .MESSAGE , ARGUMENT_NAME })
73
+ @ FieldValidation (rule = RuleRegistry .ALPHANUMERIC ,
74
+ message = {AlphanumericRule .MESSAGE , ARGUMENT_NAME })
75
+ private JTextField viewModelArgumentName ;
56
76
57
77
/**
58
78
* Constructor.
@@ -68,7 +88,6 @@ public InjectAViewModelDialog(
68
88
69
89
this .project = project ;
70
90
this .targetBlockTag = targetBlockTag ;
71
- this .validator = new InjectAViewModelDialogValidator (this );
72
91
this .validatorBundle = new ValidatorBundle ();
73
92
this .commonBundle = new CommonBundle ();
74
93
@@ -84,19 +103,8 @@ protected void textChanged(final @NotNull DocumentEvent event) {
84
103
setModal (true );
85
104
getRootPane ().setDefaultButton (buttonOK );
86
105
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
- });
106
+ buttonOK .addActionListener ((final ActionEvent event ) -> onOK ());
107
+ buttonCancel .addActionListener ((final ActionEvent event ) -> onCancel ());
100
108
101
109
setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
102
110
addWindowListener (new WindowAdapter () {
@@ -106,13 +114,11 @@ public void windowClosing(final WindowEvent event) {
106
114
}
107
115
});
108
116
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 );
117
+ contentPane .registerKeyboardAction (
118
+ (final ActionEvent event ) -> onCancel (),
119
+ KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
120
+ JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
121
+ );
116
122
}
117
123
118
124
protected void updateArgumentText () {
@@ -123,7 +129,7 @@ protected void updateArgumentText() {
123
129
}
124
130
125
131
protected void onOK () {
126
- if (!validator . validate ( project )) {
132
+ if (!validateFormFields ( )) {
127
133
return ;
128
134
}
129
135
final String moduleName = GetModuleNameByDirectoryUtil .execute (
0 commit comments