|
9 | 9 | import com.intellij.psi.PsiDirectory; |
10 | 10 | import com.magento.idea.magento2plugin.actions.generation.NewCronGroupAction; |
11 | 11 | import com.magento.idea.magento2plugin.actions.generation.data.CronGroupXmlData; |
12 | | -import com.magento.idea.magento2plugin.actions.generation.dialog.validator.NewCronGroupValidator; |
| 12 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation; |
| 13 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry; |
| 14 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierRule; |
| 15 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; |
13 | 16 | import com.magento.idea.magento2plugin.actions.generation.generator.ModuleCronGroupXmlGenerator; |
14 | 17 | import com.magento.idea.magento2plugin.ui.FilteredComboBox; |
15 | 18 | import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; |
|
30 | 33 |
|
31 | 34 | @SuppressWarnings({ |
32 | 35 | "PMD.TooManyFields", |
33 | | - "PMD.TooManyMethods" |
| 36 | + "PMD.TooManyMethods", |
| 37 | + "PMD.ExcessiveImports," |
34 | 38 | }) |
35 | 39 | public class NewCronGroupDialog extends AbstractDialog { |
36 | | - private final NewCronGroupValidator validator; |
37 | 40 | private final String moduleName; |
38 | 41 | private final Project project; |
39 | 42 | private JPanel contentPanel; |
40 | 43 | private JButton buttonOK; |
41 | 44 | private JButton buttonCancel; |
| 45 | + private static final String NAME = "name"; |
| 46 | + |
| 47 | + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, |
| 48 | + message = {NotEmptyRule.MESSAGE, NAME}) |
| 49 | + @FieldValidation(rule = RuleRegistry.IDENTIFIER, |
| 50 | + message = {IdentifierRule.MESSAGE, NAME}) |
42 | 51 | private JTextField cronGroupName; |
| 52 | + |
43 | 53 | private JSpinner scheduleGenerateEvery; |
44 | 54 | private JSpinner scheduleAheadFor; |
45 | 55 | private JSpinner scheduleLifetime; |
@@ -67,7 +77,6 @@ public NewCronGroupDialog(final Project project, final PsiDirectory directory) { |
67 | 77 | setContentPane(contentPanel); |
68 | 78 | setModal(true); |
69 | 79 | getRootPane().setDefaultButton(buttonOK); |
70 | | - this.validator = NewCronGroupValidator.getInstance(); |
71 | 80 | this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); |
72 | 81 |
|
73 | 82 | buttonOK.addActionListener(event -> onOK()); |
@@ -125,14 +134,15 @@ public static void open(final Project project, final PsiDirectory directory) { |
125 | 134 | } |
126 | 135 |
|
127 | 136 | private void onOK() { |
128 | | - if (!validator.validate(this)) { |
| 137 | + if (!validateFormFields()) { |
129 | 138 | return; |
130 | 139 | } |
131 | 140 |
|
132 | 141 | generateFile(); |
133 | 142 | this.setVisible(false); |
134 | 143 | } |
135 | 144 |
|
| 145 | + @Override |
136 | 146 | protected void onCancel() { |
137 | 147 | dispose(); |
138 | 148 | } |
|
0 commit comments