Skip to content

Commit 9ec4c38

Browse files
committed
Changed validator for CreateAPluginDialog
1 parent 706421a commit 9ec4c38

File tree

5 files changed

+61
-292
lines changed

5 files changed

+61
-292
lines changed

resources/magento2/common.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ common.theme.target=Target Theme
2323
common.area.target=Target Area
2424
common.name=Name
2525
common.className=Class Name
26+
common.pluginName=Plugin Name
2627
common.directoryPath=Directory Path
2728
common.methodType=Method Type
2829
common.sortOrder=Sort Order

resources/magento2/validation.properties

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
validator.notEmpty=The {0} field must not be empty
22
validator.package.validPath=Please specify a valid Magento 2 installation path
3-
validator.alphaNumericCharacters={0} must contain letters and numbers only
3+
validator.alphaNumericCharacters=The {0} field must contain letters and numbers only
44
validator.alphaNumericAndUnderscoreCharacters={0} must contain letters, numbers and underscores only
5-
validator.alreadyDeclared={0} is already declared in the {1} module.
6-
validator.startWithNumberOrCapitalLetter={0} must start from a number or a capital letter
7-
validator.onlyNumbers={0} must contain numbers only
5+
validator.alreadyDeclared={0} is already declared in the {1} module
6+
validator.startWithNumberOrCapitalLetter=The {0} field must start with a number or a capital letter
7+
validator.onlyNumbers=The {0} field must contain numbers only
88
validator.mustNotBeNegative={0} must not be negative
9-
validator.identifier={0} must contain letters, numbers, dashes, and underscores only
10-
validator.class.isNotValid={0} is not valid class name
9+
validator.identifier=The {0} field must contain letters, numbers, dashes, and underscores only
10+
validator.class.isNotValid=The {0} field does not contain a valid class name
1111
validator.class.shouldBeUnique=Duplicated class {0}
1212
validator.namespace.isNotValid={0} is not valid namespace name
13-
validator.directory.isNotValid={0} is not valid
13+
validator.directory.isNotValid=The {0} field does not contain a valid directory
1414
validator.module.noSuchModule=No such module {0}
1515
validator.file.alreadyExists={0} already exists
1616
validator.file.cantBeCreated={0} can't be created

src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
109109
</constraints>
110110
<properties>
111-
<text resource-bundle="magento2/common" key="common.name"/>
111+
<text resource-bundle="magento2/common" key="common.pluginName"/>
112112
</properties>
113113
</component>
114114
<component id="9431c" class="javax.swing.JTextField" binding="pluginName">

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

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
import com.magento.idea.magento2plugin.actions.generation.CreateAPluginAction;
1212
import com.magento.idea.magento2plugin.actions.generation.data.PluginDiXmlData;
1313
import com.magento.idea.magento2plugin.actions.generation.data.PluginFileData;
14-
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.CreateAPluginDialogValidator;
14+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
15+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
16+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphanumericRule;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule;
18+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierRule;
19+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
20+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NumericRule;
21+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule;
22+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.StartWithNumberOrCapitalLetterRule;
1523
import com.magento.idea.magento2plugin.actions.generation.generator.PluginClassGenerator;
1624
import com.magento.idea.magento2plugin.actions.generation.generator.PluginDiXmlGenerator;
1725
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
@@ -21,7 +29,6 @@
2129
import com.magento.idea.magento2plugin.magento.packages.Package;
2230
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
2331
import java.awt.event.ActionEvent;
24-
import java.awt.event.ActionListener;
2532
import java.awt.event.KeyEvent;
2633
import java.awt.event.WindowAdapter;
2734
import java.awt.event.WindowEvent;
@@ -41,18 +48,50 @@ public class CreateAPluginDialog extends AbstractDialog {
4148
private final Project project;
4249
private final Method targetMethod;
4350
private final PhpClass targetClass;
44-
@NotNull
45-
private final CreateAPluginDialogValidator validator;
4651
private JPanel contentPane;
4752
private JButton buttonOK;
4853
private JButton buttonCancel;
49-
private JTextField pluginClassName;
50-
private JTextField pluginDirectory;
5154
private JComboBox pluginType;
52-
private FilteredComboBox pluginModule;
5355
private JComboBox pluginArea;
56+
57+
private static final String CLASS_NAME = "class name";
58+
private static final String DIRECTORY = "directory path";
59+
private static final String SORT_ORDER = "sort order";
60+
private static final String PLUGIN_NAME = "plugin name";
61+
private static final String TARGET_MODULE = "target module";
62+
63+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
64+
message = {NotEmptyRule.MESSAGE, TARGET_MODULE})
65+
private FilteredComboBox pluginModule;
66+
67+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
68+
message = {NotEmptyRule.MESSAGE, CLASS_NAME})
69+
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
70+
message = {PhpClassRule.MESSAGE, CLASS_NAME})
71+
@FieldValidation(rule = RuleRegistry.ALPHANUMERIC,
72+
message = {AlphanumericRule.MESSAGE, CLASS_NAME})
73+
@FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER,
74+
message = {StartWithNumberOrCapitalLetterRule.MESSAGE, CLASS_NAME})
75+
private JTextField pluginClassName;
76+
77+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
78+
message = {NotEmptyRule.MESSAGE, DIRECTORY})
79+
@FieldValidation(rule = RuleRegistry.DIRECTORY,
80+
message = {DirectoryRule.MESSAGE, DIRECTORY})
81+
private JTextField pluginDirectory;
82+
83+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
84+
message = {NotEmptyRule.MESSAGE, SORT_ORDER})
85+
@FieldValidation(rule = RuleRegistry.NUMERIC,
86+
message = {NumericRule.MESSAGE, SORT_ORDER})
5487
private JTextField pluginSortOrder;
88+
89+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
90+
message = {NotEmptyRule.MESSAGE, PLUGIN_NAME})
91+
@FieldValidation(rule = RuleRegistry.IDENTIFIER,
92+
message = {IdentifierRule.MESSAGE, PLUGIN_NAME})
5593
private JTextField pluginName;
94+
5695
private JLabel pluginDirectoryName;//NOPMD
5796
private JLabel selectPluginModule;//NOPMD
5897
private JLabel pluginTypeLabel;//NOPMD
@@ -77,25 +116,15 @@ public CreateAPluginDialog(
77116
this.project = project;
78117
this.targetMethod = targetMethod;
79118
this.targetClass = targetClass;
80-
this.validator = CreateAPluginDialogValidator.getInstance(this);
81119

82120
setContentPane(contentPane);
83121
setModal(true);
84122
getRootPane().setDefaultButton(buttonOK);
85123
fillPluginTypeOptions();
86124
fillTargetAreaOptions();
87125

88-
buttonOK.addActionListener(new ActionListener() {
89-
public void actionPerformed(final ActionEvent event) {
90-
onOK();
91-
}
92-
});
93-
94-
buttonCancel.addActionListener(new ActionListener() {
95-
public void actionPerformed(final ActionEvent event) {
96-
onCancel();
97-
}
98-
});
126+
buttonOK.addActionListener((final ActionEvent event) -> onOK());
127+
buttonCancel.addActionListener((final ActionEvent event) -> onCancel());
99128

100129
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
101130
addWindowListener(new WindowAdapter() {
@@ -104,11 +133,9 @@ public void windowClosing(final WindowEvent event) {
104133
}
105134
});
106135

107-
contentPane.registerKeyboardAction(new ActionListener() {
108-
public void actionPerformed(final ActionEvent event) {
109-
onCancel();
110-
}
111-
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
136+
contentPane.registerKeyboardAction(
137+
(final ActionEvent event) -> onCancel(),
138+
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
112139
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
113140
);
114141
}
@@ -126,7 +153,7 @@ private void fillTargetAreaOptions() {
126153
}
127154

128155
protected void onOK() {
129-
if (!validator.validate(project)) {
156+
if (!validateFormFields()) {
130157
return;
131158
}
132159
new PluginClassGenerator(new PluginFileData(

0 commit comments

Comments
 (0)