|
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.*; |
| 24 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.uiComponent.FormButtonsValidator; |
| 25 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.uiComponent.FormFieldsValidator; |
| 26 | +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.uiComponent.FormFieldsetsValidator; |
22 | 27 | import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator;
|
23 | 28 | import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator;
|
24 | 29 | import com.magento.idea.magento2plugin.actions.generation.generator.RoutesXmlGenerator;
|
|
37 | 42 | import com.magento.idea.magento2plugin.ui.table.DeleteRowButton;
|
38 | 43 | import com.magento.idea.magento2plugin.ui.table.TableButton;
|
39 | 44 | import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
|
| 45 | + |
| 46 | +import java.awt.*; |
40 | 47 | import java.awt.event.ActionEvent;
|
41 | 48 | import java.awt.event.ActionListener;
|
42 | 49 | import java.awt.event.KeyEvent;
|
|
65 | 72 | "PMD.GodClass"
|
66 | 73 | })
|
67 | 74 | public class NewUiComponentFormDialog extends AbstractDialog {
|
68 |
| - private final NewUiComponentFormValidator validator; |
| 75 | + private final FormButtonsValidator formButtonsValidator; |
| 76 | + private final FormFieldsetsValidator formFieldsetsValidator; |
| 77 | + private final FormFieldsValidator formFieldsValidator; |
69 | 78 | private final Project project;
|
70 | 79 | private final String moduleName;
|
71 | 80 | private JPanel contentPane;
|
72 | 81 | private JButton buttonOK;
|
73 | 82 | private JButton buttonCancel;
|
74 | 83 | private FilteredComboBox formAreaSelect;
|
| 84 | + |
| 85 | + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Name"}) |
| 86 | + @FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE, "Name"}) |
75 | 87 | private JTextField formName;
|
| 88 | + |
| 89 | + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Label"}) |
76 | 90 | private JTextField formLabel;
|
| 91 | + |
77 | 92 | private JTable formButtons;
|
78 | 93 | private JButton addButton;
|
79 | 94 | private JTable fieldsets;
|
80 | 95 | private JTable fields;
|
81 | 96 | private JButton addFieldset;
|
82 | 97 | private JButton addField;
|
| 98 | + |
| 99 | + @FieldValidation(rule = RuleRegistry.ROUTE_ID, message = {RouteIdRule.MESSAGE}) |
83 | 100 | private JTextField route;
|
| 101 | + |
| 102 | + @FieldValidation(rule = RuleRegistry.PHP_NAMESPACE_NAME, |
| 103 | + message = {PhpNamespaceNameRule.MESSAGE, "View Controller Name"}) |
84 | 104 | private JTextField viewControllerName;
|
| 105 | + |
| 106 | + @FieldValidation(rule = RuleRegistry.PHP_CLASS, message = {PhpClassRule.MESSAGE, "View Action Name"}) |
| 107 | + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "View Action Name"}) |
| 108 | + @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, message = {AlphanumericRule.MESSAGE, "View Action Name"}) |
| 109 | + @FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER, |
| 110 | + message = {StartWithNumberOrCapitalLetterRule.MESSAGE, "View Action Name"}) |
85 | 111 | private JTextField viewActionName;
|
| 112 | + |
| 113 | + @FieldValidation(rule = RuleRegistry.PHP_NAMESPACE_NAME, |
| 114 | + message = {PhpNamespaceNameRule.MESSAGE, "Submit Controller Name"}) |
86 | 115 | private JTextField submitControllerName;
|
| 116 | + |
| 117 | + @FieldValidation(rule = RuleRegistry.PHP_CLASS, message = {PhpClassRule.MESSAGE, "Submit Action Name"}) |
| 118 | + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Submit Action Name"}) |
| 119 | + @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, message = {AlphanumericRule.MESSAGE, "Submit Action Name"}) |
| 120 | + @FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER, |
| 121 | + message = {StartWithNumberOrCapitalLetterRule.MESSAGE, "Submit Action Name"}) |
87 | 122 | private JTextField submitActionName;
|
| 123 | + |
| 124 | + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Data Provider class name"}) |
| 125 | + @FieldValidation(rule = RuleRegistry.PHP_CLASS, message = {PhpClassRule.MESSAGE, "Data Provider class name"}) |
| 126 | + @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, |
| 127 | + message = {AlphanumericRule.MESSAGE, "Data Provider class name"}) |
88 | 128 | private JTextField dataProviderClassName;
|
| 129 | + |
| 130 | + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Data Provider directory"}) |
| 131 | + @FieldValidation(rule = RuleRegistry.DIRECTORY, message = {DirectoryRule.MESSAGE, "Data Provider directory"}) |
| 132 | + @FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER, |
| 133 | + message = {AlphanumericRule.MESSAGE, "Data Provider directory"}) |
89 | 134 | private JTextField dataProviderDirectory;
|
| 135 | + |
90 | 136 | private JLabel aclLabel;
|
| 137 | + |
| 138 | + @FieldValidation(rule = RuleRegistry.ACL_RESOURCE_ID, message = {AclResourceIdRule.MESSAGE}) |
91 | 139 | private JTextField acl;
|
| 140 | + |
92 | 141 | private JLabel formButtonsLabel;//NOPMD
|
93 | 142 | private JLabel formNameLabel;//NOPMD
|
94 | 143 | private JLabel formLabelLabel;//NOPMD
|
@@ -127,7 +176,10 @@ public class NewUiComponentFormDialog extends AbstractDialog {
|
127 | 176 | public NewUiComponentFormDialog(final Project project, final PsiDirectory directory) {
|
128 | 177 | super();
|
129 | 178 | this.project = project;
|
130 |
| - this.validator = new NewUiComponentFormValidator(this); |
| 179 | + updateDialogSizeToDefaults(); |
| 180 | + formButtonsValidator = new FormButtonsValidator(this); |
| 181 | + formFieldsetsValidator = new FormFieldsetsValidator(this); |
| 182 | + formFieldsValidator = new FormFieldsValidator(this); |
131 | 183 | this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project);
|
132 | 184 |
|
133 | 185 | setContentPane(contentPane);
|
@@ -338,7 +390,7 @@ public static void open(final Project project, final PsiDirectory directory) {
|
338 | 390 | }
|
339 | 391 |
|
340 | 392 | private void onOK() {
|
341 |
| - if (!validator.validate()) { |
| 393 | + if (!validateFormFields()) { |
342 | 394 | return;
|
343 | 395 | }
|
344 | 396 |
|
@@ -639,4 +691,17 @@ private void toggleAcl() {
|
639 | 691 | acl.setVisible(false);
|
640 | 692 | aclLabel.setVisible(false);
|
641 | 693 | }
|
| 694 | + |
| 695 | + @Override |
| 696 | + protected boolean validateFormFields() { |
| 697 | + return super.validateFormFields() |
| 698 | + && formButtonsValidator.validate() |
| 699 | + && formFieldsetsValidator.validate() |
| 700 | + && formFieldsValidator.validate(); |
| 701 | + } |
| 702 | + |
| 703 | + private void updateDialogSizeToDefaults() { |
| 704 | + Dimension screenSize = getToolkit().getScreenSize(); |
| 705 | + setPreferredSize(new Dimension(screenSize.width/2, screenSize.height/2)); |
| 706 | + } |
642 | 707 | }
|
0 commit comments