Skip to content

Commit 155bb58

Browse files
author
Vitaliy
authored
Merge branch '2.1.0-develop' into issue-301
2 parents 7853387 + bbfc850 commit 155bb58

File tree

10 files changed

+87
-342
lines changed

10 files changed

+87
-342
lines changed

resources/magento2/common.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ common.httpMethod=HTTP Method
88
common.controller.name=Controller Name
99
common.controller.inheritAction=Inherit Action Class
1010
common.controller.backend.acl=Admin Resource ACL
11-
common.controller.action=Controller Action
11+
common.controller.action=Action Name
1212
common.ok=OK
1313
common.yes=Yes
1414
common.no=No

resources/magento2/validation.properties

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
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} must contain letters and numbers only
44
validator.alphaNumericAndUnderscoreCharacters={0} must contain letters, numbers and underscores only
55
validator.alreadyDeclared={0} is already declared in the {1} module.
6-
validator.startWithNumberOrCapitalLetter={0} must start from a number or a capital letter
6+
validator.startWithNumberOrCapitalLetter=The {0} must start from a number or a capital letter
77
validator.onlyNumbers={0} must contain numbers only
88
validator.mustNotBeNegative={0} must not be negative
99
validator.identifier={0} must contain letters, numbers, dashes, and underscores only
10-
validator.class.isNotValid={0} is not valid class name
10+
validator.class.isNotValid=The {0} field does not contain a valid class name
1111
validator.class.shouldBeUnique=Duplicated class {0}
12-
validator.namespace.isNotValid={0} is not valid namespace name
12+
validator.namespace.isNotValid=The {0} is not valid namespace name
1313
validator.directory.isNotValid={0} is not valid
14+
validator.directory.php.isNotValid=The {0} field does not contain a valid PHP directory
1415
validator.module.noSuchModule=No such module {0}
1516
validator.file.alreadyExists={0} already exists
1617
validator.file.cantBeCreated={0} can't be created

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

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
import com.intellij.psi.PsiFile;
1111
import com.magento.idea.magento2plugin.actions.generation.NewBlockAction;
1212
import com.magento.idea.magento2plugin.actions.generation.data.BlockFileData;
13-
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.NewBlockValidator;
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.NotEmptyRule;
16+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpDirectoryRule;
1418
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleBlockClassGenerator;
1519
import com.magento.idea.magento2plugin.magento.files.BlockPhp;
1620
import com.magento.idea.magento2plugin.magento.packages.File;
1721
import com.magento.idea.magento2plugin.magento.packages.Package;
1822
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
1923
import java.awt.event.ActionEvent;
20-
import java.awt.event.ActionListener;
2124
import java.awt.event.KeyEvent;
2225
import java.awt.event.WindowAdapter;
2326
import java.awt.event.WindowEvent;
@@ -30,17 +33,28 @@
3033
import javax.swing.KeyStroke;
3134

3235
public class NewBlockDialog extends AbstractDialog {
33-
private final NewBlockValidator validator;
3436
private final PsiDirectory baseDir;
3537
private final String moduleName;
3638
private JPanel contentPanel;
3739
private JButton buttonOK;
3840
private JButton buttonCancel;
39-
private JTextField blockName;
40-
private JTextField blockParentDir;
4141
private final Project project;
4242
private JTextPane warning;//NOPMD
4343
private JRadioButton adminhtmlRadioButton;//NOPMD
44+
private static final String NAME = "name";
45+
private static final String DIRECTORY = "directory";
46+
47+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
48+
message = {NotEmptyRule.MESSAGE, NAME})
49+
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
50+
message = {PhpClassRule.MESSAGE, NAME})
51+
private JTextField blockName;
52+
53+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
54+
message = {NotEmptyRule.MESSAGE, DIRECTORY})
55+
@FieldValidation(rule = RuleRegistry.PHP_DIRECTORY,
56+
message = {PhpDirectoryRule.MESSAGE, DIRECTORY})
57+
private JTextField blockParentDir;
4458

4559
/**
4660
* Constructor.
@@ -54,25 +68,15 @@ public NewBlockDialog(final Project project, final PsiDirectory directory) {
5468
this.project = project;
5569
this.baseDir = directory;
5670
this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project);
57-
this.validator = NewBlockValidator.getInstance(this);
5871

5972
setContentPane(contentPanel);
6073
setModal(true);
6174
setTitle("Create a new Magento 2 block..");
6275
getRootPane().setDefaultButton(buttonOK);
6376
suggestBlockDirectory();
6477

65-
buttonOK.addActionListener(new ActionListener() {
66-
public void actionPerformed(final ActionEvent event) {
67-
onOK();
68-
}
69-
});
70-
71-
buttonCancel.addActionListener(new ActionListener() {
72-
public void actionPerformed(final ActionEvent event) {
73-
onCancel();
74-
}
75-
});
78+
buttonOK.addActionListener((final ActionEvent event) -> onOK());
79+
buttonCancel.addActionListener((final ActionEvent event) -> onCancel());
7680

7781
// call onCancel() when cross is clicked
7882
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
@@ -83,12 +87,11 @@ public void windowClosing(final WindowEvent event) {
8387
});
8488

8589
// call onCancel() on ESCAPE
86-
contentPanel.registerKeyboardAction(new ActionListener() {
87-
public void actionPerformed(final ActionEvent event) {
88-
onCancel();
89-
}
90-
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
91-
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90+
contentPanel.registerKeyboardAction(
91+
(final ActionEvent event) -> onCancel(),
92+
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
93+
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
94+
);
9295
}
9396

9497
/**
@@ -105,7 +108,7 @@ public static void open(final Project project, final PsiDirectory directory) {
105108
}
106109

107110
protected void onOK() {
108-
if (!validator.validate()) {
111+
if (!validateFormFields()) {
109112
return;
110113
}
111114
generateFile();
@@ -174,6 +177,7 @@ private String getNamespace() {
174177
return parts[0] + Package.fqnSeparator + parts[1] + Package.fqnSeparator + directoryPart;
175178
}
176179

180+
@Override
177181
public void onCancel() {
178182
// add your code here if necessary
179183
dispose();

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
import com.intellij.psi.PsiFile;
1111
import com.magento.idea.magento2plugin.actions.generation.NewControllerAction;
1212
import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData;
13-
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.NewControllerValidator;
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.NotEmptyRule;
16+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpDirectoryRule;
1418
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator;
1519
import com.magento.idea.magento2plugin.magento.files.ControllerBackendPhp;
1620
import com.magento.idea.magento2plugin.magento.files.ControllerFrontendPhp;
@@ -21,7 +25,6 @@
2125
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
2226
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
2327
import java.awt.event.ActionEvent;
24-
import java.awt.event.ActionListener;
2528
import java.awt.event.KeyEvent;
2629
import java.awt.event.WindowAdapter;
2730
import java.awt.event.WindowEvent;
@@ -37,22 +40,35 @@
3740

3841
@SuppressWarnings({
3942
"PMD.TooManyFields",
40-
"PMD.ConstructorCallsOverridableMethod"
43+
"PMD.ConstructorCallsOverridableMethod",
44+
"PMD.ExcessiveImports"
4145
})
4246
public class NewControllerDialog extends AbstractDialog {
43-
private final NewControllerValidator validator;
4447
private final String moduleName;
4548
private final Project project;
4649
private JPanel contentPane;
4750
private JButton buttonOK;
4851
private JButton buttonCancel;
4952
private FilteredComboBox controllerAreaSelect;
5053
private FilteredComboBox httpMethodSelect;
51-
private JTextField controllerName;
5254
private JTextField controllerParentDir;
5355
private JCheckBox inheritClass;
5456
private JPanel adminPanel;
5557
private JTextField acl;
58+
59+
private static final String CONTROLLER_NAME = "controller name";
60+
private static final String ACTION_NAME = "action name";
61+
62+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
63+
message = {NotEmptyRule.MESSAGE, CONTROLLER_NAME})
64+
@FieldValidation(rule = RuleRegistry.PHP_DIRECTORY,
65+
message = {PhpDirectoryRule.MESSAGE, CONTROLLER_NAME})
66+
private JTextField controllerName;
67+
68+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
69+
message = {NotEmptyRule.MESSAGE, ACTION_NAME})
70+
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
71+
message = {PhpClassRule.MESSAGE, ACTION_NAME})
5672
private JTextField actionName;
5773

5874
/**
@@ -65,7 +81,6 @@ public NewControllerDialog(final Project project, final PsiDirectory directory)
6581
super();
6682
this.project = project;
6783
this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project);
68-
this.validator = NewControllerValidator.getInstance(this);
6984

7085
setContentPane(contentPane);
7186
setModal(true);
@@ -87,11 +102,7 @@ public void windowClosing(final WindowEvent event) {
87102

88103
// call onCancel() on ESCAPE
89104
contentPane.registerKeyboardAction(
90-
new ActionListener() {
91-
public void actionPerformed(final ActionEvent event) {
92-
onCancel();
93-
}
94-
},
105+
(final ActionEvent event) -> onCancel(),
95106
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
96107
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
97108
);
@@ -178,7 +189,7 @@ public static void open(final Project project, final PsiDirectory directory) {
178189
}
179190

180191
private void onOK() {
181-
if (!validator.validate()) {
192+
if (!validateFormFields()) {
182193
return;
183194
}
184195

@@ -243,6 +254,7 @@ private Boolean getIsInheritClass() {
243254
return inheritClass.isSelected();
244255
}
245256

257+
@Override
246258
protected void onCancel() {
247259
dispose();
248260
}

0 commit comments

Comments
 (0)