Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.MenuIndex" />
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.DeclarativeSchemaElementsIndex" />
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.UIComponentIndex" />
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.ProductTypeIndex" />

<codeInsight.lineMarkerProvider language="PHP" implementationClass="com.magento.idea.magento2plugin.linemarker.php.PluginLineMarkerProvider"/>
<codeInsight.lineMarkerProvider language="PHP" implementationClass="com.magento.idea.magento2plugin.linemarker.php.PluginTargetLineMarkerProvider"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ${CLASS_NAME} implements ${IMPLEMENTS} {
'${ATTRIBUTE_CODE}',
[
#set ($attributeSet = ${ATTRIBUTE_SET})
#foreach ($attribute in $attributeSet.split(","))
#foreach ($attribute in $attributeSet.split("->"))
$attribute,
#end
]
Expand Down
1 change: 1 addition & 0 deletions resources/magento2/validation.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ validator.db.invalidTableNameLength=Table name must contain up to 64 characters
validator.lowerSnakeCase=The {0} field must be of the lower snake case format
validator.menuIdentifierInvalid=The menu identifier is invalid
validator.someFieldsHaveErrors=Please, check the dialog. Some fields have errors
validator.commaSeparatedString.isNotValid=The {0} field must contain comma separated string without whitespaces
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public interface EavEntityDataInterface {
public String getDataPatchName();

public String getEntityClass();

public String getSource();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ProductEntityData implements EavEntityDataInterface {
private String input;
private String source;
private String scope;
private String applyTo;
private boolean required;
private boolean usedInGrid;
private boolean visibleInGrid;
Expand Down Expand Up @@ -73,6 +74,10 @@ public void setScope(final String scope) {
this.scope = scope;
}

public void setApplyTo(final String applyTo) {
this.applyTo = applyTo;
}

public void setRequired(final boolean required) {
this.required = required;
}
Expand Down Expand Up @@ -174,6 +179,7 @@ public String getGroup() {
return group;
}

@Override
public String getSource() {
return source;
}
Expand All @@ -182,6 +188,10 @@ public String getScope() {
return scope;
}

public String getApplyTo() {
return applyTo;
}

public boolean isRequired() {
return required;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<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">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="-1" y="5" width="870" height="659"/>
<xy x="-1" y="5" width="764" height="763"/>
</constraints>
<properties>
<enabled value="true"/>
<preferredSize width="800" height="800"/>
</properties>
<border type="none"/>
<children>
<grid id="6fc7e" layout-manager="GridLayoutManager" row-count="16" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="6fc7e" layout-manager="GridLayoutManager" row-count="17" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<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"/>
Expand Down Expand Up @@ -322,6 +322,53 @@
</component>
</children>
</grid>
<component id="64ef9" class="javax.swing.JCheckBox" binding="applyToAllProductsCheckBox">
<constraints>
<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"/>
</constraints>
<properties>
<selected value="true"/>
<text value="Apply to all products types"/>
</properties>
</component>
<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">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<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"/>
</constraints>
<properties>
<visible value="false"/>
</properties>
<border type="none"/>
<children>
<component id="b41e7" class="javax.swing.JLabel">
<constraints>
<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">
<preferred-size width="144" height="15"/>
</grid>
</constraints>
<properties>
<text value="Apply to"/>
<toolTipText value=""/>
</properties>
</component>
<scrollpane id="f0efd">
<constraints>
<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"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="9e8b9" class="javax.swing.JList" binding="productsTypesList">
<constraints/>
<properties>
<enabled value="true"/>
</properties>
</component>
</children>
</scrollpane>
</children>
</grid>
</children>
</grid>
<hspacer id="75d92">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData;
import com.magento.idea.magento2plugin.actions.generation.data.SourceModelData;
import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData;
import com.magento.idea.magento2plugin.actions.generation.dialog.event.ApplyToVisibleListener;
import com.magento.idea.magento2plugin.actions.generation.dialog.event.EavAttributeInputItemListener;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.CommaSeparatedStringRule;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.Lowercase;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator;
Expand All @@ -26,15 +28,19 @@
import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType;
import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity;
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
import com.magento.idea.magento2plugin.util.magento.GetProductTypesListUtil;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
Expand Down Expand Up @@ -92,6 +98,12 @@ public class NewEavAttributeDialog extends AbstractDialog {
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, "Source Model Name"})
private JTextField sourceModelNameTexField;
@FieldValidation(rule = RuleRegistry.COMMA_SEPARATED_STRING,
message = {CommaSeparatedStringRule.MESSAGE, "Apply To"})
private JTextField applyToTextField;
private JCheckBox applyToAllProductsCheckBox;
private JPanel applyToPanel;
private JList productsTypesList;
private final Project project;
private final SourceModelData sourceModelData;

Expand All @@ -112,12 +124,27 @@ public NewEavAttributeDialog(final Project project, final PsiDirectory directory
addActionListenersForButtons();
addCancelActionForWindow();
addCancelActionForEsc();
addApplyToVisibilityAction();
setAutocompleteListenerForAttributeCodeField();
fillEntityComboBoxes();
fillProductsTypesList();
addDependBetweenInputAndSourceModel();
setDefaultSources();
}

private void fillProductsTypesList() {
final List<String> productTypes = GetProductTypesListUtil.execute(project);

final DefaultListModel<String> listModel = new DefaultListModel<>();
listModel.addAll(productTypes);
productsTypesList.setModel(listModel);
productsTypesList.setSelectedIndex(0);
}

private void addApplyToVisibilityAction() {
applyToAllProductsCheckBox.addChangeListener(new ApplyToVisibleListener(applyToPanel));
}

@SuppressWarnings("PMD.AccessorMethodGeneration")
private void addDependBetweenInputAndSourceModel() {
inputComboBox.addItemListener(
Expand Down Expand Up @@ -295,7 +322,7 @@ private void generateSourceModelFile() {

if (selectedSource == null
|| !selectedSource.getText().equals(
AttributeSourceModel.GENERATE_SOURCE.getSource()
AttributeSourceModel.GENERATE_SOURCE.getSource()
)) {
return;
}
Expand Down Expand Up @@ -336,6 +363,12 @@ private ProductEntityData populateProductEntityData(final ProductEntityData prod
productEntityData.setScope(getAttributeScope());
productEntityData.setSource(getAttributeSource());

if (!applyToAllProductsCheckBox.isSelected()) {
productEntityData.setApplyTo(
String.join(",", productsTypesList.getSelectedValuesList())
);
}

return productEntityData;
}

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

if (selectedItem == null
|| selectedItem.getText().equals(
AttributeSourceModel.NULLABLE_SOURCE.getSource()
AttributeSourceModel.NULLABLE_SOURCE.getSource()
)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation.dialog.event;

import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.jetbrains.annotations.NotNull;

public class ApplyToVisibleListener implements ChangeListener {

private final JPanel applyToPanel;

public ApplyToVisibleListener(@NotNull final JPanel applyToPanel) {
this.applyToPanel = applyToPanel;
}

@Override
public void stateChanged(final ChangeEvent changeEvent) {
final JCheckBox checkBox = (JCheckBox) changeEvent.getSource();

if (checkBox.isSelected()) {
applyToPanel.setVisible(false);
} else {
applyToPanel.setVisible(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphanumericWithUnderscoreRule;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.BoxNotEmptyRule;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.CliCommandRule;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.CommaSeparatedStringRule;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.ConfigPathRule;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.CronScheduleRule;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule;
Expand Down Expand Up @@ -52,7 +53,8 @@ public enum RuleRegistry {
CLI_COMMAND(CliCommandRule.class),
NUMERIC(NumericRule.class),
TABLE_NAME_LENGTH(TableNameLength.class),
MENU_IDENTIFIER(MenuIdentifierRule.class);
MENU_IDENTIFIER(MenuIdentifierRule.class),
COMMA_SEPARATED_STRING(CommaSeparatedStringRule.class);

private Class<?> rule;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule;

import com.magento.idea.magento2plugin.util.RegExUtil;

public class CommaSeparatedStringRule implements ValidationRule {
public static final String MESSAGE = "validator.commaSeparatedString.isNotValid";
private static final ValidationRule INSTANCE = new CommaSeparatedStringRule();

@Override
public boolean check(final String value) {
return value.isEmpty() || value.matches(RegExUtil.Magento.COMMA_SEPARATED_STRING);
}

public static ValidationRule getInstance() {
return INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected void fillAttributes(final Properties attributes) {
.appendProperty("NAMESPACE", this.getFile().getNamespace())
.appendProperty("ENTITY_CLASS", data.getEntityClass())
.appendProperty("ATTRIBUTE_CODE", data.getCode())
.appendProperty("ATTRIBUTE_SET", String.join(",", getAttributesList(data)))
.appendProperty("ATTRIBUTE_SET", String.join("->", getAttributesList(data)))
.append(
"IMPLEMENTS",
DataPatchDependency.DATA_PATCH_INTERFACE.getClassPatch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ private Map<String, String> getMappedAttributes(final ProductEntityData eavEntit
mappedAttributes.put(EavAttribute.VISIBLE_ON_FRONT.getAttribute(),
Boolean.toString(eavEntityData.isVisibleOnFront()));

if (eavEntityData.getApplyTo() != null && !eavEntityData.getApplyTo().isEmpty()) {
mappedAttributes.put(EavAttribute.APPLY_TO.getAttribute(),
wrapStringValueForTemplate(eavEntityData.getApplyTo()));
Comment on lines +75 to +76
Copy link
Contributor

@eduard13 eduard13 Apr 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ProkopovVitaliy, just want to bring your attention, that breaking a multiple arguments to a new line, should move all the arguments to a new empty line, like following.

Suggested change
mappedAttributes.put(EavAttribute.APPLY_TO.getAttribute(),
wrapStringValueForTemplate(eavEntityData.getApplyTo()));
mappedAttributes.put(
EavAttribute.APPLY_TO.getAttribute(),
wrapStringValueForTemplate(eavEntityData.getApplyTo())
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eduard13 Thanks for recommendation, really it's looks better in your variant. I will take this into account.

Thanks!

}

return mappedAttributes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.magento.idea.magento2plugin.stubs.indexes.xml.DeclarativeSchemaElementsIndex;
import com.magento.idea.magento2plugin.stubs.indexes.xml.MenuIndex;
import com.magento.idea.magento2plugin.stubs.indexes.xml.PhpClassNameIndex;
import com.magento.idea.magento2plugin.stubs.indexes.xml.ProductTypeIndex;
import com.magento.idea.magento2plugin.stubs.indexes.xml.UIComponentIndex;

@SuppressWarnings({"PMD.ClassNamingConventions", "PMD.UseUtilityClass"})
Expand Down Expand Up @@ -69,7 +70,9 @@ public static void manualReindex() {
SectionIndex.KEY,
TestNameIndex.KEY,
//graphql
GraphQlResolverIndex.KEY
GraphQlResolverIndex.KEY,
//product types
ProductTypeIndex.KEY
};

for (final ID<?, ?> id: indexIds) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.magento.files;

import com.intellij.lang.Language;
import com.intellij.lang.xml.XMLLanguage;

public class ProductTypeXml implements ModuleFileInterface {
public static final String FILE_NAME = "product_types.xml";
public static final String TEMPLATE = "Magento Product Types";

//attributes
public static final String XML_TAG_TYPE = "type";
public static final String XML_ATTRIBUTE_NAME = "name";

@Override
public String getFileName() {
return FILE_NAME;
}

@Override
public String getTemplate() {
return TEMPLATE;
}

@Override
public Language getLanguage() {
return XMLLanguage.INSTANCE;
}
}
Loading