|
18 | 18 | import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormFieldData; |
19 | 19 | import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormFieldsetData; |
20 | 20 | import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormFileData; |
21 | | -import com.magento.idea.magento2plugin.actions.generation.dialog.validator.NewUiComponentFormValidator; |
| 21 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation; |
| 22 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry; |
| 23 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AclResourceIdRule; |
| 24 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphanumericRule; |
| 25 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule; |
| 26 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierRule; |
| 27 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; |
| 28 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule; |
| 29 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpNamespaceNameRule; |
| 30 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.RouteIdRule; |
| 31 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.StartWithNumberOrCapitalLetterRule; |
| 32 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.ui.component.FormButtonsValidator; |
| 33 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.ui.component.FormFieldsValidator; |
| 34 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.ui.component.FormFieldsetsValidator; |
22 | 35 | import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator; |
23 | 36 | import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; |
24 | 37 | import com.magento.idea.magento2plugin.actions.generation.generator.RoutesXmlGenerator; |
|
37 | 50 | import com.magento.idea.magento2plugin.ui.table.DeleteRowButton; |
38 | 51 | import com.magento.idea.magento2plugin.ui.table.TableButton; |
39 | 52 | import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; |
| 53 | +import java.awt.Dimension; |
40 | 54 | import java.awt.event.ActionEvent; |
41 | 55 | import java.awt.event.ActionListener; |
42 | 56 | import java.awt.event.KeyEvent; |
|
65 | 79 | "PMD.GodClass" |
66 | 80 | }) |
67 | 81 | public class NewUiComponentFormDialog extends AbstractDialog { |
68 | | - private final NewUiComponentFormValidator validator; |
| 82 | + private final FormButtonsValidator formButtonsValidator; |
| 83 | + private final FormFieldsetsValidator formFieldsetsValidator; |
| 84 | + private final FormFieldsValidator formFieldsValidator; |
69 | 85 | private final Project project; |
70 | 86 | private final String moduleName; |
71 | 87 | private JPanel contentPane; |
72 | 88 | private JButton buttonOK; |
73 | 89 | private JButton buttonCancel; |
74 | 90 | private FilteredComboBox formAreaSelect; |
| 91 | + |
| 92 | + private static final String VIEW_ACTION_NAME = "View Action Name"; |
| 93 | + private static final String SUBMIT_ACTION_NAME = "Submit Action Name"; |
| 94 | + private static final String DATA_PROVIDER_CLASS_NAME = "Data Provider class name"; |
| 95 | + private static final String DATA_PROVIDER_DIRECTORY = "Data Provider directory"; |
| 96 | + |
| 97 | + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Name"}) |
| 98 | + @FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE, "Name"}) |
75 | 99 | private JTextField formName; |
| 100 | + |
| 101 | + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Label"}) |
76 | 102 | private JTextField formLabel; |
| 103 | + |
77 | 104 | private JTable formButtons; |
78 | 105 | private JButton addButton; |
79 | 106 | private JTable fieldsets; |
80 | 107 | private JTable fields; |
81 | 108 | private JButton addFieldset; |
82 | 109 | private JButton addField; |
| 110 | + |
| 111 | + @FieldValidation(rule = RuleRegistry.ROUTE_ID, message = {RouteIdRule.MESSAGE}) |
83 | 112 | private JTextField route; |
| 113 | + |
| 114 | + @FieldValidation(rule = RuleRegistry.PHP_NAMESPACE_NAME, |
| 115 | + message = {PhpNamespaceNameRule.MESSAGE, "View Controller Name"}) |
84 | 116 | private JTextField viewControllerName; |
| 117 | + |
| 118 | + @FieldValidation(rule = RuleRegistry.PHP_CLASS, |
| 119 | + message = {PhpClassRule.MESSAGE, VIEW_ACTION_NAME}) |
| 120 | + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, |
| 121 | + message = {NotEmptyRule.MESSAGE, VIEW_ACTION_NAME}) |
| 122 | + @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, |
| 123 | + message = {AlphanumericRule.MESSAGE, VIEW_ACTION_NAME}) |
| 124 | + @FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER, |
| 125 | + message = {StartWithNumberOrCapitalLetterRule.MESSAGE, VIEW_ACTION_NAME}) |
85 | 126 | private JTextField viewActionName; |
| 127 | + |
| 128 | + @FieldValidation(rule = RuleRegistry.PHP_NAMESPACE_NAME, |
| 129 | + message = {PhpNamespaceNameRule.MESSAGE, "Submit Controller Name"}) |
86 | 130 | private JTextField submitControllerName; |
| 131 | + |
| 132 | + @FieldValidation(rule = RuleRegistry.PHP_CLASS, |
| 133 | + message = {PhpClassRule.MESSAGE, SUBMIT_ACTION_NAME}) |
| 134 | + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, |
| 135 | + message = {NotEmptyRule.MESSAGE, SUBMIT_ACTION_NAME}) |
| 136 | + @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, |
| 137 | + message = {AlphanumericRule.MESSAGE, SUBMIT_ACTION_NAME}) |
| 138 | + @FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER, |
| 139 | + message = {StartWithNumberOrCapitalLetterRule.MESSAGE, SUBMIT_ACTION_NAME}) |
87 | 140 | private JTextField submitActionName; |
| 141 | + |
| 142 | + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, |
| 143 | + message = {NotEmptyRule.MESSAGE, DATA_PROVIDER_CLASS_NAME}) |
| 144 | + @FieldValidation(rule = RuleRegistry.PHP_CLASS, |
| 145 | + message = {PhpClassRule.MESSAGE, DATA_PROVIDER_CLASS_NAME}) |
| 146 | + @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, |
| 147 | + message = {AlphanumericRule.MESSAGE, DATA_PROVIDER_CLASS_NAME}) |
88 | 148 | private JTextField dataProviderClassName; |
| 149 | + |
| 150 | + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, |
| 151 | + message = {NotEmptyRule.MESSAGE, DATA_PROVIDER_DIRECTORY}) |
| 152 | + @FieldValidation(rule = RuleRegistry.DIRECTORY, |
| 153 | + message = {DirectoryRule.MESSAGE, DATA_PROVIDER_DIRECTORY}) |
| 154 | + @FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER, |
| 155 | + message = {AlphanumericRule.MESSAGE, DATA_PROVIDER_DIRECTORY}) |
89 | 156 | private JTextField dataProviderDirectory; |
| 157 | + |
90 | 158 | private JLabel aclLabel; |
| 159 | + |
| 160 | + @FieldValidation(rule = RuleRegistry.ACL_RESOURCE_ID, message = {AclResourceIdRule.MESSAGE}) |
91 | 161 | private JTextField acl; |
| 162 | + |
92 | 163 | private JLabel formButtonsLabel;//NOPMD |
93 | 164 | private JLabel formNameLabel;//NOPMD |
94 | 165 | private JLabel formLabelLabel;//NOPMD |
@@ -127,7 +198,10 @@ public class NewUiComponentFormDialog extends AbstractDialog { |
127 | 198 | public NewUiComponentFormDialog(final Project project, final PsiDirectory directory) { |
128 | 199 | super(); |
129 | 200 | this.project = project; |
130 | | - this.validator = new NewUiComponentFormValidator(this); |
| 201 | + updateDialogSizeToDefaults(); |
| 202 | + formButtonsValidator = new FormButtonsValidator(this); |
| 203 | + formFieldsetsValidator = new FormFieldsetsValidator(this); |
| 204 | + formFieldsValidator = new FormFieldsValidator(this); |
131 | 205 | this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); |
132 | 206 |
|
133 | 207 | setContentPane(contentPane); |
@@ -338,7 +412,7 @@ public static void open(final Project project, final PsiDirectory directory) { |
338 | 412 | } |
339 | 413 |
|
340 | 414 | private void onOK() { |
341 | | - if (!validator.validate()) { |
| 415 | + if (!validateFormFields()) { |
342 | 416 | return; |
343 | 417 | } |
344 | 418 |
|
@@ -442,6 +516,7 @@ private PsiFile generateLayoutFile() { |
442 | 516 | ), project).generate(NewUiComponentFormAction.ACTION_NAME, false); |
443 | 517 | } |
444 | 518 |
|
| 519 | + @Override |
445 | 520 | protected void onCancel() { |
446 | 521 | dispose(); |
447 | 522 | } |
@@ -639,4 +714,17 @@ private void toggleAcl() { |
639 | 714 | acl.setVisible(false); |
640 | 715 | aclLabel.setVisible(false); |
641 | 716 | } |
| 717 | + |
| 718 | + @Override |
| 719 | + protected boolean validateFormFields() { |
| 720 | + return super.validateFormFields() |
| 721 | + && formButtonsValidator.validate() |
| 722 | + && formFieldsetsValidator.validate() |
| 723 | + && formFieldsValidator.validate(); |
| 724 | + } |
| 725 | + |
| 726 | + private void updateDialogSizeToDefaults() { |
| 727 | + final Dimension screenSize = getToolkit().getScreenSize(); |
| 728 | + setPreferredSize(new Dimension(screenSize.width / 2, screenSize.height / 2)); |
| 729 | + } |
642 | 730 | } |
0 commit comments