1010import com .magento .idea .magento2plugin .actions .generation .CreateAnObserverAction ;
1111import com .magento .idea .magento2plugin .actions .generation .data .ObserverEventsXmlData ;
1212import com .magento .idea .magento2plugin .actions .generation .data .ObserverFileData ;
13- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .CreateAnObserverDialogValidator ;
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 .AlphanumericWithUnderscoreRule ;
16+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .DirectoryRule ;
17+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
18+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .PhpClassRule ;
1419import com .magento .idea .magento2plugin .actions .generation .generator .ObserverClassGenerator ;
1520import com .magento .idea .magento2plugin .actions .generation .generator .ObserverEventsXmlGenerator ;
1621import com .magento .idea .magento2plugin .indexes .ModuleIndex ;
3641 "PMD.MissingSerialVersionUID" ,
3742 "PMD.DataClass" ,
3843 "PMD.UnusedPrivateField" ,
44+ "PMD.ExcessiveImports" ,
3945})
4046public class CreateAnObserverDialog extends AbstractDialog {
4147 @ NotNull
4248 private final Project project ;
43- @ NotNull
44- private final CreateAnObserverDialogValidator validator ;
4549 private final String targetEvent ;
4650 private JPanel contentPane ;
4751 private JButton buttonOK ;
4852 private JButton buttonCancel ;
49- private JTextField observerClassName ;
50- private JTextField observerDirectory ;
51- private FilteredComboBox observerModule ;
5253 private JComboBox observerArea ;
53- private JTextField observerName ;
5454 private JLabel observerClassNameLabel ;
5555 private JLabel observerDirectoryName ;
5656 private JLabel selectObserverModule ;
5757 private JLabel observerAreaLabel ;
5858 private JLabel observerNameLabel ;
59+ private static final String OBSERVER_MODULE = "target module" ;
60+ private static final String OBSERVER_CLASS = "class name" ;
61+ private static final String OBSERVER_DIRECTORY = "directory" ;
62+ private static final String OBSERVER_NAME = "name" ;
63+
64+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
65+ message = {NotEmptyRule .MESSAGE , OBSERVER_MODULE })
66+ private FilteredComboBox observerModule ;
67+
68+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
69+ message = {NotEmptyRule .MESSAGE , OBSERVER_CLASS })
70+ @ FieldValidation (rule = RuleRegistry .PHP_CLASS ,
71+ message = {PhpClassRule .MESSAGE , OBSERVER_CLASS })
72+ private JTextField observerClassName ;
73+
74+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
75+ message = {NotEmptyRule .MESSAGE , OBSERVER_DIRECTORY })
76+ @ FieldValidation (rule = RuleRegistry .DIRECTORY ,
77+ message = {DirectoryRule .MESSAGE , OBSERVER_DIRECTORY })
78+ private JTextField observerDirectory ;
79+
80+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
81+ message = {NotEmptyRule .MESSAGE , OBSERVER_NAME })
82+ @ FieldValidation (rule = RuleRegistry .ALPHANUMERIC_WITH_UNDERSCORE ,
83+ message = {AlphanumericWithUnderscoreRule .MESSAGE , OBSERVER_NAME })
84+ private JTextField observerName ;
5985
6086 /**
6187 * Constructor.
@@ -68,7 +94,6 @@ public CreateAnObserverDialog(@NotNull final Project project, final String targe
6894
6995 this .project = project ;
7096 this .targetEvent = targetEvent ;
71- this .validator = CreateAnObserverDialogValidator .getInstance (this );
7297
7398 setContentPane (contentPane );
7499 setModal (true );
@@ -119,7 +144,7 @@ private void fillTargetAreaOptions() {
119144 * Perform code generation using input data.
120145 */
121146 private void onOK () {
122- if (!validator . validate ( project )) {
147+ if (!validateFormFields ( )) {
123148 return ;
124149 }
125150 new ObserverClassGenerator (new ObserverFileData (
0 commit comments