Skip to content

Commit aa4ab41

Browse files
author
Vitaliy Boyko
committed
64: static fixes
1 parent 5887d66 commit aa4ab41

File tree

11 files changed

+226
-185
lines changed

11 files changed

+226
-185
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ intellij {
3939
'CSS',
4040
'JavaScriptLanguage',
4141
'com.intellij.lang.jsgraphql:2.3.0',
42-
'platform-images'
42+
'platform-images',
43+
'copyright'
4344
]
4445
updateSinceUntilBuild false
4546
sameSinceUntilBuild false

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<depends>JavaScript</depends>
3636
<depends>com.intellij.modules.platform</depends>
3737
<depends>com.intellij.platform.images</depends>
38+
<depends>com.intellij.copyright</depends>
3839
<depends optional="true" config-file="withJsGraphQl.xml">com.intellij.lang.jsgraphql</depends>
3940

4041
<actions>

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

Lines changed: 25 additions & 17 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;
67

78
import com.intellij.openapi.actionSystem.AnActionEvent;
@@ -12,24 +13,30 @@
1213
import com.intellij.psi.PsiFile;
1314
import com.magento.idea.magento2plugin.MagentoIcons;
1415
import com.magento.idea.magento2plugin.actions.generation.dialog.OverrideInThemeDialog;
16+
import com.magento.idea.magento2plugin.magento.packages.ComponentType;
17+
import com.magento.idea.magento2plugin.magento.packages.Package;
1518
import com.magento.idea.magento2plugin.project.Settings;
16-
import com.magento.idea.magento2plugin.util.magento.ComponentType;
1719
import com.magento.idea.magento2plugin.util.magento.GetComponentNameByDirectory;
18-
import com.magento.idea.magento2plugin.util.magento.GetComponentTypeByName;
20+
import com.magento.idea.magento2plugin.util.magento.GetComponentTypeByNameUtil;
1921
import org.jetbrains.annotations.NotNull;
2022

2123
public class OverrideInThemeAction extends DumbAwareAction {
22-
public static String ACTION_NAME = "Override in theme...";
23-
public static String ACTION_DESCRIPTION = "Override template in project theme.";
24+
public static String actionName = "Override in theme...";
25+
public static String actionDescription = "Override template in project theme.";
2426
private PsiFile psiFile;
2527

2628
public OverrideInThemeAction() {
27-
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
29+
super(actionName, actionDescription, MagentoIcons.MODULE);
2830
}
2931

30-
public void update(@NotNull AnActionEvent event) {
32+
/**
33+
* Action entry point.
34+
*
35+
* @param event AnActionEvent
36+
*/
37+
public void update(final @NotNull AnActionEvent event) {
3138
boolean status = false;
32-
Project project = event.getData(PlatformDataKeys.PROJECT);
39+
final Project project = event.getData(PlatformDataKeys.PROJECT);
3340
psiFile = event.getData(PlatformDataKeys.PSI_FILE);
3441

3542
if (Settings.isEnabled(project)) {
@@ -38,42 +45,43 @@ public void update(@NotNull AnActionEvent event) {
3845
psiFile.getVirtualFile(),
3946
project
4047
);
41-
} catch (NullPointerException e) {
48+
} catch (NullPointerException e) { //NOPMD
4249
// Ignore
4350
}
4451
}
4552

4653
this.setStatus(event, status);
4754
}
4855

49-
private boolean isOverrideAllowed(VirtualFile file, Project project) throws NullPointerException {
56+
private boolean isOverrideAllowed(final VirtualFile file, final Project project) {
5057
if (file.isDirectory()) {
5158
return false;
5259
}
5360

5461
boolean isAllowed = false;
5562

56-
GetComponentNameByDirectory getComponentNameByDirectory = GetComponentNameByDirectory.getInstance(project);
57-
String componentType = GetComponentTypeByName.execute(getComponentNameByDirectory
63+
final GetComponentNameByDirectory getComponentNameByDirectory = GetComponentNameByDirectory
64+
.getInstance(project);
65+
final String componentType = GetComponentTypeByNameUtil.execute(getComponentNameByDirectory
5866
.execute(psiFile.getContainingDirectory()));
5967

60-
if (componentType.equals(ComponentType.TYPE_MODULE)) {
61-
isAllowed = file.getPath().contains("view");
62-
} else if (componentType.equals(ComponentType.TYPE_THEME)) {
68+
if (componentType.equals(ComponentType.module.toString())) {
69+
isAllowed = file.getPath().contains(Package.moduleViewDir);
70+
} else if (componentType.equals(ComponentType.theme.toString())) {
6371
isAllowed = true;
6472
}
6573

6674
return isAllowed;
6775
}
6876

69-
private void setStatus(AnActionEvent event, boolean status) {
77+
private void setStatus(final AnActionEvent event, final boolean status) {
7078
event.getPresentation().setVisible(status);
7179
event.getPresentation().setEnabled(status);
7280
}
7381

7482
@Override
75-
public void actionPerformed(@NotNull AnActionEvent e) {
76-
OverrideInThemeDialog.open(e.getProject(), this.psiFile);
83+
public void actionPerformed(final @NotNull AnActionEvent event) {
84+
OverrideInThemeDialog.open(event.getProject(), this.psiFile);
7785
}
7886

7987
@Override

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

Lines changed: 44 additions & 19 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;
@@ -11,11 +12,18 @@
1112
import com.magento.idea.magento2plugin.actions.generation.generator.OverrideInThemeGenerator;
1213
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
1314
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
14-
import org.jetbrains.annotations.NotNull;
15-
16-
import javax.swing.*;
17-
import java.awt.event.*;
15+
import java.awt.event.ActionEvent;
16+
import java.awt.event.ActionListener;
17+
import java.awt.event.KeyEvent;
18+
import java.awt.event.WindowAdapter;
19+
import java.awt.event.WindowEvent;
1820
import java.util.List;
21+
import javax.swing.JButton;
22+
import javax.swing.JComponent;
23+
import javax.swing.JLabel;
24+
import javax.swing.JPanel;
25+
import javax.swing.KeyStroke;
26+
import org.jetbrains.annotations.NotNull;
1927

2028
public class OverrideInThemeDialog extends AbstractDialog {
2129
@NotNull
@@ -26,52 +34,62 @@ public class OverrideInThemeDialog extends AbstractDialog {
2634
private JPanel contentPane;
2735
private JButton buttonOK;
2836
private JButton buttonCancel;
29-
private JLabel selectTheme;
37+
private JLabel selectTheme; //NOPMD
3038
private FilteredComboBox theme;
3139

32-
public OverrideInThemeDialog(@NotNull Project project, PsiFile psiFile) {
40+
/**
41+
* Constructor.
42+
*
43+
* @param project Project
44+
* @param psiFile PsiFile
45+
*/
46+
public OverrideInThemeDialog(final @NotNull Project project, final PsiFile psiFile) {
47+
super();
48+
3349
this.project = project;
3450
this.psiFile = psiFile;
3551
this.validator = OverrideInThemeDialogValidator.getInstance(this);
3652

3753
setContentPane(contentPane);
3854
setModal(true);
3955
getRootPane().setDefaultButton(buttonOK);
40-
pushToMiddle();
4156

4257
buttonOK.addActionListener(new ActionListener() {
43-
public void actionPerformed(ActionEvent e) {
44-
onOK();
58+
public void actionPerformed(final ActionEvent event) {
59+
onOK(); //NOPMD
4560
}
4661
});
4762

4863
buttonCancel.addActionListener(new ActionListener() {
49-
public void actionPerformed(ActionEvent e) {
64+
public void actionPerformed(final ActionEvent event) {
5065
onCancel();
5166
}
5267
});
5368

5469
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
5570
addWindowListener(new WindowAdapter() {
56-
public void windowClosing(WindowEvent e) {
71+
public void windowClosing(final WindowEvent event) {
5772
onCancel();
5873
}
5974
});
6075

6176
contentPane.registerKeyboardAction(new ActionListener() {
62-
public void actionPerformed(ActionEvent e) {
77+
public void actionPerformed(final ActionEvent event) {
6378
onCancel();
6479
}
65-
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
80+
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
81+
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
6682
}
6783

6884
private void onOK() {
6985
if (!validator.validate(project)) {
70-
JBPopupFactory.getInstance().createMessage("Invalid theme selection.").showCenteredInCurrentWindow(project);
86+
JBPopupFactory.getInstance().createMessage("Invalid theme selection.")
87+
.showCenteredInCurrentWindow(project);
7188
return;
7289
}
7390

74-
OverrideInThemeGenerator overrideInThemeGenerator = OverrideInThemeGenerator.getInstance(project);
91+
final OverrideInThemeGenerator overrideInThemeGenerator =
92+
new OverrideInThemeGenerator(project);
7593
overrideInThemeGenerator.execute(psiFile, this.getTheme());
7694

7795
this.setVisible(false);
@@ -81,14 +99,21 @@ public String getTheme() {
8199
return this.theme.getSelectedItem().toString();
82100
}
83101

84-
public static void open(@NotNull Project project, PsiFile psiFile) {
85-
OverrideInThemeDialog dialog = new OverrideInThemeDialog(project, psiFile);
102+
/**
103+
* Open popup.
104+
*
105+
* @param project Project
106+
* @param psiFile PsiFile
107+
*/
108+
public static void open(final @NotNull Project project, final PsiFile psiFile) {
109+
final OverrideInThemeDialog dialog = new OverrideInThemeDialog(project, psiFile);
86110
dialog.pack();
111+
dialog.centerDialog(dialog);
87112
dialog.setVisible(true);
88113
}
89114

90-
private void createUIComponents() {
91-
List<String> allThemesList = ModuleIndex.getInstance(project).getEditableThemeNames();
115+
private void createUIComponents() { //NOPMD
116+
final List<String> allThemesList = ModuleIndex.getInstance(project).getEditableThemeNames();
92117

93118
this.theme = new FilteredComboBox(allThemesList);
94119
}

0 commit comments

Comments
 (0)