Skip to content

Commit d5e2476

Browse files
Merge branch 'mainline-eav-attr-code-genearators' into 545-attribute-options
# Conflicts: # resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft # src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form # src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java # src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java # src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java # tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java
2 parents 38d9892 + b30c699 commit d5e2476

File tree

18 files changed

+457
-5
lines changed

18 files changed

+457
-5
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.MenuIndex" />
142142
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.DeclarativeSchemaElementsIndex" />
143143
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.UIComponentIndex" />
144+
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.ProductTypeIndex" />
144145

145146
<codeInsight.lineMarkerProvider language="PHP" implementationClass="com.magento.idea.magento2plugin.linemarker.php.PluginLineMarkerProvider"/>
146147
<codeInsight.lineMarkerProvider language="PHP" implementationClass="com.magento.idea.magento2plugin.linemarker.php.PluginTargetLineMarkerProvider"/>

resources/magento2/validation.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ validator.db.invalidTableNameLength=Table name must contain up to 64 characters
3737
validator.lowerSnakeCase=The {0} field must be of the lower snake case format
3838
validator.menuIdentifierInvalid=The menu identifier is invalid
3939
validator.someFieldsHaveErrors=Please, check the dialog. Some fields have errors
40+
validator.commaSeparatedString.isNotValid=The {0} field must contain comma separated string without whitespaces

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ public interface EavEntityDataInterface {
1919
public String getDataPatchName();
2020

2121
public String getEntityClass();
22+
23+
public String getSource();
2224
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class ProductEntityData implements EavEntityDataInterface {
1818
private String input;
1919
private String source;
2020
private String scope;
21+
private String applyTo;
2122
private boolean required;
2223
private boolean usedInGrid;
2324
private boolean visibleInGrid;
@@ -76,6 +77,10 @@ public void setScope(final String scope) {
7677
this.scope = scope;
7778
}
7879

80+
public void setApplyTo(final String applyTo) {
81+
this.applyTo = applyTo;
82+
}
83+
7984
public void setRequired(final boolean required) {
8085
this.required = required;
8186
}
@@ -193,6 +198,7 @@ public String getGroup() {
193198
return group;
194199
}
195200

201+
@Override
196202
public String getSource() {
197203
return source;
198204
}
@@ -201,6 +207,10 @@ public String getScope() {
201207
return scope;
202208
}
203209

210+
public String getApplyTo() {
211+
return applyTo;
212+
}
213+
204214
public boolean isRequired() {
205215
return required;
206216
}

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

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
<grid id="28350" binding="contentPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="10" left="10" bottom="10" right="10"/>
55
<constraints>
6-
<xy x="-1" y="5" width="870" height="790"/>
6+
<xy x="-1" y="5" width="764" height="763"/>
77
</constraints>
88
<properties>
99
<enabled value="true"/>
1010
<preferredSize width="800" height="800"/>
1111
</properties>
1212
<border type="none"/>
1313
<children>
14-
<grid id="6fc7e" layout-manager="GridLayoutManager" row-count="16" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
14+
<grid id="6fc7e" layout-manager="GridLayoutManager" row-count="17" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1515
<margin top="0" left="0" bottom="0" right="0"/>
1616
<constraints>
1717
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -322,6 +322,53 @@
322322
</component>
323323
</children>
324324
</grid>
325+
<component id="64ef9" class="javax.swing.JCheckBox" binding="applyToAllProductsCheckBox">
326+
<constraints>
327+
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
328+
</constraints>
329+
<properties>
330+
<selected value="true"/>
331+
<text value="Apply to all products types"/>
332+
</properties>
333+
</component>
334+
<grid id="27880" binding="applyToPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
335+
<margin top="0" left="0" bottom="0" right="0"/>
336+
<constraints>
337+
<grid row="16" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
338+
</constraints>
339+
<properties>
340+
<visible value="false"/>
341+
</properties>
342+
<border type="none"/>
343+
<children>
344+
<component id="b41e7" class="javax.swing.JLabel">
345+
<constraints>
346+
<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">
347+
<preferred-size width="144" height="15"/>
348+
</grid>
349+
</constraints>
350+
<properties>
351+
<text value="Apply to"/>
352+
<toolTipText value=""/>
353+
</properties>
354+
</component>
355+
<scrollpane id="f0efd">
356+
<constraints>
357+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
358+
</constraints>
359+
<properties/>
360+
<border type="none"/>
361+
<children>
362+
<component id="9e8b9" class="javax.swing.JList" binding="productsTypesList">
363+
<constraints/>
364+
<properties>
365+
<enabled value="true"/>
366+
</properties>
367+
</component>
368+
</children>
369+
</scrollpane>
370+
</children>
371+
</grid>
325372
</children>
326373
</grid>
327374
<hspacer id="75d92">

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData;
1313
import com.magento.idea.magento2plugin.actions.generation.data.SourceModelData;
1414
import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData;
15+
import com.magento.idea.magento2plugin.actions.generation.dialog.event.ApplyToVisibleListener;
1516
import com.magento.idea.magento2plugin.actions.generation.dialog.event.AttributeSourcePanelComponentListener;
1617
import com.magento.idea.magento2plugin.actions.generation.dialog.event.AttributeSourceRelationsItemListener;
1718
import com.magento.idea.magento2plugin.actions.generation.dialog.event.EavAttributeInputItemListener;
1819
import com.magento.idea.magento2plugin.actions.generation.dialog.event.OptionsPanelVisibilityChangeListener;
1920
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
2021
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
22+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.CommaSeparatedStringRule;
2123
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.Lowercase;
2224
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
2325
import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator;
@@ -31,17 +33,20 @@
3133
import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity;
3234
import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper;
3335
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
36+
import com.magento.idea.magento2plugin.util.magento.GetProductTypesListUtil;
3437
import java.awt.event.KeyEvent;
3538
import java.awt.event.WindowAdapter;
3639
import java.awt.event.WindowEvent;
3740
import java.util.Arrays;
3841
import java.util.HashMap;
3942
import java.util.LinkedList;
4043
import java.util.List;
44+
import javax.swing.DefaultListModel;
4145
import javax.swing.JButton;
4246
import javax.swing.JCheckBox;
4347
import javax.swing.JComboBox;
4448
import javax.swing.JComponent;
49+
import javax.swing.JList;
4550
import javax.swing.JPanel;
4651
import javax.swing.JTable;
4752
import javax.swing.JTextField;
@@ -103,6 +108,11 @@ public class NewEavAttributeDialog extends AbstractDialog {
103108
private JTable optionTable;
104109
private JButton addOptionButton;
105110
private JPanel optionsPanel;
111+
@FieldValidation(rule = RuleRegistry.COMMA_SEPARATED_STRING,
112+
message = {CommaSeparatedStringRule.MESSAGE, "Apply To"})
113+
private JCheckBox applyToAllProductsCheckBox;
114+
private JPanel applyToPanel;
115+
private JList productsTypesList;
106116
private final Project project;
107117
private final SourceModelData sourceModelData;
108118
private TableGroupWrapper entityPropertiesTableGroupWrapper;
@@ -126,6 +136,9 @@ public NewEavAttributeDialog(final Project project, final PsiDirectory directory
126136
addActionListenersForButtons();
127137
addCancelActionForWindow();
128138
addCancelActionForEsc();
139+
addApplyToVisibilityAction();
140+
fillEntityComboBoxes();
141+
fillProductsTypesList();
129142
addDependBetweenInputAndSourceModel();
130143
addOptionPanelListener();
131144
setAutocompleteListenerForAttributeCodeField();
@@ -148,6 +161,19 @@ private void initPropertiesTable() {
148161
entityPropertiesTableGroupWrapper.initTableGroup();
149162
}
150163

164+
private void fillProductsTypesList() {
165+
final List<String> productTypes = GetProductTypesListUtil.execute(project);
166+
167+
final DefaultListModel<String> listModel = new DefaultListModel<>();
168+
listModel.addAll(productTypes);
169+
productsTypesList.setModel(listModel);
170+
productsTypesList.setSelectedIndex(0);
171+
}
172+
173+
private void addApplyToVisibilityAction() {
174+
applyToAllProductsCheckBox.addChangeListener(new ApplyToVisibleListener(applyToPanel));
175+
}
176+
151177
@SuppressWarnings("PMD.AccessorMethodGeneration")
152178
private void addDependBetweenInputAndSourceModel() {
153179
inputComboBox.addItemListener(
@@ -368,6 +394,12 @@ private ProductEntityData populateProductEntityData(final ProductEntityData prod
368394
productEntityData.setOptionsSortOrder(GetAttributeOptionPropertiesUtil.getSortOrders(
369395
entityPropertiesTableGroupWrapper.getColumnsData()));
370396

397+
if (!applyToAllProductsCheckBox.isSelected()) {
398+
productEntityData.setApplyTo(
399+
String.join(",", productsTypesList.getSelectedValuesList())
400+
);
401+
}
402+
371403
return productEntityData;
372404
}
373405

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.event;
7+
8+
import javax.swing.JCheckBox;
9+
import javax.swing.JPanel;
10+
import javax.swing.event.ChangeEvent;
11+
import javax.swing.event.ChangeListener;
12+
import org.jetbrains.annotations.NotNull;
13+
14+
public class ApplyToVisibleListener implements ChangeListener {
15+
16+
private final JPanel applyToPanel;
17+
18+
public ApplyToVisibleListener(@NotNull final JPanel applyToPanel) {
19+
this.applyToPanel = applyToPanel;
20+
}
21+
22+
@Override
23+
public void stateChanged(final ChangeEvent changeEvent) {
24+
final JCheckBox checkBox = (JCheckBox) changeEvent.getSource();
25+
26+
if (checkBox.isSelected()) {
27+
applyToPanel.setVisible(false);
28+
} else {
29+
applyToPanel.setVisible(true);
30+
}
31+
}
32+
}

src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphanumericWithUnderscoreRule;
1313
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.BoxNotEmptyRule;
1414
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.CliCommandRule;
15+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.CommaSeparatedStringRule;
1516
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.ConfigPathRule;
1617
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.CronScheduleRule;
1718
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule;
@@ -52,7 +53,8 @@ public enum RuleRegistry {
5253
CLI_COMMAND(CliCommandRule.class),
5354
NUMERIC(NumericRule.class),
5455
TABLE_NAME_LENGTH(TableNameLength.class),
55-
MENU_IDENTIFIER(MenuIdentifierRule.class);
56+
MENU_IDENTIFIER(MenuIdentifierRule.class),
57+
COMMA_SEPARATED_STRING(CommaSeparatedStringRule.class);
5658

5759
private Class<?> rule;
5860

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.validator.rule;
7+
8+
import com.magento.idea.magento2plugin.util.RegExUtil;
9+
10+
public class CommaSeparatedStringRule implements ValidationRule {
11+
public static final String MESSAGE = "validator.commaSeparatedString.isNotValid";
12+
private static final ValidationRule INSTANCE = new CommaSeparatedStringRule();
13+
14+
@Override
15+
public boolean check(final String value) {
16+
return value.isEmpty() || value.matches(RegExUtil.Magento.COMMA_SEPARATED_STRING);
17+
}
18+
19+
public static ValidationRule getInstance() {
20+
return INSTANCE;
21+
}
22+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ private Map<String, String> getMappedAttributes(final ProductEntityData eavEntit
8080
getMappedOptions(eavEntityData.getOptions(), eavEntityData.getOptionsSortOrder()));
8181
}
8282

83+
if (eavEntityData.getApplyTo() != null && !eavEntityData.getApplyTo().isEmpty()) {
84+
mappedAttributes.put(EavAttribute.APPLY_TO.getAttribute(),
85+
wrapStringValueForTemplate(eavEntityData.getApplyTo()));
86+
}
87+
8388
return mappedAttributes;
8489
}
8590

0 commit comments

Comments
 (0)