Skip to content

Commit 6f8bdac

Browse files
Refactored code
1 parent 485ae55 commit 6f8bdac

File tree

8 files changed

+106
-36
lines changed

8 files changed

+106
-36
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.magento.idea.magento2plugin.actions.generation;
22

33
import com.intellij.ide.IdeView;
4-
import com.intellij.openapi.actionSystem.*;
4+
import com.intellij.openapi.actionSystem.AnAction;
5+
import com.intellij.openapi.actionSystem.AnActionEvent;
6+
import com.intellij.openapi.actionSystem.CommonDataKeys;
7+
import com.intellij.openapi.actionSystem.DataContext;
8+
import com.intellij.openapi.actionSystem.LangDataKeys;
59
import com.intellij.openapi.project.Project;
610
import com.intellij.psi.PsiDirectory;
711
import com.magento.idea.magento2plugin.MagentoIcons;

src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22

33
public interface EavEntityDataInterface {
44
public String getCode();
5+
56
public String getType();
7+
68
public String getLabel();
9+
710
public String getInput();
11+
812
public String getNamespace();
13+
914
public String getModuleName();
15+
1016
public String getDirectory();
17+
1118
public String getDataPatchName();
19+
1220
public String getEntityClass();
1321
}

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

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,27 @@
1313
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.Lowercase;
1414
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
1515
import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator;
16-
import com.magento.idea.magento2plugin.magento.packages.eav.*;
1716
import com.magento.idea.magento2plugin.magento.packages.File;
1817
import com.magento.idea.magento2plugin.magento.packages.Package;
18+
import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInputs;
19+
import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScopes;
20+
import com.magento.idea.magento2plugin.magento.packages.eav.AttributeTypes;
21+
import com.magento.idea.magento2plugin.magento.packages.eav.EavEntities;
1922
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
23+
import java.awt.event.KeyEvent;
24+
import java.awt.event.WindowAdapter;
25+
import java.awt.event.WindowEvent;
26+
import javax.swing.JButton;
27+
import javax.swing.JCheckBox;
28+
import javax.swing.JComboBox;
29+
import javax.swing.JComponent;
30+
import javax.swing.JPanel;
31+
import javax.swing.JTextField;
32+
import javax.swing.KeyStroke;
33+
import javax.swing.event.DocumentEvent;
2034
import org.codehaus.plexus.util.StringUtils;
2135
import org.jetbrains.annotations.NotNull;
2236

23-
import javax.swing.*;
24-
import javax.swing.event.DocumentEvent;
25-
import java.awt.event.*;
26-
2737
public class NewEavAttributeDialog extends AbstractDialog {
2838
private static Boolean IS_MODAL = true;
2939
private final String moduleName;
@@ -63,6 +73,12 @@ public class NewEavAttributeDialog extends AbstractDialog {
6373
private final Project project;
6474
private final PsiDirectory directory;
6575

76+
/**
77+
* Constructor.
78+
*
79+
* @param project Project
80+
* @param directory PsiDirectory
81+
*/
6682
public NewEavAttributeDialog(Project project, PsiDirectory directory) {
6783
super();
6884

@@ -118,19 +134,27 @@ protected void textChanged(final @NotNull DocumentEvent event) {
118134

119135
private void fillEntityTypeComboBox() {
120136
for (final EavEntities entity : EavEntities.values()) {
121-
entityType.addItem(new ComboBoxItemData(entity.name(), entity.name()));
137+
entityType.addItem(
138+
new ComboBoxItemData(entity.name(), entity.name())
139+
);
122140
}
123141

124142
for (final AttributeTypes typeValue : AttributeTypes.values()) {
125-
typeComboBox.addItem(new ComboBoxItemData(typeValue.getType(), typeValue.getType()));
143+
typeComboBox.addItem(
144+
new ComboBoxItemData(typeValue.getType(), typeValue.getType())
145+
);
126146
}
127147

128148
for (final AttributeInputs inputValue : AttributeInputs.values()) {
129-
inputComboBox.addItem(new ComboBoxItemData(inputValue.getInput(), inputValue.getInput()));
149+
inputComboBox.addItem(
150+
new ComboBoxItemData(inputValue.getInput(), inputValue.getInput())
151+
);
130152
}
131153

132154
for (final AttributeScopes globalValue : AttributeScopes.values()) {
133-
scopeComboBox.addItem(new ComboBoxItemData(globalValue.getScope(), globalValue.name()));
155+
scopeComboBox.addItem(
156+
new ComboBoxItemData(globalValue.getScope(), globalValue.name())
157+
);
134158
}
135159
}
136160

src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
import com.magento.idea.magento2plugin.magento.packages.eav.DataPatchDependency;
2121
import com.magento.idea.magento2plugin.util.GetPhpClassByFQN;
2222
import com.sun.istack.NotNull;
23+
import java.util.ArrayList;
24+
import java.util.List;
25+
import java.util.Properties;
26+
import javax.swing.JOptionPane;
2327
import org.jetbrains.annotations.Nullable;
2428

25-
import javax.swing.*;
26-
import java.util.*;
27-
2829
public class EavAttributeSetupPatchGenerator extends FileGenerator {
2930
private final EavEntityDataInterface eavEntityData;
3031
private final Project project;
@@ -33,6 +34,12 @@ public class EavAttributeSetupPatchGenerator extends FileGenerator {
3334
private final ValidatorBundle validatorBundle;
3435
private final CommonBundle commonBundle;
3536

37+
/**
38+
* Constructor.
39+
*
40+
* @param eavEntityData EavEntityDataInterface
41+
* @param project Project
42+
*/
3643
public EavAttributeSetupPatchGenerator(
3744
final @NotNull EavEntityDataInterface eavEntityData,
3845
Project project
@@ -53,11 +60,15 @@ public PsiFile generate(String actionName) {
5360
final PhpClass dataPatchClass = GetPhpClassByFQN.getInstance(project)
5461
.execute(getDataPatchFqn());
5562

56-
if (validateIfFileAlreadyExist(dataPatchClass, errorTitle)) return null;
63+
if (validateIfFileAlreadyExist(dataPatchClass, errorTitle)) {
64+
return null;
65+
}
5766

5867
final PhpFile dataPathFile = createDataPathClass(actionName);
5968

60-
if (validateIfFileCanBeCreated(errorTitle, dataPathFile)) return null;
69+
if (validateIfFileCanBeCreated(errorTitle, dataPathFile)) {
70+
return null;
71+
}
6172

6273
return dataPathFile;
6374
}
@@ -151,7 +162,8 @@ protected void fillAttributes(Properties attributes) {
151162

152163
final String eavSetup = DataPatchDependency.ENV_SETUP.getClassPatch();
153164
final String eavSetupFactory = DataPatchDependency.EAV_SETUP_FACTORY.getClassPatch();
154-
final String moduleDataSetupInterface = DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch();
165+
final String moduleDataSetupInterface =
166+
DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch();
155167
final String entityClass = eavEntityData.getEntityClass();
156168

157169
attributes.setProperty(
@@ -183,13 +195,13 @@ protected void fillAttributes(Properties attributes) {
183195

184196
List<String> entityAttributes = getAttributesList(eavEntityData);
185197
attributes.setProperty("ATTRIBUTE_SET", String.join(",", entityAttributes));
186-
187-
188198
}
189199

190200
private List<String> getAttributesList(EavEntityDataInterface eavEntityData) {
191201
AttributeMapperFactory attributeMapperFactory = new AttributeMapperFactory();
192-
AttributeMapperInterface attributeMapper = attributeMapperFactory.createByEntityClass(eavEntityData.getEntityClass());
202+
AttributeMapperInterface attributeMapper = attributeMapperFactory.createByEntityClass(
203+
eavEntityData.getEntityClass()
204+
);
193205

194206
return attributeMapper.mapAttributesByEntityData(eavEntityData);
195207
}

src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import com.sun.istack.NotNull;
55

66
public class AttributeMapperFactory {
7+
/**
8+
* Create entity mapper by entity class
9+
*
10+
* @param entityClass String
11+
*/
712
public AttributeMapperInterface createByEntityClass(@NotNull String entityClass) {
813
if (entityClass.equals(EavEntities.PRODUCT.getEntityClass())) {
914
return new ProductAttributeMapper();

src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface;
44
import com.sun.istack.NotNull;
5-
65
import java.util.List;
76

87
public interface AttributeMapperInterface {

src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData;
55
import com.magento.idea.magento2plugin.magento.packages.eav.EavAttributes;
66
import com.sun.istack.NotNull;
7-
87
import java.util.ArrayList;
98
import java.util.HashMap;
109
import java.util.List;
@@ -34,21 +33,35 @@ public List<String> mapAttributesByEntityData(@NotNull EavEntityDataInterface en
3433
private Map<String, String> getMappedAttributes(ProductEntityData eavEntityData) {
3534
Map<String, String> mappedAttributes = new HashMap<>();
3635

37-
mappedAttributes.put(EavAttributes.group.name(), wrapStringValueForTemplate(eavEntityData.getGroup()));
38-
mappedAttributes.put(EavAttributes.type.name(), wrapStringValueForTemplate(eavEntityData.getType()));
39-
mappedAttributes.put(EavAttributes.label.name(), wrapStringValueForTemplate(eavEntityData.getLabel()));
40-
mappedAttributes.put(EavAttributes.input.name(), wrapStringValueForTemplate(eavEntityData.getInput()));
41-
42-
mappedAttributes.put(EavAttributes.source.name(), eavEntityData.getSource());
43-
mappedAttributes.put(EavAttributes.required.name(), Boolean.toString(eavEntityData.isRequired()));
44-
mappedAttributes.put(EavAttributes.sort_order.name(), Integer.toString(eavEntityData.getSortOrder()));
45-
mappedAttributes.put(EavAttributes.global.name(), eavEntityData.getScope());
46-
mappedAttributes.put(EavAttributes.is_used_in_grid.name(), Boolean.toString(eavEntityData.isUsedInGrid()));
47-
mappedAttributes.put(EavAttributes.is_visible_in_grid.name(), Boolean.toString(eavEntityData.isVisibleInGrid()));
48-
mappedAttributes.put(EavAttributes.is_filterable_in_grid.name(), Boolean.toString(eavEntityData.isFilterableInGrid()));
49-
mappedAttributes.put(EavAttributes.visible.name(), Boolean.toString(eavEntityData.isVisible()));
50-
mappedAttributes.put(EavAttributes.is_html_allowed_on_front.name(), Boolean.toString(eavEntityData.isHtmlAllowedOnFront()));
51-
mappedAttributes.put(EavAttributes.visible_on_front.name(), Boolean.toString(eavEntityData.isVisibleOnFront()));
36+
mappedAttributes.put(EavAttributes.group.name(),
37+
wrapStringValueForTemplate(eavEntityData.getGroup()));
38+
mappedAttributes.put(EavAttributes.type.name(),
39+
wrapStringValueForTemplate(eavEntityData.getType()));
40+
mappedAttributes.put(EavAttributes.label.name(),
41+
wrapStringValueForTemplate(eavEntityData.getLabel()));
42+
mappedAttributes.put(EavAttributes.input.name(),
43+
wrapStringValueForTemplate(eavEntityData.getInput()));
44+
45+
mappedAttributes.put(EavAttributes.source.name(),
46+
eavEntityData.getSource());
47+
mappedAttributes.put(EavAttributes.required.name(),
48+
Boolean.toString(eavEntityData.isRequired()));
49+
mappedAttributes.put(EavAttributes.sort_order.name(),
50+
Integer.toString(eavEntityData.getSortOrder()));
51+
mappedAttributes.put(EavAttributes.global.name(),
52+
eavEntityData.getScope());
53+
mappedAttributes.put(EavAttributes.is_used_in_grid.name(),
54+
Boolean.toString(eavEntityData.isUsedInGrid()));
55+
mappedAttributes.put(EavAttributes.is_visible_in_grid.name(),
56+
Boolean.toString(eavEntityData.isVisibleInGrid()));
57+
mappedAttributes.put(EavAttributes.is_filterable_in_grid.name(),
58+
Boolean.toString(eavEntityData.isFilterableInGrid()));
59+
mappedAttributes.put(EavAttributes.visible.name(),
60+
Boolean.toString(eavEntityData.isVisible()));
61+
mappedAttributes.put(EavAttributes.is_html_allowed_on_front.name(),
62+
Boolean.toString(eavEntityData.isHtmlAllowedOnFront()));
63+
mappedAttributes.put(EavAttributes.visible_on_front.name(),
64+
Boolean.toString(eavEntityData.isVisibleOnFront()));
5265

5366
return mappedAttributes;
5467
}

src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ public void setFileName(String fileName) {
1313
this.fileName = fileName;
1414
}
1515

16+
/**
17+
* Create instance by class name
18+
*
19+
* @param className String
20+
*/
1621
public static EavAttributeDataPatchPhp getInstance(final String className) {
1722
if (null == INSTANCE) {
1823
INSTANCE = new EavAttributeDataPatchPhp();

0 commit comments

Comments
 (0)