Skip to content

Commit a2257a1

Browse files
authored
Merge pull request #336 from drpayyne/issue-283
Changed validator for CreateAnObserverDialog
2 parents 2e9f42f + 8312dd7 commit a2257a1

File tree

3 files changed

+36
-208
lines changed

3 files changed

+36
-208
lines changed

src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
import com.magento.idea.magento2plugin.actions.generation.CreateAnObserverAction;
1111
import com.magento.idea.magento2plugin.actions.generation.data.ObserverEventsXmlData;
1212
import com.magento.idea.magento2plugin.actions.generation.data.ObserverFileData;
13-
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.CreateAnObserverDialogValidator;
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.AlphanumericWithUnderscoreRule;
16+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
18+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule;
1419
import com.magento.idea.magento2plugin.actions.generation.generator.ObserverClassGenerator;
1520
import com.magento.idea.magento2plugin.actions.generation.generator.ObserverEventsXmlGenerator;
1621
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
@@ -36,26 +41,47 @@
3641
"PMD.MissingSerialVersionUID",
3742
"PMD.DataClass",
3843
"PMD.UnusedPrivateField",
44+
"PMD.ExcessiveImports",
3945
})
4046
public class CreateAnObserverDialog extends AbstractDialog {
4147
@NotNull
4248
private final Project project;
43-
@NotNull
44-
private final CreateAnObserverDialogValidator validator;
4549
private final String targetEvent;
4650
private JPanel contentPane;
4751
private JButton buttonOK;
4852
private JButton buttonCancel;
49-
private JTextField observerClassName;
50-
private JTextField observerDirectory;
51-
private FilteredComboBox observerModule;
5253
private JComboBox observerArea;
53-
private JTextField observerName;
5454
private JLabel observerClassNameLabel;
5555
private JLabel observerDirectoryName;
5656
private JLabel selectObserverModule;
5757
private JLabel observerAreaLabel;
5858
private JLabel observerNameLabel;
59+
private static final String OBSERVER_MODULE = "target module";
60+
private static final String OBSERVER_CLASS = "class name";
61+
private static final String OBSERVER_DIRECTORY = "directory";
62+
private static final String OBSERVER_NAME = "name";
63+
64+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
65+
message = {NotEmptyRule.MESSAGE, OBSERVER_MODULE})
66+
private FilteredComboBox observerModule;
67+
68+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
69+
message = {NotEmptyRule.MESSAGE, OBSERVER_CLASS})
70+
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
71+
message = {PhpClassRule.MESSAGE, OBSERVER_CLASS})
72+
private JTextField observerClassName;
73+
74+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
75+
message = {NotEmptyRule.MESSAGE, OBSERVER_DIRECTORY})
76+
@FieldValidation(rule = RuleRegistry.DIRECTORY,
77+
message = {DirectoryRule.MESSAGE, OBSERVER_DIRECTORY})
78+
private JTextField observerDirectory;
79+
80+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
81+
message = {NotEmptyRule.MESSAGE, OBSERVER_NAME})
82+
@FieldValidation(rule = RuleRegistry.ALPHANUMERIC_WITH_UNDERSCORE,
83+
message = {AlphanumericWithUnderscoreRule.MESSAGE, OBSERVER_NAME})
84+
private JTextField observerName;
5985

6086
/**
6187
* Constructor.
@@ -68,7 +94,6 @@ public CreateAnObserverDialog(@NotNull final Project project, final String targe
6894

6995
this.project = project;
7096
this.targetEvent = targetEvent;
71-
this.validator = CreateAnObserverDialogValidator.getInstance(this);
7297

7398
setContentPane(contentPane);
7499
setModal(true);
@@ -119,7 +144,7 @@ private void fillTargetAreaOptions() {
119144
* Perform code generation using input data.
120145
*/
121146
private void onOK() {
122-
if (!validator.validate(project)) {
147+
if (!validateFormFields()) {
123148
return;
124149
}
125150
new ObserverClassGenerator(new ObserverFileData(

src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/CreateAnObserverDialogValidator.java

Lines changed: 0 additions & 198 deletions
This file was deleted.

src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/PhpClassRule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule;
77

8+
import com.jetbrains.php.refactoring.PhpNameUtil;
89
import com.magento.idea.magento2plugin.util.RegExUtil;
910

1011
public class PhpClassRule implements ValidationRule {
@@ -13,7 +14,7 @@ public class PhpClassRule implements ValidationRule {
1314

1415
@Override
1516
public boolean check(final String value) {
16-
return value.matches(RegExUtil.Magento.PHP_CLASS);
17+
return value.matches(RegExUtil.Magento.PHP_CLASS) && PhpNameUtil.isValidClassName(value);
1718
}
1819

1920
public static ValidationRule getInstance() {

0 commit comments

Comments
 (0)