11
11
import com .magento .idea .magento2plugin .actions .generation .CreateAPluginAction ;
12
12
import com .magento .idea .magento2plugin .actions .generation .data .PluginDiXmlData ;
13
13
import com .magento .idea .magento2plugin .actions .generation .data .PluginFileData ;
14
- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .CreateAPluginDialogValidator ;
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 .DirectoryRule ;
17
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .IdentifierRule ;
18
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
19
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NumericRule ;
20
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .PhpClassRule ;
15
21
import com .magento .idea .magento2plugin .actions .generation .generator .PluginClassGenerator ;
16
22
import com .magento .idea .magento2plugin .actions .generation .generator .PluginDiXmlGenerator ;
17
23
import com .magento .idea .magento2plugin .indexes .ModuleIndex ;
21
27
import com .magento .idea .magento2plugin .magento .packages .Package ;
22
28
import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
23
29
import java .awt .event .ActionEvent ;
24
- import java .awt .event .ActionListener ;
25
30
import java .awt .event .KeyEvent ;
26
31
import java .awt .event .WindowAdapter ;
27
32
import java .awt .event .WindowEvent ;
35
40
import javax .swing .KeyStroke ;
36
41
import org .jetbrains .annotations .NotNull ;
37
42
38
- @ SuppressWarnings ({"PMD.TooManyFields" , "PMD.DataClass" , "PMD.UnusedPrivateMethod" })
43
+ @ SuppressWarnings ({
44
+ "PMD.TooManyFields" ,
45
+ "PMD.DataClass" ,
46
+ "PMD.UnusedPrivateMethod" ,
47
+ "PMD.ExcessiveImports"
48
+ })
39
49
public class CreateAPluginDialog extends AbstractDialog {
40
50
@ NotNull
41
51
private final Project project ;
42
52
private final Method targetMethod ;
43
53
private final PhpClass targetClass ;
44
- @ NotNull
45
- private final CreateAPluginDialogValidator validator ;
46
54
private JPanel contentPane ;
47
55
private JButton buttonOK ;
48
56
private JButton buttonCancel ;
49
- private JTextField pluginClassName ;
50
- private JTextField pluginDirectory ;
51
57
private JComboBox pluginType ;
52
- private FilteredComboBox pluginModule ;
53
58
private JComboBox pluginArea ;
59
+
60
+ private static final String CLASS_NAME = "class name" ;
61
+ private static final String DIRECTORY = "directory path" ;
62
+ private static final String SORT_ORDER = "sort order" ;
63
+ private static final String PLUGIN_NAME = "plugin name" ;
64
+ private static final String TARGET_MODULE = "target module" ;
65
+
66
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
67
+ message = {NotEmptyRule .MESSAGE , TARGET_MODULE })
68
+ private FilteredComboBox pluginModule ;
69
+
70
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
71
+ message = {NotEmptyRule .MESSAGE , CLASS_NAME })
72
+ @ FieldValidation (rule = RuleRegistry .PHP_CLASS ,
73
+ message = {PhpClassRule .MESSAGE , CLASS_NAME })
74
+ private JTextField pluginClassName ;
75
+
76
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
77
+ message = {NotEmptyRule .MESSAGE , DIRECTORY })
78
+ @ FieldValidation (rule = RuleRegistry .DIRECTORY ,
79
+ message = {DirectoryRule .MESSAGE , DIRECTORY })
80
+ private JTextField pluginDirectory ;
81
+
82
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
83
+ message = {NotEmptyRule .MESSAGE , SORT_ORDER })
84
+ @ FieldValidation (rule = RuleRegistry .NUMERIC ,
85
+ message = {NumericRule .MESSAGE , SORT_ORDER })
54
86
private JTextField pluginSortOrder ;
87
+
88
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
89
+ message = {NotEmptyRule .MESSAGE , PLUGIN_NAME })
90
+ @ FieldValidation (rule = RuleRegistry .IDENTIFIER ,
91
+ message = {IdentifierRule .MESSAGE , PLUGIN_NAME })
55
92
private JTextField pluginName ;
93
+
56
94
private JLabel pluginDirectoryName ;//NOPMD
57
95
private JLabel selectPluginModule ;//NOPMD
58
96
private JLabel pluginTypeLabel ;//NOPMD
@@ -77,25 +115,15 @@ public CreateAPluginDialog(
77
115
this .project = project ;
78
116
this .targetMethod = targetMethod ;
79
117
this .targetClass = targetClass ;
80
- this .validator = CreateAPluginDialogValidator .getInstance (this );
81
118
82
119
setContentPane (contentPane );
83
120
setModal (true );
84
121
getRootPane ().setDefaultButton (buttonOK );
85
122
fillPluginTypeOptions ();
86
123
fillTargetAreaOptions ();
87
124
88
- buttonOK .addActionListener (new ActionListener () {
89
- public void actionPerformed (final ActionEvent event ) {
90
- onOK ();
91
- }
92
- });
93
-
94
- buttonCancel .addActionListener (new ActionListener () {
95
- public void actionPerformed (final ActionEvent event ) {
96
- onCancel ();
97
- }
98
- });
125
+ buttonOK .addActionListener ((final ActionEvent event ) -> onOK ());
126
+ buttonCancel .addActionListener ((final ActionEvent event ) -> onCancel ());
99
127
100
128
setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
101
129
addWindowListener (new WindowAdapter () {
@@ -104,11 +132,9 @@ public void windowClosing(final WindowEvent event) {
104
132
}
105
133
});
106
134
107
- contentPane .registerKeyboardAction (new ActionListener () {
108
- public void actionPerformed (final ActionEvent event ) {
109
- onCancel ();
110
- }
111
- }, KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
135
+ contentPane .registerKeyboardAction (
136
+ (final ActionEvent event ) -> onCancel (),
137
+ KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
112
138
JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
113
139
);
114
140
}
@@ -126,7 +152,7 @@ private void fillTargetAreaOptions() {
126
152
}
127
153
128
154
protected void onOK () {
129
- if (!validator . validate ( project )) {
155
+ if (!validateFormFields ( )) {
130
156
return ;
131
157
}
132
158
new PluginClassGenerator (new PluginFileData (
0 commit comments