10
10
import com .magento .idea .magento2plugin .actions .generation .NewCronjobAction ;
11
11
import com .magento .idea .magento2plugin .actions .generation .data .CronjobClassData ;
12
12
import com .magento .idea .magento2plugin .actions .generation .data .CrontabXmlData ;
13
- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .NewCronjobValidator ;
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 .ConfigPathRule ;
16
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .CronScheduleRule ;
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 .PhpClassRule ;
14
21
import com .magento .idea .magento2plugin .actions .generation .generator .CronjobClassGenerator ;
15
22
import com .magento .idea .magento2plugin .actions .generation .generator .CrontabXmlGenerator ;
16
23
import com .magento .idea .magento2plugin .actions .generation .generator .util .NamespaceBuilder ;
19
26
import com .magento .idea .magento2plugin .util .CamelCaseToSnakeCase ;
20
27
import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
21
28
import java .awt .event .ActionEvent ;
22
- import java .awt .event .ActionListener ;
23
29
import java .awt .event .FocusEvent ;
24
30
import java .awt .event .FocusListener ;
25
31
import java .awt .event .KeyEvent ;
44
50
"PMD.AvoidCatchingGenericException" ,
45
51
"PMD.ImmutableField" ,
46
52
"PMD.AccessorMethodGeneration" ,
53
+ "PMD.ExcessiveImports" ,
47
54
})
48
55
public class NewCronjobDialog extends AbstractDialog {
49
56
private JPanel contentPane ;
50
57
private JButton buttonOK ;
51
58
private JButton buttonCancel ;
52
- private JTextField cronjobClassNameField ;
53
- private JTextField cronjobDirectoryField ;
54
59
private JRadioButton fixedScheduleRadioButton ;
55
60
private JRadioButton configurableScheduleRadioButton ;
56
61
private JRadioButton everyMinuteRadioButton ;
57
62
private JRadioButton customScheduleRadioButton ;
58
- private JTextField cronjobScheduleField ;
59
63
private JRadioButton atMidnightRadioButton ;
60
64
private JPanel fixedSchedulePanel ;
61
- private JTextField configPathField ;
62
65
private JPanel configurableSchedulePanel ;
63
- private FilteredComboBox cronGroupComboBox ;
66
+ private static final String CLASS_NAME = "class name" ;
67
+ private static final String DIRECTORY = "directory" ;
68
+ private static final String CRON_NAME = "name" ;
69
+ private static final String SCHEDULE = "schedule" ;
70
+ private static final String CONFIG_PATH = "config path" ;
71
+ private static final String CRON_GROUP = "cron group" ;
72
+
73
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
74
+ message = {NotEmptyRule .MESSAGE , CLASS_NAME })
75
+ @ FieldValidation (rule = RuleRegistry .PHP_CLASS ,
76
+ message = {PhpClassRule .MESSAGE , CLASS_NAME })
77
+ private JTextField cronjobClassNameField ;
78
+
79
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
80
+ message = {NotEmptyRule .MESSAGE , DIRECTORY })
81
+ @ FieldValidation (rule = RuleRegistry .DIRECTORY ,
82
+ message = {DirectoryRule .MESSAGE , DIRECTORY })
83
+ private JTextField cronjobDirectoryField ;
84
+
85
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
86
+ message = {NotEmptyRule .MESSAGE , CRON_NAME })
87
+ @ FieldValidation (rule = RuleRegistry .IDENTIFIER ,
88
+ message = {IdentifierRule .MESSAGE , CRON_NAME })
64
89
private JTextField cronjobNameField ;
65
90
91
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
92
+ message = {NotEmptyRule .MESSAGE , SCHEDULE })
93
+ @ FieldValidation (rule = RuleRegistry .CRON_SCHEDULE ,
94
+ message = {CronScheduleRule .MESSAGE , SCHEDULE })
95
+ private JTextField cronjobScheduleField ;
96
+
97
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
98
+ message = {NotEmptyRule .MESSAGE , CONFIG_PATH })
99
+ @ FieldValidation (rule = RuleRegistry .CONFIG_PATH ,
100
+ message = {ConfigPathRule .MESSAGE , CONFIG_PATH })
101
+ private JTextField configPathField ;
102
+
103
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
104
+ message = {NotEmptyRule .MESSAGE , CRON_GROUP })
105
+ private FilteredComboBox cronGroupComboBox ;
106
+
66
107
private Project project ;
67
108
private String moduleName ;
68
- private NewCronjobValidator validator ;
69
109
private CamelCaseToSnakeCase camelCaseToSnakeCase ;
70
110
71
111
/**
@@ -78,26 +118,29 @@ public NewCronjobDialog(final Project project, final PsiDirectory directory) {
78
118
super ();
79
119
this .project = project ;
80
120
this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
81
- this .validator = NewCronjobValidator .getInstance ();
82
121
this .camelCaseToSnakeCase = CamelCaseToSnakeCase .getInstance ();
83
122
84
123
setContentPane (contentPane );
85
124
setModal (true );
86
125
getRootPane ().setDefaultButton (buttonOK );
87
126
setTitle ("Create a new Magento 2 cronjob.." );
127
+ configPathField .setEditable (false );
88
128
89
129
buttonOK .addActionListener (e -> onOK ());
90
130
buttonCancel .addActionListener (e -> onCancel ());
91
131
92
132
fixedScheduleRadioButton .addActionListener (e -> {
93
133
configurableSchedulePanel .setVisible (false );
94
134
fixedSchedulePanel .setVisible (true );
135
+ configPathField .setEditable (false );
95
136
});
96
137
97
138
configurableScheduleRadioButton .addActionListener (e -> {
98
139
fixedSchedulePanel .setVisible (false );
99
140
configurableSchedulePanel .setVisible (true );
141
+ configPathField .setEditable (true );
100
142
configPathField .grabFocus ();
143
+ everyMinuteRadioButton .doClick ();
101
144
});
102
145
103
146
everyMinuteRadioButton .addActionListener (e -> {
@@ -139,16 +182,9 @@ public void windowClosing(final WindowEvent event) {
139
182
}
140
183
});
141
184
142
- final ActionListener actionListener = new ActionListener () {
143
- @ Override
144
- public void actionPerformed (final ActionEvent event ) {
145
- onCancel ();
146
- }
147
- };
148
-
149
185
// call onCancel() on ESCAPE
150
186
contentPane .registerKeyboardAction (
151
- actionListener ,
187
+ ( final ActionEvent event ) -> onCancel () ,
152
188
KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
153
189
JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
154
190
);
@@ -237,7 +273,7 @@ private String suggestCronjobName(final String cronjobClassname) {
237
273
* When new cronjob dialog is filled, validate the input data and generate a new cronjob.
238
274
*/
239
275
private void onOK () {
240
- if (!validator . validate ( this . project , this )) {
276
+ if (!validateFormFields ( )) {
241
277
return ;
242
278
}
243
279
0 commit comments