10
10
import com .intellij .psi .PsiFile ;
11
11
import com .magento .idea .magento2plugin .actions .generation .NewBlockAction ;
12
12
import 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 ;
14
18
import com .magento .idea .magento2plugin .actions .generation .generator .ModuleBlockClassGenerator ;
15
19
import com .magento .idea .magento2plugin .magento .files .BlockPhp ;
16
20
import com .magento .idea .magento2plugin .magento .packages .File ;
17
21
import com .magento .idea .magento2plugin .magento .packages .Package ;
18
22
import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
19
23
import java .awt .event .ActionEvent ;
20
- import java .awt .event .ActionListener ;
21
24
import java .awt .event .KeyEvent ;
22
25
import java .awt .event .WindowAdapter ;
23
26
import java .awt .event .WindowEvent ;
30
33
import javax .swing .KeyStroke ;
31
34
32
35
public class NewBlockDialog extends AbstractDialog {
33
- private final NewBlockValidator validator ;
34
36
private final PsiDirectory baseDir ;
35
37
private final String moduleName ;
36
38
private JPanel contentPanel ;
37
39
private JButton buttonOK ;
38
40
private JButton buttonCancel ;
39
- private JTextField blockName ;
40
- private JTextField blockParentDir ;
41
41
private final Project project ;
42
42
private JTextPane warning ;//NOPMD
43
43
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 ;
44
58
45
59
/**
46
60
* Constructor.
@@ -54,25 +68,15 @@ public NewBlockDialog(final Project project, final PsiDirectory directory) {
54
68
this .project = project ;
55
69
this .baseDir = directory ;
56
70
this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
57
- this .validator = NewBlockValidator .getInstance (this );
58
71
59
72
setContentPane (contentPanel );
60
73
setModal (true );
61
74
setTitle ("Create a new Magento 2 block.." );
62
75
getRootPane ().setDefaultButton (buttonOK );
63
76
suggestBlockDirectory ();
64
77
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 ());
76
80
77
81
// call onCancel() when cross is clicked
78
82
setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
@@ -83,12 +87,11 @@ public void windowClosing(final WindowEvent event) {
83
87
});
84
88
85
89
// 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
+ );
92
95
}
93
96
94
97
/**
@@ -105,7 +108,7 @@ public static void open(final Project project, final PsiDirectory directory) {
105
108
}
106
109
107
110
protected void onOK () {
108
- if (!validator . validate ()) {
111
+ if (!validateFormFields ()) {
109
112
return ;
110
113
}
111
114
generateFile ();
@@ -174,6 +177,7 @@ private String getNamespace() {
174
177
return parts [0 ] + Package .fqnSeparator + parts [1 ] + Package .fqnSeparator + directoryPart ;
175
178
}
176
179
180
+ @ Override
177
181
public void onCancel () {
178
182
// add your code here if necessary
179
183
dispose ();
0 commit comments