Skip to content

Commit afd1d59

Browse files
author
Sergiy Zhovnir
committed
Add code adjustments
1 parent b6987f7 commit afd1d59

18 files changed

+1041
-220
lines changed

resources/magento2/common.properties

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ common.module.name=Module Name
44
common.module.version=Version
55
common.module.license=License(s)
66
common.dependencies=Dependencies
7-
common.controller.area=Controller Area
7+
common.httpMethod=HTTP Method
88
common.controller.name=Controller Name
9-
common.controller.parentDir=Controller Parent Directory
10-
common.controller.httpMethod=HTTP Method
119
common.controller.inheritAction=Inherit Action Class
1210
common.controller.backend.acl=Admin Resource ACL
1311
common.controller.action=Controller Action

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.form

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
8383
</constraints>
8484
<properties>
85-
<text resource-bundle="magento2/common" key="common.controller.parentDir"/>
85+
<text resource-bundle="magento2/common" key="common.parentDirectory"/>
8686
</properties>
8787
</component>
8888
<component id="7df01" class="javax.swing.JTextField" binding="controllerParentDir">
@@ -129,15 +129,15 @@
129129
<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"/>
130130
</constraints>
131131
<properties>
132-
<text resource-bundle="magento2/common" key="common.controller.area"/>
132+
<text resource-bundle="magento2/common" key="common.area.target"/>
133133
</properties>
134134
</component>
135135
<component id="b8f6d" class="javax.swing.JLabel">
136136
<constraints>
137137
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
138138
</constraints>
139139
<properties>
140-
<text resource-bundle="magento2/common" key="common.controller.httpMethod"/>
140+
<text resource-bundle="magento2/common" key="common.httpMethod"/>
141141
</properties>
142142
</component>
143143
<component id="3eabb" class="com.magento.idea.magento2plugin.ui.FilteredComboBox" binding="httpMethodSelect" custom-create="true">
@@ -159,7 +159,7 @@
159159
<text resource-bundle="magento2/common" key="common.controller.inheritAction"/>
160160
</properties>
161161
</component>
162-
<grid id="5b6ca" binding="AdminPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
162+
<grid id="5b6ca" binding="adminPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
163163
<margin top="0" left="0" bottom="0" right="0"/>
164164
<constraints>
165165
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java

Lines changed: 99 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.actions.generation.dialog;
67

78
import com.intellij.openapi.project.Project;
@@ -18,9 +19,18 @@
1819
import com.magento.idea.magento2plugin.magento.packages.Package;
1920
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
2021
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;
2434
import java.util.ArrayList;
2535
import java.util.Arrays;
2636

@@ -40,10 +50,16 @@ public class NewControllerDialog extends AbstractDialog {
4050
private JTextField controllerName;
4151
private JTextField controllerParentDir;
4252
private JCheckBox inheritClass;
43-
private JPanel AdminPanel;
53+
private JPanel adminPanel;
4454
private JTextField acl;
4555
private JTextField actionName;
4656

57+
/**
58+
* Open new dialog for adding new controller.
59+
*
60+
* @param project Project
61+
* @param directory PsiDirectory
62+
*/
4763
public NewControllerDialog(Project project, PsiDirectory directory) {
4864
this.project = project;
4965
this.baseDir = directory;
@@ -70,37 +86,90 @@ public void windowClosing(WindowEvent e) {
7086
});
7187

7288
// 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+
);
7898
}
7999

80100
private String getModuleName() {
81101
return moduleName;
82102
}
83103

104+
/**
105+
* Get controller name.
106+
*
107+
* @return String
108+
*/
84109
public String getControllerName() {
85110
return controllerName.getText().trim();
86111
}
87112

113+
/**
114+
* Get HTTP method name.
115+
*
116+
* @return String
117+
*/
88118
public String getHttpMethodName() {
89119
return httpMethodSelect.getSelectedItem().toString();
90120
}
91121

122+
/**
123+
* Get area.
124+
*
125+
* @return String
126+
*/
92127
public String getArea() {
93128
return controllerAreaSelect.getSelectedItem().toString();
94129
}
95130

131+
/**
132+
* Get ACL.
133+
*
134+
* @return String
135+
*/
96136
public String getAcl() {
97137
return acl.getText().trim();
98138
}
99139

140+
/**
141+
* Get action name.
142+
*
143+
* @return String
144+
*/
100145
public String getActionName() {
101146
return actionName.getText().trim();
102147
}
103148

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+
*/
104173
public static void open(Project project, PsiDirectory directory) {
105174
NewControllerDialog dialog = new NewControllerDialog(project, directory);
106175
dialog.pack();
@@ -130,14 +199,6 @@ private PsiFile generateFile() {
130199
), project).generate(NewControllerAction.ACTION_NAME, true);
131200
}
132201

133-
public String getControllerDirectory() {
134-
return controllerParentDir.getText().trim();
135-
}
136-
137-
public String getActionDirectory() {
138-
return getControllerDirectory() + File.separator + getControllerName();
139-
}
140-
141202
private void suggestControllerDirectory() {
142203
String area = getArea();
143204
if (area.equals(Package.Areas.adminhtml.toString())) {
@@ -150,10 +211,10 @@ private void suggestControllerDirectory() {
150211
private void toggleAdminPanel() {
151212
String area = getArea();
152213
if (area.equals(Package.Areas.adminhtml.toString()) && inheritClass.isSelected()) {
153-
AdminPanel.setVisible(true);
214+
adminPanel.setVisible(true);
154215
return;
155216
}
156-
AdminPanel.setVisible(false);
217+
adminPanel.setVisible(false);
157218
}
158219

159220
private String getModuleIdentifierPath() {
@@ -169,10 +230,21 @@ private String getNamespace() {
169230
if (parts[0] == null || parts[1] == null || parts.length > 2) {
170231
return null;
171232
}
172-
String directoryPart = getControllerDirectory().replace(File.separator, Package.FQN_SEPARATOR);
233+
String directoryPart = getControllerDirectory().replace(
234+
File.separator,
235+
Package.FQN_SEPARATOR
236+
);
173237
String controllerPart = Package.FQN_SEPARATOR + getControllerName();
174238

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+
);
176248
}
177249

178250
private Boolean getIsInheritClass() {
@@ -185,7 +257,12 @@ protected void onCancel() {
185257

186258
private ArrayList<String> getAreaList()
187259
{
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+
);
189266
}
190267

191268
private void createUIComponents() {

0 commit comments

Comments
 (0)