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