Skip to content

Commit 571b5f7

Browse files
authored
Merge branch '2.1.0-develop' into issue-294
2 parents 060bba8 + e1fae67 commit 571b5f7

File tree

4 files changed

+59
-401
lines changed

4 files changed

+59
-401
lines changed

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

Lines changed: 27 additions & 23 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.NewGraphQlResolverAction;
1212
import com.magento.idea.magento2plugin.actions.generation.data.GraphQlResolverFileData;
13-
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.NewGraphQlResolverValidator;
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.ModuleGraphQlResolverClassGenerator;
1519
import com.magento.idea.magento2plugin.magento.files.GraphQlResolverPhp;
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;
@@ -28,15 +31,26 @@
2831
import javax.swing.KeyStroke;
2932

3033
public class NewGraphQlResolverDialog extends AbstractDialog {
31-
private final NewGraphQlResolverValidator validator;
3234
private final PsiDirectory baseDir;
3335
private final String moduleName;
3436
private JPanel contentPanel;
3537
private JButton buttonOK;
3638
private JButton buttonCancel;
39+
private final Project project;
40+
private static final String CLASS_NAME = "class name";
41+
private static final String PARENT_DIRECTORY = "directory";
42+
43+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
44+
message = {NotEmptyRule.MESSAGE, CLASS_NAME})
45+
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
46+
message = {PhpClassRule.MESSAGE, CLASS_NAME})
3747
private JTextField graphQlResolverClassName;
48+
49+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
50+
message = {NotEmptyRule.MESSAGE, PARENT_DIRECTORY})
51+
@FieldValidation(rule = RuleRegistry.PHP_DIRECTORY,
52+
message = {PhpDirectoryRule.MESSAGE, PARENT_DIRECTORY})
3853
private JTextField graphQlResolverParentDir;
39-
private final Project project;
4054

4155
/**
4256
* Constructor.
@@ -50,25 +64,15 @@ public NewGraphQlResolverDialog(final Project project, final PsiDirectory direct
5064
this.project = project;
5165
this.baseDir = directory;
5266
this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project);
53-
this.validator = NewGraphQlResolverValidator.getInstance(this);
5467

5568
setContentPane(contentPanel);
5669
setModal(true);
5770
setTitle("Create a new Magento 2 GraphQL Resolver.");
5871
getRootPane().setDefaultButton(buttonOK);
5972
suggestGraphQlResolverDirectory();
6073

61-
buttonOK.addActionListener(new ActionListener() {
62-
public void actionPerformed(final ActionEvent event) {
63-
onOK();
64-
}
65-
});
66-
67-
buttonCancel.addActionListener(new ActionListener() {
68-
public void actionPerformed(final ActionEvent event) {
69-
onCancel();
70-
}
71-
});
74+
buttonOK.addActionListener((final ActionEvent event) -> onOK());
75+
buttonCancel.addActionListener((final ActionEvent event) -> onCancel());
7276

7377
// call onCancel() when cross is clicked
7478
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
@@ -79,12 +83,11 @@ public void windowClosing(final WindowEvent event) {
7983
});
8084

8185
// call onCancel() on ESCAPE
82-
contentPanel.registerKeyboardAction(new ActionListener() {
83-
public void actionPerformed(final ActionEvent event) {
84-
onCancel();
85-
}
86-
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
87-
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
86+
contentPanel.registerKeyboardAction(
87+
(final ActionEvent event) -> onCancel(),
88+
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
89+
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
90+
);
8891
}
8992

9093
/**
@@ -101,7 +104,7 @@ public static void open(final Project project, final PsiDirectory directory) {
101104
}
102105

103106
protected void onOK() {
104-
if (!validator.validate()) {
107+
if (!validateFormFields()) {
105108
return;
106109
}
107110
generateFile();
@@ -176,6 +179,7 @@ private String getGraphQlResolverClassFqn() {
176179
return getNamespace().concat(Package.fqnSeparator).concat(getGraphQlResolverClassName());
177180
}
178181

182+
@Override
179183
public void onCancel() {
180184
// add your code here if necessary
181185
dispose();

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

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
import com.magento.idea.magento2plugin.actions.generation.OverrideClassByAPreferenceAction;
1313
import com.magento.idea.magento2plugin.actions.generation.data.PreferenceDiXmFileData;
1414
import com.magento.idea.magento2plugin.actions.generation.data.PreferenceFileData;
15-
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.OverrideClassByAPreferenceDialogValidator;
15+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
16+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
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;
1620
import com.magento.idea.magento2plugin.actions.generation.generator.PreferenceClassGenerator;
1721
import com.magento.idea.magento2plugin.actions.generation.generator.PreferenceDiXmlGenerator;
1822
import com.magento.idea.magento2plugin.bundles.CommonBundle;
@@ -23,7 +27,6 @@
2327
import com.magento.idea.magento2plugin.magento.packages.Package;
2428
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
2529
import java.awt.event.ActionEvent;
26-
import java.awt.event.ActionListener;
2730
import java.awt.event.KeyEvent;
2831
import java.awt.event.WindowAdapter;
2932
import java.awt.event.WindowEvent;
@@ -44,23 +47,37 @@ public class OverrideClassByAPreferenceDialog extends AbstractDialog { //NOPMD
4447
@NotNull
4548
private final Project project;
4649
private final PhpClass targetClass;
47-
@NotNull
48-
private final OverrideClassByAPreferenceDialogValidator validator;
4950
private JPanel contentPane;
5051
private JButton buttonOK;
5152
private JButton buttonCancel;
52-
private JTextField preferenceClassName;
53-
private JTextField preferenceDirectory;
5453
private final CommonBundle commonBundle;
5554
private final ValidatorBundle validatorBundle;
56-
private FilteredComboBox preferenceModule;
5755
private JLabel inheritClassLabel;
5856
private JComboBox preferenceArea;
5957
private JCheckBox inheritClass;
6058
private JLabel preferenceAreaLabel;//NOPMD
6159
private JLabel selectPreferenceModule;//NOPMD
6260
private JLabel preferenceDirectoryLabel;//NOPMD
6361
private JLabel preferenceClassNameLabel;//NOPMD
62+
private static final String MODULE = "target module";
63+
private static final String CLASS = "class name";
64+
private static final String DIRECTORY = "directory";
65+
66+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
67+
message = {NotEmptyRule.MESSAGE, MODULE})
68+
private FilteredComboBox preferenceModule;
69+
70+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
71+
message = {NotEmptyRule.MESSAGE, CLASS})
72+
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
73+
message = {PhpClassRule.MESSAGE, CLASS})
74+
private JTextField preferenceClassName;
75+
76+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
77+
message = {NotEmptyRule.MESSAGE, DIRECTORY})
78+
@FieldValidation(rule = RuleRegistry.DIRECTORY,
79+
message = {DirectoryRule.MESSAGE, DIRECTORY})
80+
private JTextField preferenceDirectory;
6481

6582
/**
6683
* Constructor.
@@ -76,7 +93,6 @@ public OverrideClassByAPreferenceDialog(
7693

7794
this.project = project;
7895
this.targetClass = targetClass;
79-
this.validator = OverrideClassByAPreferenceDialogValidator.getInstance(this);
8096
this.validatorBundle = new ValidatorBundle();
8197
this.commonBundle = new CommonBundle();
8298

@@ -91,19 +107,8 @@ public OverrideClassByAPreferenceDialog(
91107
suggestPreferenceClassName(targetClass);
92108
suggestPreferenceDirectory(targetClass);
93109

94-
buttonOK.addActionListener(new ActionListener() {
95-
@Override
96-
public void actionPerformed(final ActionEvent event) {
97-
onOK();
98-
}
99-
});
100-
101-
buttonCancel.addActionListener(new ActionListener() {
102-
@Override
103-
public void actionPerformed(final ActionEvent event) {
104-
onCancel();
105-
}
106-
});
110+
buttonOK.addActionListener((final ActionEvent event) -> onOK());
111+
buttonCancel.addActionListener((final ActionEvent event) -> onCancel());
107112

108113
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
109114
addWindowListener(new WindowAdapter() {
@@ -113,13 +118,11 @@ public void windowClosing(final WindowEvent event) {
113118
}
114119
});
115120

116-
contentPane.registerKeyboardAction(new ActionListener() {
117-
@Override
118-
public void actionPerformed(final ActionEvent event) {
119-
onCancel();
120-
}
121-
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
122-
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
121+
contentPane.registerKeyboardAction(
122+
(final ActionEvent event) -> onCancel(),
123+
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
124+
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
125+
);
123126
}
124127

125128
private void suggestPreferenceDirectory(final PhpClass targetClass) {
@@ -148,7 +151,7 @@ private void fillTargetAreaOptions() {
148151
}
149152

150153
protected void onOK() {
151-
if (!validator.validate(project)) {
154+
if (!validateFormFields()) {
152155
return;
153156
}
154157
final PsiFile diXml = new PreferenceDiXmlGenerator(new PreferenceDiXmFileData(
@@ -184,7 +187,6 @@ protected void onOK() {
184187
isInheritClass()
185188
), project).generate(OverrideClassByAPreferenceAction.ACTION_NAME, true);
186189

187-
188190
this.setVisible(false);
189191
}
190192

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

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)