12
12
import com .magento .idea .magento2plugin .actions .generation .OverrideClassByAPreferenceAction ;
13
13
import com .magento .idea .magento2plugin .actions .generation .data .PreferenceDiXmFileData ;
14
14
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 ;
16
20
import com .magento .idea .magento2plugin .actions .generation .generator .PreferenceClassGenerator ;
17
21
import com .magento .idea .magento2plugin .actions .generation .generator .PreferenceDiXmlGenerator ;
18
22
import com .magento .idea .magento2plugin .bundles .CommonBundle ;
23
27
import com .magento .idea .magento2plugin .magento .packages .Package ;
24
28
import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
25
29
import java .awt .event .ActionEvent ;
26
- import java .awt .event .ActionListener ;
27
30
import java .awt .event .KeyEvent ;
28
31
import java .awt .event .WindowAdapter ;
29
32
import java .awt .event .WindowEvent ;
@@ -44,23 +47,37 @@ public class OverrideClassByAPreferenceDialog extends AbstractDialog { //NOPMD
44
47
@ NotNull
45
48
private final Project project ;
46
49
private final PhpClass targetClass ;
47
- @ NotNull
48
- private final OverrideClassByAPreferenceDialogValidator validator ;
49
50
private JPanel contentPane ;
50
51
private JButton buttonOK ;
51
52
private JButton buttonCancel ;
52
- private JTextField preferenceClassName ;
53
- private JTextField preferenceDirectory ;
54
53
private final CommonBundle commonBundle ;
55
54
private final ValidatorBundle validatorBundle ;
56
- private FilteredComboBox preferenceModule ;
57
55
private JLabel inheritClassLabel ;
58
56
private JComboBox preferenceArea ;
59
57
private JCheckBox inheritClass ;
60
58
private JLabel preferenceAreaLabel ;//NOPMD
61
59
private JLabel selectPreferenceModule ;//NOPMD
62
60
private JLabel preferenceDirectoryLabel ;//NOPMD
63
61
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 ;
64
81
65
82
/**
66
83
* Constructor.
@@ -76,7 +93,6 @@ public OverrideClassByAPreferenceDialog(
76
93
77
94
this .project = project ;
78
95
this .targetClass = targetClass ;
79
- this .validator = OverrideClassByAPreferenceDialogValidator .getInstance (this );
80
96
this .validatorBundle = new ValidatorBundle ();
81
97
this .commonBundle = new CommonBundle ();
82
98
@@ -91,19 +107,8 @@ public OverrideClassByAPreferenceDialog(
91
107
suggestPreferenceClassName (targetClass );
92
108
suggestPreferenceDirectory (targetClass );
93
109
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 ());
107
112
108
113
setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
109
114
addWindowListener (new WindowAdapter () {
@@ -113,13 +118,11 @@ public void windowClosing(final WindowEvent event) {
113
118
}
114
119
});
115
120
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
+ );
123
126
}
124
127
125
128
private void suggestPreferenceDirectory (final PhpClass targetClass ) {
@@ -148,7 +151,7 @@ private void fillTargetAreaOptions() {
148
151
}
149
152
150
153
protected void onOK () {
151
- if (!validator . validate ( project )) {
154
+ if (!validateFormFields ( )) {
152
155
return ;
153
156
}
154
157
final PsiFile diXml = new PreferenceDiXmlGenerator (new PreferenceDiXmFileData (
@@ -184,7 +187,6 @@ protected void onOK() {
184
187
isInheritClass ()
185
188
), project ).generate (OverrideClassByAPreferenceAction .ACTION_NAME , true );
186
189
187
-
188
190
this .setVisible (false );
189
191
}
190
192
0 commit comments