1010import com .intellij .psi .PsiFile ;
1111import com .magento .idea .magento2plugin .actions .generation .NewBlockAction ;
1212import com .magento .idea .magento2plugin .actions .generation .data .BlockFileData ;
13- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .NewBlockValidator ;
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 .NotEmptyRule ;
16+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .PhpClassRule ;
17+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .PhpDirectoryRule ;
1418import com .magento .idea .magento2plugin .actions .generation .generator .ModuleBlockClassGenerator ;
1519import com .magento .idea .magento2plugin .magento .files .BlockPhp ;
1620import com .magento .idea .magento2plugin .magento .packages .File ;
1721import com .magento .idea .magento2plugin .magento .packages .Package ;
1822import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
1923import java .awt .event .ActionEvent ;
20- import java .awt .event .ActionListener ;
2124import java .awt .event .KeyEvent ;
2225import java .awt .event .WindowAdapter ;
2326import java .awt .event .WindowEvent ;
3033import javax .swing .KeyStroke ;
3134
3235public class NewBlockDialog extends AbstractDialog {
33- private final NewBlockValidator validator ;
3436 private final PsiDirectory baseDir ;
3537 private final String moduleName ;
3638 private JPanel contentPanel ;
3739 private JButton buttonOK ;
3840 private JButton buttonCancel ;
39- private JTextField blockName ;
40- private JTextField blockParentDir ;
4141 private final Project project ;
4242 private JTextPane warning ;//NOPMD
4343 private JRadioButton adminhtmlRadioButton ;//NOPMD
44+ private static final String NAME = "name" ;
45+ private static final String DIRECTORY = "directory" ;
46+
47+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
48+ message = {NotEmptyRule .MESSAGE , NAME })
49+ @ FieldValidation (rule = RuleRegistry .PHP_CLASS ,
50+ message = {PhpClassRule .MESSAGE , NAME })
51+ private JTextField blockName ;
52+
53+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
54+ message = {NotEmptyRule .MESSAGE , DIRECTORY })
55+ @ FieldValidation (rule = RuleRegistry .PHP_DIRECTORY ,
56+ message = {PhpDirectoryRule .MESSAGE , DIRECTORY })
57+ private JTextField blockParentDir ;
4458
4559 /**
4660 * Constructor.
@@ -54,25 +68,15 @@ public NewBlockDialog(final Project project, final PsiDirectory directory) {
5468 this .project = project ;
5569 this .baseDir = directory ;
5670 this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
57- this .validator = NewBlockValidator .getInstance (this );
5871
5972 setContentPane (contentPanel );
6073 setModal (true );
6174 setTitle ("Create a new Magento 2 block.." );
6275 getRootPane ().setDefaultButton (buttonOK );
6376 suggestBlockDirectory ();
6477
65- buttonOK .addActionListener (new ActionListener () {
66- public void actionPerformed (final ActionEvent event ) {
67- onOK ();
68- }
69- });
70-
71- buttonCancel .addActionListener (new ActionListener () {
72- public void actionPerformed (final ActionEvent event ) {
73- onCancel ();
74- }
75- });
78+ buttonOK .addActionListener ((final ActionEvent event ) -> onOK ());
79+ buttonCancel .addActionListener ((final ActionEvent event ) -> onCancel ());
7680
7781 // call onCancel() when cross is clicked
7882 setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
@@ -83,12 +87,11 @@ public void windowClosing(final WindowEvent event) {
8387 });
8488
8589 // call onCancel() on ESCAPE
86- contentPanel .registerKeyboardAction (new ActionListener () {
87- public void actionPerformed (final ActionEvent event ) {
88- onCancel ();
89- }
90- }, KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
91- JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
90+ contentPanel .registerKeyboardAction (
91+ (final ActionEvent event ) -> onCancel (),
92+ KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
93+ JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
94+ );
9295 }
9396
9497 /**
@@ -105,7 +108,7 @@ public static void open(final Project project, final PsiDirectory directory) {
105108 }
106109
107110 protected void onOK () {
108- if (!validator . validate ()) {
111+ if (!validateFormFields ()) {
109112 return ;
110113 }
111114 generateFile ();
@@ -174,6 +177,7 @@ private String getNamespace() {
174177 return parts [0 ] + Package .fqnSeparator + parts [1 ] + Package .fqnSeparator + directoryPart ;
175178 }
176179
180+ @ Override
177181 public void onCancel () {
178182 // add your code here if necessary
179183 dispose ();
0 commit comments