77
88import com .intellij .openapi .project .Project ;
99import com .intellij .psi .PsiDirectory ;
10+ import com .intellij .psi .PsiFile ;
1011import com .jetbrains .php .lang .psi .elements .PhpClass ;
12+ import com .magento .idea .magento2plugin .actions .generation .NewUiComponentFormAction ;
1113import 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 ;
1217import com .magento .idea .magento2plugin .actions .generation .data .UiComponentDataProviderData ;
1318import com .magento .idea .magento2plugin .actions .generation .data .UiComponentGridData ;
1419import com .magento .idea .magento2plugin .actions .generation .data .UiComponentGridToolbarData ;
1520import 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 ;
1624import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentDataProviderGenerator ;
1725import 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 ;
1828import com .magento .idea .magento2plugin .magento .files .UiComponentDataProviderPhp ;
1929import com .magento .idea .magento2plugin .magento .packages .Areas ;
2030import com .magento .idea .magento2plugin .magento .packages .File ;
31+ import com .magento .idea .magento2plugin .magento .packages .HttpMethod ;
2132import com .magento .idea .magento2plugin .magento .packages .Package ;
2233import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
2334import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
2839import java .util .ArrayList ;
2940import java .util .Arrays ;
3041import 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 .*;
3843
3944@ SuppressWarnings ({"PMD.TooManyFields" , "PMD.ExcessiveImports" , "PMD.UnusedPrivateMethod" })
4045public class NewUiComponentGridDialog extends AbstractDialog {
@@ -60,6 +65,20 @@ public class NewUiComponentGridDialog extends AbstractDialog {
6065 private JTextField dataProviderParentDirectory ;
6166 private JTextField acl ;
6267 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 ;
6382 private JLabel collectionLabel ;
6483
6584 /**
@@ -171,7 +190,10 @@ private void onOK() {
171190 return ;
172191 }
173192
174- generateFile ();
193+ generateViewControllerFile ();
194+ generateLayoutFile ();
195+ generateMenuFile ();
196+ generateUiComponentFile ();
175197 this .setVisible (false );
176198 }
177199
@@ -185,7 +207,7 @@ private void addActionListeners() {
185207 dataProviderType .addActionListener (event -> onDataProviderTypeChange ());
186208 }
187209
188- private void generateFile () {
210+ private void generateUiComponentFile () {
189211 final UiComponentDataProviderGenerator dataProviderGenerator ;
190212 dataProviderGenerator = new UiComponentDataProviderGenerator (
191213 getGridDataProviderData (),
@@ -200,6 +222,47 @@ private void generateFile() {
200222 gridXmlGenerator .generate (NewUiComponentGridAction .ACTION_NAME , true );
201223 }
202224
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+
203266 private String getModuleName () {
204267 return moduleName ;
205268 }
@@ -362,4 +425,46 @@ private String getDataProviderClass() {
362425 private String getDataProviderDirectory () {
363426 return dataProviderParentDirectory .getText ().trim ();
364427 }
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+ }
365470}
0 commit comments