10
10
import com .intellij .psi .PsiFile ;
11
11
import com .magento .idea .magento2plugin .actions .generation .NewGraphQlResolverAction ;
12
12
import com .magento .idea .magento2plugin .actions .generation .data .GraphQlResolverFileData ;
13
- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .NewGraphQlResolverValidator ;
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 .ModuleGraphQlResolverClassGenerator ;
15
19
import com .magento .idea .magento2plugin .magento .files .GraphQlResolverPhp ;
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 ;
28
31
import javax .swing .KeyStroke ;
29
32
30
33
public class NewGraphQlResolverDialog extends AbstractDialog {
31
- private final NewGraphQlResolverValidator validator ;
32
34
private final PsiDirectory baseDir ;
33
35
private final String moduleName ;
34
36
private JPanel contentPanel ;
35
37
private JButton buttonOK ;
36
38
private JButton buttonCancel ;
39
+ private final Project project ;
40
+ private static final String CLASS_NAME = "class name" ;
41
+ private static final String PARENT_DIRECTORY = "directory" ;
42
+
43
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
44
+ message = {NotEmptyRule .MESSAGE , CLASS_NAME })
45
+ @ FieldValidation (rule = RuleRegistry .PHP_CLASS ,
46
+ message = {PhpClassRule .MESSAGE , CLASS_NAME })
37
47
private JTextField graphQlResolverClassName ;
48
+
49
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
50
+ message = {NotEmptyRule .MESSAGE , PARENT_DIRECTORY })
51
+ @ FieldValidation (rule = RuleRegistry .PHP_DIRECTORY ,
52
+ message = {PhpDirectoryRule .MESSAGE , PARENT_DIRECTORY })
38
53
private JTextField graphQlResolverParentDir ;
39
- private final Project project ;
40
54
41
55
/**
42
56
* Constructor.
@@ -50,25 +64,15 @@ public NewGraphQlResolverDialog(final Project project, final PsiDirectory direct
50
64
this .project = project ;
51
65
this .baseDir = directory ;
52
66
this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
53
- this .validator = NewGraphQlResolverValidator .getInstance (this );
54
67
55
68
setContentPane (contentPanel );
56
69
setModal (true );
57
70
setTitle ("Create a new Magento 2 GraphQL Resolver." );
58
71
getRootPane ().setDefaultButton (buttonOK );
59
72
suggestGraphQlResolverDirectory ();
60
73
61
- buttonOK .addActionListener (new ActionListener () {
62
- public void actionPerformed (final ActionEvent event ) {
63
- onOK ();
64
- }
65
- });
66
-
67
- buttonCancel .addActionListener (new ActionListener () {
68
- public void actionPerformed (final ActionEvent event ) {
69
- onCancel ();
70
- }
71
- });
74
+ buttonOK .addActionListener ((final ActionEvent event ) -> onOK ());
75
+ buttonCancel .addActionListener ((final ActionEvent event ) -> onCancel ());
72
76
73
77
// call onCancel() when cross is clicked
74
78
setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
@@ -79,12 +83,11 @@ public void windowClosing(final WindowEvent event) {
79
83
});
80
84
81
85
// call onCancel() on ESCAPE
82
- contentPanel .registerKeyboardAction (new ActionListener () {
83
- public void actionPerformed (final ActionEvent event ) {
84
- onCancel ();
85
- }
86
- }, KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
87
- JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
86
+ contentPanel .registerKeyboardAction (
87
+ (final ActionEvent event ) -> onCancel (),
88
+ KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
89
+ JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
90
+ );
88
91
}
89
92
90
93
/**
@@ -101,7 +104,7 @@ public static void open(final Project project, final PsiDirectory directory) {
101
104
}
102
105
103
106
protected void onOK () {
104
- if (!validator . validate ()) {
107
+ if (!validateFormFields ()) {
105
108
return ;
106
109
}
107
110
generateFile ();
@@ -176,6 +179,7 @@ private String getGraphQlResolverClassFqn() {
176
179
return getNamespace ().concat (Package .fqnSeparator ).concat (getGraphQlResolverClassName ());
177
180
}
178
181
182
+ @ Override
179
183
public void onCancel () {
180
184
// add your code here if necessary
181
185
dispose ();
0 commit comments