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 ;
1314import com .magento .idea .magento2plugin .actions .generation .generator .ObserverClassGenerator ;
1415import com .magento .idea .magento2plugin .actions .generation .generator .ObserverEventsXmlGenerator ;
1516import com .magento .idea .magento2plugin .indexes .ModuleIndex ;
17+ import com .magento .idea .magento2plugin .magento .packages .File ;
1618import com .magento .idea .magento2plugin .magento .packages .Package ;
1719import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
18- import org .jetbrains .annotations .NotNull ;
19- import javax .swing .*;
20- import java .awt .event .*;
21- import com .magento .idea .magento2plugin .magento .packages .File ;
20+ import java .awt .event .KeyEvent ;
21+ import java .awt .event .WindowAdapter ;
22+ import java .awt .event .WindowEvent ;
2223import java .util .List ;
24+ import javax .swing .JButton ;
25+ import javax .swing .JComboBox ;
26+ import javax .swing .JComponent ;
27+ import javax .swing .JLabel ;
28+ import javax .swing .JPanel ;
29+ import javax .swing .JTextField ;
30+ import javax .swing .KeyStroke ;
31+ import org .jetbrains .annotations .NotNull ;
2332
24- public class CreateAnObserverDialog extends AbstractDialog {
33+ public class CreateAnObserverDialog extends AbstractDialog { //NOPMD
2534 @ NotNull
2635 private final Project project ;
27- private String targetEvent ;
2836 @ NotNull
2937 private final CreateAnObserverDialogValidator validator ;
38+ private final String targetEvent ;
3039 private JPanel contentPane ;
3140 private JButton buttonOK ;
3241 private JButton buttonCancel ;
3342 private JTextField observerClassName ;
34- private JLabel observerClassNameLabel ;
3543 private JTextField observerDirectory ;
36- private JLabel observerDirectoryName ;
37- private JLabel selectObserverModule ;
3844 private FilteredComboBox observerModule ;
3945 private JComboBox observerArea ;
40- private JLabel observerAreaLabel ;
41- private JLabel observerNameLabel ;
4246 private JTextField observerName ;
47+ private JLabel observerClassNameLabel ;//NOPMD
48+ private JLabel observerDirectoryName ;//NOPMD
49+ private JLabel selectObserverModule ;//NOPMD
50+ private JLabel observerAreaLabel ;//NOPMD
51+ private JLabel observerNameLabel ;//NOPMD
52+
53+ /**
54+ * Constructor.
55+ *
56+ * @param project Project Scope
57+ * @param targetEvent Action Event
58+ */
59+ public CreateAnObserverDialog (@ NotNull final Project project , final String targetEvent ) {
60+ super ();
4361
44- public CreateAnObserverDialog (@ NotNull Project project , String targetEvent ) {
4562 this .project = project ;
4663 this .targetEvent = targetEvent ;
4764 this .validator = CreateAnObserverDialogValidator .getInstance (this );
@@ -51,38 +68,48 @@ public CreateAnObserverDialog(@NotNull Project project, String targetEvent) {
5168 getRootPane ().setDefaultButton (buttonOK );
5269 fillTargetAreaOptions ();
5370
54- buttonOK .addActionListener (new ActionListener () {
55- public void actionPerformed (ActionEvent e ) {
56- onOK ();
57- }
58- });
59-
60- buttonCancel .addActionListener (new ActionListener () {
61- public void actionPerformed (ActionEvent e ) {
62- onCancel ();
63- }
64- });
71+ buttonOK .addActionListener (e -> onOK ());
72+ buttonCancel .addActionListener (e -> onCancel ());
6573
6674 setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
6775 addWindowListener (new WindowAdapter () {
68- public void windowClosing (WindowEvent e ) {
76+ public void windowClosing (final WindowEvent event ) {
6977 onCancel ();
7078 }
7179 });
7280
73- contentPane .registerKeyboardAction (new ActionListener () {
74- public void actionPerformed (ActionEvent e ) {
75- onCancel ();
76- }
77- }, KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ), JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
81+ contentPane .registerKeyboardAction (
82+ e -> onCancel (),
83+ KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
84+ JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
85+ );
86+ }
87+
88+ /**
89+ * Open an action dialog.
90+ *
91+ * @param project Project Scope
92+ * @param targetEvent Action Event
93+ */
94+ public static void open (@ NotNull final Project project , final String targetEvent ) {
95+ final CreateAnObserverDialog dialog = new CreateAnObserverDialog (project , targetEvent );
96+ dialog .pack ();
97+ dialog .centerDialog (dialog );
98+ dialog .setVisible (true );
7899 }
79100
101+ /**
102+ * Setup observer area combobox.
103+ */
80104 private void fillTargetAreaOptions () {
81- for ( Package .Areas area : Package .Areas .values ()) {
105+ for ( final Package .Areas area : Package .Areas .values ()) {
82106 observerArea .addItem (area .toString ());
83107 }
84108 }
85109
110+ /**
111+ * Perform code generation using input data.
112+ */
86113 private void onOK () {
87114 if (!validator .validate (project )) {
88115 return ;
@@ -127,24 +154,25 @@ public String getObserverModule() {
127154 return this .observerModule .getSelectedItem ().toString ();
128155 }
129156
130- public static void open (@ NotNull Project project , String targetEvent ) {
131- CreateAnObserverDialog dialog = new CreateAnObserverDialog (project , targetEvent );
132- dialog .pack ();
133- dialog .centerDialog (dialog );
134- dialog .setVisible (true );
135- }
136-
137- private void createUIComponents () {
138- List <String > allModulesList = ModuleIndex .getInstance (project ).getEditableModuleNames ();
157+ private void createUIComponents () { //NOPMD
158+ final List <String > allModulesList = ModuleIndex .getInstance (project )
159+ .getEditableModuleNames ();
139160
140161 this .observerModule = new FilteredComboBox (allModulesList );
141162 }
142163
143164 private String getNamespace () {
144- String targetModule = getObserverModule ();
145- String namespace = targetModule .replace (Package .VENDOR_MODULE_NAME_SEPARATOR , Package .FQN_SEPARATOR );
165+ final String targetModule = getObserverModule ();
166+ String namespace = targetModule .replace (
167+ Package .VENDOR_MODULE_NAME_SEPARATOR ,
168+ Package .FQN_SEPARATOR
169+ );
170+
146171 namespace = namespace .concat (Package .FQN_SEPARATOR );
147- return namespace .concat (getObserverDirectory ().replace (File .separator , Package .FQN_SEPARATOR ));
172+ return namespace .concat (getObserverDirectory ().replace (
173+ File .separator ,
174+ Package .FQN_SEPARATOR )
175+ );
148176 }
149177
150178 private String getObserverClassFqn () {
0 commit comments