Skip to content

Commit b30c699

Browse files
authored
Merge pull request #540 from ProkopovVitaliy/539-add-apply-to-property
539 add apply to property
2 parents fb65c63 + 731b667 commit b30c699

File tree

20 files changed

+462
-9
lines changed

20 files changed

+462
-9
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/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: 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="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,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: 35 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;
@@ -26,15 +28,19 @@
2628
import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType;
2729
import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity;
2830
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
31+
import com.magento.idea.magento2plugin.util.magento.GetProductTypesListUtil;
2932
import java.awt.event.ItemEvent;
3033
import java.awt.event.ItemListener;
3134
import java.awt.event.KeyEvent;
3235
import java.awt.event.WindowAdapter;
3336
import java.awt.event.WindowEvent;
37+
import java.util.List;
38+
import javax.swing.DefaultListModel;
3439
import javax.swing.JButton;
3540
import javax.swing.JCheckBox;
3641
import javax.swing.JComboBox;
3742
import javax.swing.JComponent;
43+
import javax.swing.JList;
3844
import javax.swing.JPanel;
3945
import javax.swing.JTextField;
4046
import javax.swing.KeyStroke;
@@ -92,6 +98,12 @@ public class NewEavAttributeDialog extends AbstractDialog {
9298
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
9399
message = {NotEmptyRule.MESSAGE, "Source Model Name"})
94100
private JTextField sourceModelNameTexField;
101+
@FieldValidation(rule = RuleRegistry.COMMA_SEPARATED_STRING,
102+
message = {CommaSeparatedStringRule.MESSAGE, "Apply To"})
103+
private JTextField applyToTextField;
104+
private JCheckBox applyToAllProductsCheckBox;
105+
private JPanel applyToPanel;
106+
private JList productsTypesList;
95107
private final Project project;
96108
private final SourceModelData sourceModelData;
97109

@@ -112,12 +124,27 @@ public NewEavAttributeDialog(final Project project, final PsiDirectory directory
112124
addActionListenersForButtons();
113125
addCancelActionForWindow();
114126
addCancelActionForEsc();
127+
addApplyToVisibilityAction();
115128
setAutocompleteListenerForAttributeCodeField();
116129
fillEntityComboBoxes();
130+
fillProductsTypesList();
117131
addDependBetweenInputAndSourceModel();
118132
setDefaultSources();
119133
}
120134

135+
private void fillProductsTypesList() {
136+
final List<String> productTypes = GetProductTypesListUtil.execute(project);
137+
138+
final DefaultListModel<String> listModel = new DefaultListModel<>();
139+
listModel.addAll(productTypes);
140+
productsTypesList.setModel(listModel);
141+
productsTypesList.setSelectedIndex(0);
142+
}
143+
144+
private void addApplyToVisibilityAction() {
145+
applyToAllProductsCheckBox.addChangeListener(new ApplyToVisibleListener(applyToPanel));
146+
}
147+
121148
@SuppressWarnings("PMD.AccessorMethodGeneration")
122149
private void addDependBetweenInputAndSourceModel() {
123150
inputComboBox.addItemListener(
@@ -295,7 +322,7 @@ private void generateSourceModelFile() {
295322

296323
if (selectedSource == null
297324
|| !selectedSource.getText().equals(
298-
AttributeSourceModel.GENERATE_SOURCE.getSource()
325+
AttributeSourceModel.GENERATE_SOURCE.getSource()
299326
)) {
300327
return;
301328
}
@@ -336,6 +363,12 @@ private ProductEntityData populateProductEntityData(final ProductEntityData prod
336363
productEntityData.setScope(getAttributeScope());
337364
productEntityData.setSource(getAttributeSource());
338365

366+
if (!applyToAllProductsCheckBox.isSelected()) {
367+
productEntityData.setApplyTo(
368+
String.join(",", productsTypesList.getSelectedValuesList())
369+
);
370+
}
371+
339372
return productEntityData;
340373
}
341374

@@ -344,7 +377,7 @@ private String getAttributeSource() {
344377

345378
if (selectedItem == null
346379
|| selectedItem.getText().equals(
347-
AttributeSourceModel.NULLABLE_SOURCE.getSource()
380+
AttributeSourceModel.NULLABLE_SOURCE.getSource()
348381
)) {
349382
return null;
350383
}
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+
}

0 commit comments

Comments
 (0)