Skip to content

Commit 3b0b191

Browse files
873: Code refactoring
1 parent 6304129 commit 3b0b191

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/com/magento/idea/magento2plugin/actions/generation/NewEmailTemplateAction.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import com.magento.idea.magento2plugin.MagentoIcons;
1717
import com.magento.idea.magento2plugin.actions.generation.dialog.NewEmailTemplateDialog;
1818

19-
@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.FieldNamingConventions"})
2019
public class NewEmailTemplateAction extends AnAction {
20+
2121
public static final String ACTION_NAME = "Magento 2 Email Template";
2222
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 email template";
2323

@@ -36,17 +36,16 @@ public void actionPerformed(final AnActionEvent event) {
3636
if (view == null) {
3737
return;
3838
}
39-
4039
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
40+
4141
if (project == null) {
4242
return;
4343
}
44-
4544
final PsiDirectory directory = view.getOrChooseDirectory();
45+
4646
if (directory == null) {
4747
return;
4848
}
49-
5049
NewEmailTemplateDialog.open(project, directory);
5150
}
5251

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import com.magento.idea.magento2plugin.magento.packages.Areas;
2222
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
2323
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
24-
import java.awt.event.ActionEvent;
25-
import java.awt.event.ActionListener;
2624
import java.awt.event.KeyEvent;
2725
import java.awt.event.WindowAdapter;
2826
import java.awt.event.WindowEvent;
@@ -36,15 +34,18 @@
3634
import javax.swing.KeyStroke;
3735

3836
public class NewEmailTemplateDialog extends AbstractDialog {
39-
private final String moduleName;
40-
private final Project project;
41-
private final NewEmailTemplateDialogValidator validator;
37+
4238
private static final String EMAIL_TEMPLATE_ID = "id";
4339
private static final String LABEL = "label";
4440
private static final String FILENAME = "file name";
41+
42+
private final String moduleName;
43+
private final Project project;
44+
private final NewEmailTemplateDialogValidator validator;
4545
private JPanel contentPane;
4646
private JButton buttonOK;
4747
private JButton buttonCancel;
48+
4849
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
4950
message = {NotEmptyRule.MESSAGE, EMAIL_TEMPLATE_ID})
5051
@FieldValidation(rule = RuleRegistry.IDENTIFIER,
@@ -58,6 +59,7 @@ public class NewEmailTemplateDialog extends AbstractDialog {
5859
@FieldValidation(rule = RuleRegistry.IDENTIFIER,
5960
message = {IdentifierRule.MESSAGE, FILENAME})
6061
private JTextField fileName;
62+
6163
private FilteredComboBox area;
6264
private FilteredComboBox templateType;
6365
private JTextField subject;
@@ -83,18 +85,16 @@ public NewEmailTemplateDialog(final Project project, final PsiDirectory director
8385
// call onCancel() when cross is clicked
8486
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
8587
addWindowListener(new WindowAdapter() {
88+
89+
@Override
8690
public void windowClosing(final WindowEvent windowEvent) {
8791
onCancel();
8892
}
8993
});
9094

9195
// call onCancel() on ESCAPE
9296
contentPane.registerKeyboardAction(
93-
new ActionListener() {
94-
public void actionPerformed(final ActionEvent actionEvent) {
95-
onCancel();
96-
}
97-
},
97+
actionEvent -> onCancel(),
9898
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
9999
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
100100
);
@@ -230,11 +230,6 @@ private void generateFile() {
230230
xmlGenerator.generate(NewEmailTemplateAction.ACTION_NAME, true);
231231
}
232232

233-
protected void onCancel() {
234-
// add your code here if necessary
235-
dispose();
236-
}
237-
238233
@SuppressWarnings({"PMD.UnusedPrivateMethod"})
239234
private void createUIComponents() {
240235
this.area = new FilteredComboBox(getAreaList());

0 commit comments

Comments
 (0)