Skip to content

Commit 0d7bdc2

Browse files
committed
Refactoring the bundle messaging
1 parent 8c8b1c8 commit 0d7bdc2

17 files changed

+172
-118
lines changed

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
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;
11+
import com.magento.idea.magento2plugin.bundles.ValidatorBundle;
1212
import javax.swing.*;
1313
import java.util.List;
1414

1515
public class CreateAPluginDialogValidator {
1616
private static CreateAPluginDialogValidator INSTANCE = null;
17+
private ValidatorBundle validatorBundle;
1718
private CreateAPluginDialog dialog;
1819

1920
public static CreateAPluginDialogValidator getInstance(CreateAPluginDialog dialog) {
@@ -25,88 +26,92 @@ public static CreateAPluginDialogValidator getInstance(CreateAPluginDialog dialo
2526
return INSTANCE;
2627
}
2728

29+
public CreateAPluginDialogValidator() {
30+
this.validatorBundle = new ValidatorBundle();
31+
}
32+
2833
public boolean validate(Project project)
2934
{
3035
String errorTitle = "Error";
3136
String pluginClassName = dialog.getPluginClassName();
3237

3338
if (pluginClassName.length() == 0) {
34-
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Plugin Class Name");
39+
String errorMessage = validatorBundle.message("validator.notEmpty", "Plugin Class Name");
3540
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
3641

3742
return false;
3843
}
3944

4045
if (!pluginClassName.matches(Regex.ALPHANUMERIC)) {
41-
String errorMessage = ValidatorBundle.message("validator.alphaNumericCharacters", "Plugin Class Name");
46+
String errorMessage = validatorBundle.message("validator.alphaNumericCharacters", "Plugin Class Name");
4247
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
4348

4449
return false;
4550
}
4651

4752
if (!Character.isUpperCase(pluginClassName.charAt(0)) && !Character.isDigit(pluginClassName.charAt(0))) {
48-
String errorMessage = ValidatorBundle.message("validator.startWithNumberOrCapitalLetter", "Plugin Class Name");
53+
String errorMessage = validatorBundle.message("validator.startWithNumberOrCapitalLetter", "Plugin Class Name");
4954
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
5055

5156
return false;
5257
}
5358

5459
String pluginDirectory = dialog.getPluginDirectory();
5560
if (pluginDirectory.length() == 0) {
56-
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Plugin Directory");
61+
String errorMessage = validatorBundle.message("validator.notEmpty", "Plugin Directory");
5762
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
5863

5964
return false;
6065
}
6166

6267
if (!pluginDirectory.matches(Regex.DIRECTORY)) {
63-
String errorMessage = ValidatorBundle.message("validator.directory.isNotValid", "Plugin Directory");
68+
String errorMessage = validatorBundle.message("validator.directory.isNotValid", "Plugin Directory");
6469
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
6570

6671
return false;
6772
}
6873

6974
String pluginName = dialog.getPluginName();
7075
if (pluginName.length() == 0) {
71-
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Plugin Name");
76+
String errorMessage = validatorBundle.message("validator.notEmpty", "Plugin Name");
7277
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
7378

7479
return false;
7580
}
7681

7782
if (!pluginName.matches(Regex.IDENTIFIER)) {
78-
String errorMessage = ValidatorBundle.message("validator.identifier", "Plugin Name");
83+
String errorMessage = validatorBundle.message("validator.identifier", "Plugin Name");
7984
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
8085

8186
return false;
8287
}
8388

8489
String sortOrder = dialog.getPluginSortOrder();
8590
if (sortOrder.length() == 0) {
86-
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Sort Order");
91+
String errorMessage = validatorBundle.message("validator.notEmpty", "Sort Order");
8792
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
8893

8994
return false;
9095
}
9196

9297
if (!sortOrder.matches(Regex.NUMERIC)) {
93-
String errorMessage = ValidatorBundle.message("validator.onlyNumbers", "Sort Order");
98+
String errorMessage = validatorBundle.message("validator.onlyNumbers", "Sort Order");
9499
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
95100

96101
return false;
97102
}
98103

99104
String pluginModule = dialog.getPluginModule();
100105
if (pluginModule.length() == 0) {
101-
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Plugin Module");
106+
String errorMessage = validatorBundle.message("validator.notEmpty", "Plugin Module");
102107
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
103108

104109
return false;
105110
}
106111

107112
List<String> allModulesList = ModuleIndex.getInstance(project).getEditableModuleNames();
108113
if (!allModulesList.contains(pluginModule)) {
109-
String errorMessage = ValidatorBundle.message("validator.module.noSuchModule", pluginModule);
114+
String errorMessage = validatorBundle.message("validator.module.noSuchModule", pluginModule);
110115
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
111116

112117
return false;

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
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-
import com.magento.idea.magento2plugin.validators.ValidatorBundle;
11+
import com.magento.idea.magento2plugin.bundles.ValidatorBundle;
1212
import javax.swing.*;
1313
import java.util.List;
1414

1515
public class CreateAnObserverDialogValidator {
1616
private static CreateAnObserverDialogValidator INSTANCE = null;
17+
private ValidatorBundle validatorBundle;
1718
private CreateAnObserverDialog dialog;
1819

1920
public static CreateAnObserverDialogValidator getInstance(CreateAnObserverDialog dialog) {
@@ -24,26 +25,30 @@ public static CreateAnObserverDialogValidator getInstance(CreateAnObserverDialog
2425
return INSTANCE;
2526
}
2627

28+
public CreateAnObserverDialogValidator() {
29+
this.validatorBundle = new ValidatorBundle();
30+
}
31+
2732
public boolean validate(Project project)
2833
{
2934
String errorTitle = "Error";
3035
String observerClassName = dialog.getObserverClassName();
3136
if (observerClassName.length() == 0) {
32-
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Observer Class Name");
37+
String errorMessage = validatorBundle.message("validator.notEmpty", "Observer Class Name");
3338
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
3439

3540
return false;
3641
}
3742

3843
if (!observerClassName.matches(Regex.ALPHANUMERIC)) {
39-
String errorMessage = ValidatorBundle.message("validator.alphaNumericCharacters", "Observer Class Name");
44+
String errorMessage = validatorBundle.message("validator.alphaNumericCharacters", "Observer Class Name");
4045
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
4146

4247
return false;
4348
}
4449

4550
if (!Character.isUpperCase(observerClassName.charAt(0)) && !Character.isDigit(observerClassName.charAt(0))) {
46-
String errorMessage = ValidatorBundle.message("validator.startWithNumberOrCapitalLetter", "Observer Class Name");
51+
String errorMessage = validatorBundle.message("validator.startWithNumberOrCapitalLetter", "Observer Class Name");
4752
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
4853

4954
return false;
@@ -52,14 +57,14 @@ public boolean validate(Project project)
5257
String observerDirectory = dialog.getObserverDirectory();
5358

5459
if (observerDirectory.length() == 0) {
55-
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Observer Directory");
60+
String errorMessage = validatorBundle.message("validator.notEmpty", "Observer Directory");
5661
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
5762

5863
return false;
5964
}
6065

6166
if (!observerDirectory.matches(Regex.DIRECTORY)) {
62-
String errorMessage = ValidatorBundle.message("validator.directory.isNotValid", "Observer Directory");
67+
String errorMessage = validatorBundle.message("validator.directory.isNotValid", "Observer Directory");
6368
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
6469

6570
return false;
@@ -68,15 +73,15 @@ public boolean validate(Project project)
6873

6974
String observerModule = dialog.getObserverModule();
7075
if (observerModule.length() == 0) {
71-
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Observer Module");
76+
String errorMessage = validatorBundle.message("validator.notEmpty", "Observer Module");
7277
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
7378

7479
return false;
7580
}
7681

7782
List<String> allModulesList = ModuleIndex.getInstance(project).getEditableModuleNames();
7883
if (!allModulesList.contains(observerModule)) {
79-
String errorMessage = ValidatorBundle.message("validator.module.noSuchModule", observerModule);
84+
String errorMessage = validatorBundle.message("validator.module.noSuchModule", observerModule);
8085
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
8186

8287
return false;

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
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;
9+
import com.magento.idea.magento2plugin.bundles.ValidatorBundle;
1010
import javax.swing.*;
1111

1212
public class NewBlockValidator {
1313
private static NewBlockValidator INSTANCE = null;
14+
private ValidatorBundle validatorBundle;
1415
private NewBlockDialog dialog;
1516

1617
public static NewBlockValidator getInstance(NewBlockDialog dialog) {
@@ -21,42 +22,46 @@ public static NewBlockValidator getInstance(NewBlockDialog dialog) {
2122
return INSTANCE;
2223
}
2324

25+
public NewBlockValidator() {
26+
this.validatorBundle = new ValidatorBundle();
27+
}
28+
2429
public boolean validate()
2530
{
2631
String errorTitle = "Error";
2732

2833
String moduleName = dialog.getBlockName();
2934
if (moduleName.length() == 0) {
30-
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Block Name");
35+
String errorMessage = validatorBundle.message("validator.notEmpty", "Block Name");
3136
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
3237

3338
return false;
3439
}
3540

3641
if (!moduleName.matches(Regex.ALPHANUMERIC)) {
37-
String errorMessage = ValidatorBundle.message("validator.alphaNumericCharacters", "Block Name");
42+
String errorMessage = validatorBundle.message("validator.alphaNumericCharacters", "Block Name");
3843
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
3944

4045
return false;
4146
}
4247

4348
if (!Character.isUpperCase(moduleName.charAt(0)) && !Character.isDigit(moduleName.charAt(0))) {
44-
String errorMessage = ValidatorBundle.message("validator.startWithNumberOrCapitalLetter", "Block Name");
49+
String errorMessage = validatorBundle.message("validator.startWithNumberOrCapitalLetter", "Block Name");
4550
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
4651

4752
return false;
4853
}
4954

5055
String pluginDirectory = dialog.getBlockDirectory();
5156
if (pluginDirectory.length() == 0) {
52-
String errorMessage = ValidatorBundle.message("validator.notEmpty", "Block Directory");
57+
String errorMessage = validatorBundle.message("validator.notEmpty", "Block Directory");
5358
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
5459

5560
return false;
5661
}
5762

5863
if (!pluginDirectory.matches(Regex.DIRECTORY)) {
59-
String errorMessage = ValidatorBundle.message("validator.directory.isNotValid", "Block Directory");
64+
String errorMessage = validatorBundle.message("validator.directory.isNotValid", "Block Directory");
6065
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
6166

6267
return false;

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
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;
9+
import com.magento.idea.magento2plugin.bundles.ValidatorBundle;
1010

1111
import javax.swing.*;
1212

1313
public class NewGraphQlResolverValidator {
1414
private static NewGraphQlResolverValidator INSTANCE = null;
15+
private ValidatorBundle validatorBundle;
1516
private NewGraphQlResolverDialog dialog;
1617

1718
public static NewGraphQlResolverValidator getInstance(NewGraphQlResolverDialog dialog) {
@@ -22,42 +23,46 @@ public static NewGraphQlResolverValidator getInstance(NewGraphQlResolverDialog d
2223
return INSTANCE;
2324
}
2425

26+
public NewGraphQlResolverValidator() {
27+
this.validatorBundle = new ValidatorBundle();
28+
}
29+
2530
public boolean validate()
2631
{
2732
String errorTitle = "Error";
2833

2934
String resolverClassName = dialog.getGraphQlResolverClassName();
3035
if (resolverClassName.length() == 0) {
31-
String errorMessage = ValidatorBundle.message("validator.notEmpty", "GraphQL Resolver Name");
36+
String errorMessage = validatorBundle.message("validator.notEmpty", "GraphQL Resolver Name");
3237
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
3338

3439
return false;
3540
}
3641

3742
if (!resolverClassName.matches(Regex.ALPHANUMERIC)) {
38-
String errorMessage = ValidatorBundle.message("validator.alphaNumericCharacters", "GraphQL Resolver Name");
43+
String errorMessage = validatorBundle.message("validator.alphaNumericCharacters", "GraphQL Resolver Name");
3944
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
4045

4146
return false;
4247
}
4348

4449
if (!Character.isUpperCase(resolverClassName.charAt(0)) && !Character.isDigit(resolverClassName.charAt(0))) {
45-
String errorMessage = ValidatorBundle.message("validator.startWithNumberOrCapitalLetter", "GraphQL Resolver Name");
50+
String errorMessage = validatorBundle.message("validator.startWithNumberOrCapitalLetter", "GraphQL Resolver Name");
4651
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
4752

4853
return false;
4954
}
5055

5156
String graphQlResolverDirectory = dialog.getGraphQlResolverDirectory();
5257
if (graphQlResolverDirectory.length() == 0) {
53-
String errorMessage = ValidatorBundle.message("validator.notEmpty", "GraphQL Resolver Directory");
58+
String errorMessage = validatorBundle.message("validator.notEmpty", "GraphQL Resolver Directory");
5459
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
5560

5661
return false;
5762
}
5863

5964
if (!graphQlResolverDirectory.matches(Regex.DIRECTORY)) {
60-
String errorMessage = ValidatorBundle.message("validator.directory.isNotValid", "GraphQL Resolver Directory");
65+
String errorMessage = validatorBundle.message("validator.directory.isNotValid", "GraphQL Resolver Directory");
6166
JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE);
6267

6368
return false;

0 commit comments

Comments
 (0)