14
14
import com .magento .idea .magento2plugin .actions .generation .NewUiComponentGridAction ;
15
15
import com .magento .idea .magento2plugin .actions .generation .data .AclXmlData ;
16
16
import com .magento .idea .magento2plugin .actions .generation .data .ControllerFileData ;
17
+ import com .magento .idea .magento2plugin .actions .generation .data .DataProviderDeclarationData ;
17
18
import com .magento .idea .magento2plugin .actions .generation .data .LayoutXmlData ;
18
19
import com .magento .idea .magento2plugin .actions .generation .data .MenuXmlData ;
20
+ import com .magento .idea .magento2plugin .actions .generation .data .RoutesXmlData ;
19
21
import com .magento .idea .magento2plugin .actions .generation .data .UiComponentDataProviderData ;
20
22
import com .magento .idea .magento2plugin .actions .generation .data .UiComponentGridData ;
21
23
import com .magento .idea .magento2plugin .actions .generation .data .UiComponentGridToolbarData ;
32
34
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .RouteIdRule ;
33
35
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .StartWithNumberOrCapitalLetterRule ;
34
36
import com .magento .idea .magento2plugin .actions .generation .generator .AclXmlGenerator ;
37
+ import com .magento .idea .magento2plugin .actions .generation .generator .DataProviderDeclarationGenerator ;
35
38
import com .magento .idea .magento2plugin .actions .generation .generator .LayoutXmlGenerator ;
36
39
import com .magento .idea .magento2plugin .actions .generation .generator .MenuXmlGenerator ;
37
40
import com .magento .idea .magento2plugin .actions .generation .generator .ModuleControllerClassGenerator ;
41
+ import com .magento .idea .magento2plugin .actions .generation .generator .RoutesXmlGenerator ;
38
42
import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentDataProviderGenerator ;
39
43
import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentGridXmlGenerator ;
40
44
import com .magento .idea .magento2plugin .actions .generation .generator .util .NamespaceBuilder ;
41
45
import com .magento .idea .magento2plugin .magento .files .ControllerBackendPhp ;
46
+ import com .magento .idea .magento2plugin .magento .files .ModuleMenuXml ;
42
47
import com .magento .idea .magento2plugin .magento .files .UiComponentDataProviderPhp ;
43
48
import com .magento .idea .magento2plugin .magento .packages .Areas ;
44
49
import com .magento .idea .magento2plugin .magento .packages .File ;
45
50
import com .magento .idea .magento2plugin .magento .packages .HttpMethod ;
46
51
import com .magento .idea .magento2plugin .magento .packages .Package ;
47
52
import com .magento .idea .magento2plugin .stubs .indexes .xml .MenuIndex ;
48
53
import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
54
+ import com .magento .idea .magento2plugin .util .FirstLetterToLowercaseUtil ;
49
55
import com .magento .idea .magento2plugin .util .magento .GetAclResourcesListUtil ;
50
56
import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
51
57
import com .magento .idea .magento2plugin .util .magento .GetResourceCollections ;
66
72
import javax .swing .KeyStroke ;
67
73
import org .jetbrains .annotations .NotNull ;
68
74
69
- @ SuppressWarnings ({"PMD.TooManyFields" , "PMD.ExcessiveImports" , "PMD.UnusedPrivateMethod" })
75
+ @ SuppressWarnings ({
76
+ "PMD.TooManyFields" ,
77
+ "PMD.ExcessiveImports" ,
78
+ "PMD.UnusedPrivateMethod" ,
79
+ "PMD.ToManyMethods" ,
80
+ "PMD.GodClass"
81
+ })
70
82
public class NewUiComponentGridDialog extends AbstractDialog {
71
83
private static final String ACTION_NAME = "Action Name" ;
72
84
private static final String DATA_PROVIDER_CLASS_NAME = "Data Provider Class Name" ;
73
85
private static final String DATA_PROVIDER_DIRECTORY = "Data Provider Directory" ;
86
+ private static final String NAME = "Name" ;
74
87
75
88
private final Project project ;
76
89
private final String moduleName ;
@@ -79,12 +92,12 @@ public class NewUiComponentGridDialog extends AbstractDialog {
79
92
private JButton buttonOK ;
80
93
private JButton buttonCancel ;
81
94
82
- @ FieldValidation (rule = RuleRegistry .NOT_EMPTY , message = {NotEmptyRule .MESSAGE , "Name" })
83
- @ FieldValidation (rule = RuleRegistry .IDENTIFIER , message = {IdentifierRule .MESSAGE , "Name" })
95
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY , message = {NotEmptyRule .MESSAGE , NAME })
96
+ @ FieldValidation (rule = RuleRegistry .IDENTIFIER , message = {IdentifierRule .MESSAGE , NAME })
84
97
private JTextField uiComponentName ;
85
98
86
- @ FieldValidation (rule = RuleRegistry .NOT_EMPTY , message = {NotEmptyRule .MESSAGE , "Name" })
87
- @ FieldValidation (rule = RuleRegistry .IDENTIFIER , message = {IdentifierRule .MESSAGE , "Name" })
99
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY , message = {NotEmptyRule .MESSAGE , NAME })
100
+ @ FieldValidation (rule = RuleRegistry .IDENTIFIER , message = {IdentifierRule .MESSAGE , NAME })
88
101
private JTextField idField ;
89
102
90
103
private JCheckBox addToolBar ;
@@ -168,7 +181,13 @@ public class NewUiComponentGridDialog extends AbstractDialog {
168
181
private JLabel aclGeneralLabel ;//NOPMD
169
182
private JLabel parentAclID ;//NOPMD
170
183
private JLabel aclTitleLabel ;//NOPMD
184
+ private JLabel controllerGeneralLabel ;//NOPMD
185
+ private JLabel dataProviderGeneralLabel ;//NOPMD
186
+ private JLabel general ;//NOPMD
171
187
private JLabel collectionLabel ;//NOPMD
188
+ private JLabel dataProviderParentDirectoryLabel ;
189
+ private JLabel tableNameLabel ;
190
+ private JTextField tableName ;
172
191
173
192
/**
174
193
* New UI component grid dialog constructor.
@@ -206,7 +225,13 @@ public void windowClosing(final WindowEvent event) {
206
225
KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
207
226
JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
208
227
);
209
- menuIdentifier .setText (getModuleName () + "::listing" );
228
+
229
+ final String componentIdentifierSuffix = "::listing" ;
230
+ menuIdentifier .setText (getModuleName () + componentIdentifierSuffix );
231
+ acl .setText (getModuleName () + componentIdentifierSuffix );
232
+
233
+ dataProviderParentDirectory .setVisible (false );
234
+ dataProviderParentDirectoryLabel .setVisible (false );
210
235
}
211
236
212
237
/**
@@ -283,6 +308,9 @@ private void onOK() {
283
308
generateLayoutFile ();
284
309
generateMenuFile ();
285
310
generateAclXmlFile ();
311
+ generateRoutesXmlFile ();
312
+ generateDataProviderClass ();
313
+ generateDataProviderDeclaration ();
286
314
generateUiComponentFile ();
287
315
this .setVisible (false );
288
316
}
@@ -297,21 +325,49 @@ private void addActionListeners() {
297
325
dataProviderType .addActionListener (event -> onDataProviderTypeChange ());
298
326
}
299
327
328
+ private PsiFile generateRoutesXmlFile () {
329
+ return new RoutesXmlGenerator (new RoutesXmlData (
330
+ getArea (),
331
+ getRoute (),
332
+ getModuleName ()
333
+ ), project ).generate (NewUiComponentFormAction .ACTION_NAME , false );
334
+ }
335
+
300
336
private void generateUiComponentFile () {
301
- final UiComponentDataProviderGenerator dataProviderGenerator ;
302
- dataProviderGenerator = new UiComponentDataProviderGenerator (
303
- getGridDataProviderData (),
304
- getModuleName (),
305
- project
306
- );
307
337
final UiComponentGridXmlGenerator gridXmlGenerator = new UiComponentGridXmlGenerator (
308
338
getUiComponentGridData (),
309
339
project
310
340
);
311
- dataProviderGenerator .generate (NewUiComponentGridAction .ACTION_NAME );
312
341
gridXmlGenerator .generate (NewUiComponentGridAction .ACTION_NAME , true );
313
342
}
314
343
344
+ private void generateDataProviderClass () {
345
+ if (getDataProviderType ().equals (UiComponentDataProviderPhp .CUSTOM_TYPE )) {
346
+ final UiComponentDataProviderGenerator dataProviderGenerator ;
347
+ dataProviderGenerator = new UiComponentDataProviderGenerator (
348
+ getGridDataProviderData (),
349
+ getModuleName (),
350
+ project
351
+ );
352
+ dataProviderGenerator .generate (NewUiComponentGridAction .ACTION_NAME );
353
+ }
354
+ }
355
+
356
+ private void generateDataProviderDeclaration () {
357
+ if (getDataProviderType ().equals (UiComponentDataProviderPhp .COLLECTION_TYPE )) {
358
+ final DataProviderDeclarationGenerator dataProviderGenerator ;
359
+ dataProviderGenerator = new DataProviderDeclarationGenerator (
360
+ new DataProviderDeclarationData (
361
+ getModuleName (),
362
+ getDataProviderClass (),
363
+ getCollection (),
364
+ getUiComponentName () + "_data_source" ,
365
+ getTableName ()
366
+ ), project );
367
+ dataProviderGenerator .generate (NewUiComponentGridAction .ACTION_NAME );
368
+ }
369
+ }
370
+
315
371
private PsiFile generateViewControllerFile () {
316
372
final NamespaceBuilder namespace = new NamespaceBuilder (
317
373
getModuleName (),
@@ -388,15 +444,24 @@ private void onDataProviderTypeChange() {
388
444
389
445
collection .setVisible (visible );
390
446
collectionLabel .setVisible (visible );
447
+ tableName .setVisible (visible );
448
+ tableNameLabel .setVisible (visible );
449
+ dataProviderParentDirectory .setVisible (!visible );
450
+ dataProviderParentDirectoryLabel .setVisible (!visible );
391
451
}
392
452
393
453
@ SuppressWarnings ({"PMD.UnusedPrivateMethod" })
394
454
private void createUIComponents () {
395
455
this .collection = new FilteredComboBox (getCollectionOptions ());
396
456
this .dataProviderType = new FilteredComboBox (getProviderTypeOptions ());
397
457
this .areaSelect = new FilteredComboBox (getAreaOptions ());
458
+ areaSelect .setEnabled (false );
398
459
this .parentMenu = new FilteredComboBox (getMenuReferences ());
399
460
this .parentAcl = new FilteredComboBox (getAclResourcesList ());
461
+
462
+ if (getAclResourcesList ().contains (ModuleMenuXml .defaultAcl )) {
463
+ parentAcl .setSelectedItem (ModuleMenuXml .defaultAcl );
464
+ }
400
465
}
401
466
402
467
@ NotNull
@@ -411,7 +476,6 @@ private List<String> getMenuReferences() {
411
476
private List <String > getCollectionOptions () {
412
477
if (this .collectionOptions == null ) {
413
478
this .collectionOptions = new ArrayList <>();
414
- this .collectionOptions .add ("" );
415
479
final GetResourceCollections getResourceCollections ;
416
480
getResourceCollections = GetResourceCollections .getInstance (
417
481
this .project
@@ -428,8 +492,8 @@ private List<String> getCollectionOptions() {
428
492
private List <String > getProviderTypeOptions () {
429
493
return new ArrayList <>(
430
494
Arrays .asList (
431
- UiComponentDataProviderPhp .CUSTOM_TYPE ,
432
- UiComponentDataProviderPhp .COLLECTION_TYPE
495
+ UiComponentDataProviderPhp .COLLECTION_TYPE ,
496
+ UiComponentDataProviderPhp .CUSTOM_TYPE
433
497
)
434
498
);
435
499
}
@@ -465,6 +529,9 @@ private String getDataProviderNamespace() {
465
529
}
466
530
467
531
private String getDataProviderClassFqn () {
532
+ if (!getDataProviderType ().equals (UiComponentDataProviderPhp .CUSTOM_TYPE )) {
533
+ return UiComponentDataProviderPhp .DEFAULT_DATA_PROVIDER ;
534
+ }
468
535
return String .format (
469
536
"%s%s%s" ,
470
537
getDataProviderNamespace (),
@@ -568,9 +635,9 @@ public String getMenuIdentifier() {
568
635
private String getMenuAction () {
569
636
return getRoute ()
570
637
+ File .separator
571
- + getControllerName (). toLowerCase ( new java . util . Locale ( "en" , "EN" ))
638
+ + FirstLetterToLowercaseUtil . convert ( getControllerName ( ))
572
639
+ File .separator
573
- + getActionName (). toLowerCase ( new java . util . Locale ( "en" , "EN" ));
640
+ + FirstLetterToLowercaseUtil . convert ( getActionName ( ));
574
641
}
575
642
576
643
public String getMenuTitle () {
@@ -588,4 +655,8 @@ public String getParentAcl() {
588
655
public String getAclTitle () {
589
656
return aclTitle .getText ().trim ();
590
657
}
658
+
659
+ public String getTableName () {
660
+ return tableName .getText ().trim ();
661
+ }
591
662
}
0 commit comments