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 ;
1819import com .magento .idea .magento2plugin .magento .packages .Package ;
1920import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
2021import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectory ;
21-
22- import javax .swing .*;
23- import java .awt .event .*;
22+ import javax .swing .JPanel ;
23+ import javax .swing .JButton ;
24+ import javax .swing .JLabel ;
25+ import javax .swing .JTextField ;
26+ import javax .swing .JCheckBox ;
27+ import javax .swing .JComponent ;
28+ import javax .swing .KeyStroke ;
29+ import java .awt .event .WindowAdapter ;
30+ import java .awt .event .WindowEvent ;
31+ import java .awt .event .ActionListener ;
32+ import java .awt .event .ActionEvent ;
33+ import java .awt .event .KeyEvent ;
2434import java .util .ArrayList ;
2535import java .util .Arrays ;
2636
@@ -40,10 +50,16 @@ public class NewControllerDialog extends AbstractDialog {
4050 private JTextField controllerName ;
4151 private JTextField controllerParentDir ;
4252 private JCheckBox inheritClass ;
43- private JPanel AdminPanel ;
53+ private JPanel adminPanel ;
4454 private JTextField acl ;
4555 private JTextField actionName ;
4656
57+ /**
58+ * Open new dialog for adding new controller.
59+ *
60+ * @param project Project
61+ * @param directory PsiDirectory
62+ */
4763 public NewControllerDialog (Project project , PsiDirectory directory ) {
4864 this .project = project ;
4965 this .baseDir = directory ;
@@ -70,37 +86,90 @@ public void windowClosing(WindowEvent e) {
7086 });
7187
7288 // call onCancel() on ESCAPE
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 );
89+ contentPane .registerKeyboardAction (
90+ new ActionListener () {
91+ public void actionPerformed (ActionEvent e ) {
92+ onCancel ();
93+ }
94+ },
95+ KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
96+ JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
97+ );
7898 }
7999
80100 private String getModuleName () {
81101 return moduleName ;
82102 }
83103
104+ /**
105+ * Get controller name.
106+ *
107+ * @return String
108+ */
84109 public String getControllerName () {
85110 return controllerName .getText ().trim ();
86111 }
87112
113+ /**
114+ * Get HTTP method name.
115+ *
116+ * @return String
117+ */
88118 public String getHttpMethodName () {
89119 return httpMethodSelect .getSelectedItem ().toString ();
90120 }
91121
122+ /**
123+ * Get area.
124+ *
125+ * @return String
126+ */
92127 public String getArea () {
93128 return controllerAreaSelect .getSelectedItem ().toString ();
94129 }
95130
131+ /**
132+ * Get ACL.
133+ *
134+ * @return String
135+ */
96136 public String getAcl () {
97137 return acl .getText ().trim ();
98138 }
99139
140+ /**
141+ * Get action name.
142+ *
143+ * @return String
144+ */
100145 public String getActionName () {
101146 return actionName .getText ().trim ();
102147 }
103148
149+ /**
150+ * Get controller directory.
151+ *
152+ * @return String
153+ */
154+ public String getControllerDirectory () {
155+ return controllerParentDir .getText ().trim ();
156+ }
157+
158+ /**
159+ * Get action directory.
160+ *
161+ * @return String
162+ */
163+ public String getActionDirectory () {
164+ return getControllerDirectory () + File .separator + getControllerName ();
165+ }
166+
167+ /**
168+ * Open new controller dialog.
169+ *
170+ * @param project Project
171+ * @param directory PsiDirectory
172+ */
104173 public static void open (Project project , PsiDirectory directory ) {
105174 NewControllerDialog dialog = new NewControllerDialog (project , directory );
106175 dialog .pack ();
@@ -130,14 +199,6 @@ private PsiFile generateFile() {
130199 ), project ).generate (NewControllerAction .ACTION_NAME , true );
131200 }
132201
133- public String getControllerDirectory () {
134- return controllerParentDir .getText ().trim ();
135- }
136-
137- public String getActionDirectory () {
138- return getControllerDirectory () + File .separator + getControllerName ();
139- }
140-
141202 private void suggestControllerDirectory () {
142203 String area = getArea ();
143204 if (area .equals (Package .Areas .adminhtml .toString ())) {
@@ -150,10 +211,10 @@ private void suggestControllerDirectory() {
150211 private void toggleAdminPanel () {
151212 String area = getArea ();
152213 if (area .equals (Package .Areas .adminhtml .toString ()) && inheritClass .isSelected ()) {
153- AdminPanel .setVisible (true );
214+ adminPanel .setVisible (true );
154215 return ;
155216 }
156- AdminPanel .setVisible (false );
217+ adminPanel .setVisible (false );
157218 }
158219
159220 private String getModuleIdentifierPath () {
@@ -169,10 +230,21 @@ private String getNamespace() {
169230 if (parts [0 ] == null || parts [1 ] == null || parts .length > 2 ) {
170231 return null ;
171232 }
172- String directoryPart = getControllerDirectory ().replace (File .separator , Package .FQN_SEPARATOR );
233+ String directoryPart = getControllerDirectory ().replace (
234+ File .separator ,
235+ Package .FQN_SEPARATOR
236+ );
173237 String controllerPart = Package .FQN_SEPARATOR + getControllerName ();
174238
175- return parts [0 ] + Package .FQN_SEPARATOR + parts [1 ] + Package .FQN_SEPARATOR + directoryPart + controllerPart ;
239+ return String .format (
240+ "%s%s%s%s%s%s" ,
241+ parts [0 ],
242+ Package .FQN_SEPARATOR ,
243+ parts [1 ],
244+ Package .FQN_SEPARATOR ,
245+ directoryPart ,
246+ controllerPart
247+ );
176248 }
177249
178250 private Boolean getIsInheritClass () {
@@ -185,7 +257,12 @@ protected void onCancel() {
185257
186258 private ArrayList <String > getAreaList ()
187259 {
188- return new ArrayList <>(Arrays .asList (Package .Areas .frontend .toString (), Package .Areas .adminhtml .toString ()));
260+ return new ArrayList <>(
261+ Arrays .asList (
262+ Package .Areas .frontend .toString (),
263+ Package .Areas .adminhtml .toString ()
264+ )
265+ );
189266 }
190267
191268 private void createUIComponents () {
0 commit comments