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 ;
3539import javax .swing .event .DocumentEvent ;
3640import org .jetbrains .annotations .NotNull ;
3741
42+ @ SuppressWarnings ({
43+ "PMD.ExcessiveImports"
44+ })
3845public class InjectAViewModelDialog extends AbstractDialog {
3946 @ NotNull
4047 private final Project project ;
41- @ NotNull
42- private final InjectAViewModelDialogValidator validator ;
4348 private final XmlTag targetBlockTag ;
4449 private JPanel contentPane ;
4550 private JButton buttonOK ;
4651 private JButton buttonCancel ;
47- private JTextField viewModelClassName ;
48- private JTextField viewModelDirectory ;
4952 private final CommonBundle commonBundle ;
5053 private final ValidatorBundle validatorBundle ;
51- private JTextField viewModelArgumentName ;
5254 private JLabel inheritClassLabel ;//NOPMD
5355 private JLabel viewModelDirectoryLabel ;//NOPMD
5456 private JLabel viewModelClassNameLabel ;//NOPMD
5557 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 ;
5679
5780 /**
5881 * Constructor.
@@ -68,7 +91,6 @@ public InjectAViewModelDialog(
6891
6992 this .project = project ;
7093 this .targetBlockTag = targetBlockTag ;
71- this .validator = new InjectAViewModelDialogValidator (this );
7294 this .validatorBundle = new ValidatorBundle ();
7395 this .commonBundle = new CommonBundle ();
7496
@@ -84,19 +106,8 @@ protected void textChanged(final @NotNull DocumentEvent event) {
84106 setModal (true );
85107 getRootPane ().setDefaultButton (buttonOK );
86108
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 ());
100111
101112 setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
102113 addWindowListener (new WindowAdapter () {
@@ -106,13 +117,11 @@ public void windowClosing(final WindowEvent event) {
106117 }
107118 });
108119
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+ );
116125 }
117126
118127 protected void updateArgumentText () {
@@ -123,7 +132,7 @@ protected void updateArgumentText() {
123132 }
124133
125134 protected void onOK () {
126- if (!validator . validate ( project )) {
135+ if (!validateFormFields ( )) {
127136 return ;
128137 }
129138 final String moduleName = GetModuleNameByDirectoryUtil .execute (
0 commit comments