22 * Copyright © Magento, Inc. All rights reserved.
33 * See COPYING.txt for license details.
44 */
5+
56package com .magento .idea .magento2plugin .actions .generation .dialog ;
67
78import com .intellij .openapi .project .Project ;
1516import com .magento .idea .magento2plugin .actions .generation .generator .PluginDiXmlGenerator ;
1617import com .magento .idea .magento2plugin .indexes .ModuleIndex ;
1718import 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 ;
1821import com .magento .idea .magento2plugin .magento .packages .Package ;
1922import 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 ;
2528import 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 ;
2637
38+ @ SuppressWarnings ({"PMD.TooManyFields" , "PMD.DataClass" , "PMD.UnusedPrivateMethod" })
2739public class CreateAPluginDialog extends AbstractDialog {
2840 @ NotNull
2941 private final Project project ;
30- private Method targetMethod ;
31- private PhpClass targetClass ;
42+ private final Method targetMethod ;
43+ private final PhpClass targetClass ;
3244 @ NotNull
3345 private final CreateAPluginDialogValidator validator ;
3446 private JPanel contentPane ;
3547 private JButton buttonOK ;
3648 private JButton buttonCancel ;
3749 private JTextField pluginClassName ;
38- private JLabel pluginClassNameLabel ;
3950 private JTextField pluginDirectory ;
40- private JLabel pluginDirectoryName ;
41- private JLabel selectPluginModule ;
4251 private JComboBox pluginType ;
43- private JLabel pluginTypeLabel ;
4452 private FilteredComboBox pluginModule ;
4553 private JComboBox pluginArea ;
46- private JLabel pluginAreaLabel ;
47- private JTextField pluginName ;
48- private JLabel pluginNameLabel ;
4954 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 ();
5377 this .project = project ;
5478 this .targetMethod = targetMethod ;
5579 this .targetClass = targetClass ;
@@ -62,44 +86,46 @@ public CreateAPluginDialog(@NotNull Project project, Method targetMethod, PhpCla
6286 fillTargetAreaOptions ();
6387
6488 buttonOK .addActionListener (new ActionListener () {
65- public void actionPerformed (ActionEvent e ) {
89+ public void actionPerformed (final ActionEvent event ) {
6690 onOK ();
6791 }
6892 });
6993
7094 buttonCancel .addActionListener (new ActionListener () {
71- public void actionPerformed (ActionEvent e ) {
95+ public void actionPerformed (final ActionEvent event ) {
7296 onCancel ();
7397 }
7498 });
7599
76100 setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
77101 addWindowListener (new WindowAdapter () {
78- public void windowClosing (WindowEvent e ) {
102+ public void windowClosing (final WindowEvent event ) {
79103 onCancel ();
80104 }
81105 });
82106
83107 contentPane .registerKeyboardAction (new ActionListener () {
84- public void actionPerformed (ActionEvent e ) {
108+ public void actionPerformed (final ActionEvent event ) {
85109 onCancel ();
86110 }
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+ );
88114 }
89115
90116 private void fillPluginTypeOptions () {
91- for (Plugin .PluginType pluginPrefixType : Plugin .PluginType .values ()) {
117+ for (final Plugin .PluginType pluginPrefixType : Plugin .PluginType .values ()) {
92118 pluginType .addItem (pluginPrefixType .toString ());
93119 }
94120 }
95121
96122 private void fillTargetAreaOptions () {
97- for ( Package . Areas area : Package . Areas .values ()) {
123+ for ( final Areas area : Areas .values ()) {
98124 pluginArea .addItem (area .toString ());
99125 }
100126 }
101127
102- private void onOK () {
128+ protected void onOK () {
103129 if (!validator .validate (project )) {
104130 return ;
105131 }
@@ -154,27 +180,46 @@ public String getPluginModule() {
154180 return this .pluginModule .getSelectedItem ().toString ();
155181 }
156182
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+ );
159200 dialog .pack ();
160201 dialog .centerDialog (dialog );
161202 dialog .setVisible (true );
162203 }
163204
164205 private void createUIComponents () {
165- List <String > allModulesList = ModuleIndex .getInstance (project ).getEditableModuleNames ();
206+ final List <String > allModulesList = ModuleIndex .getInstance (project )
207+ .getEditableModuleNames ();
166208
167209 this .pluginModule = new FilteredComboBox (allModulesList );
168210 }
169211
170212 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 ));
175220 }
176221
177222 private String getPluginClassFqn () {
178- return getNamespace ().concat (Package .FQN_SEPARATOR ).concat (getPluginClassName ());
223+ return getNamespace ().concat (Package .fqnSeparator ).concat (getPluginClassName ());
179224 }
180225}
0 commit comments