2
2
* Copyright © Magento, Inc. All rights reserved.
3
3
* See COPYING.txt for license details.
4
4
*/
5
+
5
6
package com .magento .idea .magento2plugin .actions .generation .dialog ;
6
7
7
8
import com .intellij .openapi .project .Project ;
15
16
import com .magento .idea .magento2plugin .actions .generation .generator .PluginDiXmlGenerator ;
16
17
import com .magento .idea .magento2plugin .indexes .ModuleIndex ;
17
18
import com .magento .idea .magento2plugin .magento .files .Plugin ;
19
+ import com .magento .idea .magento2plugin .magento .packages .Areas ;
20
+ import com .magento .idea .magento2plugin .magento .packages .File ;
18
21
import com .magento .idea .magento2plugin .magento .packages .Package ;
19
22
import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
20
- import org . jetbrains . annotations . NotNull ;
21
- import javax . swing .* ;
22
- import java .awt .* ;
23
- import java .awt .event .* ;
24
- import com . magento . idea . magento2plugin . magento . packages . File ;
23
+ import java . awt . event . ActionEvent ;
24
+ import java . awt . event . ActionListener ;
25
+ import java .awt .event . KeyEvent ;
26
+ import java .awt .event .WindowAdapter ;
27
+ import java . awt . event . WindowEvent ;
25
28
import java .util .List ;
29
+ import javax .swing .JButton ;
30
+ import javax .swing .JComboBox ;
31
+ import javax .swing .JComponent ;
32
+ import javax .swing .JLabel ;
33
+ import javax .swing .JPanel ;
34
+ import javax .swing .JTextField ;
35
+ import javax .swing .KeyStroke ;
36
+ import org .jetbrains .annotations .NotNull ;
26
37
38
+ @ SuppressWarnings ({"PMD.TooManyFields" , "PMD.DataClass" , "PMD.UnusedPrivateMethod" })
27
39
public class CreateAPluginDialog extends AbstractDialog {
28
40
@ NotNull
29
41
private final Project project ;
30
- private Method targetMethod ;
31
- private PhpClass targetClass ;
42
+ private final Method targetMethod ;
43
+ private final PhpClass targetClass ;
32
44
@ NotNull
33
45
private final CreateAPluginDialogValidator validator ;
34
46
private JPanel contentPane ;
35
47
private JButton buttonOK ;
36
48
private JButton buttonCancel ;
37
49
private JTextField pluginClassName ;
38
- private JLabel pluginClassNameLabel ;
39
50
private JTextField pluginDirectory ;
40
- private JLabel pluginDirectoryName ;
41
- private JLabel selectPluginModule ;
42
51
private JComboBox pluginType ;
43
- private JLabel pluginTypeLabel ;
44
52
private FilteredComboBox pluginModule ;
45
53
private JComboBox pluginArea ;
46
- private JLabel pluginAreaLabel ;
47
- private JTextField pluginName ;
48
- private JLabel pluginNameLabel ;
49
54
private JTextField pluginSortOrder ;
50
- private JLabel pluginSortOrderLabel ;
51
-
52
- public CreateAPluginDialog (@ NotNull Project project , Method targetMethod , PhpClass targetClass ) {
55
+ private JTextField pluginName ;
56
+ private JLabel pluginDirectoryName ;//NOPMD
57
+ private JLabel selectPluginModule ;//NOPMD
58
+ private JLabel pluginTypeLabel ;//NOPMD
59
+ private JLabel pluginAreaLabel ;//NOPMD
60
+ private JLabel pluginNameLabel ;//NOPMD
61
+ private JLabel pluginClassNameLabel ;//NOPMD
62
+ private JLabel pluginSortOrderLabel ;//NOPMD
63
+
64
+ /**
65
+ * Constructor.
66
+ *
67
+ * @param project Project
68
+ * @param targetMethod Method
69
+ * @param targetClass PhpClass
70
+ */
71
+ public CreateAPluginDialog (
72
+ final @ NotNull Project project ,
73
+ final Method targetMethod ,
74
+ final PhpClass targetClass
75
+ ) {
76
+ super ();
53
77
this .project = project ;
54
78
this .targetMethod = targetMethod ;
55
79
this .targetClass = targetClass ;
@@ -62,44 +86,46 @@ public CreateAPluginDialog(@NotNull Project project, Method targetMethod, PhpCla
62
86
fillTargetAreaOptions ();
63
87
64
88
buttonOK .addActionListener (new ActionListener () {
65
- public void actionPerformed (ActionEvent e ) {
89
+ public void actionPerformed (final ActionEvent event ) {
66
90
onOK ();
67
91
}
68
92
});
69
93
70
94
buttonCancel .addActionListener (new ActionListener () {
71
- public void actionPerformed (ActionEvent e ) {
95
+ public void actionPerformed (final ActionEvent event ) {
72
96
onCancel ();
73
97
}
74
98
});
75
99
76
100
setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
77
101
addWindowListener (new WindowAdapter () {
78
- public void windowClosing (WindowEvent e ) {
102
+ public void windowClosing (final WindowEvent event ) {
79
103
onCancel ();
80
104
}
81
105
});
82
106
83
107
contentPane .registerKeyboardAction (new ActionListener () {
84
- public void actionPerformed (ActionEvent e ) {
108
+ public void actionPerformed (final ActionEvent event ) {
85
109
onCancel ();
86
110
}
87
- }, KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ), JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
111
+ }, KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
112
+ JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
113
+ );
88
114
}
89
115
90
116
private void fillPluginTypeOptions () {
91
- for (Plugin .PluginType pluginPrefixType : Plugin .PluginType .values ()) {
117
+ for (final Plugin .PluginType pluginPrefixType : Plugin .PluginType .values ()) {
92
118
pluginType .addItem (pluginPrefixType .toString ());
93
119
}
94
120
}
95
121
96
122
private void fillTargetAreaOptions () {
97
- for ( Package . Areas area : Package . Areas .values ()) {
123
+ for ( final Areas area : Areas .values ()) {
98
124
pluginArea .addItem (area .toString ());
99
125
}
100
126
}
101
127
102
- private void onOK () {
128
+ protected void onOK () {
103
129
if (!validator .validate (project )) {
104
130
return ;
105
131
}
@@ -154,27 +180,46 @@ public String getPluginModule() {
154
180
return this .pluginModule .getSelectedItem ().toString ();
155
181
}
156
182
157
- public static void open (@ NotNull Project project , Method targetMethod , PhpClass targetClass ) {
158
- CreateAPluginDialog dialog = new CreateAPluginDialog (project , targetMethod , targetClass );
183
+ /**
184
+ * Open an action dialog.
185
+ *
186
+ * @param project Project
187
+ * @param targetMethod Method
188
+ * @param targetClass PhpClass
189
+ */
190
+ public static void open (
191
+ final @ NotNull Project project ,
192
+ final Method targetMethod ,
193
+ final PhpClass targetClass
194
+ ) {
195
+ final CreateAPluginDialog dialog = new CreateAPluginDialog (
196
+ project ,
197
+ targetMethod ,
198
+ targetClass
199
+ );
159
200
dialog .pack ();
160
201
dialog .centerDialog (dialog );
161
202
dialog .setVisible (true );
162
203
}
163
204
164
205
private void createUIComponents () {
165
- List <String > allModulesList = ModuleIndex .getInstance (project ).getEditableModuleNames ();
206
+ final List <String > allModulesList = ModuleIndex .getInstance (project )
207
+ .getEditableModuleNames ();
166
208
167
209
this .pluginModule = new FilteredComboBox (allModulesList );
168
210
}
169
211
170
212
private String getNamespace () {
171
- String targetModule = getPluginModule ();
172
- String namespace = targetModule .replace (Package .VENDOR_MODULE_NAME_SEPARATOR , Package .FQN_SEPARATOR );
173
- namespace = namespace .concat (Package .FQN_SEPARATOR );
174
- return namespace .concat (getPluginDirectory ().replace (File .separator , Package .FQN_SEPARATOR ));
213
+ final String targetModule = getPluginModule ();
214
+ String namespace = targetModule .replace (
215
+ Package .vendorModuleNameSeparator ,
216
+ Package .fqnSeparator
217
+ );
218
+ namespace = namespace .concat (Package .fqnSeparator );
219
+ return namespace .concat (getPluginDirectory ().replace (File .separator , Package .fqnSeparator ));
175
220
}
176
221
177
222
private String getPluginClassFqn () {
178
- return getNamespace ().concat (Package .FQN_SEPARATOR ).concat (getPluginClassName ());
223
+ return getNamespace ().concat (Package .fqnSeparator ).concat (getPluginClassName ());
179
224
}
180
225
}
0 commit comments