1010import com .magento .idea .magento2plugin .actions .generation .NewCronjobAction ;
1111import com .magento .idea .magento2plugin .actions .generation .data .CronjobClassData ;
1212import 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 ;
1422import com .magento .idea .magento2plugin .actions .generation .generator .CronjobClassGenerator ;
1523import com .magento .idea .magento2plugin .actions .generation .generator .CrontabXmlGenerator ;
1624import com .magento .idea .magento2plugin .actions .generation .generator .util .NamespaceBuilder ;
1927import com .magento .idea .magento2plugin .util .CamelCaseToSnakeCase ;
2028import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
2129import java .awt .event .ActionEvent ;
22- import java .awt .event .ActionListener ;
2330import java .awt .event .FocusEvent ;
2431import java .awt .event .FocusListener ;
2532import java .awt .event .KeyEvent ;
4451 "PMD.AvoidCatchingGenericException" ,
4552 "PMD.ImmutableField" ,
4653 "PMD.AccessorMethodGeneration" ,
54+ "PMD.ExcessiveImports" ,
4755})
4856public class NewCronjobDialog extends AbstractDialog {
4957 private JPanel contentPane ;
5058 private JButton buttonOK ;
5159 private JButton buttonCancel ;
52- private JTextField cronjobClassNameField ;
53- private JTextField cronjobDirectoryField ;
5460 private JRadioButton fixedScheduleRadioButton ;
5561 private JRadioButton configurableScheduleRadioButton ;
5662 private JRadioButton everyMinuteRadioButton ;
5763 private JRadioButton customScheduleRadioButton ;
58- private JTextField cronjobScheduleField ;
5964 private JRadioButton atMidnightRadioButton ;
6065 private JPanel fixedSchedulePanel ;
61- private JTextField configPathField ;
6266 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 })
6490 private JTextField cronjobNameField ;
6591
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+
66110 private Project project ;
67111 private String moduleName ;
68- private NewCronjobValidator validator ;
69112 private CamelCaseToSnakeCase camelCaseToSnakeCase ;
70113
71114 /**
@@ -78,26 +121,29 @@ public NewCronjobDialog(final Project project, final PsiDirectory directory) {
78121 super ();
79122 this .project = project ;
80123 this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
81- this .validator = NewCronjobValidator .getInstance ();
82124 this .camelCaseToSnakeCase = CamelCaseToSnakeCase .getInstance ();
83125
84126 setContentPane (contentPane );
85127 setModal (true );
86128 getRootPane ().setDefaultButton (buttonOK );
87129 setTitle ("Create a new Magento 2 cronjob.." );
130+ configPathField .setEditable (false );
88131
89132 buttonOK .addActionListener (e -> onOK ());
90133 buttonCancel .addActionListener (e -> onCancel ());
91134
92135 fixedScheduleRadioButton .addActionListener (e -> {
93136 configurableSchedulePanel .setVisible (false );
94137 fixedSchedulePanel .setVisible (true );
138+ configPathField .setEditable (false );
95139 });
96140
97141 configurableScheduleRadioButton .addActionListener (e -> {
98142 fixedSchedulePanel .setVisible (false );
99143 configurableSchedulePanel .setVisible (true );
144+ configPathField .setEditable (true );
100145 configPathField .grabFocus ();
146+ everyMinuteRadioButton .doClick ();
101147 });
102148
103149 everyMinuteRadioButton .addActionListener (e -> {
@@ -139,16 +185,9 @@ public void windowClosing(final WindowEvent event) {
139185 }
140186 });
141187
142- final ActionListener actionListener = new ActionListener () {
143- @ Override
144- public void actionPerformed (final ActionEvent event ) {
145- onCancel ();
146- }
147- };
148-
149188 // call onCancel() on ESCAPE
150189 contentPane .registerKeyboardAction (
151- actionListener ,
190+ ( final ActionEvent event ) -> onCancel () ,
152191 KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
153192 JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
154193 );
@@ -237,7 +276,7 @@ private String suggestCronjobName(final String cronjobClassname) {
237276 * When new cronjob dialog is filled, validate the input data and generate a new cronjob.
238277 */
239278 private void onOK () {
240- if (!validator . validate ( this . project , this )) {
279+ if (!validateFormFields ( )) {
241280 return ;
242281 }
243282
0 commit comments