Skip to content

Commit d8b22c4

Browse files
author
Vitaliy Boyko
committed
Merge branch '2.1.0-develop' of github.com:magento/magento2-phpstorm-plugin into forwardport-2.0.1->2.1.0
� Conflicts: � .github/workflows/gradle.yml � build.gradle
2 parents 52f2f43 + 2e9f42f commit d8b22c4

28 files changed

+377
-1402
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: Run automated tests
55

66
on:
77
pull_request:
8-
branches: [ master, 2.0.0-develop, 2.0.1-develop ]
8+
branches: [ master, 2.0.1-develop, 2.1.0-develop ]
99

1010
jobs:
1111
build-linux:

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repositories {
1515
}
1616

1717
group 'com.magento.idea'
18-
version '2.0.1'
18+
version '2.1.0'
1919

2020
apply plugin: 'org.jetbrains.intellij'
2121
apply plugin: 'java'

resources/magento2/common.properties

Lines changed: 3 additions & 2 deletions
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
@@ -22,7 +22,8 @@ common.module.target=Target Module
2222
common.theme.target=Target Theme
2323
common.area.target=Target Area
2424
common.name=Name
25-
common.className=Class Name
25+
common.className=Class name
26+
common.argument=Argument name
2627
common.directoryPath=Directory Path
2728
common.methodType=Method Type
2829
common.sortOrder=Sort Order

resources/magento2/validation.properties

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
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
15+
validator.command.isNotValid=The {0} field does not contain a valid Magento 2 CLI command
1416
validator.module.noSuchModule=No such module {0}
1517
validator.file.alreadyExists={0} already exists
1618
validator.file.cantBeCreated={0} can't be created

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import javax.swing.JComponent;
2727
import javax.swing.JDialog;
2828
import javax.swing.JOptionPane;
29+
import javax.swing.JTextArea;
2930
import javax.swing.JTextField;
3031

3132
/**
@@ -185,6 +186,8 @@ private String resolveFieldValueByComponentType(final Object field) {
185186
return ((JTextField) field).getText();
186187
} else if (field instanceof JComboBox) {
187188
return ((JComboBox) field).getSelectedItem().toString();
189+
} else if (field instanceof JTextArea) {
190+
return ((JTextArea) field).getText();
188191
}
189192
return null;
190193
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
<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"/>
108108
</constraints>
109109
<properties>
110-
<text value="Argument Name"/>
110+
<text resource-bundle="magento2/common" key="common.argument"/>
111111
</properties>
112112
</component>
113113
<component id="c3a92" class="javax.swing.JTextField" binding="viewModelArgumentName">

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

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
import com.intellij.ui.DocumentAdapter;
1212
import com.magento.idea.magento2plugin.actions.generation.InjectAViewModelAction;
1313
import com.magento.idea.magento2plugin.actions.generation.data.ViewModelFileData;
14-
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.InjectAViewModelDialogValidator;
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.NotEmptyRule;
19+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule;
1520
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleViewModelClassGenerator;
1621
import com.magento.idea.magento2plugin.actions.generation.generator.code.ClassArgumentInXmlConfigGenerator;
1722
import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder;
@@ -21,7 +26,6 @@
2126
import com.magento.idea.magento2plugin.util.FirstLetterToLowercaseUtil;
2227
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
2328
import java.awt.event.ActionEvent;
24-
import java.awt.event.ActionListener;
2529
import java.awt.event.KeyEvent;
2630
import java.awt.event.WindowAdapter;
2731
import java.awt.event.WindowEvent;
@@ -35,24 +39,43 @@
3539
import javax.swing.event.DocumentEvent;
3640
import org.jetbrains.annotations.NotNull;
3741

42+
@SuppressWarnings({
43+
"PMD.ExcessiveImports"
44+
})
3845
public class InjectAViewModelDialog extends AbstractDialog {
3946
@NotNull
4047
private final Project project;
41-
@NotNull
42-
private final InjectAViewModelDialogValidator validator;
4348
private final XmlTag targetBlockTag;
4449
private JPanel contentPane;
4550
private JButton buttonOK;
4651
private JButton buttonCancel;
47-
private JTextField viewModelClassName;
48-
private JTextField viewModelDirectory;
4952
private final CommonBundle commonBundle;
5053
private final ValidatorBundle validatorBundle;
51-
private JTextField viewModelArgumentName;
5254
private JLabel inheritClassLabel;//NOPMD
5355
private JLabel viewModelDirectoryLabel;//NOPMD
5456
private JLabel viewModelClassNameLabel;//NOPMD
5557
private JLabel viewModelArgumentNameLabel;//NOPMD
58+
private static final String CLASS_NAME = "class name";
59+
private static final String DIRECTORY = "directory";
60+
private static final String ARGUMENT_NAME = "argument name";
61+
62+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
63+
message = {NotEmptyRule.MESSAGE, CLASS_NAME})
64+
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
65+
message = {PhpClassRule.MESSAGE, CLASS_NAME})
66+
private JTextField viewModelClassName;
67+
68+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
69+
message = {NotEmptyRule.MESSAGE, DIRECTORY})
70+
@FieldValidation(rule = RuleRegistry.DIRECTORY,
71+
message = {DirectoryRule.MESSAGE, DIRECTORY})
72+
private JTextField viewModelDirectory;
73+
74+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
75+
message = {NotEmptyRule.MESSAGE, ARGUMENT_NAME})
76+
@FieldValidation(rule = RuleRegistry.ALPHANUMERIC,
77+
message = {AlphanumericRule.MESSAGE, ARGUMENT_NAME})
78+
private JTextField viewModelArgumentName;
5679

5780
/**
5881
* Constructor.
@@ -68,7 +91,6 @@ public InjectAViewModelDialog(
6891

6992
this.project = project;
7093
this.targetBlockTag = targetBlockTag;
71-
this.validator = new InjectAViewModelDialogValidator(this);
7294
this.validatorBundle = new ValidatorBundle();
7395
this.commonBundle = new CommonBundle();
7496

@@ -84,19 +106,8 @@ protected void textChanged(final @NotNull DocumentEvent event) {
84106
setModal(true);
85107
getRootPane().setDefaultButton(buttonOK);
86108

87-
buttonOK.addActionListener(new ActionListener() {
88-
@Override
89-
public void actionPerformed(final ActionEvent event) {
90-
onOK();
91-
}
92-
});
93-
94-
buttonCancel.addActionListener(new ActionListener() {
95-
@Override
96-
public void actionPerformed(final ActionEvent event) {
97-
onCancel();
98-
}
99-
});
109+
buttonOK.addActionListener((final ActionEvent event) -> onOK());
110+
buttonCancel.addActionListener((final ActionEvent event) -> onCancel());
100111

101112
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
102113
addWindowListener(new WindowAdapter() {
@@ -106,13 +117,11 @@ public void windowClosing(final WindowEvent event) {
106117
}
107118
});
108119

109-
contentPane.registerKeyboardAction(new ActionListener() {
110-
@Override
111-
public void actionPerformed(final ActionEvent event) {
112-
onCancel();
113-
}
114-
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
115-
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
120+
contentPane.registerKeyboardAction(
121+
(final ActionEvent event) -> onCancel(),
122+
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
123+
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
124+
);
116125
}
117126

118127
protected void updateArgumentText() {
@@ -123,7 +132,7 @@ protected void updateArgumentText() {
123132
}
124133

125134
protected void onOK() {
126-
if (!validator.validate(project)) {
135+
if (!validateFormFields()) {
127136
return;
128137
}
129138
final String moduleName = GetModuleNameByDirectoryUtil.execute(

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();

0 commit comments

Comments
 (0)