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