Skip to content

Commit 3ab4345

Browse files
committed
Implementing the validation logic to all validators
1 parent b17cc97 commit 3ab4345

File tree

11 files changed

+179
-133
lines changed

11 files changed

+179
-133
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ validator.notEmpty={0} must not be empty
22
validator.package.validPath=Please specify a valid Magento 2 installation path!
33
validator.alphaNumericCharacters={0} must contain letters and numbers only
44
validator.startWithNumberOrCapitalLetter={0} must start from a number or a capital letter
5+
validator.directory.isNotValid={0} is not valid
6+
validator.module.noSuchModule=No such module {0}.

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.magento.idea.magento2plugin.actions.generation.dialog.CreateAPluginDialog;
99
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
1010
import com.magento.idea.magento2plugin.util.Regex;
11+
import com.magento.idea.magento2plugin.validators.ValidatorBundle;
1112
import javax.swing.*;
1213
import java.util.List;
1314

@@ -19,6 +20,7 @@ public static CreateAPluginDialogValidator getInstance(CreateAPluginDialog dialo
1920
if (null == INSTANCE) {
2021
INSTANCE = new CreateAPluginDialogValidator();
2122
}
23+
2224
INSTANCE.dialog = dialog;
2325
return INSTANCE;
2426
}
@@ -27,35 +29,48 @@ public boolean validate(Project project)
2729
{
2830
String errorTitle = "Error";
2931
String pluginClassName = dialog.getPluginClassName();
32+
3033
if (pluginClassName.length() == 0) {
31-
JOptionPane.showMessageDialog(null, "Plugin Class Name must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
34+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Plugin Class Name");
35+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
36+
3237
return false;
3338
}
3439

3540
if (!pluginClassName.matches(Regex.ALPHANUMERIC)) {
36-
JOptionPane.showMessageDialog(null, "Plugin Class Name must contain letters and numbers only.", errorTitle, JOptionPane.ERROR_MESSAGE);
41+
String errorMessage = ValidatorBundle.message("validator.alphaNumericCharacters", "Plugin Class Name");
42+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
43+
3744
return false;
3845
}
3946

4047
if (!Character.isUpperCase(pluginClassName.charAt(0)) && !Character.isDigit(pluginClassName.charAt(0))) {
41-
JOptionPane.showMessageDialog(null, "Plugin Class Name must start from a number or a capital letter", errorTitle, JOptionPane.ERROR_MESSAGE);
48+
String errorMessage = ValidatorBundle.message("validator.startWithNumberOrCapitalLetter", "Plugin Class Name");
49+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
50+
4251
return false;
4352
}
4453

4554
String pluginDirectory = dialog.getPluginDirectory();
4655
if (pluginDirectory.length() == 0) {
47-
JOptionPane.showMessageDialog(null, "Plugin Directory must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
56+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Plugin Directory");
57+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
58+
4859
return false;
4960
}
5061

5162
if (!pluginDirectory.matches(Regex.DIRECTORY)) {
52-
JOptionPane.showMessageDialog(null, "Plugin Directory is not valid.", errorTitle, JOptionPane.ERROR_MESSAGE);
63+
String errorMessage = ValidatorBundle.message("validator.directory.isNotValid", "Plugin Directory");
64+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
65+
5366
return false;
5467
}
5568

5669
String pluginName = dialog.getPluginName();
5770
if (pluginName.length() == 0) {
58-
JOptionPane.showMessageDialog(null, "Plugin Name must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
71+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Plugin Name");
72+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
73+
5974
return false;
6075
}
6176

@@ -66,7 +81,9 @@ public boolean validate(Project project)
6681

6782
String sortOrder = dialog.getPluginSortOrder();
6883
if (sortOrder.length() == 0) {
69-
JOptionPane.showMessageDialog(null, "Sort Order must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
84+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Sort Order");
85+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
86+
7087
return false;
7188
}
7289

@@ -77,7 +94,9 @@ public boolean validate(Project project)
7794

7895
String pluginModule = dialog.getPluginModule();
7996
if (pluginModule.length() == 0) {
80-
JOptionPane.showMessageDialog(null, "Plugin Module must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
97+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Plugin Module");
98+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
99+
81100
return false;
82101
}
83102

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.magento.idea.magento2plugin.actions.generation.dialog.CreateAnObserverDialog;
99
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
1010
import com.magento.idea.magento2plugin.util.Regex;
11-
11+
import com.magento.idea.magento2plugin.validators.ValidatorBundle;
1212
import javax.swing.*;
1313
import java.util.List;
1414

@@ -29,41 +29,56 @@ public boolean validate(Project project)
2929
String errorTitle = "Error";
3030
String observerClassName = dialog.getObserverClassName();
3131
if (observerClassName.length() == 0) {
32-
JOptionPane.showMessageDialog(null, "Observer Class Name must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
32+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Observer Class Name");
33+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
34+
3335
return false;
3436
}
3537

3638
if (!observerClassName.matches(Regex.ALPHANUMERIC)) {
37-
JOptionPane.showMessageDialog(null, "Observer Class Name must contain letters and numbers only.", errorTitle, JOptionPane.ERROR_MESSAGE);
39+
String errorMessage = ValidatorBundle.message("validator.alphaNumericCharacters", "Observer Class Name");
40+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
41+
3842
return false;
3943
}
4044

4145
if (!Character.isUpperCase(observerClassName.charAt(0)) && !Character.isDigit(observerClassName.charAt(0))) {
42-
JOptionPane.showMessageDialog(null, "Observer Class Name must start from a number or a capital letter", errorTitle, JOptionPane.ERROR_MESSAGE);
46+
String errorMessage = ValidatorBundle.message("validator.startWithNumberOrCapitalLetter", "Observer Class Name");
47+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
48+
4349
return false;
4450
}
4551

4652
String observerDirectory = dialog.getObserverDirectory();
53+
4754
if (observerDirectory.length() == 0) {
48-
JOptionPane.showMessageDialog(null, "Observer Directory must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
55+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Observer Directory");
56+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
57+
4958
return false;
5059
}
5160

5261
if (!observerDirectory.matches(Regex.DIRECTORY)) {
53-
JOptionPane.showMessageDialog(null, "Observer Directory is not valid.", errorTitle, JOptionPane.ERROR_MESSAGE);
62+
String errorMessage = ValidatorBundle.message("validator.directory.isNotValid", "Observer Directory");
63+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
64+
5465
return false;
5566
}
5667

5768

5869
String observerModule = dialog.getObserverModule();
5970
if (observerModule.length() == 0) {
60-
JOptionPane.showMessageDialog(null, "Observer Module must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
71+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Observer Module");
72+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
73+
6174
return false;
6275
}
6376

6477
List<String> allModulesList = ModuleIndex.getInstance(project).getEditableModuleNames();
6578
if (!allModulesList.contains(observerModule)) {
66-
JOptionPane.showMessageDialog(null, "No such module '".concat(observerModule).concat("'."), errorTitle, JOptionPane.ERROR_MESSAGE);
79+
String errorMessage = ValidatorBundle.message("validator.module.noSuchModule", observerModule);
80+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
81+
6782
return false;
6883
}
6984

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.magento.idea.magento2plugin.actions.generation.dialog.NewBlockDialog;
88
import com.magento.idea.magento2plugin.util.Regex;
9+
import com.magento.idea.magento2plugin.validators.ValidatorBundle;
910
import javax.swing.*;
1011

1112
public class NewBlockValidator {
@@ -26,28 +27,38 @@ public boolean validate()
2627

2728
String moduleName = dialog.getBlockName();
2829
if (moduleName.length() == 0) {
29-
JOptionPane.showMessageDialog(null, "Block Name must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
30+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Block Name");
31+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
32+
3033
return false;
3134
}
3235

3336
if (!moduleName.matches(Regex.ALPHANUMERIC)) {
34-
JOptionPane.showMessageDialog(null, "Block Name must contain letters and numbers only.", errorTitle, JOptionPane.ERROR_MESSAGE);
37+
String errorMessage = ValidatorBundle.message("validator.alphaNumericCharacters", "Block Name");
38+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
39+
3540
return false;
3641
}
3742

3843
if (!Character.isUpperCase(moduleName.charAt(0)) && !Character.isDigit(moduleName.charAt(0))) {
39-
JOptionPane.showMessageDialog(null, "Block Name must start from a number or a capital letter", errorTitle, JOptionPane.ERROR_MESSAGE);
44+
String errorMessage = ValidatorBundle.message("validator.startWithNumberOrCapitalLetter", "Block Name");
45+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
46+
4047
return false;
4148
}
4249

4350
String pluginDirectory = dialog.getBlockDirectory();
4451
if (pluginDirectory.length() == 0) {
45-
JOptionPane.showMessageDialog(null, "Block Directory must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
52+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Block Directory");
53+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
54+
4655
return false;
4756
}
4857

4958
if (!pluginDirectory.matches(Regex.DIRECTORY)) {
50-
JOptionPane.showMessageDialog(null, "Block Directory is not valid.", errorTitle, JOptionPane.ERROR_MESSAGE);
59+
String errorMessage = ValidatorBundle.message("validator.directory.isNotValid", "Block Directory");
60+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
61+
5162
return false;
5263
}
5364

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.magento.idea.magento2plugin.actions.generation.dialog.NewGraphQlResolverDialog;
88
import com.magento.idea.magento2plugin.util.Regex;
9+
import com.magento.idea.magento2plugin.validators.ValidatorBundle;
910

1011
import javax.swing.*;
1112

@@ -27,28 +28,38 @@ public boolean validate()
2728

2829
String resolverClassName = dialog.getGraphQlResolverClassName();
2930
if (resolverClassName.length() == 0) {
30-
JOptionPane.showMessageDialog(null, "GraphQL Resolver Name must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
31+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "GraphQL Resolver Name");
32+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
33+
3134
return false;
3235
}
3336

3437
if (!resolverClassName.matches(Regex.ALPHANUMERIC)) {
35-
JOptionPane.showMessageDialog(null, "GraphQL Resolver Name must contain letters and numbers only.", errorTitle, JOptionPane.ERROR_MESSAGE);
38+
String errorMessage = ValidatorBundle.message("validator.alphaNumericCharacters", "GraphQL Resolver Name");
39+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
40+
3641
return false;
3742
}
3843

3944
if (!Character.isUpperCase(resolverClassName.charAt(0)) && !Character.isDigit(resolverClassName.charAt(0))) {
40-
JOptionPane.showMessageDialog(null, "GraphQL Resolver Name must start from a number or a capital letter", errorTitle, JOptionPane.ERROR_MESSAGE);
45+
String errorMessage = ValidatorBundle.message("validator.startWithNumberOrCapitalLetter", "GraphQL Resolver Name");
46+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
47+
4148
return false;
4249
}
4350

4451
String graphQlResolverDirectory = dialog.getGraphQlResolverDirectory();
4552
if (graphQlResolverDirectory.length() == 0) {
46-
JOptionPane.showMessageDialog(null, "GraphQL Resolver Directory must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
53+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "GraphQL Resolver Directory");
54+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
55+
4756
return false;
4857
}
4958

5059
if (!graphQlResolverDirectory.matches(Regex.DIRECTORY)) {
51-
JOptionPane.showMessageDialog(null, "GraphQL Resolver Directory is not valid.", errorTitle, JOptionPane.ERROR_MESSAGE);
60+
String errorMessage = ValidatorBundle.message("validator.directory.isNotValid", "GraphQL Resolver Directory");
61+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
62+
5263
return false;
5364
}
5465

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package com.magento.idea.magento2plugin.actions.generation.dialog.validator;
66

77
import com.magento.idea.magento2plugin.actions.generation.dialog.NewModuleDialog;
8+
import com.magento.idea.magento2plugin.validators.ValidatorBundle;
89
import com.magento.idea.magento2plugin.util.Regex;
910
import javax.swing.*;
1011

@@ -25,43 +26,59 @@ public boolean validate()
2526
String errorTitle = "Error";
2627
String packageName = dialog.getPackageName();
2728
if (packageName.length() == 0) {
28-
JOptionPane.showMessageDialog(null, "Package Name must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
29+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Package Name");
30+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
31+
2932
return false;
3033
}
3134

3235
if (!packageName.matches(Regex.ALPHANUMERIC)) {
33-
JOptionPane.showMessageDialog(null, "Package Name must contain letters and numbers only.", errorTitle, JOptionPane.ERROR_MESSAGE);
36+
String errorMessage = ValidatorBundle.message("validator.alphaNumericCharacters", "Package Name");
37+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
38+
3439
return false;
3540
}
3641

3742
if (!Character.isUpperCase(packageName.charAt(0)) && !Character.isDigit(packageName.charAt(0))) {
38-
JOptionPane.showMessageDialog(null, "Package Name must start from a number or a capital letter", errorTitle, JOptionPane.ERROR_MESSAGE);
43+
String errorMessage = ValidatorBundle.message("validator.startWithNumberOrCapitalLetter", "Package Name");
44+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
45+
3946
return false;
4047
}
4148

4249
String moduleName = dialog.getModuleName();
4350
if (moduleName.length() == 0) {
44-
JOptionPane.showMessageDialog(null, "Module Name must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
51+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Module Name");
52+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
53+
4554
return false;
4655
}
4756

4857
if (!moduleName.matches(Regex.ALPHANUMERIC)) {
49-
JOptionPane.showMessageDialog(null, "Module Name must contain letters and numbers only.", errorTitle, JOptionPane.ERROR_MESSAGE);
58+
String errorMessage = ValidatorBundle.message("validator.alphaNumericCharacters", "Module Name");
59+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
60+
5061
return false;
5162
}
5263

5364
if (!Character.isUpperCase(moduleName.charAt(0)) && !Character.isDigit(moduleName.charAt(0))) {
54-
JOptionPane.showMessageDialog(null, "Module Name must start from a number or a capital letter", errorTitle, JOptionPane.ERROR_MESSAGE);
65+
String errorMessage = ValidatorBundle.message("validator.startWithNumberOrCapitalLetter", "Module Name");
66+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
67+
5568
return false;
5669
}
5770

5871
if (dialog.getModuleVersion().length() == 0) {
59-
JOptionPane.showMessageDialog(null, "Module Version must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
72+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Module Version");
73+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
74+
6075
return false;
6176
}
6277

6378
if (dialog.getModuleDescription().length() == 0) {
64-
JOptionPane.showMessageDialog(null, "Module Version must not be empty.", errorTitle, JOptionPane.ERROR_MESSAGE);
79+
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Module Description");
80+
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
81+
6582
return false;
6683
}
6784

0 commit comments

Comments
 (0)