Skip to content

Commit 5b037e5

Browse files
committed
Changed validator for CreateAnObserverDialog
1 parent cafc9db commit 5b037e5

File tree

3 files changed

+35
-208
lines changed

3 files changed

+35
-208
lines changed

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

Lines changed: 33 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;
@@ -40,22 +45,42 @@
4045
public class CreateAnObserverDialog extends AbstractDialog {
4146
@NotNull
4247
private final Project project;
43-
@NotNull
44-
private final CreateAnObserverDialogValidator validator;
4548
private final String targetEvent;
4649
private JPanel contentPane;
4750
private JButton buttonOK;
4851
private JButton buttonCancel;
49-
private JTextField observerClassName;
50-
private JTextField observerDirectory;
51-
private FilteredComboBox observerModule;
5252
private JComboBox observerArea;
53-
private JTextField observerName;
5453
private JLabel observerClassNameLabel;
5554
private JLabel observerDirectoryName;
5655
private JLabel selectObserverModule;
5756
private JLabel observerAreaLabel;
5857
private JLabel observerNameLabel;
58+
private static final String OBSERVER_MODULE = "target module";
59+
private static final String OBSERVER_CLASS = "class name";
60+
private static final String OBSERVER_DIRECTORY = "directory";
61+
private static final String OBSERVER_NAME = "name";
62+
63+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
64+
message = {NotEmptyRule.MESSAGE, OBSERVER_MODULE})
65+
private FilteredComboBox observerModule;
66+
67+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
68+
message = {NotEmptyRule.MESSAGE, OBSERVER_CLASS})
69+
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
70+
message = {PhpClassRule.MESSAGE, OBSERVER_CLASS})
71+
private JTextField observerClassName;
72+
73+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
74+
message = {NotEmptyRule.MESSAGE, OBSERVER_DIRECTORY})
75+
@FieldValidation(rule = RuleRegistry.DIRECTORY,
76+
message = {DirectoryRule.MESSAGE, OBSERVER_DIRECTORY})
77+
private JTextField observerDirectory;
78+
79+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
80+
message = {NotEmptyRule.MESSAGE, OBSERVER_NAME})
81+
@FieldValidation(rule = RuleRegistry.ALPHANUMERIC_WITH_UNDERSCORE,
82+
message = {AlphanumericWithUnderscoreRule.MESSAGE, OBSERVER_NAME})
83+
private JTextField observerName;
5984

6085
/**
6186
* Constructor.
@@ -68,7 +93,6 @@ public CreateAnObserverDialog(@NotNull final Project project, final String targe
6893

6994
this.project = project;
7095
this.targetEvent = targetEvent;
71-
this.validator = CreateAnObserverDialogValidator.getInstance(this);
7296

7397
setContentPane(contentPane);
7498
setModal(true);
@@ -119,7 +143,7 @@ private void fillTargetAreaOptions() {
119143
* Perform code generation using input data.
120144
*/
121145
private void onOK() {
122-
if (!validator.validate(project)) {
146+
if (!validateFormFields()) {
123147
return;
124148
}
125149
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)