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 ;
18
19
import com .magento .idea .magento2plugin .magento .packages .Package ;
19
20
import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
20
21
import 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 ;
24
34
import java .util .ArrayList ;
25
35
import java .util .Arrays ;
26
36
@@ -40,10 +50,16 @@ public class NewControllerDialog extends AbstractDialog {
40
50
private JTextField controllerName ;
41
51
private JTextField controllerParentDir ;
42
52
private JCheckBox inheritClass ;
43
- private JPanel AdminPanel ;
53
+ private JPanel adminPanel ;
44
54
private JTextField acl ;
45
55
private JTextField actionName ;
46
56
57
+ /**
58
+ * Open new dialog for adding new controller.
59
+ *
60
+ * @param project Project
61
+ * @param directory PsiDirectory
62
+ */
47
63
public NewControllerDialog (Project project , PsiDirectory directory ) {
48
64
this .project = project ;
49
65
this .baseDir = directory ;
@@ -70,37 +86,90 @@ public void windowClosing(WindowEvent e) {
70
86
});
71
87
72
88
// 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
+ );
78
98
}
79
99
80
100
private String getModuleName () {
81
101
return moduleName ;
82
102
}
83
103
104
+ /**
105
+ * Get controller name.
106
+ *
107
+ * @return String
108
+ */
84
109
public String getControllerName () {
85
110
return controllerName .getText ().trim ();
86
111
}
87
112
113
+ /**
114
+ * Get HTTP method name.
115
+ *
116
+ * @return String
117
+ */
88
118
public String getHttpMethodName () {
89
119
return httpMethodSelect .getSelectedItem ().toString ();
90
120
}
91
121
122
+ /**
123
+ * Get area.
124
+ *
125
+ * @return String
126
+ */
92
127
public String getArea () {
93
128
return controllerAreaSelect .getSelectedItem ().toString ();
94
129
}
95
130
131
+ /**
132
+ * Get ACL.
133
+ *
134
+ * @return String
135
+ */
96
136
public String getAcl () {
97
137
return acl .getText ().trim ();
98
138
}
99
139
140
+ /**
141
+ * Get action name.
142
+ *
143
+ * @return String
144
+ */
100
145
public String getActionName () {
101
146
return actionName .getText ().trim ();
102
147
}
103
148
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
+ */
104
173
public static void open (Project project , PsiDirectory directory ) {
105
174
NewControllerDialog dialog = new NewControllerDialog (project , directory );
106
175
dialog .pack ();
@@ -130,14 +199,6 @@ private PsiFile generateFile() {
130
199
), project ).generate (NewControllerAction .ACTION_NAME , true );
131
200
}
132
201
133
- public String getControllerDirectory () {
134
- return controllerParentDir .getText ().trim ();
135
- }
136
-
137
- public String getActionDirectory () {
138
- return getControllerDirectory () + File .separator + getControllerName ();
139
- }
140
-
141
202
private void suggestControllerDirectory () {
142
203
String area = getArea ();
143
204
if (area .equals (Package .Areas .adminhtml .toString ())) {
@@ -150,10 +211,10 @@ private void suggestControllerDirectory() {
150
211
private void toggleAdminPanel () {
151
212
String area = getArea ();
152
213
if (area .equals (Package .Areas .adminhtml .toString ()) && inheritClass .isSelected ()) {
153
- AdminPanel .setVisible (true );
214
+ adminPanel .setVisible (true );
154
215
return ;
155
216
}
156
- AdminPanel .setVisible (false );
217
+ adminPanel .setVisible (false );
157
218
}
158
219
159
220
private String getModuleIdentifierPath () {
@@ -169,10 +230,21 @@ private String getNamespace() {
169
230
if (parts [0 ] == null || parts [1 ] == null || parts .length > 2 ) {
170
231
return null ;
171
232
}
172
- String directoryPart = getControllerDirectory ().replace (File .separator , Package .FQN_SEPARATOR );
233
+ String directoryPart = getControllerDirectory ().replace (
234
+ File .separator ,
235
+ Package .FQN_SEPARATOR
236
+ );
173
237
String controllerPart = Package .FQN_SEPARATOR + getControllerName ();
174
238
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
+ );
176
248
}
177
249
178
250
private Boolean getIsInheritClass () {
@@ -185,7 +257,12 @@ protected void onCancel() {
185
257
186
258
private ArrayList <String > getAreaList ()
187
259
{
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
+ );
189
266
}
190
267
191
268
private void createUIComponents () {
0 commit comments