Skip to content

Commit 4fa88f8

Browse files
Added apply_to property for attribute generation
1 parent 305f66b commit 4fa88f8

File tree

13 files changed

+155
-8
lines changed

13 files changed

+155
-8
lines changed

resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class ${CLASS_NAME} implements ${IMPLEMENTS} {
8282
'${ATTRIBUTE_CODE}',
8383
[
8484
#set ($attributeSet = ${ATTRIBUTE_SET})
85-
#foreach ($attribute in $attributeSet.split(","))
85+
#foreach ($attribute in $attributeSet.split("->"))
8686
$attribute,
8787
#end
8888
]

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
@@ -17,6 +17,7 @@ public class ProductEntityData implements EavEntityDataInterface {
1717
private String input;
1818
private String source;
1919
private String scope;
20+
private String applyTo;
2021
private boolean required;
2122
private boolean usedInGrid;
2223
private boolean visibleInGrid;
@@ -73,6 +74,10 @@ public void setScope(final String scope) {
7374
this.scope = scope;
7475
}
7576

77+
public void setApplyTo(final String applyTo) {
78+
this.applyTo = applyTo;
79+
}
80+
7681
public void setRequired(final boolean required) {
7782
this.required = required;
7883
}
@@ -174,6 +179,7 @@ public String getGroup() {
174179
return group;
175180
}
176181

182+
@Override
177183
public String getSource() {
178184
return source;
179185
}
@@ -182,6 +188,10 @@ public String getScope() {
182188
return scope;
183189
}
184190

191+
public String getApplyTo() {
192+
return applyTo;
193+
}
194+
185195
public boolean isRequired() {
186196
return required;
187197
}

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

Lines changed: 53 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="3" 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="659"/>
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,57 @@
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="2" 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="148" height="15"/>
348+
</grid>
349+
</constraints>
350+
<properties>
351+
<text value="Apply to"/>
352+
<toolTipText value=""/>
353+
</properties>
354+
</component>
355+
<component id="fffe8" class="javax.swing.JTextField" binding="applyToTextField">
356+
<constraints>
357+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
358+
<preferred-size width="150" height="-1"/>
359+
</grid>
360+
</constraints>
361+
<properties/>
362+
</component>
363+
<component id="fbc8d" class="javax.swing.JTextPane" binding="applyToRecommendationTextPanel">
364+
<constraints>
365+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
366+
<preferred-size width="150" height="-1"/>
367+
</grid>
368+
</constraints>
369+
<properties>
370+
<text value="Enter comma separated product types for which attribute will available, for example: simple,configurable,bundle,virtual,downloadable,category. Or leave this property blank if you want apply attribute for all product types."/>
371+
<toolTipText value=""/>
372+
</properties>
373+
</component>
374+
</children>
375+
</grid>
325376
</children>
326377
</grid>
327378
<hspacer id="75d92">

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
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.EavAttributeInputItemListener;
1617
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
1718
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
19+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.CommaSeparatedStringRule;
1820
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.Lowercase;
1921
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
2022
import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator;
@@ -37,6 +39,7 @@
3739
import javax.swing.JComponent;
3840
import javax.swing.JPanel;
3941
import javax.swing.JTextField;
42+
import javax.swing.JTextPane;
4043
import javax.swing.KeyStroke;
4144
import javax.swing.event.DocumentEvent;
4245
import org.codehaus.plexus.util.StringUtils;
@@ -92,6 +95,12 @@ public class NewEavAttributeDialog extends AbstractDialog {
9295
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
9396
message = {NotEmptyRule.MESSAGE, "Source Model Name"})
9497
private JTextField sourceModelNameTexField;
98+
@FieldValidation(rule = RuleRegistry.COMMA_SEPARATED_STRING,
99+
message = {CommaSeparatedStringRule.MESSAGE, "Apply To"})
100+
private JTextField applyToTextField;
101+
private JCheckBox applyToAllProductsCheckBox;
102+
private JPanel applyToPanel;
103+
private JTextPane applyToRecommendationTextPanel;
95104
private final Project project;
96105
private final SourceModelData sourceModelData;
97106

@@ -112,12 +121,17 @@ public NewEavAttributeDialog(final Project project, final PsiDirectory directory
112121
addActionListenersForButtons();
113122
addCancelActionForWindow();
114123
addCancelActionForEsc();
124+
addApplyToVisibilityAction();
115125
setAutocompleteListenerForAttributeCodeField();
116126
fillEntityComboBoxes();
117127
addDependBetweenInputAndSourceModel();
118128
setDefaultSources();
119129
}
120130

131+
private void addApplyToVisibilityAction() {
132+
applyToAllProductsCheckBox.addChangeListener(new ApplyToVisibleListener(applyToPanel));
133+
}
134+
121135
@SuppressWarnings("PMD.AccessorMethodGeneration")
122136
private void addDependBetweenInputAndSourceModel() {
123137
inputComboBox.addItemListener(
@@ -295,7 +309,7 @@ private void generateSourceModelFile() {
295309

296310
if (selectedSource == null
297311
|| !selectedSource.getText().equals(
298-
AttributeSourceModel.GENERATE_SOURCE.getSource()
312+
AttributeSourceModel.GENERATE_SOURCE.getSource()
299313
)) {
300314
return;
301315
}
@@ -336,6 +350,10 @@ private ProductEntityData populateProductEntityData(final ProductEntityData prod
336350
productEntityData.setScope(getAttributeScope());
337351
productEntityData.setSource(getAttributeSource());
338352

353+
if (!applyToAllProductsCheckBox.isSelected()) {
354+
productEntityData.setApplyTo(applyToTextField.getText().trim());
355+
}
356+
339357
return productEntityData;
340358
}
341359

@@ -344,7 +362,7 @@ private String getAttributeSource() {
344362

345363
if (selectedItem == null
346364
|| selectedItem.getText().equals(
347-
AttributeSourceModel.NULLABLE_SOURCE.getSource()
365+
AttributeSourceModel.NULLABLE_SOURCE.getSource()
348366
)) {
349367
return null;
350368
}
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/EavAttributeSetupPatchGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected void fillAttributes(final Properties attributes) {
6363
.appendProperty("NAMESPACE", this.getFile().getNamespace())
6464
.appendProperty("ENTITY_CLASS", data.getEntityClass())
6565
.appendProperty("ATTRIBUTE_CODE", data.getCode())
66-
.appendProperty("ATTRIBUTE_SET", String.join(",", getAttributesList(data)))
66+
.appendProperty("ATTRIBUTE_SET", String.join("->", getAttributesList(data)))
6767
.append(
6868
"IMPLEMENTS",
6969
DataPatchDependency.DATA_PATCH_INTERFACE.getClassPatch()

0 commit comments

Comments
 (0)