1111import com .intellij .ui .DocumentAdapter ;
1212import com .magento .idea .magento2plugin .actions .generation .InjectAViewModelAction ;
1313import 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 ;
1520import com .magento .idea .magento2plugin .actions .generation .generator .ModuleViewModelClassGenerator ;
1621import com .magento .idea .magento2plugin .actions .generation .generator .code .ClassArgumentInXmlConfigGenerator ;
1722import com .magento .idea .magento2plugin .actions .generation .generator .util .NamespaceBuilder ;
2126import com .magento .idea .magento2plugin .util .FirstLetterToLowercaseUtil ;
2227import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
2328import java .awt .event .ActionEvent ;
24- import java .awt .event .ActionListener ;
2529import java .awt .event .KeyEvent ;
2630import java .awt .event .WindowAdapter ;
2731import java .awt .event .WindowEvent ;
3842public class InjectAViewModelDialog extends AbstractDialog {
3943 @ NotNull
4044 private final Project project ;
41- @ NotNull
42- private final InjectAViewModelDialogValidator validator ;
4345 private final XmlTag targetBlockTag ;
4446 private JPanel contentPane ;
4547 private JButton buttonOK ;
4648 private JButton buttonCancel ;
47- private JTextField viewModelClassName ;
48- private JTextField viewModelDirectory ;
4949 private final CommonBundle commonBundle ;
5050 private final ValidatorBundle validatorBundle ;
51- private JTextField viewModelArgumentName ;
5251 private JLabel inheritClassLabel ;//NOPMD
5352 private JLabel viewModelDirectoryLabel ;//NOPMD
5453 private JLabel viewModelClassNameLabel ;//NOPMD
5554 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 ;
5676
5777 /**
5878 * Constructor.
@@ -68,7 +88,6 @@ public InjectAViewModelDialog(
6888
6989 this .project = project ;
7090 this .targetBlockTag = targetBlockTag ;
71- this .validator = new InjectAViewModelDialogValidator (this );
7291 this .validatorBundle = new ValidatorBundle ();
7392 this .commonBundle = new CommonBundle ();
7493
@@ -84,19 +103,8 @@ protected void textChanged(final @NotNull DocumentEvent event) {
84103 setModal (true );
85104 getRootPane ().setDefaultButton (buttonOK );
86105
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 ());
100108
101109 setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
102110 addWindowListener (new WindowAdapter () {
@@ -106,13 +114,11 @@ public void windowClosing(final WindowEvent event) {
106114 }
107115 });
108116
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+ );
116122 }
117123
118124 protected void updateArgumentText () {
@@ -123,7 +129,7 @@ protected void updateArgumentText() {
123129 }
124130
125131 protected void onOK () {
126- if (!validator . validate ( project )) {
132+ if (!validateFormFields ( )) {
127133 return ;
128134 }
129135 final String moduleName = GetModuleNameByDirectoryUtil .execute (
0 commit comments