Skip to content

Commit dc66b27

Browse files
author
Vitaliy Boyko
committed
89: init
1 parent d6a6cca commit dc66b27

File tree

7 files changed

+629
-0
lines changed

7 files changed

+629
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<action id="MagentoCreateAViewModel" class="com.magento.idea.magento2plugin.actions.generation.NewViewModelAction" />
6363
<action id="MagentoCreateAGraphQlResolver" class="com.magento.idea.magento2plugin.actions.generation.NewGraphQlResolverAction" />
6464
<action id="MagentoCreateCLICommand" class="com.magento.idea.magento2plugin.actions.generation.NewCLICommandAction" />
65+
<action id="MagentoCreateAController" class="com.magento.idea.magento2plugin.actions.generation.NewUiFormAction" />
6566
<add-to-group group-id="NewGroup" anchor="last"/>
6667
</group>
6768

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation;
7+
8+
import com.intellij.ide.IdeView;
9+
import com.intellij.openapi.actionSystem.AnAction;
10+
import com.intellij.openapi.actionSystem.AnActionEvent;
11+
import com.intellij.openapi.actionSystem.CommonDataKeys;
12+
import com.intellij.openapi.actionSystem.DataContext;
13+
import com.intellij.openapi.actionSystem.LangDataKeys;
14+
import com.intellij.openapi.project.Project;
15+
import com.intellij.psi.PsiDirectory;
16+
import com.magento.idea.magento2plugin.MagentoIcons;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewUiFormDialog;
18+
19+
public class NewUiFormAction extends AnAction {
20+
public static final String ACTION_NAME = "Magento 2 UI Form";
21+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 UI Form";
22+
23+
/**
24+
* Constructor.
25+
*/
26+
public NewUiFormAction() {
27+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
28+
}
29+
30+
@Override
31+
public void actionPerformed(final AnActionEvent event) {
32+
final DataContext dataContext = event.getDataContext();
33+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
34+
35+
if (view == null) {
36+
return;
37+
}
38+
39+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
40+
if (project == null) {
41+
return;
42+
}
43+
44+
final PsiDirectory directory = view.getOrChooseDirectory();
45+
if (directory == null) {
46+
return;
47+
}
48+
49+
NewUiFormDialog.open(project, directory);
50+
}
51+
52+
@Override
53+
public boolean isDumbAware() {
54+
return false;
55+
}
56+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.data;
7+
8+
@SuppressWarnings({"PMD.DataClass"})
9+
public class UiFormFileData {
10+
private final String formName;
11+
private final String formArea;
12+
13+
/**
14+
* UI Form data file constructor.
15+
*
16+
* @param formName String
17+
* @param formArea String
18+
*/
19+
public UiFormFileData(
20+
final String formName,
21+
final String formArea
22+
) {
23+
this.formName = formName;
24+
this.formArea = formArea;
25+
}
26+
27+
/**
28+
* Get action directory.
29+
*
30+
* @return String
31+
*/
32+
public String getFormName() {
33+
return formName;
34+
}
35+
36+
/**
37+
* Get controller area.
38+
*
39+
* @return String
40+
*/
41+
public String getFormArea() {
42+
return formArea;
43+
}
44+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.magento.idea.magento2plugin.actions.generation.dialog.NewUiFormDialog">
3+
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="10" left="10" bottom="10" right="10"/>
5+
<constraints>
6+
<xy x="48" y="54" width="454" height="423"/>
7+
</constraints>
8+
<properties>
9+
<preferredSize width="450" height="300"/>
10+
</properties>
11+
<border type="none"/>
12+
<children>
13+
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
14+
<margin top="0" left="0" bottom="0" right="0"/>
15+
<constraints>
16+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
17+
</constraints>
18+
<properties/>
19+
<border type="none"/>
20+
<children>
21+
<hspacer id="98af6">
22+
<constraints>
23+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
24+
</constraints>
25+
</hspacer>
26+
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
27+
<margin top="0" left="0" bottom="0" right="0"/>
28+
<constraints>
29+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
30+
</constraints>
31+
<properties/>
32+
<border type="none"/>
33+
<children>
34+
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
35+
<constraints>
36+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
37+
</constraints>
38+
<properties>
39+
<text resource-bundle="magento2/common" key="common.ok"/>
40+
</properties>
41+
</component>
42+
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
43+
<constraints>
44+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
45+
</constraints>
46+
<properties>
47+
<text resource-bundle="magento2/common" key="common.cancel"/>
48+
</properties>
49+
</component>
50+
</children>
51+
</grid>
52+
</children>
53+
</grid>
54+
<grid id="e3588" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
55+
<margin top="0" left="0" bottom="0" right="0"/>
56+
<constraints>
57+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
58+
</constraints>
59+
<properties/>
60+
<border type="none"/>
61+
<children>
62+
<component id="5a121" class="javax.swing.JLabel">
63+
<constraints>
64+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
65+
</constraints>
66+
<properties>
67+
<text resource-bundle="magento2/common" key="common.controller.name"/>
68+
</properties>
69+
</component>
70+
<component id="4e6cb" class="javax.swing.JTextField" binding="formName">
71+
<constraints>
72+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
73+
<preferred-size width="150" height="-1"/>
74+
</grid>
75+
</constraints>
76+
<properties>
77+
<text value=""/>
78+
</properties>
79+
</component>
80+
</children>
81+
</grid>
82+
<component id="b8894" class="com.magento.idea.magento2plugin.ui.FilteredComboBox" binding="formAreaSelect" custom-create="true">
83+
<constraints>
84+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
85+
</constraints>
86+
<properties>
87+
<toolTipText value=""/>
88+
</properties>
89+
<clientProperties>
90+
<html.disable class="java.lang.Boolean" value="false"/>
91+
</clientProperties>
92+
</component>
93+
<component id="ad25c" class="javax.swing.JLabel">
94+
<constraints>
95+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
96+
</constraints>
97+
<properties>
98+
<text resource-bundle="magento2/common" key="common.area.target"/>
99+
</properties>
100+
</component>
101+
</children>
102+
</grid>
103+
</form>
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.dialog;
7+
8+
import com.intellij.openapi.project.Project;
9+
import com.intellij.psi.PsiDirectory;
10+
import com.intellij.psi.PsiFile;
11+
import com.magento.idea.magento2plugin.actions.generation.NewUiFormAction;
12+
import com.magento.idea.magento2plugin.actions.generation.data.UiFormFileData;
13+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.NewUiFormValidator;
14+
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleUiFormGenerator;
15+
import com.magento.idea.magento2plugin.magento.packages.Areas;
16+
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
17+
import java.awt.event.ActionEvent;
18+
import java.awt.event.ActionListener;
19+
import java.awt.event.KeyEvent;
20+
import java.awt.event.WindowAdapter;
21+
import java.awt.event.WindowEvent;
22+
import java.util.ArrayList;
23+
import java.util.Arrays;
24+
import java.util.List;
25+
import javax.swing.JButton;
26+
import javax.swing.JComponent;
27+
import javax.swing.JPanel;
28+
import javax.swing.JTextField;
29+
import javax.swing.KeyStroke;
30+
31+
@SuppressWarnings({
32+
"PMD.TooManyFields",
33+
"PMD.ConstructorCallsOverridableMethod"
34+
})
35+
public class NewUiFormDialog extends AbstractDialog {
36+
private final NewUiFormValidator validator;
37+
private final Project project;
38+
private JPanel contentPane;
39+
private JButton buttonOK;
40+
private JButton buttonCancel;
41+
private FilteredComboBox formAreaSelect;
42+
private JTextField formName;
43+
44+
/**
45+
* Open new dialog for adding new controller.
46+
*
47+
* @param project Project
48+
* @param directory PsiDirectory
49+
*/
50+
public NewUiFormDialog(final Project project, final PsiDirectory directory) {
51+
super();
52+
this.project = project;
53+
this.validator = new NewUiFormValidator(this);
54+
55+
setContentPane(contentPane);
56+
setModal(true);
57+
getRootPane().setDefaultButton(buttonOK);
58+
59+
buttonOK.addActionListener(e -> onOK());
60+
buttonCancel.addActionListener(e -> onCancel());
61+
62+
// call onCancel() when cross is clicked
63+
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
64+
addWindowListener(new WindowAdapter() {
65+
public void windowClosing(final WindowEvent event) {
66+
onCancel();
67+
}
68+
});
69+
70+
// call onCancel() on ESCAPE
71+
contentPane.registerKeyboardAction(
72+
new ActionListener() {
73+
public void actionPerformed(final ActionEvent event) {
74+
onCancel();
75+
}
76+
},
77+
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
78+
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
79+
);
80+
}
81+
82+
/**
83+
* Get controller name.
84+
*
85+
* @return String
86+
*/
87+
public String getFormName() {
88+
return formName.getText().trim();
89+
}
90+
91+
/**
92+
* Get area.
93+
*
94+
* @return String
95+
*/
96+
public String getArea() {
97+
return formAreaSelect.getSelectedItem().toString();
98+
}
99+
100+
/**
101+
* Open new controller dialog.
102+
*
103+
* @param project Project
104+
* @param directory PsiDirectory
105+
*/
106+
public static void open(final Project project, final PsiDirectory directory) {
107+
final NewUiFormDialog dialog = new NewUiFormDialog(project, directory);
108+
dialog.pack();
109+
dialog.centerDialog(dialog);
110+
dialog.setVisible(true);
111+
}
112+
113+
private void onOK() {
114+
if (!validator.validate()) {
115+
return;
116+
}
117+
118+
generateFile();
119+
this.setVisible(false);
120+
}
121+
122+
private PsiFile generateFile() {
123+
return new ModuleUiFormGenerator(new UiFormFileData(
124+
getFormName(),
125+
getArea()
126+
), project).generate(NewUiFormAction.ACTION_NAME, true);
127+
}
128+
129+
protected void onCancel() {
130+
dispose();
131+
}
132+
133+
private List<String> getAreaList() {
134+
return new ArrayList<>(
135+
Arrays.asList(
136+
Areas.frontend.toString(),
137+
Areas.adminhtml.toString()
138+
)
139+
);
140+
}
141+
142+
@SuppressWarnings({"PMD.UnusedPrivateMethod"})
143+
private void createUIComponents() {
144+
this.formAreaSelect = new FilteredComboBox(getAreaList());
145+
}
146+
}

0 commit comments

Comments
 (0)