7
7
8
8
import com .intellij .openapi .project .Project ;
9
9
import com .intellij .psi .PsiDirectory ;
10
+ import com .intellij .psi .PsiFile ;
10
11
import com .jetbrains .php .lang .psi .elements .PhpClass ;
12
+ import com .magento .idea .magento2plugin .actions .generation .NewUiComponentFormAction ;
11
13
import com .magento .idea .magento2plugin .actions .generation .NewUiComponentGridAction ;
14
+ import com .magento .idea .magento2plugin .actions .generation .data .ControllerFileData ;
15
+ import com .magento .idea .magento2plugin .actions .generation .data .LayoutXmlData ;
16
+ import com .magento .idea .magento2plugin .actions .generation .data .MenuXmlData ;
12
17
import com .magento .idea .magento2plugin .actions .generation .data .UiComponentDataProviderData ;
13
18
import com .magento .idea .magento2plugin .actions .generation .data .UiComponentGridData ;
14
19
import com .magento .idea .magento2plugin .actions .generation .data .UiComponentGridToolbarData ;
15
20
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .NewUiComponentGridDialogValidator ;
21
+ import com .magento .idea .magento2plugin .actions .generation .generator .LayoutXmlGenerator ;
22
+ import com .magento .idea .magento2plugin .actions .generation .generator .MenuXmlGenerator ;
23
+ import com .magento .idea .magento2plugin .actions .generation .generator .ModuleControllerClassGenerator ;
16
24
import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentDataProviderGenerator ;
17
25
import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentGridXmlGenerator ;
26
+ import com .magento .idea .magento2plugin .actions .generation .generator .util .NamespaceBuilder ;
27
+ import com .magento .idea .magento2plugin .magento .files .ControllerBackendPhp ;
18
28
import com .magento .idea .magento2plugin .magento .files .UiComponentDataProviderPhp ;
19
29
import com .magento .idea .magento2plugin .magento .packages .Areas ;
20
30
import com .magento .idea .magento2plugin .magento .packages .File ;
31
+ import com .magento .idea .magento2plugin .magento .packages .HttpMethod ;
21
32
import com .magento .idea .magento2plugin .magento .packages .Package ;
22
33
import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
23
34
import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
28
39
import java .util .ArrayList ;
29
40
import java .util .Arrays ;
30
41
import java .util .List ;
31
- import javax .swing .JButton ;
32
- import javax .swing .JCheckBox ;
33
- import javax .swing .JComponent ;
34
- import javax .swing .JLabel ;
35
- import javax .swing .JPanel ;
36
- import javax .swing .JTextField ;
37
- import javax .swing .KeyStroke ;
42
+ import javax .swing .*;
38
43
39
44
@ SuppressWarnings ({"PMD.TooManyFields" , "PMD.ExcessiveImports" , "PMD.UnusedPrivateMethod" })
40
45
public class NewUiComponentGridDialog extends AbstractDialog {
@@ -60,6 +65,20 @@ public class NewUiComponentGridDialog extends AbstractDialog {
60
65
private JTextField dataProviderParentDirectory ;
61
66
private JTextField acl ;
62
67
private JLabel aclLabel ;
68
+ private JLabel routeLabel ;
69
+ private JLabel controllerLabel ;
70
+ private JLabel actionLabel ;
71
+ private JTextField route ;
72
+ private JTextField controllerName ;
73
+ private JTextField actionName ;
74
+ private JComboBox parentMenuItem ;
75
+ private JLabel parentMenuItemLabel ;
76
+ private JTextField sortOrder ;
77
+ private JTextField menuIdentifier ;
78
+ private JLabel sortOrderLabel ;
79
+ private JLabel menuIdentifierLabel ;
80
+ private JTextField menuTitle ;
81
+ private JLabel menuTitleLabel ;
63
82
private JLabel collectionLabel ;
64
83
65
84
/**
@@ -171,7 +190,10 @@ private void onOK() {
171
190
return ;
172
191
}
173
192
174
- generateFile ();
193
+ generateViewControllerFile ();
194
+ generateLayoutFile ();
195
+ generateMenuFile ();
196
+ generateUiComponentFile ();
175
197
this .setVisible (false );
176
198
}
177
199
@@ -185,7 +207,7 @@ private void addActionListeners() {
185
207
dataProviderType .addActionListener (event -> onDataProviderTypeChange ());
186
208
}
187
209
188
- private void generateFile () {
210
+ private void generateUiComponentFile () {
189
211
final UiComponentDataProviderGenerator dataProviderGenerator ;
190
212
dataProviderGenerator = new UiComponentDataProviderGenerator (
191
213
getGridDataProviderData (),
@@ -200,6 +222,47 @@ private void generateFile() {
200
222
gridXmlGenerator .generate (NewUiComponentGridAction .ACTION_NAME , true );
201
223
}
202
224
225
+ private PsiFile generateViewControllerFile () {
226
+ final NamespaceBuilder namespace = new NamespaceBuilder (
227
+ getModuleName (),
228
+ getActionName (),
229
+ getControllerDirectory ()
230
+ );
231
+ return new ModuleControllerClassGenerator (new ControllerFileData (
232
+ getControllerDirectory (),
233
+ getActionName (),
234
+ getModuleName (),
235
+ getArea (),
236
+ HttpMethod .GET .toString (),
237
+ getAcl (),
238
+ true ,
239
+ namespace .getNamespace ()
240
+ ), project ).generate (NewUiComponentFormAction .ACTION_NAME , false );
241
+ }
242
+
243
+ private PsiFile generateLayoutFile () {
244
+ return new LayoutXmlGenerator (new LayoutXmlData (
245
+ getArea (),
246
+ getRoute (),
247
+ getModuleName (),
248
+ getControllerName (),
249
+ getActionName (),
250
+ getUiComponentName ()
251
+ ), project ).generate (NewUiComponentFormAction .ACTION_NAME , false );
252
+ }
253
+
254
+ private PsiFile generateMenuFile () {
255
+ return new MenuXmlGenerator (new MenuXmlData (
256
+ getParentMenuItem (),
257
+ getSortOrder (),
258
+ getModuleName (),
259
+ getMenuIdentifier (),
260
+ getMenuTitle (),
261
+ getAcl (),
262
+ getMenuAction ()
263
+ ), project ).generate (NewUiComponentFormAction .ACTION_NAME , false );
264
+ }
265
+
203
266
private String getModuleName () {
204
267
return moduleName ;
205
268
}
@@ -362,4 +425,46 @@ private String getDataProviderClass() {
362
425
private String getDataProviderDirectory () {
363
426
return dataProviderParentDirectory .getText ().trim ();
364
427
}
428
+
429
+ public String getActionName () {
430
+ return actionName .getText ().trim ();
431
+ }
432
+
433
+ private String getControllerDirectory () {
434
+ final String directory = ControllerBackendPhp .DEFAULT_DIR ;
435
+
436
+ return directory + File .separator + getControllerName ();
437
+ }
438
+
439
+ public String getControllerName () {
440
+ return controllerName .getText ().trim ();
441
+ }
442
+
443
+ public String getRoute () {
444
+ return route .getText ().trim ();
445
+ }
446
+
447
+ private String getParentMenuItem () {
448
+ return parentMenuItem .getSelectedItem ().toString ();
449
+ }
450
+
451
+ public String getSortOrder () {
452
+ return sortOrder .getText ().trim ();
453
+ }
454
+
455
+ public String getMenuIdentifier () {
456
+ return menuIdentifier .getText ().trim ();
457
+ }
458
+
459
+ private String getMenuAction () {
460
+ return getRoute ()
461
+ + File .separator
462
+ + getControllerName ().toLowerCase ()
463
+ + File .separator
464
+ + getActionName ().toLowerCase ();
465
+ }
466
+
467
+ public String getMenuTitle () {
468
+ return menuTitle .getText ().trim ();
469
+ }
365
470
}
0 commit comments