From 639c881dcb7361e3fc0d3b24f5420f2ed01def7e Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Tue, 6 Apr 2021 12:19:48 +0300 Subject: [PATCH 001/111] Created Product attribute setup patch generator --- resources/META-INF/plugin.xml | 1 + ...ento Eav Attribute Data Patch Class.php.ft | 91 ++++++ .../generation/NewEavAttributeAction.java | 44 +++ .../data/EavEntityDataInterface.java | 13 + .../generation/data/ProductEntityData.java | 183 +++++++++++ .../dialog/NewEavAttributeDialog.form | 273 ++++++++++++++++ .../dialog/NewEavAttributeDialog.java | 306 ++++++++++++++++++ .../EavAttributeSetupPatchGenerator.java | 196 +++++++++++ .../util/eav/AttributeMapperFactory.java | 14 + .../util/eav/AttributeMapperInterface.java | 10 + .../util/eav/ProductAttributeMapper.java | 59 ++++ .../files/EavAttributeDataPatchPhp.java | 40 +++ .../magento/packages/eav/AttributeInputs.java | 27 ++ .../magento/packages/eav/AttributeScopes.java | 17 + .../packages/eav/AttributeSourceModels.java | 18 ++ .../magento/packages/eav/AttributeTypes.java | 20 ++ .../packages/eav/DataPatchDependency.java | 18 ++ .../magento/packages/eav/EavAttributes.java | 18 ++ .../magento/packages/eav/EavEntities.java | 15 + 19 files changed, 1363 insertions(+) create mode 100644 resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInputs.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScopes.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModels.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeTypes.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttributes.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntities.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 633c25327..4bf1603e6 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -72,6 +72,7 @@ + diff --git a/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft b/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft new file mode 100644 index 000000000..aadf9d90d --- /dev/null +++ b/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft @@ -0,0 +1,91 @@ +moduleDataSetup = $moduleDataSetup; + $this->eavSetupFactory = $eavSetupFactory; + } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } + + /** + * Run code inside patch + * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert + * means run PatchInterface::revert() + * + * If we speak about data, under revert means: $transaction->rollback() + * + * @return $this + */ + public function apply() + { + /** @var ${EAV_SETUP} $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); + + $eavSetup->addAttribute( + ${ENTITY_CLASS}::ENTITY, + '${ATTRIBUTE_CODE}', + [ + #set ($attributeSet = ${ATTRIBUTE_SET}) + #foreach ($attribute in $attributeSet.split(",")) + $attribute, + #end +] + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java new file mode 100644 index 000000000..20bb495c2 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java @@ -0,0 +1,44 @@ +package com.magento.idea.magento2plugin.actions.generation; + +import com.intellij.ide.IdeView; +import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.magento.idea.magento2plugin.MagentoIcons; +import com.magento.idea.magento2plugin.actions.generation.dialog.NewEavAttributeDialog; +import org.jetbrains.annotations.NotNull; + +public class NewEavAttributeAction extends AnAction { + public static final String ACTION_NAME = "Magento 2 EAV Attribute"; + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Attribute"; + + public NewEavAttributeAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); + } + + @Override + public void actionPerformed(@NotNull AnActionEvent e) { + final DataContext dataContext = e.getDataContext(); + final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); + if (view == null) { + return; + } + + final Project project = CommonDataKeys.PROJECT.getData(dataContext); + if (project == null) { + return; + } + + final PsiDirectory directory = view.getOrChooseDirectory(); + if (directory == null) { + return; + } + + NewEavAttributeDialog.open(project, directory); + } + + @Override + public boolean isDumbAware() { + return false; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java b/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java new file mode 100644 index 000000000..1bcb35e64 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java @@ -0,0 +1,13 @@ +package com.magento.idea.magento2plugin.actions.generation.data; + +public interface EavEntityDataInterface { + public String getCode(); + public String getType(); + public String getLabel(); + public String getInput(); + public String getNamespace(); + public String getModuleName(); + public String getDirectory(); + public String getDataPatchName(); + public String getEntityClass(); +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java new file mode 100644 index 000000000..06600b30b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java @@ -0,0 +1,183 @@ +package com.magento.idea.magento2plugin.actions.generation.data; + +import com.magento.idea.magento2plugin.magento.packages.eav.EavEntities; + +public class ProductEntityData implements EavEntityDataInterface { + private String group; + private String code; + private String type; + private String label; + private String input; + private String source; + private String scope; + private boolean isRequired = false; + private boolean isUsedInGrid = false; + private boolean isVisibleInGrid = false; + private boolean isFilterableInGrid = false; + private boolean isVisible = true; + private boolean isHtmlAllowedOnFront = false; + private boolean isVisibleOnFront = false; + private int sortOrder = 0; + + private String dataPatchName; + private String namespace; + private String directory; + private String moduleName; + + public void setGroup(String group) { + this.group = group; + } + + public void setCode(String code) { + this.code = code; + } + + public void setType(String type) { + this.type = type; + } + + public void setLabel(String label) { + this.label = label; + } + + public void setInput(String input) { + this.input = input; + } + + public void setSource(String source) { + this.source = source; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public void setRequired(boolean required) { + isRequired = required; + } + + public void setUsedInGrid(boolean usedInGrid) { + isUsedInGrid = usedInGrid; + } + + public void setVisibleInGrid(boolean visibleInGrid) { + isVisibleInGrid = visibleInGrid; + } + + public void setFilterableInGrid(boolean filterableInGrid) { + isFilterableInGrid = filterableInGrid; + } + + public void setVisible(boolean visible) { + isVisible = visible; + } + + public void setHtmlAllowedOnFront(boolean htmlAllowedOnFront) { + isHtmlAllowedOnFront = htmlAllowedOnFront; + } + + public void setVisibleOnFront(boolean visibleOnFront) { + isVisibleOnFront = visibleOnFront; + } + + public void setSortOrder(int sortOrder) { + this.sortOrder = sortOrder; + } + + public void setDataPatchName(String dataPatchName) { + this.dataPatchName = dataPatchName; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public void setDirectory(String directory) { + this.directory = directory; + } + + public void setModuleName(String moduleName) { + this.moduleName = moduleName; + } + + public String getCode() { + return code; + } + + public String getType() { + return type; + } + + public String getLabel() { + return label; + } + + public String getInput() { + return input; + } + + public String getGroup() { + return group; + } + + public String getNamespace() { + return namespace; + } + + public String getModuleName() { + return moduleName; + } + + public String getDirectory() { + return directory; + } + + public String getDataPatchName() { + return dataPatchName; + } + + public String getSource() { + return source; + } + + public String getScope() { + return scope; + } + + public boolean isRequired() { + return isRequired; + } + + public boolean isUsedInGrid() { + return isUsedInGrid; + } + + public boolean isVisibleInGrid() { + return isVisibleInGrid; + } + + public boolean isFilterableInGrid() { + return isFilterableInGrid; + } + + public boolean isVisible() { + return isVisible; + } + + public boolean isHtmlAllowedOnFront() { + return isHtmlAllowedOnFront; + } + + public boolean isVisibleOnFront() { + return isVisibleOnFront; + } + + public int getSortOrder() { + return sortOrder; + } + + @Override + public String getEntityClass() { + return EavEntities.PRODUCT.getEntityClass(); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form new file mode 100644 index 000000000..56b0a08fb --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form @@ -0,0 +1,273 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java new file mode 100644 index 000000000..727e6ef05 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java @@ -0,0 +1,306 @@ +package com.magento.idea.magento2plugin.actions.generation.dialog; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.intellij.ui.DocumentAdapter; +import com.magento.idea.magento2plugin.actions.generation.NewEavAttributeAction; +import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; +import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData; +import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +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.Lowercase; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; +import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator; +import com.magento.idea.magento2plugin.magento.packages.eav.*; +import com.magento.idea.magento2plugin.magento.packages.File; +import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; +import org.codehaus.plexus.util.StringUtils; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import java.awt.event.*; + +public class NewEavAttributeDialog extends AbstractDialog { + private static Boolean IS_MODAL = true; + private final String moduleName; + private JPanel contentPanel; + private JButton buttonOK; + private JButton buttonCancel; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Code"}) + @FieldValidation(rule = RuleRegistry.LOWERCASE, + message = {Lowercase.MESSAGE, "Attribute Code"}) + private JTextField codeTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Label"}) + private JTextField labelTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Group"}) + private JTextField groupTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Data Patch Name"}) + private JTextField dataPatchNameTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) + @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, + message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) + private JTextField sortOrderTextField; + private JComboBox entityType; + private JComboBox inputComboBox; + private JComboBox typeComboBox; + private JComboBox scopeComboBox; + private JCheckBox isRequiredCheckBox; + private JCheckBox isUsedInGridGridCheckBox; + private JCheckBox isVisibleInGridCheckBox; + private JCheckBox isFilterableInGridCheckBox; + private JCheckBox visibleCheckBox; + private JCheckBox isHtmlAllowedOnCheckBox; + private JCheckBox visibleOnFrontCheckBox; + private final Project project; + private final PsiDirectory directory; + + public NewEavAttributeDialog(Project project, PsiDirectory directory) { + super(); + + this.project = project; + this.directory = directory; + this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); + + setPanelConfiguration(); + addActionListenersForButtons(); + addCancelActionForWindow(); + addCancelActionForEsc(); + setAutocompleteListenerForAttributeCodeField(); + fillEntityTypeComboBox(); + } + + private void setPanelConfiguration() { + setContentPane(contentPanel); + setModal(IS_MODAL); + getRootPane().setDefaultButton(buttonOK); + } + + private void addActionListenersForButtons() { + buttonOK.addActionListener(e -> onOk()); + buttonCancel.addActionListener(e -> onCancel()); + } + + private void addCancelActionForWindow() { + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(final WindowEvent event) { + onCancel(); + } + }); + } + + private void addCancelActionForEsc() { + contentPanel.registerKeyboardAction( + event -> onCancel(), + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT + ); + } + + private void setAutocompleteListenerForAttributeCodeField() { + this.codeTextField.getDocument().addDocumentListener(new DocumentAdapter() { + @Override + protected void textChanged(final @NotNull DocumentEvent event) { + updateDataPatchFileName(); + } + }); + } + + private void fillEntityTypeComboBox() { + for (final EavEntities entity : EavEntities.values()) { + entityType.addItem(new ComboBoxItemData(entity.name(), entity.name())); + } + + for (final AttributeTypes typeValue : AttributeTypes.values()) { + typeComboBox.addItem(new ComboBoxItemData(typeValue.getType(), typeValue.getType())); + } + + for (final AttributeInputs inputValue : AttributeInputs.values()) { + inputComboBox.addItem(new ComboBoxItemData(inputValue.getInput(), inputValue.getInput())); + } + + for (final AttributeScopes globalValue : AttributeScopes.values()) { + scopeComboBox.addItem(new ComboBoxItemData(globalValue.getScope(), globalValue.name())); + } + } + + private void updateDataPatchFileName() { + String attributeCode = this.codeTextField.getText(); + + if (attributeCode.isEmpty()) { + dataPatchNameTextField.setText(""); + + return; + } + + String dataPatchSuffix = "Add"; + String dataPatchPrefix = "Attribute"; + + String[] attributeCodeParts = attributeCode.split("_"); + String fileName = ""; + + for (String fileNamePart : attributeCodeParts) { + fileName += StringUtils.capitalise(fileNamePart); + } + + dataPatchNameTextField.setText(dataPatchSuffix + fileName + dataPatchPrefix); + } + + /** + * Open dialog. + * + * @param project Project + * @param directory PsiDirectory + */ + public static void open(final Project project, final PsiDirectory directory) { + final NewEavAttributeDialog dialog = new NewEavAttributeDialog(project, directory); + dialog.pack(); + dialog.centerDialog(dialog); + dialog.setVisible(IS_MODAL); + } + + private void onOk() { + if (!validateFormFields()) { + return; + } + + generateFile(); + setVisible(false); + } + + private PsiFile generateFile() { + return new EavAttributeSetupPatchGenerator( + getEntityData(), + project + ).generate(NewEavAttributeAction.ACTION_NAME, true); + } + + private EavEntityDataInterface getEntityData() { + EavEntityDataInterface entityData = null; + if (getSelectedEntityType().equals(EavEntities.PRODUCT.name())) { + entityData = populateProductEntityData(new ProductEntityData()); + } + + return entityData; + } + + private ProductEntityData populateProductEntityData(ProductEntityData productEntityData) { + productEntityData.setNamespace(getDataPathNamespace()); + productEntityData.setDirectory(getDataPathDirectory()); + productEntityData.setModuleName(getModuleName()); + + productEntityData.setDataPatchName(getDataPatchName()); + productEntityData.setGroup(getAttributeGroup()); + productEntityData.setCode(getAttributeCode()); + productEntityData.setType(getAttributeType()); + productEntityData.setLabel(getAttributeLabel()); + productEntityData.setInput(getAttributeInput()); + productEntityData.setScope(getAttributeScope()); + productEntityData.setSortOrder(getAttributeSortOrder()); + productEntityData.setRequired(isAttributeRequired()); + productEntityData.setUsedInGrid(isAttributeUsedInGrid()); + productEntityData.setVisibleInGrid(isAttributeVisibleOnGrid()); + productEntityData.setFilterableInGrid(isAttributeFilterableInGrid()); + productEntityData.setVisible(isAttributeVisible()); + productEntityData.setHtmlAllowedOnFront(isAttributeHtmlAllowedOnFront()); + productEntityData.setVisibleOnFront(isAttributeVisibleOnFront()); + + return productEntityData; + } + + private boolean isAttributeVisibleOnFront() { + return visibleOnFrontCheckBox.isSelected(); + } + + private boolean isAttributeHtmlAllowedOnFront() { + return isHtmlAllowedOnCheckBox.isSelected(); + } + + private boolean isAttributeVisible() { + return visibleCheckBox.isSelected(); + } + + private boolean isAttributeFilterableInGrid() { + return isFilterableInGridCheckBox.isSelected(); + } + + private boolean isAttributeVisibleOnGrid() { + return isVisibleInGridCheckBox.isSelected(); + } + + private boolean isAttributeUsedInGrid() { + return isUsedInGridGridCheckBox.isSelected(); + } + + private boolean isAttributeRequired() { + return isRequiredCheckBox.isSelected(); + } + + private int getAttributeSortOrder() { + return Integer.parseInt(sortOrderTextField.getText().trim()); + } + + private String getAttributeScope() { + ComboBoxItemData selectedScope = (ComboBoxItemData) scopeComboBox.getSelectedItem(); + + return selectedScope.getKey().toString().trim(); + } + + private String getAttributeCode() { + return codeTextField.getText().toString().trim(); + } + + private String getSelectedEntityType() { + return entityType.getSelectedItem().toString().trim(); + } + + private String getAttributeLabel() { + return labelTextField.getText().toString().trim(); + } + + private String getAttributeInput() { + return inputComboBox.getSelectedItem().toString().trim(); + } + + private String getAttributeGroup() { + return groupTextField.getText().toString().trim(); + } + + private String getDataPatchName() { + return dataPatchNameTextField.getText().toString().trim(); + } + + private String getDataPathNamespace() { + final String[] parts = moduleName.split(Package.vendorModuleNameSeparator); + if (parts[0] == null || parts[1] == null || parts.length > 2) { + return null; + } + final String directoryPart = getDataPathDirectory().replace( + File.separator, + Package.fqnSeparator + ); + return parts[0] + Package.fqnSeparator + parts[1] + Package.fqnSeparator + directoryPart; + } + + private String getAttributeType() { + return typeComboBox.getSelectedItem().toString().trim(); + } + + private String getDataPathDirectory() { + return "Setup/Patch/Data"; + } + + private String getModuleName() { + return moduleName; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java new file mode 100644 index 000000000..aa3fc84b8 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java @@ -0,0 +1,196 @@ +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.jetbrains.php.lang.psi.PhpFile; +import com.jetbrains.php.lang.psi.elements.PhpClass; +import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; +import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.eav.AttributeMapperFactory; +import com.magento.idea.magento2plugin.actions.generation.generator.util.eav.AttributeMapperInterface; +import com.magento.idea.magento2plugin.bundles.CommonBundle; +import com.magento.idea.magento2plugin.bundles.ValidatorBundle; +import com.magento.idea.magento2plugin.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.EavAttributeDataPatchPhp; +import com.magento.idea.magento2plugin.magento.packages.File; +import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.magento.packages.eav.DataPatchDependency; +import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import com.sun.istack.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.util.*; + +public class EavAttributeSetupPatchGenerator extends FileGenerator { + private final EavEntityDataInterface eavEntityData; + private final Project project; + private final DirectoryGenerator directoryGenerator; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final ValidatorBundle validatorBundle; + private final CommonBundle commonBundle; + + public EavAttributeSetupPatchGenerator( + final @NotNull EavEntityDataInterface eavEntityData, + Project project + ) { + super(project); + + this.eavEntityData = eavEntityData; + this.project = project; + this.directoryGenerator = new DirectoryGenerator(); + this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); + this.validatorBundle = new ValidatorBundle(); + this.commonBundle = new CommonBundle(); + } + + @Override + public PsiFile generate(String actionName) { + final String errorTitle = commonBundle.message("common.error"); + final PhpClass dataPatchClass = GetPhpClassByFQN.getInstance(project) + .execute(getDataPatchFqn()); + + if (validateIfFileAlreadyExist(dataPatchClass, errorTitle)) return null; + + final PhpFile dataPathFile = createDataPathClass(actionName); + + if (validateIfFileCanBeCreated(errorTitle, dataPathFile)) return null; + + return dataPathFile; + } + + private String getDataPatchFqn() { + return eavEntityData.getNamespace() + + Package.fqnSeparator + + eavEntityData.getDataPatchName(); + } + + private boolean validateIfFileAlreadyExist(PhpClass dataPatchClass, String errorTitle) { + if (dataPatchClass != null) { + final String errorMessage = validatorBundle.message( + "validator.file.alreadyExists", + "Data Patch Class" + ); + JOptionPane.showMessageDialog( + null, + errorMessage, + errorTitle, + JOptionPane.ERROR_MESSAGE + ); + + return true; + } + + return false; + } + + @Nullable + private PhpFile createDataPathClass(final String actionName) { + PsiDirectory parentDirectory = getDataPatchDirectory(); + final Properties attributes = getAttributes(); + final PsiFile dataPatchFile = fileFromTemplateGenerator.generate( + EavAttributeDataPatchPhp.getInstance(eavEntityData.getDataPatchName()), + attributes, + parentDirectory, + actionName + ); + + if (dataPatchFile == null) { + return null; + } + + return (PhpFile) dataPatchFile; + } + + private PsiDirectory getDataPatchDirectory() { + PsiDirectory parentDirectory = new ModuleIndex(project) + .getModuleDirectoryByModuleName(eavEntityData.getModuleName()); + final String[] dataPatchDirectories = eavEntityData.getDirectory().split(File.separator); + + for (final String dataPatchDirectory : dataPatchDirectories) { + parentDirectory = directoryGenerator.findOrCreateSubdirectory( + parentDirectory, + dataPatchDirectory + ); + } + + return parentDirectory; + } + + private boolean validateIfFileCanBeCreated(String errorTitle, PhpFile dataPathFile) { + if (dataPathFile == null) { + final String errorMessage = validatorBundle.message( + "validator.file.cantBeCreated", + "Data Patch Class" + ); + JOptionPane.showMessageDialog( + null, + errorMessage, + errorTitle, + JOptionPane.ERROR_MESSAGE + ); + + return true; + } + return false; + } + + @Override + protected void fillAttributes(Properties attributes) { + attributes.setProperty("NAME", eavEntityData.getDataPatchName()); + attributes.setProperty("NAMESPACE", eavEntityData.getNamespace()); + + final String dataPatchInterface = DataPatchDependency.DATA_PATCH_INTERFACE.getClassPatch(); + attributes.setProperty( + "IMPLEMENTS", + PhpClassGeneratorUtil.getNameFromFqn(dataPatchInterface) + ); + + final String eavSetup = DataPatchDependency.ENV_SETUP.getClassPatch(); + final String eavSetupFactory = DataPatchDependency.EAV_SETUP_FACTORY.getClassPatch(); + final String moduleDataSetupInterface = DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch(); + final String entityClass = eavEntityData.getEntityClass(); + + attributes.setProperty( + "MODULE_DATA_SETUP_INTERFACE", + PhpClassGeneratorUtil.getNameFromFqn(moduleDataSetupInterface) + ); + attributes.setProperty( + "EAV_SETUP_FACTORY", + PhpClassGeneratorUtil.getNameFromFqn(eavSetupFactory) + ); + attributes.setProperty( + "EAV_SETUP", + PhpClassGeneratorUtil.getNameFromFqn(eavSetup) + ); + attributes.setProperty( + "ENTITY_CLASS", + entityClass + ); + + final List uses = new ArrayList<>(); + uses.add(dataPatchInterface); + uses.add(eavSetup); + uses.add(eavSetupFactory); + uses.add(moduleDataSetupInterface); + + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + + attributes.setProperty("ATTRIBUTE_CODE", eavEntityData.getCode()); + + List entityAttributes = getAttributesList(eavEntityData); + attributes.setProperty("ATTRIBUTE_SET", String.join(",", entityAttributes)); + + + } + + private List getAttributesList(EavEntityDataInterface eavEntityData) { + AttributeMapperFactory attributeMapperFactory = new AttributeMapperFactory(); + AttributeMapperInterface attributeMapper = attributeMapperFactory.createByEntityClass(eavEntityData.getEntityClass()); + + return attributeMapper.mapAttributesByEntityData(eavEntityData); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java new file mode 100644 index 000000000..0987b59db --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java @@ -0,0 +1,14 @@ +package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; + +import com.magento.idea.magento2plugin.magento.packages.eav.EavEntities; +import com.sun.istack.NotNull; + +public class AttributeMapperFactory { + public AttributeMapperInterface createByEntityClass(@NotNull String entityClass) { + if (entityClass.equals(EavEntities.PRODUCT.getEntityClass())) { + return new ProductAttributeMapper(); + } + + return null; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java new file mode 100644 index 000000000..a21ef972d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java @@ -0,0 +1,10 @@ +package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; + +import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; +import com.sun.istack.NotNull; + +import java.util.List; + +public interface AttributeMapperInterface { + public List mapAttributesByEntityData(@NotNull EavEntityDataInterface entityData); +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java new file mode 100644 index 000000000..712194dfa --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java @@ -0,0 +1,59 @@ +package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; + +import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; +import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData; +import com.magento.idea.magento2plugin.magento.packages.eav.EavAttributes; +import com.sun.istack.NotNull; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ProductAttributeMapper implements AttributeMapperInterface { + @Override + public List mapAttributesByEntityData(@NotNull EavEntityDataInterface entityData) { + ProductEntityData productEntityData = (ProductEntityData) entityData; + + List attributesWithValues = new ArrayList<>(); + + final Map mappedAttributes = getMappedAttributes(productEntityData); + + for (Map.Entry attributePair : mappedAttributes.entrySet()) { + final String attributeKey = "'" + attributePair.getKey() + "'"; + final String attributeValue = attributePair.getValue(); + + attributesWithValues.add( + String.join("=>", attributeKey, attributeValue) + ); + } + + return attributesWithValues; + } + + private Map getMappedAttributes(ProductEntityData eavEntityData) { + Map mappedAttributes = new HashMap<>(); + + mappedAttributes.put(EavAttributes.group.name(), wrapStringValueForTemplate(eavEntityData.getGroup())); + mappedAttributes.put(EavAttributes.type.name(), wrapStringValueForTemplate(eavEntityData.getType())); + mappedAttributes.put(EavAttributes.label.name(), wrapStringValueForTemplate(eavEntityData.getLabel())); + mappedAttributes.put(EavAttributes.input.name(), wrapStringValueForTemplate(eavEntityData.getInput())); + + mappedAttributes.put(EavAttributes.source.name(), wrapStringValueForTemplate(eavEntityData.getSource())); + mappedAttributes.put(EavAttributes.required.name(), Boolean.toString(eavEntityData.isRequired())); + mappedAttributes.put(EavAttributes.sort_order.name(), Integer.toString(eavEntityData.getSortOrder())); + mappedAttributes.put(EavAttributes.global.name(), eavEntityData.getScope()); + mappedAttributes.put(EavAttributes.is_used_in_grid.name(), Boolean.toString(eavEntityData.isUsedInGrid())); + mappedAttributes.put(EavAttributes.is_visible_in_grid.name(), Boolean.toString(eavEntityData.isVisibleInGrid())); + mappedAttributes.put(EavAttributes.is_filterable_in_grid.name(), Boolean.toString(eavEntityData.isFilterableInGrid())); + mappedAttributes.put(EavAttributes.visible.name(), Boolean.toString(eavEntityData.isVisible())); + mappedAttributes.put(EavAttributes.is_html_allowed_on_front.name(), Boolean.toString(eavEntityData.isHtmlAllowedOnFront())); + mappedAttributes.put(EavAttributes.visible_on_front.name(), Boolean.toString(eavEntityData.isVisibleOnFront())); + + return mappedAttributes; + } + + private String wrapStringValueForTemplate(final String value) { + return "'" + value + "'"; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java b/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java new file mode 100644 index 000000000..740535ac7 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java @@ -0,0 +1,40 @@ +package com.magento.idea.magento2plugin.magento.files; + +import com.intellij.lang.Language; +import com.jetbrains.php.lang.PhpLanguage; + +public class EavAttributeDataPatchPhp implements ModuleFileInterface { + public static final String TEMPLATE = "Magento Eav Attribute Data Patch Class"; + public static final String DEFAULT_DIR = "Setup/Patch/Data"; + private static EavAttributeDataPatchPhp INSTANCE = null; + private String fileName; + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public static EavAttributeDataPatchPhp getInstance(final String className) { + if (null == INSTANCE) { + INSTANCE = new EavAttributeDataPatchPhp(); + } + + INSTANCE.setFileName(className.concat(".php")); + + return INSTANCE; + } + + @Override + public String getFileName() { + return fileName; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInputs.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInputs.java new file mode 100644 index 000000000..db197dbdf --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInputs.java @@ -0,0 +1,27 @@ +package com.magento.idea.magento2plugin.magento.packages.eav; + +public enum AttributeInputs { + BOOLEAN("boolean"), + DATE("date"), + GALLERY("gallery"), + HIDDEN("hidden"), + IMAGE("image"), + MEDIA_IMAGE("media_image"), + MULTILINE("multiline"), + MULTISELECT("multiselect"), + PRICE("price"), + SELECT("select"), + TEXT("text"), + TEXTAREA("textarea"), + WEIGHT("weight"); + + private String input; + + AttributeInputs(final String input) { + this.input = input; + } + + public String getInput() { + return this.input; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScopes.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScopes.java new file mode 100644 index 000000000..79739599c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScopes.java @@ -0,0 +1,17 @@ +package com.magento.idea.magento2plugin.magento.packages.eav; + +public enum AttributeScopes { + GLOBAL("\\Magento\\Eav\\Model\\Entity\\Attribute\\ScopedAttributeInterface::SCOPE_GLOBAL"), + STORE("\\Magento\\Eav\\Model\\Entity\\Attribute\\ScopedAttributeInterface::SCOPE_STORE"), + WEBSITE("\\Magento\\Eav\\Model\\Entity\\Attribute\\ScopedAttributeInterface::SCOPE_WEBSITE"); + + private String scope; + + AttributeScopes(final String scope) { + this.scope = scope; + } + + public String getScope() { + return scope; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModels.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModels.java new file mode 100644 index 000000000..48bbcdaba --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModels.java @@ -0,0 +1,18 @@ +package com.magento.idea.magento2plugin.magento.packages.eav; + +public enum AttributeSourceModels { + BOOLEAN("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Boolean"), + TABLE("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table"), + CONFIG("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Config"), + STORE("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Store"); + + private String source; + + AttributeSourceModels(final String source) { + this.source = source; + } + + public String getSource() { + return source; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeTypes.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeTypes.java new file mode 100644 index 000000000..e3b1e95b8 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeTypes.java @@ -0,0 +1,20 @@ +package com.magento.idea.magento2plugin.magento.packages.eav; + +public enum AttributeTypes { + STATIC("static"), + VARCHAR("varchar"), + INT("int"), + TEXT("text"), + DATETIME("datetime"), + DECIMAL("decimal"); + + private String type; + + AttributeTypes(final String type) { + this.type = type; + } + + public String getType() { + return this.type; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java new file mode 100644 index 000000000..df0e393de --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java @@ -0,0 +1,18 @@ +package com.magento.idea.magento2plugin.magento.packages.eav; + +public enum DataPatchDependency { + ENV_SETUP("Magento\\Eav\\Setup\\EavSetup"), + EAV_SETUP_FACTORY("Magento\\Eav\\Setup\\EavSetupFactory"), + MODULE_DATA_SETUP_INTERFACE("Magento\\Framework\\Setup\\ModuleDataSetupInterface"), + DATA_PATCH_INTERFACE("Magento\\Framework\\Setup\\Patch\\DataPatchInterface"); + + private String classPatch; + + DataPatchDependency(String classPatch) { + this.classPatch = classPatch; + } + + public String getClassPatch() { + return classPatch; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttributes.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttributes.java new file mode 100644 index 000000000..ba95ccffa --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttributes.java @@ -0,0 +1,18 @@ +package com.magento.idea.magento2plugin.magento.packages.eav; + +public enum EavAttributes { + group, + type, + label, + input, + source, + required, + sort_order, + global, + is_used_in_grid, + is_visible_in_grid, + is_filterable_in_grid, + visible, + is_html_allowed_on_front, + visible_on_front; +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntities.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntities.java new file mode 100644 index 000000000..5aeefba08 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntities.java @@ -0,0 +1,15 @@ +package com.magento.idea.magento2plugin.magento.packages.eav; + +public enum EavEntities { + PRODUCT("\\Magento\\Catalog\\Model\\Product"); + + private String entityClass; + + EavEntities(String entityClass) { + this.entityClass = entityClass; + } + + public String getEntityClass() { + return entityClass; + } +} From 485ae5558b9290a02d78ef338fc0e20d2dea2ed7 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Tue, 6 Apr 2021 13:52:40 +0300 Subject: [PATCH 002/111] Added default value for source --- .../actions/generation/data/ProductEntityData.java | 2 +- .../generation/generator/util/eav/ProductAttributeMapper.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java index 06600b30b..2601ec032 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java @@ -8,7 +8,7 @@ public class ProductEntityData implements EavEntityDataInterface { private String type; private String label; private String input; - private String source; + private String source = null; private String scope; private boolean isRequired = false; private boolean isUsedInGrid = false; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java index 712194dfa..71a246340 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java @@ -39,7 +39,7 @@ private Map getMappedAttributes(ProductEntityData eavEntityData) mappedAttributes.put(EavAttributes.label.name(), wrapStringValueForTemplate(eavEntityData.getLabel())); mappedAttributes.put(EavAttributes.input.name(), wrapStringValueForTemplate(eavEntityData.getInput())); - mappedAttributes.put(EavAttributes.source.name(), wrapStringValueForTemplate(eavEntityData.getSource())); + mappedAttributes.put(EavAttributes.source.name(), eavEntityData.getSource()); mappedAttributes.put(EavAttributes.required.name(), Boolean.toString(eavEntityData.isRequired())); mappedAttributes.put(EavAttributes.sort_order.name(), Integer.toString(eavEntityData.getSortOrder())); mappedAttributes.put(EavAttributes.global.name(), eavEntityData.getScope()); From 6f8bdacbc321a3cf3805b3e8715e84097e242d59 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Tue, 6 Apr 2021 15:08:59 +0300 Subject: [PATCH 003/111] Refactored code --- .../generation/NewEavAttributeAction.java | 6 ++- .../data/EavEntityDataInterface.java | 8 ++++ .../dialog/NewEavAttributeDialog.java | 42 +++++++++++++---- .../EavAttributeSetupPatchGenerator.java | 30 +++++++++---- .../util/eav/AttributeMapperFactory.java | 5 +++ .../util/eav/AttributeMapperInterface.java | 1 - .../util/eav/ProductAttributeMapper.java | 45 ++++++++++++------- .../files/EavAttributeDataPatchPhp.java | 5 +++ 8 files changed, 106 insertions(+), 36 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java index 20bb495c2..c299c0c10 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java @@ -1,7 +1,11 @@ package com.magento.idea.magento2plugin.actions.generation; import com.intellij.ide.IdeView; -import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; import com.magento.idea.magento2plugin.MagentoIcons; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java b/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java index 1bcb35e64..4e377a25e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java @@ -2,12 +2,20 @@ public interface EavEntityDataInterface { public String getCode(); + public String getType(); + public String getLabel(); + public String getInput(); + public String getNamespace(); + public String getModuleName(); + public String getDirectory(); + public String getDataPatchName(); + public String getEntityClass(); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java index 727e6ef05..bf4f09ba8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java @@ -13,17 +13,27 @@ 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; -import com.magento.idea.magento2plugin.magento.packages.eav.*; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInputs; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScopes; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeTypes; +import com.magento.idea.magento2plugin.magento.packages.eav.EavEntities; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.KeyStroke; +import javax.swing.event.DocumentEvent; import org.codehaus.plexus.util.StringUtils; import org.jetbrains.annotations.NotNull; -import javax.swing.*; -import javax.swing.event.DocumentEvent; -import java.awt.event.*; - public class NewEavAttributeDialog extends AbstractDialog { private static Boolean IS_MODAL = true; private final String moduleName; @@ -63,6 +73,12 @@ public class NewEavAttributeDialog extends AbstractDialog { private final Project project; private final PsiDirectory directory; + /** + * Constructor. + * + * @param project Project + * @param directory PsiDirectory + */ public NewEavAttributeDialog(Project project, PsiDirectory directory) { super(); @@ -118,19 +134,27 @@ protected void textChanged(final @NotNull DocumentEvent event) { private void fillEntityTypeComboBox() { for (final EavEntities entity : EavEntities.values()) { - entityType.addItem(new ComboBoxItemData(entity.name(), entity.name())); + entityType.addItem( + new ComboBoxItemData(entity.name(), entity.name()) + ); } for (final AttributeTypes typeValue : AttributeTypes.values()) { - typeComboBox.addItem(new ComboBoxItemData(typeValue.getType(), typeValue.getType())); + typeComboBox.addItem( + new ComboBoxItemData(typeValue.getType(), typeValue.getType()) + ); } for (final AttributeInputs inputValue : AttributeInputs.values()) { - inputComboBox.addItem(new ComboBoxItemData(inputValue.getInput(), inputValue.getInput())); + inputComboBox.addItem( + new ComboBoxItemData(inputValue.getInput(), inputValue.getInput()) + ); } for (final AttributeScopes globalValue : AttributeScopes.values()) { - scopeComboBox.addItem(new ComboBoxItemData(globalValue.getScope(), globalValue.name())); + scopeComboBox.addItem( + new ComboBoxItemData(globalValue.getScope(), globalValue.name()) + ); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java index aa3fc84b8..a686f939b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java @@ -20,11 +20,12 @@ import com.magento.idea.magento2plugin.magento.packages.eav.DataPatchDependency; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; import com.sun.istack.NotNull; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import javax.swing.JOptionPane; import org.jetbrains.annotations.Nullable; -import javax.swing.*; -import java.util.*; - public class EavAttributeSetupPatchGenerator extends FileGenerator { private final EavEntityDataInterface eavEntityData; private final Project project; @@ -33,6 +34,12 @@ public class EavAttributeSetupPatchGenerator extends FileGenerator { private final ValidatorBundle validatorBundle; private final CommonBundle commonBundle; + /** + * Constructor. + * + * @param eavEntityData EavEntityDataInterface + * @param project Project + */ public EavAttributeSetupPatchGenerator( final @NotNull EavEntityDataInterface eavEntityData, Project project @@ -53,11 +60,15 @@ public PsiFile generate(String actionName) { final PhpClass dataPatchClass = GetPhpClassByFQN.getInstance(project) .execute(getDataPatchFqn()); - if (validateIfFileAlreadyExist(dataPatchClass, errorTitle)) return null; + if (validateIfFileAlreadyExist(dataPatchClass, errorTitle)) { + return null; + } final PhpFile dataPathFile = createDataPathClass(actionName); - if (validateIfFileCanBeCreated(errorTitle, dataPathFile)) return null; + if (validateIfFileCanBeCreated(errorTitle, dataPathFile)) { + return null; + } return dataPathFile; } @@ -151,7 +162,8 @@ protected void fillAttributes(Properties attributes) { final String eavSetup = DataPatchDependency.ENV_SETUP.getClassPatch(); final String eavSetupFactory = DataPatchDependency.EAV_SETUP_FACTORY.getClassPatch(); - final String moduleDataSetupInterface = DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch(); + final String moduleDataSetupInterface = + DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch(); final String entityClass = eavEntityData.getEntityClass(); attributes.setProperty( @@ -183,13 +195,13 @@ protected void fillAttributes(Properties attributes) { List entityAttributes = getAttributesList(eavEntityData); attributes.setProperty("ATTRIBUTE_SET", String.join(",", entityAttributes)); - - } private List getAttributesList(EavEntityDataInterface eavEntityData) { AttributeMapperFactory attributeMapperFactory = new AttributeMapperFactory(); - AttributeMapperInterface attributeMapper = attributeMapperFactory.createByEntityClass(eavEntityData.getEntityClass()); + AttributeMapperInterface attributeMapper = attributeMapperFactory.createByEntityClass( + eavEntityData.getEntityClass() + ); return attributeMapper.mapAttributesByEntityData(eavEntityData); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java index 0987b59db..2016c976a 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java @@ -4,6 +4,11 @@ import com.sun.istack.NotNull; public class AttributeMapperFactory { + /** + * Create entity mapper by entity class + * + * @param entityClass String + */ public AttributeMapperInterface createByEntityClass(@NotNull String entityClass) { if (entityClass.equals(EavEntities.PRODUCT.getEntityClass())) { return new ProductAttributeMapper(); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java index a21ef972d..9f2e9fce1 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java @@ -2,7 +2,6 @@ import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; import com.sun.istack.NotNull; - import java.util.List; public interface AttributeMapperInterface { diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java index 71a246340..b572a3056 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java @@ -4,7 +4,6 @@ import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData; import com.magento.idea.magento2plugin.magento.packages.eav.EavAttributes; import com.sun.istack.NotNull; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -34,21 +33,35 @@ public List mapAttributesByEntityData(@NotNull EavEntityDataInterface en private Map getMappedAttributes(ProductEntityData eavEntityData) { Map mappedAttributes = new HashMap<>(); - mappedAttributes.put(EavAttributes.group.name(), wrapStringValueForTemplate(eavEntityData.getGroup())); - mappedAttributes.put(EavAttributes.type.name(), wrapStringValueForTemplate(eavEntityData.getType())); - mappedAttributes.put(EavAttributes.label.name(), wrapStringValueForTemplate(eavEntityData.getLabel())); - mappedAttributes.put(EavAttributes.input.name(), wrapStringValueForTemplate(eavEntityData.getInput())); - - mappedAttributes.put(EavAttributes.source.name(), eavEntityData.getSource()); - mappedAttributes.put(EavAttributes.required.name(), Boolean.toString(eavEntityData.isRequired())); - mappedAttributes.put(EavAttributes.sort_order.name(), Integer.toString(eavEntityData.getSortOrder())); - mappedAttributes.put(EavAttributes.global.name(), eavEntityData.getScope()); - mappedAttributes.put(EavAttributes.is_used_in_grid.name(), Boolean.toString(eavEntityData.isUsedInGrid())); - mappedAttributes.put(EavAttributes.is_visible_in_grid.name(), Boolean.toString(eavEntityData.isVisibleInGrid())); - mappedAttributes.put(EavAttributes.is_filterable_in_grid.name(), Boolean.toString(eavEntityData.isFilterableInGrid())); - mappedAttributes.put(EavAttributes.visible.name(), Boolean.toString(eavEntityData.isVisible())); - mappedAttributes.put(EavAttributes.is_html_allowed_on_front.name(), Boolean.toString(eavEntityData.isHtmlAllowedOnFront())); - mappedAttributes.put(EavAttributes.visible_on_front.name(), Boolean.toString(eavEntityData.isVisibleOnFront())); + mappedAttributes.put(EavAttributes.group.name(), + wrapStringValueForTemplate(eavEntityData.getGroup())); + mappedAttributes.put(EavAttributes.type.name(), + wrapStringValueForTemplate(eavEntityData.getType())); + mappedAttributes.put(EavAttributes.label.name(), + wrapStringValueForTemplate(eavEntityData.getLabel())); + mappedAttributes.put(EavAttributes.input.name(), + wrapStringValueForTemplate(eavEntityData.getInput())); + + mappedAttributes.put(EavAttributes.source.name(), + eavEntityData.getSource()); + mappedAttributes.put(EavAttributes.required.name(), + Boolean.toString(eavEntityData.isRequired())); + mappedAttributes.put(EavAttributes.sort_order.name(), + Integer.toString(eavEntityData.getSortOrder())); + mappedAttributes.put(EavAttributes.global.name(), + eavEntityData.getScope()); + mappedAttributes.put(EavAttributes.is_used_in_grid.name(), + Boolean.toString(eavEntityData.isUsedInGrid())); + mappedAttributes.put(EavAttributes.is_visible_in_grid.name(), + Boolean.toString(eavEntityData.isVisibleInGrid())); + mappedAttributes.put(EavAttributes.is_filterable_in_grid.name(), + Boolean.toString(eavEntityData.isFilterableInGrid())); + mappedAttributes.put(EavAttributes.visible.name(), + Boolean.toString(eavEntityData.isVisible())); + mappedAttributes.put(EavAttributes.is_html_allowed_on_front.name(), + Boolean.toString(eavEntityData.isHtmlAllowedOnFront())); + mappedAttributes.put(EavAttributes.visible_on_front.name(), + Boolean.toString(eavEntityData.isVisibleOnFront())); return mappedAttributes; } diff --git a/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java b/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java index 740535ac7..287cc7461 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java +++ b/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java @@ -13,6 +13,11 @@ public void setFileName(String fileName) { this.fileName = fileName; } + /** + * Create instance by class name + * + * @param className String + */ public static EavAttributeDataPatchPhp getInstance(final String className) { if (null == INSTANCE) { INSTANCE = new EavAttributeDataPatchPhp(); From cafa5d41e999e4bc079a9338a3faf5baeb9c96eb Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Tue, 6 Apr 2021 15:15:02 +0300 Subject: [PATCH 004/111] Fixed java docs --- .../generation/generator/util/eav/AttributeMapperFactory.java | 2 +- .../magento2plugin/magento/files/EavAttributeDataPatchPhp.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java index 2016c976a..b4b9d7a1e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java @@ -5,7 +5,7 @@ public class AttributeMapperFactory { /** - * Create entity mapper by entity class + * Create entity mapper by entity class. * * @param entityClass String */ diff --git a/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java b/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java index 287cc7461..522d11b69 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java +++ b/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java @@ -14,7 +14,7 @@ public void setFileName(String fileName) { } /** - * Create instance by class name + * Create instance by class name. * * @param className String */ From feff1bf28907736022b28cb9f0f1a532d889a4b8 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Tue, 6 Apr 2021 16:26:11 +0300 Subject: [PATCH 005/111] Refactored code --- .../generation/NewEavAttributeAction.java | 9 +- .../data/EavEntityDataInterface.java | 1 + .../generation/data/ProductEntityData.java | 127 +++++++++++------- .../dialog/NewEavAttributeDialog.form | 10 +- .../dialog/NewEavAttributeDialog.java | 65 ++++----- .../EavAttributeSetupPatchGenerator.java | 25 ++-- .../util/eav/AttributeMapperFactory.java | 7 +- .../util/eav/ProductAttributeMapper.java | 45 ++++--- .../files/EavAttributeDataPatchPhp.java | 18 ++- .../magento/packages/eav/AttributeInputs.java | 5 + .../magento/packages/eav/AttributeScopes.java | 5 + .../packages/eav/AttributeSourceModels.java | 5 + .../magento/packages/eav/AttributeTypes.java | 5 + .../packages/eav/DataPatchDependency.java | 7 +- .../magento/packages/eav/EavAttributes.java | 43 ++++-- .../magento/packages/eav/EavEntities.java | 7 +- 16 files changed, 243 insertions(+), 141 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java index c299c0c10..84766ba40 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.generation; import com.intellij.ide.IdeView; @@ -21,8 +26,8 @@ public NewEavAttributeAction() { } @Override - public void actionPerformed(@NotNull AnActionEvent e) { - final DataContext dataContext = e.getDataContext(); + public void actionPerformed(final @NotNull AnActionEvent event) { + final DataContext dataContext = event.getDataContext(); final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); if (view == null) { return; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java b/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java index 4e377a25e..0957c057c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java @@ -1,5 +1,6 @@ package com.magento.idea.magento2plugin.actions.generation.data; +@SuppressWarnings({"PMD.UnnecessaryModifier"}) public interface EavEntityDataInterface { public String getCode(); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java index 2601ec032..3905d0159 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java @@ -1,141 +1,171 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.generation.data; import com.magento.idea.magento2plugin.magento.packages.eav.EavEntities; +@SuppressWarnings({"PMD.TooManyFields"}) public class ProductEntityData implements EavEntityDataInterface { private String group; private String code; private String type; private String label; private String input; - private String source = null; + private String source; private String scope; - private boolean isRequired = false; - private boolean isUsedInGrid = false; - private boolean isVisibleInGrid = false; - private boolean isFilterableInGrid = false; - private boolean isVisible = true; - private boolean isHtmlAllowedOnFront = false; - private boolean isVisibleOnFront = false; - private int sortOrder = 0; + private boolean required; + private boolean usedInGrid; + private boolean visibleInGrid; + private boolean filterableInGrid; + private boolean visible; + private boolean htmlAllowedOnFront; + private boolean visibleOnFront; + private int sortOrder; private String dataPatchName; private String namespace; private String directory; private String moduleName; - public void setGroup(String group) { + public ProductEntityData() { + this.required = false; + this.usedInGrid = false; + this.visibleInGrid = false; + this.filterableInGrid = false; + this.visible = true; + this.htmlAllowedOnFront = false; + this.visibleOnFront = false; + this.sortOrder = 0; + } + + public void setGroup(final String group) { this.group = group; } - public void setCode(String code) { + public void setCode(final String code) { this.code = code; } - public void setType(String type) { + public void setType(final String type) { this.type = type; } - public void setLabel(String label) { + public void setLabel(final String label) { this.label = label; } - public void setInput(String input) { + public void setInput(final String input) { this.input = input; } - public void setSource(String source) { + public void setSource(final String source) { this.source = source; } - public void setScope(String scope) { + public void setScope(final String scope) { this.scope = scope; } - public void setRequired(boolean required) { - isRequired = required; + public void setRequired(final boolean required) { + this.required = required; } - public void setUsedInGrid(boolean usedInGrid) { - isUsedInGrid = usedInGrid; + public void setUsedInGrid(final boolean usedInGrid) { + this.usedInGrid = usedInGrid; } - public void setVisibleInGrid(boolean visibleInGrid) { - isVisibleInGrid = visibleInGrid; + public void setVisibleInGrid(final boolean visibleInGrid) { + this.visibleInGrid = visibleInGrid; } - public void setFilterableInGrid(boolean filterableInGrid) { - isFilterableInGrid = filterableInGrid; + public void setFilterableInGrid(final boolean filterableInGrid) { + this.filterableInGrid = filterableInGrid; } - public void setVisible(boolean visible) { - isVisible = visible; + public void setVisible(final boolean visible) { + this.visible = visible; } - public void setHtmlAllowedOnFront(boolean htmlAllowedOnFront) { - isHtmlAllowedOnFront = htmlAllowedOnFront; + public void setHtmlAllowedOnFront(final boolean htmlAllowedOnFront) { + this.htmlAllowedOnFront = htmlAllowedOnFront; } - public void setVisibleOnFront(boolean visibleOnFront) { - isVisibleOnFront = visibleOnFront; + public void setVisibleOnFront(final boolean visibleOnFront) { + this.visibleOnFront = visibleOnFront; } - public void setSortOrder(int sortOrder) { + public void setSortOrder(final int sortOrder) { this.sortOrder = sortOrder; } - public void setDataPatchName(String dataPatchName) { + public void setDataPatchName(final String dataPatchName) { this.dataPatchName = dataPatchName; } - public void setNamespace(String namespace) { + public void setNamespace(final String namespace) { this.namespace = namespace; } - public void setDirectory(String directory) { + public void setDirectory(final String directory) { this.directory = directory; } - public void setModuleName(String moduleName) { + public void setModuleName(final String moduleName) { this.moduleName = moduleName; } + @Override public String getCode() { return code; } + @Override public String getType() { return type; } + @Override public String getLabel() { return label; } + @Override public String getInput() { return input; } - public String getGroup() { - return group; - } - + @Override public String getNamespace() { return namespace; } + @Override public String getModuleName() { return moduleName; } + @Override public String getDirectory() { return directory; } + @Override public String getDataPatchName() { return dataPatchName; } + @Override + public String getEntityClass() { + return EavEntities.PRODUCT.getEntityClass(); + } + + public String getGroup() { + return group; + } + public String getSource() { return source; } @@ -145,39 +175,34 @@ public String getScope() { } public boolean isRequired() { - return isRequired; + return required; } public boolean isUsedInGrid() { - return isUsedInGrid; + return usedInGrid; } public boolean isVisibleInGrid() { - return isVisibleInGrid; + return visibleInGrid; } public boolean isFilterableInGrid() { - return isFilterableInGrid; + return filterableInGrid; } public boolean isVisible() { - return isVisible; + return visible; } public boolean isHtmlAllowedOnFront() { - return isHtmlAllowedOnFront; + return htmlAllowedOnFront; } public boolean isVisibleOnFront() { - return isVisibleOnFront; + return visibleOnFront; } public int getSortOrder() { return sortOrder; } - - @Override - public String getEntityClass() { - return EavEntities.PRODUCT.getEntityClass(); - } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form index 56b0a08fb..6216cacee 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form @@ -118,7 +118,7 @@ - + @@ -144,7 +144,7 @@ - + @@ -153,7 +153,7 @@ - + @@ -161,7 +161,7 @@ - + @@ -181,7 +181,7 @@ - + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java index bf4f09ba8..94d5ac4bc 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java @@ -1,8 +1,12 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.generation.dialog; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; import com.intellij.ui.DocumentAdapter; import com.magento.idea.magento2plugin.actions.generation.NewEavAttributeAction; import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; @@ -34,8 +38,9 @@ import org.codehaus.plexus.util.StringUtils; import org.jetbrains.annotations.NotNull; +@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) public class NewEavAttributeDialog extends AbstractDialog { - private static Boolean IS_MODAL = true; + private final static Boolean IS_MODAL = true; private final String moduleName; private JPanel contentPanel; private JButton buttonOK; @@ -63,15 +68,14 @@ public class NewEavAttributeDialog extends AbstractDialog { private JComboBox inputComboBox; private JComboBox typeComboBox; private JComboBox scopeComboBox; - private JCheckBox isRequiredCheckBox; - private JCheckBox isUsedInGridGridCheckBox; - private JCheckBox isVisibleInGridCheckBox; - private JCheckBox isFilterableInGridCheckBox; + private JCheckBox requiredCheckBox; + private JCheckBox usedInGridGridCheckBox; + private JCheckBox visibleInGridCheckBox; + private JCheckBox filterableInGridCheckBox; private JCheckBox visibleCheckBox; - private JCheckBox isHtmlAllowedOnCheckBox; + private JCheckBox htmlAllowedOnCheckBox; private JCheckBox visibleOnFrontCheckBox; private final Project project; - private final PsiDirectory directory; /** * Constructor. @@ -79,11 +83,10 @@ public class NewEavAttributeDialog extends AbstractDialog { * @param project Project * @param directory PsiDirectory */ - public NewEavAttributeDialog(Project project, PsiDirectory directory) { + public NewEavAttributeDialog(final Project project, final PsiDirectory directory) { super(); this.project = project; - this.directory = directory; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); setPanelConfiguration(); @@ -123,6 +126,7 @@ private void addCancelActionForEsc() { ); } + @SuppressWarnings("PMD.AccessorMethodGeneration") private void setAutocompleteListenerForAttributeCodeField() { this.codeTextField.getDocument().addDocumentListener(new DocumentAdapter() { @Override @@ -132,6 +136,7 @@ protected void textChanged(final @NotNull DocumentEvent event) { }); } + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private void fillEntityTypeComboBox() { for (final EavEntities entity : EavEntities.values()) { entityType.addItem( @@ -159,7 +164,7 @@ private void fillEntityTypeComboBox() { } private void updateDataPatchFileName() { - String attributeCode = this.codeTextField.getText(); + final String attributeCode = this.codeTextField.getText(); if (attributeCode.isEmpty()) { dataPatchNameTextField.setText(""); @@ -167,14 +172,14 @@ private void updateDataPatchFileName() { return; } - String dataPatchSuffix = "Add"; - String dataPatchPrefix = "Attribute"; + final String dataPatchSuffix = "Add"; + final String dataPatchPrefix = "Attribute"; - String[] attributeCodeParts = attributeCode.split("_"); + final String[] attributeCodeParts = attributeCode.split("_"); String fileName = ""; - for (String fileNamePart : attributeCodeParts) { - fileName += StringUtils.capitalise(fileNamePart); + for (final String fileNamePart : attributeCodeParts) { + fileName = String.join("", fileName, StringUtils.capitalise(fileNamePart)); } dataPatchNameTextField.setText(dataPatchSuffix + fileName + dataPatchPrefix); @@ -202,8 +207,8 @@ private void onOk() { setVisible(false); } - private PsiFile generateFile() { - return new EavAttributeSetupPatchGenerator( + private void generateFile() { + new EavAttributeSetupPatchGenerator( getEntityData(), project ).generate(NewEavAttributeAction.ACTION_NAME, true); @@ -218,7 +223,7 @@ private EavEntityDataInterface getEntityData() { return entityData; } - private ProductEntityData populateProductEntityData(ProductEntityData productEntityData) { + private ProductEntityData populateProductEntityData(final ProductEntityData productEntityData) { productEntityData.setNamespace(getDataPathNamespace()); productEntityData.setDirectory(getDataPathDirectory()); productEntityData.setModuleName(getModuleName()); @@ -247,7 +252,7 @@ private boolean isAttributeVisibleOnFront() { } private boolean isAttributeHtmlAllowedOnFront() { - return isHtmlAllowedOnCheckBox.isSelected(); + return htmlAllowedOnCheckBox.isSelected(); } private boolean isAttributeVisible() { @@ -255,19 +260,19 @@ private boolean isAttributeVisible() { } private boolean isAttributeFilterableInGrid() { - return isFilterableInGridCheckBox.isSelected(); + return filterableInGridCheckBox.isSelected(); } private boolean isAttributeVisibleOnGrid() { - return isVisibleInGridCheckBox.isSelected(); + return visibleInGridCheckBox.isSelected(); } private boolean isAttributeUsedInGrid() { - return isUsedInGridGridCheckBox.isSelected(); + return usedInGridGridCheckBox.isSelected(); } private boolean isAttributeRequired() { - return isRequiredCheckBox.isSelected(); + return requiredCheckBox.isSelected(); } private int getAttributeSortOrder() { @@ -275,13 +280,13 @@ private int getAttributeSortOrder() { } private String getAttributeScope() { - ComboBoxItemData selectedScope = (ComboBoxItemData) scopeComboBox.getSelectedItem(); + final ComboBoxItemData selectedScope = (ComboBoxItemData) scopeComboBox.getSelectedItem(); - return selectedScope.getKey().toString().trim(); + return selectedScope.getKey().trim(); } private String getAttributeCode() { - return codeTextField.getText().toString().trim(); + return codeTextField.getText().trim(); } private String getSelectedEntityType() { @@ -289,7 +294,7 @@ private String getSelectedEntityType() { } private String getAttributeLabel() { - return labelTextField.getText().toString().trim(); + return labelTextField.getText().trim(); } private String getAttributeInput() { @@ -297,11 +302,11 @@ private String getAttributeInput() { } private String getAttributeGroup() { - return groupTextField.getText().toString().trim(); + return groupTextField.getText().trim(); } private String getDataPatchName() { - return dataPatchNameTextField.getText().toString().trim(); + return dataPatchNameTextField.getText().trim(); } private String getDataPathNamespace() { diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java index a686f939b..8b8cf82b1 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.generation.generator; import com.intellij.openapi.project.Project; @@ -42,7 +47,7 @@ public class EavAttributeSetupPatchGenerator extends FileGenerator { */ public EavAttributeSetupPatchGenerator( final @NotNull EavEntityDataInterface eavEntityData, - Project project + final Project project ) { super(project); @@ -55,7 +60,7 @@ public EavAttributeSetupPatchGenerator( } @Override - public PsiFile generate(String actionName) { + public PsiFile generate(final String actionName) { final String errorTitle = commonBundle.message("common.error"); final PhpClass dataPatchClass = GetPhpClassByFQN.getInstance(project) .execute(getDataPatchFqn()); @@ -79,7 +84,7 @@ private String getDataPatchFqn() { + eavEntityData.getDataPatchName(); } - private boolean validateIfFileAlreadyExist(PhpClass dataPatchClass, String errorTitle) { + private boolean validateIfFileAlreadyExist(final PhpClass dataPatchClass, final String errorTitle) { if (dataPatchClass != null) { final String errorMessage = validatorBundle.message( "validator.file.alreadyExists", @@ -100,7 +105,7 @@ private boolean validateIfFileAlreadyExist(PhpClass dataPatchClass, String error @Nullable private PhpFile createDataPathClass(final String actionName) { - PsiDirectory parentDirectory = getDataPatchDirectory(); + final PsiDirectory parentDirectory = getDataPatchDirectory(); final Properties attributes = getAttributes(); final PsiFile dataPatchFile = fileFromTemplateGenerator.generate( EavAttributeDataPatchPhp.getInstance(eavEntityData.getDataPatchName()), @@ -131,7 +136,7 @@ private PsiDirectory getDataPatchDirectory() { return parentDirectory; } - private boolean validateIfFileCanBeCreated(String errorTitle, PhpFile dataPathFile) { + private boolean validateIfFileCanBeCreated(final String errorTitle, final PhpFile dataPathFile) { if (dataPathFile == null) { final String errorMessage = validatorBundle.message( "validator.file.cantBeCreated", @@ -150,7 +155,7 @@ private boolean validateIfFileCanBeCreated(String errorTitle, PhpFile dataPathFi } @Override - protected void fillAttributes(Properties attributes) { + protected void fillAttributes(final Properties attributes) { attributes.setProperty("NAME", eavEntityData.getDataPatchName()); attributes.setProperty("NAMESPACE", eavEntityData.getNamespace()); @@ -193,13 +198,13 @@ protected void fillAttributes(Properties attributes) { attributes.setProperty("ATTRIBUTE_CODE", eavEntityData.getCode()); - List entityAttributes = getAttributesList(eavEntityData); + final List entityAttributes = getAttributesList(eavEntityData); attributes.setProperty("ATTRIBUTE_SET", String.join(",", entityAttributes)); } - private List getAttributesList(EavEntityDataInterface eavEntityData) { - AttributeMapperFactory attributeMapperFactory = new AttributeMapperFactory(); - AttributeMapperInterface attributeMapper = attributeMapperFactory.createByEntityClass( + private List getAttributesList(final EavEntityDataInterface eavEntityData) { + final AttributeMapperFactory attributeMapperFactory = new AttributeMapperFactory(); + final AttributeMapperInterface attributeMapper = attributeMapperFactory.createByEntityClass( eavEntityData.getEntityClass() ); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java index b4b9d7a1e..07f21ddaf 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; import com.magento.idea.magento2plugin.magento.packages.eav.EavEntities; @@ -9,7 +14,7 @@ public class AttributeMapperFactory { * * @param entityClass String */ - public AttributeMapperInterface createByEntityClass(@NotNull String entityClass) { + public AttributeMapperInterface createByEntityClass(@NotNull final String entityClass) { if (entityClass.equals(EavEntities.PRODUCT.getEntityClass())) { return new ProductAttributeMapper(); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java index b572a3056..b6351b76c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; @@ -11,14 +16,14 @@ public class ProductAttributeMapper implements AttributeMapperInterface { @Override - public List mapAttributesByEntityData(@NotNull EavEntityDataInterface entityData) { - ProductEntityData productEntityData = (ProductEntityData) entityData; + public List mapAttributesByEntityData(@NotNull final EavEntityDataInterface entityData) { + final ProductEntityData productEntityData = (ProductEntityData) entityData; - List attributesWithValues = new ArrayList<>(); + final List attributesWithValues = new ArrayList<>(); final Map mappedAttributes = getMappedAttributes(productEntityData); - for (Map.Entry attributePair : mappedAttributes.entrySet()) { + for (final Map.Entry attributePair : mappedAttributes.entrySet()) { final String attributeKey = "'" + attributePair.getKey() + "'"; final String attributeValue = attributePair.getValue(); @@ -30,37 +35,37 @@ public List mapAttributesByEntityData(@NotNull EavEntityDataInterface en return attributesWithValues; } - private Map getMappedAttributes(ProductEntityData eavEntityData) { - Map mappedAttributes = new HashMap<>(); + private Map getMappedAttributes(final ProductEntityData eavEntityData) { + final Map mappedAttributes = new HashMap<>(); - mappedAttributes.put(EavAttributes.group.name(), + mappedAttributes.put(EavAttributes.GROUP.getAttribute(), wrapStringValueForTemplate(eavEntityData.getGroup())); - mappedAttributes.put(EavAttributes.type.name(), + mappedAttributes.put(EavAttributes.TYPE.getAttribute(), wrapStringValueForTemplate(eavEntityData.getType())); - mappedAttributes.put(EavAttributes.label.name(), + mappedAttributes.put(EavAttributes.LABEL.getAttribute(), wrapStringValueForTemplate(eavEntityData.getLabel())); - mappedAttributes.put(EavAttributes.input.name(), + mappedAttributes.put(EavAttributes.INPUT.getAttribute(), wrapStringValueForTemplate(eavEntityData.getInput())); - mappedAttributes.put(EavAttributes.source.name(), + mappedAttributes.put(EavAttributes.SOURCE.getAttribute(), eavEntityData.getSource()); - mappedAttributes.put(EavAttributes.required.name(), + mappedAttributes.put(EavAttributes.REQUIRED.getAttribute(), Boolean.toString(eavEntityData.isRequired())); - mappedAttributes.put(EavAttributes.sort_order.name(), + mappedAttributes.put(EavAttributes.SORT_ORDER.getAttribute(), Integer.toString(eavEntityData.getSortOrder())); - mappedAttributes.put(EavAttributes.global.name(), + mappedAttributes.put(EavAttributes.GLOBAL.getAttribute(), eavEntityData.getScope()); - mappedAttributes.put(EavAttributes.is_used_in_grid.name(), + mappedAttributes.put(EavAttributes.IS_USED_IN_GRID.getAttribute(), Boolean.toString(eavEntityData.isUsedInGrid())); - mappedAttributes.put(EavAttributes.is_visible_in_grid.name(), + mappedAttributes.put(EavAttributes.IS_VISIBLE_IN_GRID.getAttribute(), Boolean.toString(eavEntityData.isVisibleInGrid())); - mappedAttributes.put(EavAttributes.is_filterable_in_grid.name(), + mappedAttributes.put(EavAttributes.IS_FILTERABLE_IN_GRID.getAttribute(), Boolean.toString(eavEntityData.isFilterableInGrid())); - mappedAttributes.put(EavAttributes.visible.name(), + mappedAttributes.put(EavAttributes.VISIBLE.getAttribute(), Boolean.toString(eavEntityData.isVisible())); - mappedAttributes.put(EavAttributes.is_html_allowed_on_front.name(), + mappedAttributes.put(EavAttributes.IS_HTML_ALLOWED_ON_FRONT.getAttribute(), Boolean.toString(eavEntityData.isHtmlAllowedOnFront())); - mappedAttributes.put(EavAttributes.visible_on_front.name(), + mappedAttributes.put(EavAttributes.VISIBLE_ON_FRONT.getAttribute(), Boolean.toString(eavEntityData.isVisibleOnFront())); return mappedAttributes; diff --git a/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java b/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java index 522d11b69..0caae7703 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java +++ b/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.magento.files; import com.intellij.lang.Language; @@ -6,10 +11,10 @@ public class EavAttributeDataPatchPhp implements ModuleFileInterface { public static final String TEMPLATE = "Magento Eav Attribute Data Patch Class"; public static final String DEFAULT_DIR = "Setup/Patch/Data"; - private static EavAttributeDataPatchPhp INSTANCE = null; + private static EavAttributeDataPatchPhp instance; private String fileName; - public void setFileName(String fileName) { + public void setFileName(final String fileName) { this.fileName = fileName; } @@ -17,15 +22,16 @@ public void setFileName(String fileName) { * Create instance by class name. * * @param className String + * @return EavAttributeDataPatchPhp */ public static EavAttributeDataPatchPhp getInstance(final String className) { - if (null == INSTANCE) { - INSTANCE = new EavAttributeDataPatchPhp(); + if (null == instance) { + instance = new EavAttributeDataPatchPhp(); } - INSTANCE.setFileName(className.concat(".php")); + instance.setFileName(className.concat(".php")); - return INSTANCE; + return instance; } @Override diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInputs.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInputs.java index db197dbdf..56ae2b7d3 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInputs.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInputs.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.magento.packages.eav; public enum AttributeInputs { diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScopes.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScopes.java index 79739599c..17ec922b2 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScopes.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScopes.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.magento.packages.eav; public enum AttributeScopes { diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModels.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModels.java index 48bbcdaba..ddc9c470b 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModels.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModels.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.magento.packages.eav; public enum AttributeSourceModels { diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeTypes.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeTypes.java index e3b1e95b8..370476301 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeTypes.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeTypes.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.magento.packages.eav; public enum AttributeTypes { diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java index df0e393de..73f2bf0fa 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.magento.packages.eav; public enum DataPatchDependency { @@ -8,7 +13,7 @@ public enum DataPatchDependency { private String classPatch; - DataPatchDependency(String classPatch) { + DataPatchDependency(final String classPatch) { this.classPatch = classPatch; } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttributes.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttributes.java index ba95ccffa..7eb684d36 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttributes.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttributes.java @@ -1,18 +1,33 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.magento.packages.eav; public enum EavAttributes { - group, - type, - label, - input, - source, - required, - sort_order, - global, - is_used_in_grid, - is_visible_in_grid, - is_filterable_in_grid, - visible, - is_html_allowed_on_front, - visible_on_front; + GROUP("group"), + TYPE("type"), + LABEL("label"), + INPUT("input"), + SOURCE("source"), + REQUIRED("required"), + SORT_ORDER("sort_order"), + GLOBAL("global"), + IS_USED_IN_GRID("is_used_in_grid"), + IS_VISIBLE_IN_GRID("is_visible_in_grid"), + IS_FILTERABLE_IN_GRID("is_filterable_in_grid"), + VISIBLE("visible"), + IS_HTML_ALLOWED_ON_FRONT("is_html_allowed_on_front"), + VISIBLE_ON_FRONT("visible_on_front"); + + private String attribute; + + EavAttributes(final String attribute) { + this.attribute = attribute; + } + + public String getAttribute() { + return attribute; + } } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntities.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntities.java index 5aeefba08..e0d819549 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntities.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntities.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.magento.packages.eav; public enum EavEntities { @@ -5,7 +10,7 @@ public enum EavEntities { private String entityClass; - EavEntities(String entityClass) { + EavEntities(final String entityClass) { this.entityClass = entityClass; } From fee3d2297bb7b5c7d7ed03b0404a2fccdd7ac8c2 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Tue, 6 Apr 2021 16:33:19 +0300 Subject: [PATCH 006/111] Fixed static tests --- .../actions/generation/data/ProductEntityData.java | 3 +++ .../generation/dialog/NewEavAttributeDialog.java | 5 ++--- .../generator/EavAttributeSetupPatchGenerator.java | 12 +++++++++--- .../generator/util/eav/ProductAttributeMapper.java | 4 +++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java index 3905d0159..3ca28752c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java @@ -30,6 +30,9 @@ public class ProductEntityData implements EavEntityDataInterface { private String directory; private String moduleName; + /** + * Constructor. + */ public ProductEntityData() { this.required = false; this.usedInGrid = false; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java index 94d5ac4bc..d35faa112 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java @@ -40,7 +40,6 @@ @SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) public class NewEavAttributeDialog extends AbstractDialog { - private final static Boolean IS_MODAL = true; private final String moduleName; private JPanel contentPanel; private JButton buttonOK; @@ -99,7 +98,7 @@ public NewEavAttributeDialog(final Project project, final PsiDirectory directory private void setPanelConfiguration() { setContentPane(contentPanel); - setModal(IS_MODAL); + setModal(true); getRootPane().setDefaultButton(buttonOK); } @@ -195,7 +194,7 @@ public static void open(final Project project, final PsiDirectory directory) { final NewEavAttributeDialog dialog = new NewEavAttributeDialog(project, directory); dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(IS_MODAL); + dialog.setVisible(true); } private void onOk() { diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java index 8b8cf82b1..dd8d91236 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java @@ -43,7 +43,7 @@ public class EavAttributeSetupPatchGenerator extends FileGenerator { * Constructor. * * @param eavEntityData EavEntityDataInterface - * @param project Project + * @param project Project */ public EavAttributeSetupPatchGenerator( final @NotNull EavEntityDataInterface eavEntityData, @@ -84,7 +84,10 @@ private String getDataPatchFqn() { + eavEntityData.getDataPatchName(); } - private boolean validateIfFileAlreadyExist(final PhpClass dataPatchClass, final String errorTitle) { + private boolean validateIfFileAlreadyExist( + final PhpClass dataPatchClass, + final String errorTitle + ) { if (dataPatchClass != null) { final String errorMessage = validatorBundle.message( "validator.file.alreadyExists", @@ -136,7 +139,10 @@ private PsiDirectory getDataPatchDirectory() { return parentDirectory; } - private boolean validateIfFileCanBeCreated(final String errorTitle, final PhpFile dataPathFile) { + private boolean validateIfFileCanBeCreated( + final String errorTitle, + final PhpFile dataPathFile + ) { if (dataPathFile == null) { final String errorMessage = validatorBundle.message( "validator.file.cantBeCreated", diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java index b6351b76c..202532afd 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java @@ -16,7 +16,9 @@ public class ProductAttributeMapper implements AttributeMapperInterface { @Override - public List mapAttributesByEntityData(@NotNull final EavEntityDataInterface entityData) { + public List mapAttributesByEntityData( + @NotNull final EavEntityDataInterface entityData + ) { final ProductEntityData productEntityData = (ProductEntityData) entityData; final List attributesWithValues = new ArrayList<>(); From d7d52d0e6867d1637a402e4460b973994d343587 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Tue, 6 Apr 2021 16:40:40 +0300 Subject: [PATCH 007/111] Removed Unnecessary modifier --- .../generation/generator/util/eav/AttributeMapperInterface.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java index 9f2e9fce1..9157acdbb 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java @@ -5,5 +5,5 @@ import java.util.List; public interface AttributeMapperInterface { - public List mapAttributesByEntityData(@NotNull EavEntityDataInterface entityData); + List mapAttributesByEntityData(@NotNull EavEntityDataInterface entityData); } From 05ee9b0c6b7b115f37bd54beebf92b69f500ad2e Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Tue, 6 Apr 2021 17:50:49 +0300 Subject: [PATCH 008/111] Removed singleton --- .../EavAttributeSetupPatchGenerator.java | 2 +- .../files/EavAttributeDataPatchPhp.java | 20 ++++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java index dd8d91236..94b6e7585 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java @@ -111,7 +111,7 @@ private PhpFile createDataPathClass(final String actionName) { final PsiDirectory parentDirectory = getDataPatchDirectory(); final Properties attributes = getAttributes(); final PsiFile dataPatchFile = fileFromTemplateGenerator.generate( - EavAttributeDataPatchPhp.getInstance(eavEntityData.getDataPatchName()), + new EavAttributeDataPatchPhp(eavEntityData.getDataPatchName()), attributes, parentDirectory, actionName diff --git a/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java b/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java index 0caae7703..f5afd761e 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java +++ b/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java @@ -11,27 +11,19 @@ public class EavAttributeDataPatchPhp implements ModuleFileInterface { public static final String TEMPLATE = "Magento Eav Attribute Data Patch Class"; public static final String DEFAULT_DIR = "Setup/Patch/Data"; - private static EavAttributeDataPatchPhp instance; private String fileName; - public void setFileName(final String fileName) { - this.fileName = fileName; - } - /** - * Create instance by class name. + * Constructor. * * @param className String - * @return EavAttributeDataPatchPhp */ - public static EavAttributeDataPatchPhp getInstance(final String className) { - if (null == instance) { - instance = new EavAttributeDataPatchPhp(); - } - - instance.setFileName(className.concat(".php")); + public EavAttributeDataPatchPhp(final String className) { + fileName = className.concat(".php"); + } - return instance; + public void setFileName(final String fileName) { + this.fileName = fileName; } @Override From e571e6cbd93ed7e698e4bbf8f37766861d6b82cd Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Wed, 7 Apr 2021 13:22:56 +0300 Subject: [PATCH 009/111] Refactored models --- .../generation/data/ProductEntityData.java | 22 +++++++++++++++++++ .../dialog/NewEavAttributeDialog.java | 20 ----------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java index 3ca28752c..8a49ecbc5 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java @@ -5,6 +5,8 @@ package com.magento.idea.magento2plugin.actions.generation.data; +import com.magento.idea.magento2plugin.magento.packages.File; +import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.magento.packages.eav.EavEntities; @SuppressWarnings({"PMD.TooManyFields"}) @@ -142,9 +144,25 @@ public String getInput() { @Override public String getNamespace() { + if (namespace == null) { + namespace = getDataPathNamespace(); + } + return namespace; } + private String getDataPathNamespace() { + final String[] parts = moduleName.split(Package.vendorModuleNameSeparator); + if (parts[0] == null || parts[1] == null || parts.length > 2) { + return null; + } + final String directoryPart = getDirectory().replace( + File.separator, + Package.fqnSeparator + ); + return parts[0] + Package.fqnSeparator + parts[1] + Package.fqnSeparator + directoryPart; + } + @Override public String getModuleName() { return moduleName; @@ -152,6 +170,10 @@ public String getModuleName() { @Override public String getDirectory() { + if (directory == null) { + directory = "Setup/Patch/Data"; + } + return directory; } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java index d35faa112..52e8fc981 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java @@ -17,8 +17,6 @@ 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; -import com.magento.idea.magento2plugin.magento.packages.File; -import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInputs; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScopes; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeTypes; @@ -223,8 +221,6 @@ private EavEntityDataInterface getEntityData() { } private ProductEntityData populateProductEntityData(final ProductEntityData productEntityData) { - productEntityData.setNamespace(getDataPathNamespace()); - productEntityData.setDirectory(getDataPathDirectory()); productEntityData.setModuleName(getModuleName()); productEntityData.setDataPatchName(getDataPatchName()); @@ -308,26 +304,10 @@ private String getDataPatchName() { return dataPatchNameTextField.getText().trim(); } - private String getDataPathNamespace() { - final String[] parts = moduleName.split(Package.vendorModuleNameSeparator); - if (parts[0] == null || parts[1] == null || parts.length > 2) { - return null; - } - final String directoryPart = getDataPathDirectory().replace( - File.separator, - Package.fqnSeparator - ); - return parts[0] + Package.fqnSeparator + parts[1] + Package.fqnSeparator + directoryPart; - } - private String getAttributeType() { return typeComboBox.getSelectedItem().toString().trim(); } - private String getDataPathDirectory() { - return "Setup/Patch/Data"; - } - private String getModuleName() { return moduleName; } From 800e1c9609c1c584c1d736be09ca29f20d6fc55c Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Wed, 7 Apr 2021 13:24:46 +0300 Subject: [PATCH 010/111] Created test for generator --- .../generateFile/AddTestAttribute.php | 100 ++++++++++++++++++ .../EavAttributeSetupPatchGeneratorTest.java | 49 +++++++++ 2 files changed, 149 insertions(+) create mode 100644 testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFile/AddTestAttribute.php create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java diff --git a/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFile/AddTestAttribute.php b/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFile/AddTestAttribute.php new file mode 100644 index 000000000..59fec32c7 --- /dev/null +++ b/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFile/AddTestAttribute.php @@ -0,0 +1,100 @@ +moduleDataSetup = $moduleDataSetup; + $this->eavSetupFactory = $eavSetupFactory; + } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } + + /** + * Run code inside patch + * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert + * means run PatchInterface::revert() + * + * If we speak about data, under revert means: $transaction->rollback() + * + * @return $this + */ + public function apply() + { + /** @var EavSetup $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); + + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'test', + [ + 'is_visible_in_grid' => false, + 'is_html_allowed_on_front' => false, + 'visible_on_front' => false, + 'visible' => true, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, + 'label' => 'Test Label', + 'source' => null, + 'type' => 'static', + 'is_used_in_grid' => false, + 'required' => false, + 'input' => 'boolean', + 'is_filterable_in_grid' => false, + 'sort_order' => 10, + 'group' => 'General', + ] + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java new file mode 100644 index 000000000..ee30c4209 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java @@ -0,0 +1,49 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScopes; + +public class EavAttributeSetupPatchGeneratorTest extends BaseGeneratorTestCase { + + /** + * Test Data patch for product's eav attribute generator. + */ + public void testGenerateFile() { + final Project project = myFixture.getProject(); + + final ProductEntityData productEntityData = new ProductEntityData(); + productEntityData.setCode("test"); + productEntityData.setVisibleInGrid(false); + productEntityData.setHtmlAllowedOnFront(false); + productEntityData.setVisibleOnFront(false); + productEntityData.setVisible(true); + productEntityData.setScope(AttributeScopes.GLOBAL.getScope()); + productEntityData.setLabel("Test Label"); + productEntityData.setType("static"); + productEntityData.setUsedInGrid(false); + productEntityData.setRequired(false); + productEntityData.setInput("boolean"); + productEntityData.setFilterableInGrid(false); + productEntityData.setSortOrder(10); + productEntityData.setGroup("General"); + + productEntityData.setDataPatchName("AddTestAttribute"); + productEntityData.setNamespace("Foo\\Bar\\Setup\\Patch\\Data"); + productEntityData.setModuleName("Foo_Bar"); + + final EavAttributeSetupPatchGenerator setupPatchGenerator = + new EavAttributeSetupPatchGenerator(productEntityData, project); + final PsiFile dataPatchFile = setupPatchGenerator.generate("test"); + + final String filePatch = this.getFixturePath("AddTestAttribute.php"); + final PsiFile expectedFile = myFixture.configureByFile(filePatch); + + assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile); + } +} From 9515d132ef8ce1365af48770e99573c91ae53e7f Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Fri, 9 Apr 2021 15:24:35 +0300 Subject: [PATCH 011/111] Added source model generation for EAV attribute input --- .../Magento Source Model Class.php.ft | 22 ++ .../generation/data/ProductEntityData.java | 4 +- .../generation/data/SourceModelData.java | 82 ++++++ .../dialog/NewEavAttributeDialog.form | 159 +++++++++-- .../dialog/NewEavAttributeDialog.java | 251 +++++++++++------- .../event/EavAttributeInputItemListener.java | 42 +++ .../generator/SourceModelGenerator.java | 164 ++++++++++++ .../util/eav/AttributeMapperFactory.java | 4 +- .../util/eav/ProductAttributeMapper.java | 37 +-- .../magento/files/SourceModelPhp.java | 38 +++ ...tributeInputs.java => AttributeInput.java} | 14 +- ...tributeScopes.java => AttributeScope.java} | 4 +- ...eModels.java => AttributeSourceModel.java} | 8 +- ...AttributeTypes.java => AttributeType.java} | 4 +- .../{EavAttributes.java => EavAttribute.java} | 4 +- .../eav/{EavEntities.java => EavEntity.java} | 4 +- .../uicomponent/AvailableSourcesByInput.java | 52 ++++ .../generateFile/AddTestAttribute.php | 2 +- .../AddBooleanInputAttributeAttribute.php | 100 +++++++ .../AddAttributeWithCustomSourceAttribute.php | 100 +++++++ .../generateFile/CustomSourceModel.php | 18 ++ .../EavAttributeSetupPatchGeneratorTest.java | 83 +++++- .../generator/SourceModelGeneratorTest.java | 34 +++ 23 files changed, 1065 insertions(+), 165 deletions(-) create mode 100644 resources/fileTemplates/internal/Magento Source Model Class.php.ft create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/EavAttributeInputItemListener.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/SourceModelPhp.java rename src/com/magento/idea/magento2plugin/magento/packages/eav/{AttributeInputs.java => AttributeInput.java} (89%) rename src/com/magento/idea/magento2plugin/magento/packages/eav/{AttributeScopes.java => AttributeScope.java} (88%) rename src/com/magento/idea/magento2plugin/magento/packages/eav/{AttributeSourceModels.java => AttributeSourceModel.java} (76%) rename src/com/magento/idea/magento2plugin/magento/packages/eav/{AttributeTypes.java => AttributeType.java} (85%) rename src/com/magento/idea/magento2plugin/magento/packages/eav/{EavAttributes.java => EavAttribute.java} (91%) rename src/com/magento/idea/magento2plugin/magento/packages/eav/{EavEntities.java => EavEntity.java} (83%) create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java create mode 100644 testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php create mode 100644 testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php create mode 100644 testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java diff --git a/resources/fileTemplates/internal/Magento Source Model Class.php.ft b/resources/fileTemplates/internal/Magento Source Model Class.php.ft new file mode 100644 index 000000000..9ea1e890a --- /dev/null +++ b/resources/fileTemplates/internal/Magento Source Model Class.php.ft @@ -0,0 +1,22 @@ + 2) { + return null; + } + final String directoryPart = getDirectory().replace( + File.separator, + Package.fqnSeparator + ); + return parts[0] + Package.fqnSeparator + parts[1] + Package.fqnSeparator + directoryPart; + } + + /** + * Get default namespace. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get directory path. + * + * @return String + */ + public String getDirectory() { + if (this.directory == null) { + return SourceModelPhp.DEFAULT_DIR; + } + + return this.directory; + } + + public void setClassName(final String className) { + this.className = className; + } + + public void setNamespace(final String namespace) { + this.namespace = namespace; + } + + public void setModuleName(final String moduleName) { + this.moduleName = moduleName; + } + + public void setDirectory(final String directory) { + this.directory = directory; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form index 6216cacee..3f1a813da 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form @@ -1,26 +1,31 @@
- + - + + - + - + - + + + - + + + @@ -28,13 +33,15 @@ - + - + + + @@ -42,7 +49,7 @@ - + @@ -50,7 +57,9 @@ - + + + @@ -58,7 +67,9 @@ - + + + @@ -66,7 +77,7 @@ - + @@ -74,7 +85,7 @@ - + @@ -82,7 +93,9 @@ - + + + @@ -90,7 +103,9 @@ - + + + @@ -98,7 +113,7 @@ - + @@ -106,7 +121,9 @@ - + + + @@ -114,7 +131,7 @@ - + @@ -128,7 +145,9 @@ - + + + @@ -136,7 +155,7 @@ - + @@ -155,7 +174,7 @@ - + @@ -173,7 +192,7 @@ - + @@ -183,7 +202,7 @@ - + @@ -201,35 +220,119 @@ - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java index 52e8fc981..a8e58a0d0 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java @@ -9,19 +9,21 @@ import com.intellij.psi.PsiDirectory; import com.intellij.ui.DocumentAdapter; import com.magento.idea.magento2plugin.actions.generation.NewEavAttributeAction; -import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; 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.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.Lowercase; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInputs; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScopes; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeTypes; -import com.magento.idea.magento2plugin.magento.packages.eav.EavEntities; +import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator; +import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.magento.packages.eav.*; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; +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; @@ -36,7 +38,7 @@ import org.codehaus.plexus.util.StringUtils; import org.jetbrains.annotations.NotNull; -@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) +@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports", "PMD.TooManyMethods", "PMD.UnusedPrivateField"}) public class NewEavAttributeDialog extends AbstractDialog { private final String moduleName; private JPanel contentPanel; @@ -65,6 +67,7 @@ public class NewEavAttributeDialog extends AbstractDialog { private JComboBox inputComboBox; private JComboBox typeComboBox; private JComboBox scopeComboBox; + private JComboBox sourceComboBox; private JCheckBox requiredCheckBox; private JCheckBox usedInGridGridCheckBox; private JCheckBox visibleInGridCheckBox; @@ -72,12 +75,21 @@ public class NewEavAttributeDialog extends AbstractDialog { private JCheckBox visibleCheckBox; private JCheckBox htmlAllowedOnCheckBox; private JCheckBox visibleOnFrontCheckBox; + private JPanel sourcePanel; + private JPanel customSourceModelPanel; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Source Model Directory"}) + private JTextField sourceModelDirectoryTexField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Source Model Name"}) + private JTextField sourceModelNameTexField; private final Project project; + private final SourceModelData sourceModelData; /** * Constructor. * - * @param project Project + * @param project Project * @param directory PsiDirectory */ public NewEavAttributeDialog(final Project project, final PsiDirectory directory) { @@ -85,13 +97,58 @@ public NewEavAttributeDialog(final Project project, final PsiDirectory directory this.project = project; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); + this.sourceModelData = new SourceModelData(); setPanelConfiguration(); addActionListenersForButtons(); addCancelActionForWindow(); addCancelActionForEsc(); setAutocompleteListenerForAttributeCodeField(); - fillEntityTypeComboBox(); + fillEntityComboBoxes(); + addDependBetweenInputAndSourceModel(); + setDefaultSources(); + } + + @SuppressWarnings("PMD.AccessorMethodGeneration") + private void addDependBetweenInputAndSourceModel() { + inputComboBox.addItemListener( + new EavAttributeInputItemListener(sourceComboBox) + ); + + sourceComboBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(final ItemEvent itemEvent) { + final String selectedSource = itemEvent.getItem().toString(); + + if (selectedSource.equals(AttributeSourceModel.GENERATE_SOURCE.getSource())) { + customSourceModelPanel.setVisible(true); + sourceModelData.setModuleName(moduleName); + + if (sourceModelDirectoryTexField.getText().trim().isEmpty()) { + sourceModelDirectoryTexField.setText(sourceModelData.getDirectory()); + } + } else { + customSourceModelPanel.setVisible(false); + } + } + }); + + sourceModelDirectoryTexField.setText(sourceModelData.getDirectory()); + } + + private void setDefaultSources() { + final ComboBoxItemData generateSourceItem = new ComboBoxItemData( + AttributeSourceModel.GENERATE_SOURCE.getSource(), + AttributeSourceModel.GENERATE_SOURCE.getSource() + ); + final ComboBoxItemData defaultSourceItem = new ComboBoxItemData( + AttributeSourceModel.NULLABLE_SOURCE.name(), + AttributeSourceModel.NULLABLE_SOURCE.getSource() + ); + sourceComboBox.addItem(defaultSourceItem); + sourceComboBox.addItem(generateSourceItem); + + sourceComboBox.setSelectedItem(defaultSourceItem); } private void setPanelConfiguration() { @@ -128,41 +185,41 @@ private void setAutocompleteListenerForAttributeCodeField() { this.codeTextField.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(final @NotNull DocumentEvent event) { - updateDataPatchFileName(); + final String attributeCode = codeTextField.getText(); + updateDataPatchFileName(attributeCode); + updateSourceModelName(attributeCode); } }); } @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") - private void fillEntityTypeComboBox() { - for (final EavEntities entity : EavEntities.values()) { + private void fillEntityComboBoxes() { + for (final EavEntity entity : EavEntity.values()) { entityType.addItem( new ComboBoxItemData(entity.name(), entity.name()) ); } - for (final AttributeTypes typeValue : AttributeTypes.values()) { + for (final AttributeType typeValue : AttributeType.values()) { typeComboBox.addItem( new ComboBoxItemData(typeValue.getType(), typeValue.getType()) ); } - for (final AttributeInputs inputValue : AttributeInputs.values()) { + for (final AttributeInput inputValue : AttributeInput.values()) { inputComboBox.addItem( new ComboBoxItemData(inputValue.getInput(), inputValue.getInput()) ); } - for (final AttributeScopes globalValue : AttributeScopes.values()) { + for (final AttributeScope globalValue : AttributeScope.values()) { scopeComboBox.addItem( new ComboBoxItemData(globalValue.getScope(), globalValue.name()) ); } } - private void updateDataPatchFileName() { - final String attributeCode = this.codeTextField.getText(); - + private void updateDataPatchFileName(final String attributeCode) { if (attributeCode.isEmpty()) { dataPatchNameTextField.setText(""); @@ -182,6 +239,24 @@ private void updateDataPatchFileName() { dataPatchNameTextField.setText(dataPatchSuffix + fileName + dataPatchPrefix); } + private void updateSourceModelName(final String attributeCode) { + + if (attributeCode.isEmpty()) { + sourceModelNameTexField.setText(""); + + return; + } + + final String[] attributeCodeParts = attributeCode.split("_"); + final StringBuilder sourceModelClassName = new StringBuilder(); + + for (final String codePart : attributeCodeParts) { + sourceModelClassName.append(StringUtils.capitalise(codePart)); + } + + sourceModelNameTexField.setText(sourceModelClassName.toString()); + } + /** * Open dialog. * @@ -200,115 +275,107 @@ private void onOk() { return; } - generateFile(); + generateSourceModelFile(); + generateDataPatchFile(); + setVisible(false); } - private void generateFile() { - new EavAttributeSetupPatchGenerator( - getEntityData(), - project - ).generate(NewEavAttributeAction.ACTION_NAME, true); - } + private void generateSourceModelFile() { + final ComboBoxItemData selectedSource = (ComboBoxItemData) sourceComboBox.getSelectedItem(); - private EavEntityDataInterface getEntityData() { - EavEntityDataInterface entityData = null; - if (getSelectedEntityType().equals(EavEntities.PRODUCT.name())) { - entityData = populateProductEntityData(new ProductEntityData()); + if (selectedSource == null + || !selectedSource.getText().equals(AttributeSourceModel.GENERATE_SOURCE.getSource())) { + return; } - return entityData; + sourceModelData.setModuleName(moduleName); + sourceModelData.setClassName(sourceModelNameTexField.getText().trim()); + sourceModelData.setDirectory(sourceModelDirectoryTexField.getText().trim()); + + new SourceModelGenerator(project, sourceModelData) + .generate(NewEavAttributeAction.ACTION_NAME, false); } - private ProductEntityData populateProductEntityData(final ProductEntityData productEntityData) { - productEntityData.setModuleName(getModuleName()); + private void generateDataPatchFile() { + new EavAttributeSetupPatchGenerator( + populateProductEntityData(new ProductEntityData()), + project + ).generate(NewEavAttributeAction.ACTION_NAME, true); + } - productEntityData.setDataPatchName(getDataPatchName()); - productEntityData.setGroup(getAttributeGroup()); - productEntityData.setCode(getAttributeCode()); + private ProductEntityData populateProductEntityData(final ProductEntityData productEntityData) { + productEntityData.setModuleName(moduleName); + + productEntityData.setDataPatchName(dataPatchNameTextField.getText().trim()); + productEntityData.setGroup(groupTextField.getText().trim()); + productEntityData.setCode(codeTextField.getText().trim()); + productEntityData.setLabel(labelTextField.getText().trim()); + productEntityData.setSortOrder(Integer.parseInt(sortOrderTextField.getText().trim())); + productEntityData.setRequired(requiredCheckBox.isSelected()); + productEntityData.setUsedInGrid(usedInGridGridCheckBox.isSelected()); + productEntityData.setVisibleInGrid(visibleInGridCheckBox.isSelected()); + productEntityData.setFilterableInGrid(filterableInGridCheckBox.isSelected()); + productEntityData.setVisible(visibleCheckBox.isSelected()); + productEntityData.setHtmlAllowedOnFront(htmlAllowedOnCheckBox.isSelected()); + productEntityData.setVisibleOnFront(visibleOnFrontCheckBox.isSelected()); productEntityData.setType(getAttributeType()); - productEntityData.setLabel(getAttributeLabel()); productEntityData.setInput(getAttributeInput()); productEntityData.setScope(getAttributeScope()); - productEntityData.setSortOrder(getAttributeSortOrder()); - productEntityData.setRequired(isAttributeRequired()); - productEntityData.setUsedInGrid(isAttributeUsedInGrid()); - productEntityData.setVisibleInGrid(isAttributeVisibleOnGrid()); - productEntityData.setFilterableInGrid(isAttributeFilterableInGrid()); - productEntityData.setVisible(isAttributeVisible()); - productEntityData.setHtmlAllowedOnFront(isAttributeHtmlAllowedOnFront()); - productEntityData.setVisibleOnFront(isAttributeVisibleOnFront()); + productEntityData.setSource(getAttributeSource()); return productEntityData; } - private boolean isAttributeVisibleOnFront() { - return visibleOnFrontCheckBox.isSelected(); - } - - private boolean isAttributeHtmlAllowedOnFront() { - return htmlAllowedOnCheckBox.isSelected(); - } - - private boolean isAttributeVisible() { - return visibleCheckBox.isSelected(); - } - - private boolean isAttributeFilterableInGrid() { - return filterableInGridCheckBox.isSelected(); - } + private String getAttributeSource() { + final ComboBoxItemData selectedItem = (ComboBoxItemData) sourceComboBox.getSelectedItem(); - private boolean isAttributeVisibleOnGrid() { - return visibleInGridCheckBox.isSelected(); - } + if (selectedItem == null + || selectedItem.getText().equals(AttributeSourceModel.NULLABLE_SOURCE.getSource())) { + return null; + } - private boolean isAttributeUsedInGrid() { - return usedInGridGridCheckBox.isSelected(); - } + if (selectedItem.getText().equals(AttributeSourceModel.GENERATE_SOURCE.getSource()) + && sourceModelData != null) { - private boolean isAttributeRequired() { - return requiredCheckBox.isSelected(); - } + return String.join( + Package.fqnSeparator, + "", + sourceModelData.getNamespace(), + sourceModelData.getClassName() + ); + } - private int getAttributeSortOrder() { - return Integer.parseInt(sortOrderTextField.getText().trim()); + return sourceComboBox.getSelectedItem().toString(); } private String getAttributeScope() { final ComboBoxItemData selectedScope = (ComboBoxItemData) scopeComboBox.getSelectedItem(); - return selectedScope.getKey().trim(); - } - - private String getAttributeCode() { - return codeTextField.getText().trim(); - } - - private String getSelectedEntityType() { - return entityType.getSelectedItem().toString().trim(); - } + if (selectedScope != null) { + selectedScope.getKey().trim(); + } - private String getAttributeLabel() { - return labelTextField.getText().trim(); + return AttributeScope.GLOBAL.getScope(); } private String getAttributeInput() { - return inputComboBox.getSelectedItem().toString().trim(); - } + final ComboBoxItemData selectedAttributeInput = (ComboBoxItemData) inputComboBox.getSelectedItem(); - private String getAttributeGroup() { - return groupTextField.getText().trim(); - } + if (selectedAttributeInput != null) { + return selectedAttributeInput.getText().trim(); + } - private String getDataPatchName() { - return dataPatchNameTextField.getText().trim(); + return ""; } private String getAttributeType() { - return typeComboBox.getSelectedItem().toString().trim(); - } + final ComboBoxItemData selectedItem = (ComboBoxItemData) typeComboBox.getSelectedItem(); + + if (selectedItem != null) { + return selectedItem.getText(); + } - private String getModuleName() { - return moduleName; + return ""; } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/EavAttributeInputItemListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/EavAttributeInputItemListener.java new file mode 100644 index 000000000..3ce92d75d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/EavAttributeInputItemListener.java @@ -0,0 +1,42 @@ +package com.magento.idea.magento2plugin.actions.generation.dialog.event; + +import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; +import com.magento.idea.magento2plugin.magento.packages.uicomponent.AvailableSourcesByInput; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.List; +import javax.swing.JComboBox; + +public class EavAttributeInputItemListener implements ItemListener { + private final JComboBox sourceComboBox; + + public EavAttributeInputItemListener(final JComboBox sourceComboBox) { + this.sourceComboBox = sourceComboBox; + } + + @Override + public void itemStateChanged(final ItemEvent itemEvent) { + final String selectedInput = itemEvent.getItem().toString(); + + final List availableSources = + new AvailableSourcesByInput(selectedInput).getItems(); + sourceComboBox.removeAllItems(); + + final ComboBoxItemData defaultSourceItem = new ComboBoxItemData( + AttributeSourceModel.NULLABLE_SOURCE.name(), + AttributeSourceModel.NULLABLE_SOURCE.getSource() + ); + + sourceComboBox.addItem(defaultSourceItem); + sourceComboBox.setSelectedItem(defaultSourceItem); + + if (availableSources.isEmpty()) { + return; + } + + for (final ComboBoxItemData comboBoxItemData : availableSources) { + sourceComboBox.addItem(comboBoxItemData); + } + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java new file mode 100644 index 000000000..debacc568 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java @@ -0,0 +1,164 @@ +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.jetbrains.php.lang.psi.PhpFile; +import com.jetbrains.php.lang.psi.elements.PhpClass; +import com.magento.idea.magento2plugin.actions.generation.data.SourceModelData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.bundles.CommonBundle; +import com.magento.idea.magento2plugin.bundles.ValidatorBundle; +import com.magento.idea.magento2plugin.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.SourceModelPhp; +import com.magento.idea.magento2plugin.magento.packages.File; +import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import javax.swing.JOptionPane; + +public class SourceModelGenerator extends FileGenerator { + private final SourceModelData sourceModelData; + private final CommonBundle commonBundle; + private final Project project; + private final ValidatorBundle validatorBundle; + private final DirectoryGenerator directoryGenerator; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + + /** + * Constructor. + * + * @param project Project + * @param sourceModelData SourceModelData + */ + public SourceModelGenerator(final Project project, final SourceModelData sourceModelData) { + super(project); + + this.project = project; + this.sourceModelData = sourceModelData; + this.commonBundle = new CommonBundle(); + this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); + this.validatorBundle = new ValidatorBundle(); + this.directoryGenerator = new DirectoryGenerator(); + } + + @Override + public PsiFile generate(final String actionName) { + final String errorTitle = commonBundle.message("common.error"); + final PhpClass dataPatchClass = GetPhpClassByFQN.getInstance(project) + .execute(getSourceModelFqn()); + + if (validateIfFileAlreadyExist(dataPatchClass, errorTitle)) { + return null; + } + + final PhpFile resourceModelFile = createResourceModelClass(actionName); + + if (validateIfFileCanBeCreated(errorTitle, resourceModelFile)) { + return null; + } + + return resourceModelFile; + } + + private boolean validateIfFileAlreadyExist( + final PhpClass dataPatchClass, + final String errorTitle + ) { + if (dataPatchClass != null) { + final String errorMessage = validatorBundle.message( + "validator.file.alreadyExists", + "Resource Class" + ); + JOptionPane.showMessageDialog( + null, + errorMessage, + errorTitle, + JOptionPane.ERROR_MESSAGE + ); + + return true; + } + + return false; + } + + private PhpFile createResourceModelClass(final String actionName) { + final PsiDirectory parentDirectory = getResourceModelDirectory(); + final Properties attributes = getAttributes(); + final PsiFile dataPatchFile = fileFromTemplateGenerator.generate( + new SourceModelPhp(sourceModelData.getClassName()), + attributes, + parentDirectory, + actionName + ); + + if (dataPatchFile == null) { + return null; + } + + return (PhpFile) dataPatchFile; + } + + private PsiDirectory getResourceModelDirectory() { + PsiDirectory parentDirectory = new ModuleIndex(project) + .getModuleDirectoryByModuleName(sourceModelData.getModuleName()); + final String[] dataPatchDirectories = sourceModelData.getDirectory().split(File.separator); + + for (final String sourceModelDirectory : dataPatchDirectories) { + parentDirectory = directoryGenerator.findOrCreateSubdirectory( + parentDirectory, + sourceModelDirectory + ); + } + + return parentDirectory; + } + + private boolean validateIfFileCanBeCreated( + final String errorTitle, + final PhpFile dataPathFile + ) { + if (dataPathFile == null) { + final String errorMessage = validatorBundle.message( + "validator.file.cantBeCreated", + "Resource Model Class" + ); + JOptionPane.showMessageDialog( + null, + errorMessage, + errorTitle, + JOptionPane.ERROR_MESSAGE + ); + + return true; + } + return false; + } + + private String getSourceModelFqn() { + return sourceModelData.getNamespace() + + Package.fqnSeparator + + sourceModelData.getClassName(); + } + + @Override + protected void fillAttributes(final Properties attributes) { + final String abstractSourceClass = + "Magento\\Eav\\Model\\Entity\\Attribute\\Source\\AbstractSource"; + final List uses = new ArrayList<>(); + uses.add(abstractSourceClass); + + attributes.setProperty("NAME", sourceModelData.getClassName()); + attributes.setProperty("NAMESPACE", sourceModelData.getNamespace()); + attributes.setProperty( + "EXTENDS", + PhpClassGeneratorUtil.getNameFromFqn(abstractSourceClass) + ); + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java index 07f21ddaf..804cf2b8d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java @@ -5,7 +5,7 @@ package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; -import com.magento.idea.magento2plugin.magento.packages.eav.EavEntities; +import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity; import com.sun.istack.NotNull; public class AttributeMapperFactory { @@ -15,7 +15,7 @@ public class AttributeMapperFactory { * @param entityClass String */ public AttributeMapperInterface createByEntityClass(@NotNull final String entityClass) { - if (entityClass.equals(EavEntities.PRODUCT.getEntityClass())) { + if (entityClass.equals(EavEntity.PRODUCT.getEntityClass())) { return new ProductAttributeMapper(); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java index 202532afd..12dc3ea9c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java @@ -7,7 +7,8 @@ import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData; -import com.magento.idea.magento2plugin.magento.packages.eav.EavAttributes; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; +import com.magento.idea.magento2plugin.magento.packages.eav.EavAttribute; import com.sun.istack.NotNull; import java.util.ArrayList; import java.util.HashMap; @@ -37,37 +38,41 @@ public List mapAttributesByEntityData( return attributesWithValues; } + @SuppressWarnings({"PMD.NullAssignment"}) private Map getMappedAttributes(final ProductEntityData eavEntityData) { final Map mappedAttributes = new HashMap<>(); - mappedAttributes.put(EavAttributes.GROUP.getAttribute(), + mappedAttributes.put(EavAttribute.GROUP.getAttribute(), wrapStringValueForTemplate(eavEntityData.getGroup())); - mappedAttributes.put(EavAttributes.TYPE.getAttribute(), + mappedAttributes.put(EavAttribute.TYPE.getAttribute(), wrapStringValueForTemplate(eavEntityData.getType())); - mappedAttributes.put(EavAttributes.LABEL.getAttribute(), + mappedAttributes.put(EavAttribute.LABEL.getAttribute(), wrapStringValueForTemplate(eavEntityData.getLabel())); - mappedAttributes.put(EavAttributes.INPUT.getAttribute(), + mappedAttributes.put(EavAttribute.INPUT.getAttribute(), wrapStringValueForTemplate(eavEntityData.getInput())); - mappedAttributes.put(EavAttributes.SOURCE.getAttribute(), - eavEntityData.getSource()); - mappedAttributes.put(EavAttributes.REQUIRED.getAttribute(), + final String eavSource = eavEntityData.getSource(); + mappedAttributes.put(EavAttribute.SOURCE.getAttribute(), + eavSource == null || eavSource.equals(AttributeSourceModel.NULLABLE_SOURCE.getSource()) + ? null : eavSource + "::class"); + + mappedAttributes.put(EavAttribute.REQUIRED.getAttribute(), Boolean.toString(eavEntityData.isRequired())); - mappedAttributes.put(EavAttributes.SORT_ORDER.getAttribute(), + mappedAttributes.put(EavAttribute.SORT_ORDER.getAttribute(), Integer.toString(eavEntityData.getSortOrder())); - mappedAttributes.put(EavAttributes.GLOBAL.getAttribute(), + mappedAttributes.put(EavAttribute.GLOBAL.getAttribute(), eavEntityData.getScope()); - mappedAttributes.put(EavAttributes.IS_USED_IN_GRID.getAttribute(), + mappedAttributes.put(EavAttribute.IS_USED_IN_GRID.getAttribute(), Boolean.toString(eavEntityData.isUsedInGrid())); - mappedAttributes.put(EavAttributes.IS_VISIBLE_IN_GRID.getAttribute(), + mappedAttributes.put(EavAttribute.IS_VISIBLE_IN_GRID.getAttribute(), Boolean.toString(eavEntityData.isVisibleInGrid())); - mappedAttributes.put(EavAttributes.IS_FILTERABLE_IN_GRID.getAttribute(), + mappedAttributes.put(EavAttribute.IS_FILTERABLE_IN_GRID.getAttribute(), Boolean.toString(eavEntityData.isFilterableInGrid())); - mappedAttributes.put(EavAttributes.VISIBLE.getAttribute(), + mappedAttributes.put(EavAttribute.VISIBLE.getAttribute(), Boolean.toString(eavEntityData.isVisible())); - mappedAttributes.put(EavAttributes.IS_HTML_ALLOWED_ON_FRONT.getAttribute(), + mappedAttributes.put(EavAttribute.IS_HTML_ALLOWED_ON_FRONT.getAttribute(), Boolean.toString(eavEntityData.isHtmlAllowedOnFront())); - mappedAttributes.put(EavAttributes.VISIBLE_ON_FRONT.getAttribute(), + mappedAttributes.put(EavAttribute.VISIBLE_ON_FRONT.getAttribute(), Boolean.toString(eavEntityData.isVisibleOnFront())); return mappedAttributes; diff --git a/src/com/magento/idea/magento2plugin/magento/files/SourceModelPhp.java b/src/com/magento/idea/magento2plugin/magento/files/SourceModelPhp.java new file mode 100644 index 000000000..6aa74b056 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/SourceModelPhp.java @@ -0,0 +1,38 @@ +package com.magento.idea.magento2plugin.magento.files; + +import com.intellij.lang.Language; +import com.jetbrains.php.lang.PhpLanguage; + +public class SourceModelPhp implements ModuleFileInterface { + public static final String TEMPLATE = "Magento Source Model Class"; + public static final String DEFAULT_DIR = "Model/Source"; + private String fileName; + + /** + * Constructor. + * + * @param className String + */ + public SourceModelPhp(final String className) { + fileName = className.concat(".php"); + } + + public void setFileName(final String fileName) { + this.fileName = fileName; + } + + @Override + public String getFileName() { + return fileName; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInputs.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInput.java similarity index 89% rename from src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInputs.java rename to src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInput.java index 56ae2b7d3..448b4714a 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInputs.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInput.java @@ -5,24 +5,24 @@ package com.magento.idea.magento2plugin.magento.packages.eav; -public enum AttributeInputs { +public enum AttributeInput { + TEXT("text"), BOOLEAN("boolean"), + MULTISELECT("multiselect"), + SELECT("select"), + TEXTAREA("textarea"), + PRICE("price"), DATE("date"), GALLERY("gallery"), HIDDEN("hidden"), IMAGE("image"), MEDIA_IMAGE("media_image"), MULTILINE("multiline"), - MULTISELECT("multiselect"), - PRICE("price"), - SELECT("select"), - TEXT("text"), - TEXTAREA("textarea"), WEIGHT("weight"); private String input; - AttributeInputs(final String input) { + AttributeInput(final String input) { this.input = input; } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScopes.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScope.java similarity index 88% rename from src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScopes.java rename to src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScope.java index 17ec922b2..e0738bc37 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScopes.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScope.java @@ -5,14 +5,14 @@ package com.magento.idea.magento2plugin.magento.packages.eav; -public enum AttributeScopes { +public enum AttributeScope { GLOBAL("\\Magento\\Eav\\Model\\Entity\\Attribute\\ScopedAttributeInterface::SCOPE_GLOBAL"), STORE("\\Magento\\Eav\\Model\\Entity\\Attribute\\ScopedAttributeInterface::SCOPE_STORE"), WEBSITE("\\Magento\\Eav\\Model\\Entity\\Attribute\\ScopedAttributeInterface::SCOPE_WEBSITE"); private String scope; - AttributeScopes(final String scope) { + AttributeScope(final String scope) { this.scope = scope; } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModels.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java similarity index 76% rename from src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModels.java rename to src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java index ddc9c470b..19c8d71a8 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModels.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java @@ -5,15 +5,17 @@ package com.magento.idea.magento2plugin.magento.packages.eav; -public enum AttributeSourceModels { +public enum AttributeSourceModel { BOOLEAN("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Boolean"), TABLE("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table"), CONFIG("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Config"), - STORE("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Store"); + STORE("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Store"), + GENERATE_SOURCE("Generate Source"), + NULLABLE_SOURCE("Set Source Model as null"); private String source; - AttributeSourceModels(final String source) { + AttributeSourceModel(final String source) { this.source = source; } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeTypes.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeType.java similarity index 85% rename from src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeTypes.java rename to src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeType.java index 370476301..988fa865a 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeTypes.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeType.java @@ -5,7 +5,7 @@ package com.magento.idea.magento2plugin.magento.packages.eav; -public enum AttributeTypes { +public enum AttributeType { STATIC("static"), VARCHAR("varchar"), INT("int"), @@ -15,7 +15,7 @@ public enum AttributeTypes { private String type; - AttributeTypes(final String type) { + AttributeType(final String type) { this.type = type; } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttributes.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java similarity index 91% rename from src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttributes.java rename to src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java index 7eb684d36..9ac14aa6e 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttributes.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java @@ -5,7 +5,7 @@ package com.magento.idea.magento2plugin.magento.packages.eav; -public enum EavAttributes { +public enum EavAttribute { GROUP("group"), TYPE("type"), LABEL("label"), @@ -23,7 +23,7 @@ public enum EavAttributes { private String attribute; - EavAttributes(final String attribute) { + EavAttribute(final String attribute) { this.attribute = attribute; } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntities.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java similarity index 83% rename from src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntities.java rename to src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java index e0d819549..11cf35df9 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntities.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java @@ -5,12 +5,12 @@ package com.magento.idea.magento2plugin.magento.packages.eav; -public enum EavEntities { +public enum EavEntity { PRODUCT("\\Magento\\Catalog\\Model\\Product"); private String entityClass; - EavEntities(final String entityClass) { + EavEntity(final String entityClass) { this.entityClass = entityClass; } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java b/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java new file mode 100644 index 000000000..778c7b027 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java @@ -0,0 +1,52 @@ +package com.magento.idea.magento2plugin.magento.packages.uicomponent; + +import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; +import com.sun.istack.NotNull; +import java.util.ArrayList; +import java.util.List; + +public class AvailableSourcesByInput { + private final String input; + + public AvailableSourcesByInput(@NotNull final String input) { + this.input = input; + } + + public List getItems() { + final List items = new ArrayList<>(); + final ComboBoxItemData generateSourceItem = new ComboBoxItemData( + AttributeSourceModel.GENERATE_SOURCE.getSource(), + AttributeSourceModel.GENERATE_SOURCE.getSource() + ); + items.add(generateSourceItem); + + if (input.equals(AttributeInput.BOOLEAN.getInput())) { + items.add(new ComboBoxItemData( + AttributeSourceModel.BOOLEAN.getSource(), + AttributeSourceModel.BOOLEAN.getSource()) + ); + } else if (input.equals(AttributeInput.SELECT.getInput()) + || input.equals(AttributeInput.MULTISELECT.getInput())) { + items.add(new ComboBoxItemData( + AttributeSourceModel.BOOLEAN.getSource(), + AttributeSourceModel.BOOLEAN.getSource()) + ); + items.add(new ComboBoxItemData( + AttributeSourceModel.TABLE.getSource(), + AttributeSourceModel.TABLE.getSource() + )); + items.add(new ComboBoxItemData( + AttributeSourceModel.STORE.getSource(), + AttributeSourceModel.STORE.getSource() + )); + items.add(new ComboBoxItemData( + AttributeSourceModel.CONFIG.getSource(), + AttributeSourceModel.CONFIG.getSource() + )); + } + + return items; + } +} diff --git a/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFile/AddTestAttribute.php b/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFile/AddTestAttribute.php index 59fec32c7..b0793c4e9 100644 --- a/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFile/AddTestAttribute.php +++ b/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFile/AddTestAttribute.php @@ -90,7 +90,7 @@ public function apply() 'type' => 'static', 'is_used_in_grid' => false, 'required' => false, - 'input' => 'boolean', + 'input' => 'text', 'is_filterable_in_grid' => false, 'sort_order' => 10, 'group' => 'General', diff --git a/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php b/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php new file mode 100644 index 000000000..5f71e121e --- /dev/null +++ b/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php @@ -0,0 +1,100 @@ +moduleDataSetup = $moduleDataSetup; + $this->eavSetupFactory = $eavSetupFactory; + } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } + + /** + * Run code inside patch + * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert + * means run PatchInterface::revert() + * + * If we speak about data, under revert means: $transaction->rollback() + * + * @return $this + */ + public function apply() + { + /** @var EavSetup $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); + + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'boolean_input_attribute', + [ + 'is_visible_in_grid' => false, + 'is_html_allowed_on_front' => false, + 'visible_on_front' => false, + 'visible' => true, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, + 'label' => 'Test Label', + 'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class, + 'type' => 'static', + 'is_used_in_grid' => false, + 'required' => false, + 'input' => 'boolean', + 'is_filterable_in_grid' => false, + 'sort_order' => 10, + 'group' => 'General', + ] + ); + } +} diff --git a/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php b/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php new file mode 100644 index 000000000..9b4ce17a7 --- /dev/null +++ b/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php @@ -0,0 +1,100 @@ +moduleDataSetup = $moduleDataSetup; + $this->eavSetupFactory = $eavSetupFactory; + } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } + + /** + * Run code inside patch + * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert + * means run PatchInterface::revert() + * + * If we speak about data, under revert means: $transaction->rollback() + * + * @return $this + */ + public function apply() + { + /** @var EavSetup $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); + + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'attribute_with_custom_source', + [ + 'is_visible_in_grid' => false, + 'is_html_allowed_on_front' => false, + 'visible_on_front' => false, + 'visible' => true, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, + 'label' => 'Test Label', + 'source' => \Foo\Bar\Model\Source\AttributeWithCustomSource::class, + 'type' => 'static', + 'is_used_in_grid' => false, + 'required' => false, + 'input' => 'text', + 'is_filterable_in_grid' => false, + 'sort_order' => 10, + 'group' => 'General', + ] + ); + } +} diff --git a/testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php b/testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php new file mode 100644 index 000000000..ee99f68e7 --- /dev/null +++ b/testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php @@ -0,0 +1,18 @@ + Date: Fri, 9 Apr 2021 15:56:44 +0300 Subject: [PATCH 012/111] Fixed label --- .../magento/packages/eav/AttributeSourceModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java index 19c8d71a8..561353822 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java @@ -10,7 +10,7 @@ public enum AttributeSourceModel { TABLE("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table"), CONFIG("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Config"), STORE("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Store"), - GENERATE_SOURCE("Generate Source"), + GENERATE_SOURCE("Custom Source"), NULLABLE_SOURCE("Set Source Model as null"); private String source; From f59095f61c8c7ea66b822c54ceccbcf048d54219 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Fri, 9 Apr 2021 16:22:53 +0300 Subject: [PATCH 013/111] Added copyright --- .../actions/generation/data/SourceModelData.java | 5 +++++ .../dialog/event/EavAttributeInputItemListener.java | 5 +++++ .../actions/generation/generator/SourceModelGenerator.java | 5 +++++ .../idea/magento2plugin/magento/files/SourceModelPhp.java | 5 +++++ .../packages/uicomponent/AvailableSourcesByInput.java | 5 +++++ .../generation/generator/SourceModelGeneratorTest.java | 5 +++++ 6 files changed, 30 insertions(+) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java index 7980caefe..77c19c031 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.generation.data; import com.magento.idea.magento2plugin.magento.files.SourceModelPhp; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/EavAttributeInputItemListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/EavAttributeInputItemListener.java index 3ce92d75d..038795da9 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/EavAttributeInputItemListener.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/EavAttributeInputItemListener.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.generation.dialog.event; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java index debacc568..e9806fbce 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.generation.generator; import com.intellij.openapi.project.Project; diff --git a/src/com/magento/idea/magento2plugin/magento/files/SourceModelPhp.java b/src/com/magento/idea/magento2plugin/magento/files/SourceModelPhp.java index 6aa74b056..12bbbbe56 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/SourceModelPhp.java +++ b/src/com/magento/idea/magento2plugin/magento/files/SourceModelPhp.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.magento.files; import com.intellij.lang.Language; diff --git a/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java b/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java index 778c7b027..1dd0dcc42 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.magento.packages.uicomponent; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java index 9ab561bb7..5d8e9e0d9 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.generation.generator; import com.intellij.openapi.project.Project; From 1714449f93203ba347663c07277762e3725d520a Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Sat, 10 Apr 2021 20:57:51 +0300 Subject: [PATCH 014/111] Refactored eav attribute generator --- ...ento Eav Attribute Data Patch Class.php.ft | 2 +- .../dialog/NewEavAttributeDialog.java | 3 +- .../EavAttributeSetupPatchGenerator.java | 224 ++++-------------- .../files/EavAttributeDataPatchFile.java | 36 +++ .../files/EavAttributeDataPatchPhp.java | 43 ---- 5 files changed, 90 insertions(+), 218 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchFile.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java diff --git a/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft b/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft index aadf9d90d..30ad2dc39 100644 --- a/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft +++ b/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft @@ -10,7 +10,7 @@ namespace ${NAMESPACE}; use $use; #end -class ${NAME} implements ${IMPLEMENTS} { +class ${CLASS_NAME} implements ${IMPLEMENTS} { /** * @var ${MODULE_DATA_SETUP_INTERFACE} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java index a8e58a0d0..ec865c1b4 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java @@ -300,7 +300,8 @@ private void generateSourceModelFile() { private void generateDataPatchFile() { new EavAttributeSetupPatchGenerator( populateProductEntityData(new ProductEntityData()), - project + project, + true ).generate(NewEavAttributeAction.ACTION_NAME, true); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java index 94b6e7585..a2eb34a78 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java @@ -6,206 +6,84 @@ package com.magento.idea.magento2plugin.actions.generation.generator; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; -import com.jetbrains.php.lang.psi.PhpFile; -import com.jetbrains.php.lang.psi.elements.PhpClass; import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; -import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.actions.generation.generator.util.eav.AttributeMapperFactory; import com.magento.idea.magento2plugin.actions.generation.generator.util.eav.AttributeMapperInterface; -import com.magento.idea.magento2plugin.bundles.CommonBundle; -import com.magento.idea.magento2plugin.bundles.ValidatorBundle; -import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.EavAttributeDataPatchPhp; -import com.magento.idea.magento2plugin.magento.packages.File; -import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.EavAttributeDataPatchFile; import com.magento.idea.magento2plugin.magento.packages.eav.DataPatchDependency; -import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import com.sun.istack.NotNull; -import java.util.ArrayList; import java.util.List; import java.util.Properties; -import javax.swing.JOptionPane; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; -public class EavAttributeSetupPatchGenerator extends FileGenerator { - private final EavEntityDataInterface eavEntityData; - private final Project project; - private final DirectoryGenerator directoryGenerator; - private final FileFromTemplateGenerator fileFromTemplateGenerator; - private final ValidatorBundle validatorBundle; - private final CommonBundle commonBundle; +public class EavAttributeSetupPatchGenerator extends PhpFileGenerator { + private final EavEntityDataInterface data; /** * Constructor. * - * @param eavEntityData EavEntityDataInterface - * @param project Project + * @param data EavEntityDataInterface + * @param project Project */ public EavAttributeSetupPatchGenerator( - final @NotNull EavEntityDataInterface eavEntityData, + final @NotNull EavEntityDataInterface data, final Project project ) { - super(project); - - this.eavEntityData = eavEntityData; - this.project = project; - this.directoryGenerator = new DirectoryGenerator(); - this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); - this.validatorBundle = new ValidatorBundle(); - this.commonBundle = new CommonBundle(); + this(data, project, true); } - @Override - public PsiFile generate(final String actionName) { - final String errorTitle = commonBundle.message("common.error"); - final PhpClass dataPatchClass = GetPhpClassByFQN.getInstance(project) - .execute(getDataPatchFqn()); - - if (validateIfFileAlreadyExist(dataPatchClass, errorTitle)) { - return null; - } - - final PhpFile dataPathFile = createDataPathClass(actionName); - - if (validateIfFileCanBeCreated(errorTitle, dataPathFile)) { - return null; - } - - return dataPathFile; - } - - private String getDataPatchFqn() { - return eavEntityData.getNamespace() - + Package.fqnSeparator - + eavEntityData.getDataPatchName(); - } - - private boolean validateIfFileAlreadyExist( - final PhpClass dataPatchClass, - final String errorTitle + /** + * Php file generator constructor. + * + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public EavAttributeSetupPatchGenerator( + final @NotNull EavEntityDataInterface data, + final @NotNull Project project, + final boolean checkFileAlreadyExists ) { - if (dataPatchClass != null) { - final String errorMessage = validatorBundle.message( - "validator.file.alreadyExists", - "Data Patch Class" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - errorTitle, - JOptionPane.ERROR_MESSAGE - ); - - return true; - } - - return false; + super(project, checkFileAlreadyExists); + this.data = data; } - @Nullable - private PhpFile createDataPathClass(final String actionName) { - final PsiDirectory parentDirectory = getDataPatchDirectory(); - final Properties attributes = getAttributes(); - final PsiFile dataPatchFile = fileFromTemplateGenerator.generate( - new EavAttributeDataPatchPhp(eavEntityData.getDataPatchName()), - attributes, - parentDirectory, - actionName - ); - - if (dataPatchFile == null) { - return null; - } - - return (PhpFile) dataPatchFile; - } - - private PsiDirectory getDataPatchDirectory() { - PsiDirectory parentDirectory = new ModuleIndex(project) - .getModuleDirectoryByModuleName(eavEntityData.getModuleName()); - final String[] dataPatchDirectories = eavEntityData.getDirectory().split(File.separator); - - for (final String dataPatchDirectory : dataPatchDirectories) { - parentDirectory = directoryGenerator.findOrCreateSubdirectory( - parentDirectory, - dataPatchDirectory - ); - } - - return parentDirectory; - } - - private boolean validateIfFileCanBeCreated( - final String errorTitle, - final PhpFile dataPathFile - ) { - if (dataPathFile == null) { - final String errorMessage = validatorBundle.message( - "validator.file.cantBeCreated", - "Data Patch Class" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - errorTitle, - JOptionPane.ERROR_MESSAGE - ); - - return true; - } - return false; + @Override + protected AbstractPhpFile initFile() { + return new EavAttributeDataPatchFile(data.getModuleName(), data.getDataPatchName()); } @Override protected void fillAttributes(final Properties attributes) { - attributes.setProperty("NAME", eavEntityData.getDataPatchName()); - attributes.setProperty("NAMESPACE", eavEntityData.getNamespace()); - - final String dataPatchInterface = DataPatchDependency.DATA_PATCH_INTERFACE.getClassPatch(); - attributes.setProperty( - "IMPLEMENTS", - PhpClassGeneratorUtil.getNameFromFqn(dataPatchInterface) - ); - - final String eavSetup = DataPatchDependency.ENV_SETUP.getClassPatch(); - final String eavSetupFactory = DataPatchDependency.EAV_SETUP_FACTORY.getClassPatch(); - final String moduleDataSetupInterface = - DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch(); - final String entityClass = eavEntityData.getEntityClass(); - + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + phpClassTypesBuilder + .appendProperty("CLASS_NAME", data.getDataPatchName()) + .appendProperty("NAMESPACE", data.getNamespace()) + .appendProperty("ENTITY_CLASS", data.getEntityClass()) + .appendProperty("ATTRIBUTE_CODE", data.getCode()) + .appendProperty("ATTRIBUTE_SET", String.join(",", getAttributesList(data))) + .append( + "IMPLEMENTS", + DataPatchDependency.DATA_PATCH_INTERFACE.getClassPatch() + ) + .append( + "MODULE_DATA_SETUP_INTERFACE", + DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch()) + .append( + "EAV_SETUP_FACTORY", + DataPatchDependency.EAV_SETUP_FACTORY.getClassPatch() + ) + .append( + "EAV_SETUP", + DataPatchDependency.ENV_SETUP.getClassPatch() + ) + .mergeProperties(attributes); attributes.setProperty( - "MODULE_DATA_SETUP_INTERFACE", - PhpClassGeneratorUtil.getNameFromFqn(moduleDataSetupInterface) + "USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()) ); - attributes.setProperty( - "EAV_SETUP_FACTORY", - PhpClassGeneratorUtil.getNameFromFqn(eavSetupFactory) - ); - attributes.setProperty( - "EAV_SETUP", - PhpClassGeneratorUtil.getNameFromFqn(eavSetup) - ); - attributes.setProperty( - "ENTITY_CLASS", - entityClass - ); - - final List uses = new ArrayList<>(); - uses.add(dataPatchInterface); - uses.add(eavSetup); - uses.add(eavSetupFactory); - uses.add(moduleDataSetupInterface); - - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - - attributes.setProperty("ATTRIBUTE_CODE", eavEntityData.getCode()); - - final List entityAttributes = getAttributesList(eavEntityData); - attributes.setProperty("ATTRIBUTE_SET", String.join(",", entityAttributes)); } private List getAttributesList(final EavEntityDataInterface eavEntityData) { diff --git a/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchFile.java b/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchFile.java new file mode 100644 index 000000000..7c6a5fb52 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchFile.java @@ -0,0 +1,36 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +public class EavAttributeDataPatchFile extends AbstractPhpFile { + public static final String HUMAN_READABLE_NAME = "Eav Attribute Data Patch Class"; + public static final String TEMPLATE = "Magento Eav Attribute Data Patch Class"; + public static final String DEFAULT_DIR = "Setup/Patch/Data"; + + /** + * Constructor. + * + * @param className String + */ + public EavAttributeDataPatchFile(final String moduleName, final String className) { + super(moduleName, className); + } + + @Override + public String getDirectory() { + return DEFAULT_DIR; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java b/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java deleted file mode 100644 index f5afd761e..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchPhp.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.jetbrains.php.lang.PhpLanguage; - -public class EavAttributeDataPatchPhp implements ModuleFileInterface { - public static final String TEMPLATE = "Magento Eav Attribute Data Patch Class"; - public static final String DEFAULT_DIR = "Setup/Patch/Data"; - private String fileName; - - /** - * Constructor. - * - * @param className String - */ - public EavAttributeDataPatchPhp(final String className) { - fileName = className.concat(".php"); - } - - public void setFileName(final String fileName) { - this.fileName = fileName; - } - - @Override - public String getFileName() { - return fileName; - } - - @Override - public String getTemplate() { - return TEMPLATE; - } - - @Override - public Language getLanguage() { - return PhpLanguage.INSTANCE; - } -} From e2b93714f245c726f2db1eaed1ab6cd75fd642f7 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Sun, 11 Apr 2021 08:15:39 +0300 Subject: [PATCH 015/111] Refactored source model generation --- .../generation/data/SourceModelData.java | 4 +- .../dialog/NewEavAttributeDialog.java | 2 +- .../generator/SourceModelGenerator.java | 155 ++++-------------- ...urceModelPhp.java => SourceModelFile.java} | 28 ++-- .../generator/SourceModelGeneratorTest.java | 2 +- 5 files changed, 45 insertions(+), 146 deletions(-) rename src/com/magento/idea/magento2plugin/magento/files/{SourceModelPhp.java => SourceModelFile.java} (50%) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java index 77c19c031..0e840de1e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java @@ -5,7 +5,7 @@ package com.magento.idea.magento2plugin.actions.generation.data; -import com.magento.idea.magento2plugin.magento.files.SourceModelPhp; +import com.magento.idea.magento2plugin.magento.files.SourceModelFile; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.Package; @@ -63,7 +63,7 @@ public String getModuleName() { */ public String getDirectory() { if (this.directory == null) { - return SourceModelPhp.DEFAULT_DIR; + return SourceModelFile.DEFAULT_DIR; } return this.directory; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java index ec865c1b4..216fb596d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java @@ -293,7 +293,7 @@ private void generateSourceModelFile() { sourceModelData.setClassName(sourceModelNameTexField.getText().trim()); sourceModelData.setDirectory(sourceModelDirectoryTexField.getText().trim()); - new SourceModelGenerator(project, sourceModelData) + new SourceModelGenerator(sourceModelData, project, true) .generate(NewEavAttributeAction.ACTION_NAME, false); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java index e9806fbce..c1d617e0f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java @@ -6,149 +6,50 @@ package com.magento.idea.magento2plugin.actions.generation.generator; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; -import com.jetbrains.php.lang.psi.PhpFile; -import com.jetbrains.php.lang.psi.elements.PhpClass; import com.magento.idea.magento2plugin.actions.generation.data.SourceModelData; -import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; -import com.magento.idea.magento2plugin.bundles.CommonBundle; -import com.magento.idea.magento2plugin.bundles.ValidatorBundle; -import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.SourceModelPhp; -import com.magento.idea.magento2plugin.magento.packages.File; -import com.magento.idea.magento2plugin.magento.packages.Package; -import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.SourceModelFile; import java.util.ArrayList; import java.util.List; import java.util.Properties; -import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; -public class SourceModelGenerator extends FileGenerator { - private final SourceModelData sourceModelData; - private final CommonBundle commonBundle; - private final Project project; - private final ValidatorBundle validatorBundle; - private final DirectoryGenerator directoryGenerator; - private final FileFromTemplateGenerator fileFromTemplateGenerator; +public class SourceModelGenerator extends PhpFileGenerator { + private final SourceModelData data; /** * Constructor. * * @param project Project - * @param sourceModelData SourceModelData + * @param data SourceModelData */ - public SourceModelGenerator(final Project project, final SourceModelData sourceModelData) { - super(project); - - this.project = project; - this.sourceModelData = sourceModelData; - this.commonBundle = new CommonBundle(); - this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); - this.validatorBundle = new ValidatorBundle(); - this.directoryGenerator = new DirectoryGenerator(); - } - - @Override - public PsiFile generate(final String actionName) { - final String errorTitle = commonBundle.message("common.error"); - final PhpClass dataPatchClass = GetPhpClassByFQN.getInstance(project) - .execute(getSourceModelFqn()); - - if (validateIfFileAlreadyExist(dataPatchClass, errorTitle)) { - return null; - } - - final PhpFile resourceModelFile = createResourceModelClass(actionName); - - if (validateIfFileCanBeCreated(errorTitle, resourceModelFile)) { - return null; - } - - return resourceModelFile; - } - - private boolean validateIfFileAlreadyExist( - final PhpClass dataPatchClass, - final String errorTitle + public SourceModelGenerator( + @NotNull final SourceModelData data, + @NotNull final Project project ) { - if (dataPatchClass != null) { - final String errorMessage = validatorBundle.message( - "validator.file.alreadyExists", - "Resource Class" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - errorTitle, - JOptionPane.ERROR_MESSAGE - ); - - return true; - } - - return false; + this(data, project, true); } - private PhpFile createResourceModelClass(final String actionName) { - final PsiDirectory parentDirectory = getResourceModelDirectory(); - final Properties attributes = getAttributes(); - final PsiFile dataPatchFile = fileFromTemplateGenerator.generate( - new SourceModelPhp(sourceModelData.getClassName()), - attributes, - parentDirectory, - actionName - ); - - if (dataPatchFile == null) { - return null; - } - - return (PhpFile) dataPatchFile; - } - - private PsiDirectory getResourceModelDirectory() { - PsiDirectory parentDirectory = new ModuleIndex(project) - .getModuleDirectoryByModuleName(sourceModelData.getModuleName()); - final String[] dataPatchDirectories = sourceModelData.getDirectory().split(File.separator); - - for (final String sourceModelDirectory : dataPatchDirectories) { - parentDirectory = directoryGenerator.findOrCreateSubdirectory( - parentDirectory, - sourceModelDirectory - ); - } - - return parentDirectory; - } - - private boolean validateIfFileCanBeCreated( - final String errorTitle, - final PhpFile dataPathFile + /** + * Constructor. + * + * @param project Project + * @param data SourceModelData + * @param checkFileAlreadyExists boolean + */ + public SourceModelGenerator( + @NotNull final SourceModelData data, + @NotNull final Project project, + final boolean checkFileAlreadyExists ) { - if (dataPathFile == null) { - final String errorMessage = validatorBundle.message( - "validator.file.cantBeCreated", - "Resource Model Class" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - errorTitle, - JOptionPane.ERROR_MESSAGE - ); - - return true; - } - return false; + super(project, checkFileAlreadyExists); + this.data = data; } - private String getSourceModelFqn() { - return sourceModelData.getNamespace() - + Package.fqnSeparator - + sourceModelData.getClassName(); + @Override + protected AbstractPhpFile initFile() { + return new SourceModelFile(data.getModuleName(), data.getClassName()); } @Override @@ -158,8 +59,8 @@ protected void fillAttributes(final Properties attributes) { final List uses = new ArrayList<>(); uses.add(abstractSourceClass); - attributes.setProperty("NAME", sourceModelData.getClassName()); - attributes.setProperty("NAMESPACE", sourceModelData.getNamespace()); + attributes.setProperty("NAME", data.getClassName()); + attributes.setProperty("NAMESPACE", data.getNamespace()); attributes.setProperty( "EXTENDS", PhpClassGeneratorUtil.getNameFromFqn(abstractSourceClass) diff --git a/src/com/magento/idea/magento2plugin/magento/files/SourceModelPhp.java b/src/com/magento/idea/magento2plugin/magento/files/SourceModelFile.java similarity index 50% rename from src/com/magento/idea/magento2plugin/magento/files/SourceModelPhp.java rename to src/com/magento/idea/magento2plugin/magento/files/SourceModelFile.java index 12bbbbe56..8bb40510e 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/SourceModelPhp.java +++ b/src/com/magento/idea/magento2plugin/magento/files/SourceModelFile.java @@ -5,39 +5,37 @@ package com.magento.idea.magento2plugin.magento.files; -import com.intellij.lang.Language; -import com.jetbrains.php.lang.PhpLanguage; +import org.jetbrains.annotations.NotNull; -public class SourceModelPhp implements ModuleFileInterface { +public class SourceModelFile extends AbstractPhpFile { + public static final String HUMAN_READABLE_NAME = "Source model class"; public static final String TEMPLATE = "Magento Source Model Class"; public static final String DEFAULT_DIR = "Model/Source"; - private String fileName; /** * Constructor. * * @param className String */ - public SourceModelPhp(final String className) { - fileName = className.concat(".php"); + public SourceModelFile( + @NotNull final String moduleName, + @NotNull final String className + ) { + super(moduleName, className); } - public void setFileName(final String fileName) { - this.fileName = fileName; + @Override + public String getDirectory() { + return DEFAULT_DIR; } @Override - public String getFileName() { - return fileName; + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; } @Override public String getTemplate() { return TEMPLATE; } - - @Override - public Language getLanguage() { - return PhpLanguage.INSTANCE; - } } diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java index 5d8e9e0d9..e31b8a96e 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java @@ -25,7 +25,7 @@ public void testGenerateFile() { sourceModelData.setNamespace(SOURCE_MODEL_NAMESPACE); final SourceModelGenerator sourceModelGeneratorGenerator = - new SourceModelGenerator(project, sourceModelData); + new SourceModelGenerator(sourceModelData, project); final PsiFile dataPatchFile = sourceModelGeneratorGenerator.generate("test"); final String filePatch = this.getFixturePath("CustomSourceModel.php"); final PsiFile expectedFile = myFixture.configureByFile(filePatch); From 1ad8406c2538107193eee6704cdf5e7e029dba99 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Sun, 11 Apr 2021 08:27:29 +0300 Subject: [PATCH 016/111] Fixed directory for source model --- .../generator/SourceModelGenerator.java | 6 +++++- .../magento/files/SourceModelFile.java | 21 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java index c1d617e0f..29e621773 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java @@ -49,7 +49,11 @@ public SourceModelGenerator( @Override protected AbstractPhpFile initFile() { - return new SourceModelFile(data.getModuleName(), data.getClassName()); + return new SourceModelFile( + data.getModuleName(), + data.getClassName(), + data.getDirectory() + ); } @Override diff --git a/src/com/magento/idea/magento2plugin/magento/files/SourceModelFile.java b/src/com/magento/idea/magento2plugin/magento/files/SourceModelFile.java index 8bb40510e..13a47c9d6 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/SourceModelFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/SourceModelFile.java @@ -11,6 +11,7 @@ public class SourceModelFile extends AbstractPhpFile { public static final String HUMAN_READABLE_NAME = "Source model class"; public static final String TEMPLATE = "Magento Source Model Class"; public static final String DEFAULT_DIR = "Model/Source"; + private String directory; /** * Constructor. @@ -24,9 +25,27 @@ public SourceModelFile( super(moduleName, className); } + /** + * Constructor. + * + * @param className String + */ + public SourceModelFile( + @NotNull final String moduleName, + @NotNull final String className, + final String directory + ) { + this(moduleName, className); + this.directory = directory; + } + @Override public String getDirectory() { - return DEFAULT_DIR; + if (directory == null) { + return DEFAULT_DIR; + } + + return directory; } @Override From b6cd7a99021cc3970b5ebcfc3d3fc76f0186ee59 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Mon, 12 Apr 2021 09:50:39 +0300 Subject: [PATCH 017/111] Refactored generators --- .../generation/data/ProductEntityData.java | 21 +---------- .../generation/data/SourceModelData.java | 35 ------------------ .../dialog/NewEavAttributeDialog.java | 37 +++++++++++++------ .../EavAttributeSetupPatchGenerator.java | 2 +- .../generator/SourceModelGenerator.java | 2 +- .../util/eav/ProductAttributeMapper.java | 15 +++++--- .../generateFile/CustomSourceModel.php | 2 +- .../CustomSourceModel.php | 18 +++++++++ .../EavAttributeSetupPatchGeneratorTest.java | 4 -- .../generator/SourceModelGeneratorTest.java | 28 ++++++++++++-- 10 files changed, 83 insertions(+), 81 deletions(-) create mode 100644 testData/actions/generation/generator/SourceModelGenerator/generateFileInCustomDirectory/CustomSourceModel.php diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java index e1e8821fc..b5d68af17 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java @@ -5,8 +5,7 @@ package com.magento.idea.magento2plugin.actions.generation.data; -import com.magento.idea.magento2plugin.magento.packages.File; -import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.magento.files.EavAttributeDataPatchFile; import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity; @SuppressWarnings({"PMD.TooManyFields"}) @@ -144,25 +143,9 @@ public String getInput() { @Override public String getNamespace() { - if (namespace == null) { - namespace = getDataPathNamespace(); - } - return namespace; } - private String getDataPathNamespace() { - final String[] parts = moduleName.split(Package.vendorModuleNameSeparator); - if (parts[0] == null || parts[1] == null || parts.length > 2) { - return null; - } - final String directoryPart = getDirectory().replace( - File.separator, - Package.fqnSeparator - ); - return parts[0] + Package.fqnSeparator + parts[1] + Package.fqnSeparator + directoryPart; - } - @Override public String getModuleName() { return moduleName; @@ -171,7 +154,7 @@ public String getModuleName() { @Override public String getDirectory() { if (directory == null) { - directory = "Setup/Patch/Data"; + directory = EavAttributeDataPatchFile.DEFAULT_DIR; } return directory; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java index 0e840de1e..c5c1b862e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java @@ -6,12 +6,9 @@ package com.magento.idea.magento2plugin.actions.generation.data; import com.magento.idea.magento2plugin.magento.files.SourceModelFile; -import com.magento.idea.magento2plugin.magento.packages.File; -import com.magento.idea.magento2plugin.magento.packages.Package; public class SourceModelData { private String className; - private String namespace; private String moduleName; private String directory; @@ -19,34 +16,6 @@ public String getClassName() { return className; } - /** - * Constructor. - */ - public String getNamespace() { - if (namespace == null) { - namespace = getDefaultSourceModelNamespace(); - } - - return namespace; - } - - /** - * Provides default namespace. - * - * @return String - */ - public String getDefaultSourceModelNamespace() { - final String[] parts = moduleName.split(Package.vendorModuleNameSeparator); - if (parts[0] == null || parts[1] == null || parts.length > 2) { - return null; - } - final String directoryPart = getDirectory().replace( - File.separator, - Package.fqnSeparator - ); - return parts[0] + Package.fqnSeparator + parts[1] + Package.fqnSeparator + directoryPart; - } - /** * Get default namespace. * @@ -73,10 +42,6 @@ public void setClassName(final String className) { this.className = className; } - public void setNamespace(final String namespace) { - this.namespace = namespace; - } - public void setModuleName(final String moduleName) { this.moduleName = moduleName; } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java index 216fb596d..07a120b9f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java @@ -19,8 +19,12 @@ import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator; -import com.magento.idea.magento2plugin.magento.packages.Package; -import com.magento.idea.magento2plugin.magento.packages.eav.*; +import com.magento.idea.magento2plugin.magento.files.SourceModelFile; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; +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 java.awt.event.ItemEvent; import java.awt.event.ItemListener; @@ -38,7 +42,12 @@ import org.codehaus.plexus.util.StringUtils; import org.jetbrains.annotations.NotNull; -@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports", "PMD.TooManyMethods", "PMD.UnusedPrivateField"}) +@SuppressWarnings({ + "PMD.TooManyFields", + "PMD.ExcessiveImports", + "PMD.TooManyMethods", + "PMD.UnusedPrivateField" +}) public class NewEavAttributeDialog extends AbstractDialog { private final String moduleName; private JPanel contentPanel; @@ -285,7 +294,9 @@ private void generateSourceModelFile() { final ComboBoxItemData selectedSource = (ComboBoxItemData) sourceComboBox.getSelectedItem(); if (selectedSource == null - || !selectedSource.getText().equals(AttributeSourceModel.GENERATE_SOURCE.getSource())) { + || !selectedSource.getText().equals( + AttributeSourceModel.GENERATE_SOURCE.getSource() + )) { return; } @@ -332,19 +343,20 @@ private String getAttributeSource() { final ComboBoxItemData selectedItem = (ComboBoxItemData) sourceComboBox.getSelectedItem(); if (selectedItem == null - || selectedItem.getText().equals(AttributeSourceModel.NULLABLE_SOURCE.getSource())) { + || selectedItem.getText().equals( + AttributeSourceModel.NULLABLE_SOURCE.getSource() + )) { return null; } if (selectedItem.getText().equals(AttributeSourceModel.GENERATE_SOURCE.getSource()) && sourceModelData != null) { - return String.join( - Package.fqnSeparator, - "", - sourceModelData.getNamespace(), - sourceModelData.getClassName() - ); + return "\\" + new SourceModelFile( + sourceModelData.getModuleName(), + sourceModelData.getClassName(), + sourceModelData.getDirectory() + ).getClassFqn(); } return sourceComboBox.getSelectedItem().toString(); @@ -361,7 +373,8 @@ private String getAttributeScope() { } private String getAttributeInput() { - final ComboBoxItemData selectedAttributeInput = (ComboBoxItemData) inputComboBox.getSelectedItem(); + final ComboBoxItemData selectedAttributeInput = + (ComboBoxItemData) inputComboBox.getSelectedItem(); if (selectedAttributeInput != null) { return selectedAttributeInput.getText().trim(); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java index a2eb34a78..49de25135 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java @@ -60,7 +60,7 @@ protected void fillAttributes(final Properties attributes) { phpClassTypesBuilder .appendProperty("CLASS_NAME", data.getDataPatchName()) - .appendProperty("NAMESPACE", data.getNamespace()) + .appendProperty("NAMESPACE", this.getFile().getNamespace()) .appendProperty("ENTITY_CLASS", data.getEntityClass()) .appendProperty("ATTRIBUTE_CODE", data.getCode()) .appendProperty("ATTRIBUTE_SET", String.join(",", getAttributesList(data))) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java index 29e621773..23dc558e6 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java @@ -64,7 +64,7 @@ protected void fillAttributes(final Properties attributes) { uses.add(abstractSourceClass); attributes.setProperty("NAME", data.getClassName()); - attributes.setProperty("NAMESPACE", data.getNamespace()); + attributes.setProperty("NAMESPACE", this.getFile().getNamespace()); attributes.setProperty( "EXTENDS", PhpClassGeneratorUtil.getNameFromFqn(abstractSourceClass) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java index 12dc3ea9c..7f456343e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java @@ -50,12 +50,8 @@ private Map getMappedAttributes(final ProductEntityData eavEntit wrapStringValueForTemplate(eavEntityData.getLabel())); mappedAttributes.put(EavAttribute.INPUT.getAttribute(), wrapStringValueForTemplate(eavEntityData.getInput())); - - final String eavSource = eavEntityData.getSource(); mappedAttributes.put(EavAttribute.SOURCE.getAttribute(), - eavSource == null || eavSource.equals(AttributeSourceModel.NULLABLE_SOURCE.getSource()) - ? null : eavSource + "::class"); - + getEntitySource(eavEntityData)); mappedAttributes.put(EavAttribute.REQUIRED.getAttribute(), Boolean.toString(eavEntityData.isRequired())); mappedAttributes.put(EavAttribute.SORT_ORDER.getAttribute(), @@ -81,4 +77,13 @@ private Map getMappedAttributes(final ProductEntityData eavEntit private String wrapStringValueForTemplate(final String value) { return "'" + value + "'"; } + + + private String getEntitySource(final ProductEntityData eavEntityData) { + final String eavSource = eavEntityData.getSource(); + + return eavSource == null + || eavSource.equals(AttributeSourceModel.NULLABLE_SOURCE.getSource()) + ? null : eavSource + "::class"; + } } diff --git a/testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php b/testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php index ee99f68e7..e9846fbc1 100644 --- a/testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php +++ b/testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php @@ -1,6 +1,6 @@ Date: Mon, 12 Apr 2021 10:30:06 +0300 Subject: [PATCH 018/111] Changed source model template --- .../fileTemplates/internal/Magento Source Model Class.php.ft | 2 +- .../SourceModelGenerator/generateFile/CustomSourceModel.php | 2 +- .../generateFileInCustomDirectory/CustomSourceModel.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/fileTemplates/internal/Magento Source Model Class.php.ft b/resources/fileTemplates/internal/Magento Source Model Class.php.ft index 9ea1e890a..108281c0e 100644 --- a/resources/fileTemplates/internal/Magento Source Model Class.php.ft +++ b/resources/fileTemplates/internal/Magento Source Model Class.php.ft @@ -17,6 +17,6 @@ class ${NAME} extends ${EXTENDS} */ public function getAllOptions(): array { - // TODO: Implement getAllOptions() method. + return []; } } diff --git a/testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php b/testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php index e9846fbc1..891b5d153 100644 --- a/testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php +++ b/testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php @@ -13,6 +13,6 @@ class CustomSourceModel extends AbstractSource */ public function getAllOptions(): array { - // TODO: Implement getAllOptions() method. + return []; } } diff --git a/testData/actions/generation/generator/SourceModelGenerator/generateFileInCustomDirectory/CustomSourceModel.php b/testData/actions/generation/generator/SourceModelGenerator/generateFileInCustomDirectory/CustomSourceModel.php index d20820add..e5eb11e9d 100644 --- a/testData/actions/generation/generator/SourceModelGenerator/generateFileInCustomDirectory/CustomSourceModel.php +++ b/testData/actions/generation/generator/SourceModelGenerator/generateFileInCustomDirectory/CustomSourceModel.php @@ -13,6 +13,6 @@ class CustomSourceModel extends AbstractSource */ public function getAllOptions(): array { - // TODO: Implement getAllOptions() method. + return []; } } From 4fa88f81535881854427f8c28b1552980f83a536 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Mon, 12 Apr 2021 12:49:25 +0300 Subject: [PATCH 019/111] Added apply_to property for attribute generation --- ...ento Eav Attribute Data Patch Class.php.ft | 2 +- resources/magento2/validation.properties | 1 + .../data/EavEntityDataInterface.java | 2 + .../generation/data/ProductEntityData.java | 10 ++++ .../dialog/NewEavAttributeDialog.form | 55 ++++++++++++++++++- .../dialog/NewEavAttributeDialog.java | 22 +++++++- .../dialog/event/ApplyToVisibleListener.java | 32 +++++++++++ .../validator/annotation/RuleRegistry.java | 4 +- .../rule/CommaSeparatedStringRule.java | 22 ++++++++ .../EavAttributeSetupPatchGenerator.java | 2 +- .../util/eav/ProductAttributeMapper.java | 5 ++ .../magento/packages/eav/EavAttribute.java | 3 +- .../idea/magento2plugin/util/RegExUtil.java | 3 + 13 files changed, 155 insertions(+), 8 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/ApplyToVisibleListener.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/CommaSeparatedStringRule.java diff --git a/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft b/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft index 30ad2dc39..6720517af 100644 --- a/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft +++ b/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft @@ -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 ] diff --git a/resources/magento2/validation.properties b/resources/magento2/validation.properties index 778209381..f8d78fcfe 100644 --- a/resources/magento2/validation.properties +++ b/resources/magento2/validation.properties @@ -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 \ No newline at end of file diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java b/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java index 0957c057c..62ae7a062 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java @@ -19,4 +19,6 @@ public interface EavEntityDataInterface { public String getDataPatchName(); public String getEntityClass(); + + public String getSource(); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java index b5d68af17..aa4558547 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java @@ -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; @@ -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; } @@ -174,6 +179,7 @@ public String getGroup() { return group; } + @Override public String getSource() { return source; } @@ -182,6 +188,10 @@ public String getScope() { return scope; } + public String getApplyTo() { + return applyTo; + } + public boolean isRequired() { return required; } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form index 3f1a813da..46a4927ed 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form @@ -3,7 +3,7 @@ - + @@ -11,7 +11,7 @@ - + @@ -322,6 +322,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java index 07a120b9f..d3fd56d21 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java @@ -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; @@ -37,6 +39,7 @@ import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JTextField; +import javax.swing.JTextPane; import javax.swing.KeyStroke; import javax.swing.event.DocumentEvent; import org.codehaus.plexus.util.StringUtils; @@ -92,6 +95,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 JTextPane applyToRecommendationTextPanel; private final Project project; private final SourceModelData sourceModelData; @@ -112,12 +121,17 @@ public NewEavAttributeDialog(final Project project, final PsiDirectory directory addActionListenersForButtons(); addCancelActionForWindow(); addCancelActionForEsc(); + addApplyToVisibilityAction(); setAutocompleteListenerForAttributeCodeField(); fillEntityComboBoxes(); addDependBetweenInputAndSourceModel(); setDefaultSources(); } + private void addApplyToVisibilityAction() { + applyToAllProductsCheckBox.addChangeListener(new ApplyToVisibleListener(applyToPanel)); + } + @SuppressWarnings("PMD.AccessorMethodGeneration") private void addDependBetweenInputAndSourceModel() { inputComboBox.addItemListener( @@ -295,7 +309,7 @@ private void generateSourceModelFile() { if (selectedSource == null || !selectedSource.getText().equals( - AttributeSourceModel.GENERATE_SOURCE.getSource() + AttributeSourceModel.GENERATE_SOURCE.getSource() )) { return; } @@ -336,6 +350,10 @@ private ProductEntityData populateProductEntityData(final ProductEntityData prod productEntityData.setScope(getAttributeScope()); productEntityData.setSource(getAttributeSource()); + if (!applyToAllProductsCheckBox.isSelected()) { + productEntityData.setApplyTo(applyToTextField.getText().trim()); + } + return productEntityData; } @@ -344,7 +362,7 @@ private String getAttributeSource() { if (selectedItem == null || selectedItem.getText().equals( - AttributeSourceModel.NULLABLE_SOURCE.getSource() + AttributeSourceModel.NULLABLE_SOURCE.getSource() )) { return null; } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/ApplyToVisibleListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/ApplyToVisibleListener.java new file mode 100644 index 000000000..a60b2d4b8 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/ApplyToVisibleListener.java @@ -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); + } + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java index 15e94f928..a47964dbf 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java @@ -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; @@ -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; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/CommaSeparatedStringRule.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/CommaSeparatedStringRule.java new file mode 100644 index 000000000..a61a6a2d7 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/CommaSeparatedStringRule.java @@ -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; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java index 49de25135..0002115c3 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java @@ -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() diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java index 7f456343e..1fda24c8f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java @@ -71,6 +71,11 @@ private Map 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())); + } + return mappedAttributes; } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java index 9ac14aa6e..2c1ebe3a8 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java @@ -19,7 +19,8 @@ public enum EavAttribute { IS_FILTERABLE_IN_GRID("is_filterable_in_grid"), VISIBLE("visible"), IS_HTML_ALLOWED_ON_FRONT("is_html_allowed_on_front"), - VISIBLE_ON_FRONT("visible_on_front"); + VISIBLE_ON_FRONT("visible_on_front"), + APPLY_TO("apply_to"); private String attribute; diff --git a/src/com/magento/idea/magento2plugin/util/RegExUtil.java b/src/com/magento/idea/magento2plugin/util/RegExUtil.java index d815864b7..5d59de80a 100644 --- a/src/com/magento/idea/magento2plugin/util/RegExUtil.java +++ b/src/com/magento/idea/magento2plugin/util/RegExUtil.java @@ -68,6 +68,9 @@ public static class Magento { public static final String XML_IDENTIFIER = "^([A-Z]+[a-zA-Z0-9]{1,}){1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}$"; + + public static final String COMMA_SEPARATED_STRING = + "^[^\\s,]+(?:,\\s*[^\\s,]+)*$"; } public class PhpRegex { From 250390c67ee69d330845279a66ee86c34e6119c5 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Mon, 12 Apr 2021 12:57:55 +0300 Subject: [PATCH 020/111] Added test for apply_to property --- .../AddAppliedToAttribute.php | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php diff --git a/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php b/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php new file mode 100644 index 000000000..7efbadc5a --- /dev/null +++ b/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php @@ -0,0 +1,101 @@ +moduleDataSetup = $moduleDataSetup; + $this->eavSetupFactory = $eavSetupFactory; + } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } + + /** + * Run code inside patch + * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert + * means run PatchInterface::revert() + * + * If we speak about data, under revert means: $transaction->rollback() + * + * @return $this + */ + public function apply() + { + /** @var EavSetup $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); + + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'applied_to_attribute', + [ + 'is_visible_in_grid' => false, + 'is_html_allowed_on_front' => false, + 'visible_on_front' => false, + 'visible' => true, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, + 'label' => 'Test Label', + 'source' => null, + 'type' => 'static', + 'is_used_in_grid' => false, + 'required' => false, + 'input' => 'text', + 'is_filterable_in_grid' => false, + 'apply_to' => 'configurable,simple', + 'sort_order' => 10, + 'group' => 'General', + ] + ); + } +} From 631cae5982d3aa48b777c0f7d741b9a74402c7ee Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Mon, 12 Apr 2021 12:58:28 +0300 Subject: [PATCH 021/111] Added test for apply_to property --- .../EavAttributeSetupPatchGeneratorTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java index 9220d35fc..a335c7ba4 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java @@ -113,4 +113,37 @@ public void testGenerateFileWithGeneratedSourceModel() { assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile); } + + public void testGenerateFileWithApplyToAttribute() { + final Project project = myFixture.getProject(); + + final ProductEntityData productEntityData = new ProductEntityData(); + productEntityData.setCode("applied_to_attribute"); + productEntityData.setVisibleInGrid(false); + productEntityData.setHtmlAllowedOnFront(false); + productEntityData.setVisibleOnFront(false); + productEntityData.setVisible(true); + productEntityData.setScope(AttributeScope.GLOBAL.getScope()); + productEntityData.setLabel("Test Label"); + productEntityData.setType("static"); + productEntityData.setUsedInGrid(false); + productEntityData.setRequired(false); + productEntityData.setInput("text"); + productEntityData.setFilterableInGrid(false); + productEntityData.setSortOrder(10); + productEntityData.setGroup("General"); + productEntityData.setApplyTo("configurable,simple"); + + productEntityData.setDataPatchName("AddAppliedToAttribute"); + productEntityData.setModuleName(MODULE_NAME); + + final EavAttributeSetupPatchGenerator setupPatchGenerator = + new EavAttributeSetupPatchGenerator(productEntityData, project); + final PsiFile dataPatchFile = setupPatchGenerator.generate("testGenerateFileWithApplyToAttribute"); + + final String filePatch = this.getFixturePath("AddAppliedToAttribute.php"); + final PsiFile expectedFile = myFixture.configureByFile(filePatch); + + assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile); + } } From 1ea811d3d0fce8c7edbfdf1ba9f99fd91dee7188 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Mon, 12 Apr 2021 14:00:33 +0300 Subject: [PATCH 022/111] Fixed panel size --- .../dialog/NewEavAttributeDialog.form | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form index 46a4927ed..0e7d386be 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form @@ -344,7 +344,7 @@ - + @@ -352,14 +352,6 @@ - - - - - - - - @@ -371,6 +363,14 @@ + + + + + + + + From 731b667509552e3a4aaf35a1bdc91dcd0870d2a5 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Tue, 13 Apr 2021 14:25:56 +0300 Subject: [PATCH 023/111] Added indexer for product types --- resources/META-INF/plugin.xml | 1 + .../dialog/NewEavAttributeDialog.form | 30 +++--- .../dialog/NewEavAttributeDialog.java | 21 +++- .../magento2plugin/indexes/IndexManager.java | 5 +- .../magento/files/ProductTypeXml.java | 33 +++++++ .../stubs/indexes/xml/ProductTypeIndex.java | 99 +++++++++++++++++++ .../util/magento/GetProductTypesListUtil.java | 25 +++++ 7 files changed, 193 insertions(+), 21 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/magento/files/ProductTypeXml.java create mode 100644 src/com/magento/idea/magento2plugin/stubs/indexes/xml/ProductTypeIndex.java create mode 100644 src/com/magento/idea/magento2plugin/util/magento/GetProductTypesListUtil.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 4beee0c89..e66ee3fc4 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -141,6 +141,7 @@ + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form index 0e7d386be..7ce800468 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form @@ -331,7 +331,7 @@ - + @@ -352,25 +352,21 @@ - + - - - - - - - - - - - - - - + - + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java index d3fd56d21..d41a12455 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java @@ -28,18 +28,21 @@ 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.JTextPane; import javax.swing.KeyStroke; import javax.swing.event.DocumentEvent; import org.codehaus.plexus.util.StringUtils; @@ -100,7 +103,7 @@ public class NewEavAttributeDialog extends AbstractDialog { private JTextField applyToTextField; private JCheckBox applyToAllProductsCheckBox; private JPanel applyToPanel; - private JTextPane applyToRecommendationTextPanel; + private JList productsTypesList; private final Project project; private final SourceModelData sourceModelData; @@ -124,10 +127,20 @@ public NewEavAttributeDialog(final Project project, final PsiDirectory directory addApplyToVisibilityAction(); setAutocompleteListenerForAttributeCodeField(); fillEntityComboBoxes(); + fillProductsTypesList(); addDependBetweenInputAndSourceModel(); setDefaultSources(); } + private void fillProductsTypesList() { + final List productTypes = GetProductTypesListUtil.execute(project); + + final DefaultListModel listModel = new DefaultListModel<>(); + listModel.addAll(productTypes); + productsTypesList.setModel(listModel); + productsTypesList.setSelectedIndex(0); + } + private void addApplyToVisibilityAction() { applyToAllProductsCheckBox.addChangeListener(new ApplyToVisibleListener(applyToPanel)); } @@ -351,7 +364,9 @@ private ProductEntityData populateProductEntityData(final ProductEntityData prod productEntityData.setSource(getAttributeSource()); if (!applyToAllProductsCheckBox.isSelected()) { - productEntityData.setApplyTo(applyToTextField.getText().trim()); + productEntityData.setApplyTo( + String.join(",", productsTypesList.getSelectedValuesList()) + ); } return productEntityData; diff --git a/src/com/magento/idea/magento2plugin/indexes/IndexManager.java b/src/com/magento/idea/magento2plugin/indexes/IndexManager.java index 9653d5c14..fc67d3273 100644 --- a/src/com/magento/idea/magento2plugin/indexes/IndexManager.java +++ b/src/com/magento/idea/magento2plugin/indexes/IndexManager.java @@ -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"}) @@ -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) { diff --git a/src/com/magento/idea/magento2plugin/magento/files/ProductTypeXml.java b/src/com/magento/idea/magento2plugin/magento/files/ProductTypeXml.java new file mode 100644 index 000000000..ea5c6a3ca --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/ProductTypeXml.java @@ -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; + } +} diff --git a/src/com/magento/idea/magento2plugin/stubs/indexes/xml/ProductTypeIndex.java b/src/com/magento/idea/magento2plugin/stubs/indexes/xml/ProductTypeIndex.java new file mode 100644 index 000000000..93f8820c4 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/stubs/indexes/xml/ProductTypeIndex.java @@ -0,0 +1,99 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.stubs.indexes.xml; + +import com.intellij.ide.highlighter.XmlFileType; +import com.intellij.psi.PsiFile; +import com.intellij.psi.xml.XmlDocument; +import com.intellij.psi.xml.XmlFile; +import com.intellij.psi.xml.XmlTag; +import com.intellij.util.indexing.*; +import com.intellij.util.io.EnumeratorStringDescriptor; +import com.intellij.util.io.KeyDescriptor; +import com.magento.idea.magento2plugin.magento.files.ProductTypeXml; +import com.magento.idea.magento2plugin.project.Settings; +import gnu.trove.THashMap; +import java.util.Map; +import org.jetbrains.annotations.NotNull; + +public class ProductTypeIndex extends ScalarIndexExtension { + private final static String TEST_DIRECTORY_PATTERN = ".*\\/[Tt]ests?\\/?.*"; + private final KeyDescriptor myKeyDescriptor = new EnumeratorStringDescriptor(); + public static final ID KEY = ID.create( + "com.magento.idea.magento2plugin.stubs.indexes.product_types"); + + @Override + public @NotNull + ID getName() { + return KEY; + } + + @Override + public @NotNull + DataIndexer getIndexer() { + return inputData -> { + final Map map = new THashMap<>(); + final String filePath = inputData.getFile().getPath(); + + if (filePath.matches(TEST_DIRECTORY_PATTERN)) { + return map; + } + + final PsiFile psiFile = inputData.getPsiFile(); + if (!Settings.isEnabled(psiFile.getProject())) { + return map; + } + + if (!(psiFile instanceof XmlFile)) { + return map; + } + + final XmlDocument xmlDocument = ((XmlFile) psiFile).getDocument(); + + if (xmlDocument == null) { + return map; + } + + final XmlTag xmlRootTag = xmlDocument.getRootTag(); + + if (xmlRootTag != null) { + parseRootTag(map, xmlRootTag); + } + + return map; + }; + } + + private void parseRootTag(final Map map, final XmlTag xmlRootTag) { + for (final XmlTag productTypeTag : xmlRootTag.findSubTags(ProductTypeXml.XML_TAG_TYPE)) { + final String productTypeName = productTypeTag.getAttributeValue(ProductTypeXml.XML_ATTRIBUTE_NAME); + map.put(productTypeName, null); + } + } + + @Override + public @NotNull + KeyDescriptor getKeyDescriptor() { + return this.myKeyDescriptor; + } + + @Override + public int getVersion() { + return 0; + } + + @Override + public FileBasedIndex.InputFilter getInputFilter() { + return file -> + file.getFileType() == XmlFileType.INSTANCE + && file.getName().equalsIgnoreCase(ProductTypeXml.FILE_NAME); + } + + @Override + public boolean dependsOnFileContent() { + return true; + } +} diff --git a/src/com/magento/idea/magento2plugin/util/magento/GetProductTypesListUtil.java b/src/com/magento/idea/magento2plugin/util/magento/GetProductTypesListUtil.java new file mode 100644 index 000000000..7638892ef --- /dev/null +++ b/src/com/magento/idea/magento2plugin/util/magento/GetProductTypesListUtil.java @@ -0,0 +1,25 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.util.magento; + +import com.intellij.openapi.project.Project; +import com.intellij.util.indexing.FileBasedIndex; +import com.magento.idea.magento2plugin.stubs.indexes.xml.ProductTypeIndex; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +public final class GetProductTypesListUtil +{ + private GetProductTypesListUtil() {} + + public static List execute(final Project project) { + final Collection productTypesList = + FileBasedIndex.getInstance().getAllKeys(ProductTypeIndex.KEY, project); + + return productTypesList.stream().sorted().collect(Collectors.toList()); + } +} From 2dd86f4624f734e8ea89a0c2e201df1f8f4277b0 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Wed, 14 Apr 2021 19:32:21 +0300 Subject: [PATCH 024/111] Added possibility to set options --- ...ento Eav Attribute Data Patch Class.php.ft | 4 +- .../generation/data/ProductEntityData.java | 19 ++++ .../dialog/NewEavAttributeDialog.form | 47 +++++++- .../dialog/NewEavAttributeDialog.java | 80 +++++++++---- ...AttributeSourcePanelComponentListener.java | 45 ++++++++ .../AttributeSourceRelationsItemListener.java | 30 +++++ .../OptionsPanelVisibilityChangeListener.java | 48 ++++++++ .../EavAttributeSetupPatchGenerator.java | 2 +- .../GetAttributeOptionPropertiesUtil.java | 55 +++++++++ .../util/eav/ProductAttributeMapper.java | 71 +++++++++++- .../packages/eav/AttributeSourceModel.java | 2 +- .../magento/packages/eav/EavAttribute.java | 3 +- .../AddAttributeWithOptionsAttribute.php | 107 ++++++++++++++++++ .../EavAttributeSetupPatchGeneratorTest.java | 42 +++++++ 14 files changed, 520 insertions(+), 35 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourcePanelComponentListener.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourceRelationsItemListener.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/OptionsPanelVisibilityChangeListener.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/GetAttributeOptionPropertiesUtil.java create mode 100644 testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php diff --git a/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft b/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft index 30ad2dc39..c235baa36 100644 --- a/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft +++ b/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft @@ -82,8 +82,8 @@ class ${CLASS_NAME} implements ${IMPLEMENTS} { '${ATTRIBUTE_CODE}', [ #set ($attributeSet = ${ATTRIBUTE_SET}) - #foreach ($attribute in $attributeSet.split(",")) - $attribute, + #foreach ($attribute in $attributeSet.split("->")) + $attribute #end ] ); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java index b5d68af17..1b1588fa8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java @@ -7,6 +7,7 @@ import com.magento.idea.magento2plugin.magento.files.EavAttributeDataPatchFile; import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity; +import java.util.Map; @SuppressWarnings({"PMD.TooManyFields"}) public class ProductEntityData implements EavEntityDataInterface { @@ -25,6 +26,8 @@ public class ProductEntityData implements EavEntityDataInterface { private boolean htmlAllowedOnFront; private boolean visibleOnFront; private int sortOrder; + private Map options; + private Map optionsSortOrder; private String dataPatchName; private String namespace; @@ -121,6 +124,22 @@ public void setModuleName(final String moduleName) { this.moduleName = moduleName; } + public void setOptions(final Map options) { + this.options = options; + } + + public void setOptionsSortOrder(final Map optionsSortOrder) { + this.optionsSortOrder = optionsSortOrder; + } + + public Map getOptions() { + return options; + } + + public Map getOptionsSortOrder() { + return optionsSortOrder; + } + @Override public String getCode() { return code; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form index 3f1a813da..f1c451af2 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form @@ -1,9 +1,9 @@ - + - + @@ -326,13 +326,13 @@ - + - + @@ -371,6 +371,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java index 07a120b9f..ea0210f9f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java @@ -12,30 +12,38 @@ 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.AttributeSourcePanelComponentListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.AttributeSourceRelationsItemListener; import com.magento.idea.magento2plugin.actions.generation.dialog.event.EavAttributeInputItemListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.OptionsPanelVisibilityChangeListener; 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.Lowercase; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.GetAttributeOptionPropertiesUtil; import com.magento.idea.magento2plugin.magento.files.SourceModelFile; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType; import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity; +import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -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.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JPanel; +import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.KeyStroke; import javax.swing.event.DocumentEvent; @@ -92,8 +100,12 @@ public class NewEavAttributeDialog extends AbstractDialog { @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Source Model Name"}) private JTextField sourceModelNameTexField; + private JTable optionTable; + private JButton addOptionButton; + private JPanel optionsPanel; private final Project project; private final SourceModelData sourceModelData; + private TableGroupWrapper entityPropertiesTableGroupWrapper; /** * Constructor. @@ -108,41 +120,57 @@ public NewEavAttributeDialog(final Project project, final PsiDirectory directory this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); this.sourceModelData = new SourceModelData(); + fillEntityComboBoxes(); + initPropertiesTable(); setPanelConfiguration(); addActionListenersForButtons(); addCancelActionForWindow(); addCancelActionForEsc(); - setAutocompleteListenerForAttributeCodeField(); - fillEntityComboBoxes(); addDependBetweenInputAndSourceModel(); + addOptionPanelListener(); + setAutocompleteListenerForAttributeCodeField(); setDefaultSources(); } + private void initPropertiesTable() { + final List columns = new LinkedList<>(Arrays.asList( + "Value", + "Sort Order" + )); + // Initialize entity properties Table Group + entityPropertiesTableGroupWrapper = new TableGroupWrapper( + optionTable, + addOptionButton, + columns, + new HashMap<>(), + new HashMap<>() + ); + entityPropertiesTableGroupWrapper.initTableGroup(); + } + @SuppressWarnings("PMD.AccessorMethodGeneration") private void addDependBetweenInputAndSourceModel() { inputComboBox.addItemListener( new EavAttributeInputItemListener(sourceComboBox) ); - sourceComboBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(final ItemEvent itemEvent) { - final String selectedSource = itemEvent.getItem().toString(); - - if (selectedSource.equals(AttributeSourceModel.GENERATE_SOURCE.getSource())) { - customSourceModelPanel.setVisible(true); - sourceModelData.setModuleName(moduleName); - - if (sourceModelDirectoryTexField.getText().trim().isEmpty()) { - sourceModelDirectoryTexField.setText(sourceModelData.getDirectory()); - } - } else { - customSourceModelPanel.setVisible(false); - } - } - }); + sourceComboBox.addItemListener( + new AttributeSourceRelationsItemListener(customSourceModelPanel) + ); - sourceModelDirectoryTexField.setText(sourceModelData.getDirectory()); + customSourceModelPanel.addComponentListener( + new AttributeSourcePanelComponentListener(sourceModelDirectoryTexField) + ); + } + + @SuppressWarnings("PMD.AccessorMethodGeneration") + private void addOptionPanelListener() { + sourceComboBox.addItemListener( + new OptionsPanelVisibilityChangeListener( + optionsPanel, + inputComboBox + ) + ); } private void setDefaultSources() { @@ -295,7 +323,7 @@ private void generateSourceModelFile() { if (selectedSource == null || !selectedSource.getText().equals( - AttributeSourceModel.GENERATE_SOURCE.getSource() + AttributeSourceModel.GENERATE_SOURCE.getSource() )) { return; } @@ -335,6 +363,10 @@ private ProductEntityData populateProductEntityData(final ProductEntityData prod productEntityData.setInput(getAttributeInput()); productEntityData.setScope(getAttributeScope()); productEntityData.setSource(getAttributeSource()); + productEntityData.setOptions(GetAttributeOptionPropertiesUtil.getValues( + entityPropertiesTableGroupWrapper.getColumnsData())); + productEntityData.setOptionsSortOrder(GetAttributeOptionPropertiesUtil.getSortOrders( + entityPropertiesTableGroupWrapper.getColumnsData())); return productEntityData; } @@ -344,7 +376,7 @@ private String getAttributeSource() { if (selectedItem == null || selectedItem.getText().equals( - AttributeSourceModel.NULLABLE_SOURCE.getSource() + AttributeSourceModel.NULLABLE_SOURCE.getSource() )) { return null; } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourcePanelComponentListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourcePanelComponentListener.java new file mode 100644 index 000000000..de00601d7 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourcePanelComponentListener.java @@ -0,0 +1,45 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.event; + +import com.magento.idea.magento2plugin.magento.files.SourceModelFile; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import javax.swing.JTextField; + +public class AttributeSourcePanelComponentListener implements ComponentListener { + private final JTextField sourceModelDirectoryTexField; + + public AttributeSourcePanelComponentListener( + final JTextField sourceModelDirectoryTexField + ) { + this.sourceModelDirectoryTexField = sourceModelDirectoryTexField; + } + + @Override + public void componentResized(final ComponentEvent componentEvent) { + // + } + + @Override + public void componentMoved(final ComponentEvent componentEvent) { + // + } + + @Override + public void componentShown(final ComponentEvent componentEvent) { + final String sourceDirectoryValue = sourceModelDirectoryTexField.getText().trim(); + + if (sourceDirectoryValue.isEmpty()) { + sourceModelDirectoryTexField.setText(SourceModelFile.DEFAULT_DIR); + } + } + + @Override + public void componentHidden(final ComponentEvent componentEvent) { + // + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourceRelationsItemListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourceRelationsItemListener.java new file mode 100644 index 000000000..986f7ea88 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourceRelationsItemListener.java @@ -0,0 +1,30 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.event; + +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import javax.swing.JPanel; + +public class AttributeSourceRelationsItemListener implements ItemListener { + private final JPanel customSourcePanel; + + public AttributeSourceRelationsItemListener(final JPanel customSourcePanel) { + this.customSourcePanel = customSourcePanel; + } + + @Override + public void itemStateChanged(final ItemEvent itemEvent) { + final String selectedSource = itemEvent.getItem().toString(); + + if (selectedSource.equals(AttributeSourceModel.GENERATE_SOURCE.getSource())) { + customSourcePanel.setVisible(true); + } else { + customSourcePanel.setVisible(false); + } + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/OptionsPanelVisibilityChangeListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/OptionsPanelVisibilityChangeListener.java new file mode 100644 index 000000000..c1ff8b062 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/OptionsPanelVisibilityChangeListener.java @@ -0,0 +1,48 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.event; + +import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import javax.swing.JComboBox; +import javax.swing.JPanel; +import org.jetbrains.annotations.NotNull; + +public class OptionsPanelVisibilityChangeListener implements ItemListener { + private final JPanel optionsPanel; + private final JComboBox inputComboBox; + + public OptionsPanelVisibilityChangeListener( + @NotNull final JPanel optionsPanel, + @NotNull final JComboBox inputComboBox + ) { + this.optionsPanel = optionsPanel; + this.inputComboBox = inputComboBox; + } + + @Override + public void itemStateChanged(final ItemEvent itemEvent) { + final String selectedSource = itemEvent.getItem().toString(); + + final ComboBoxItemData selectedInputItem = (ComboBoxItemData) inputComboBox.getSelectedItem(); + final String selectedInput = selectedInputItem == null ? "" : selectedInputItem.toString(); + + final boolean isAttributeWithoutSource = + AttributeSourceModel.NULLABLE_SOURCE.getSource().equals(selectedSource); + final boolean isAllowedInput = + AttributeInput.SELECT.getInput().equals(selectedInput) + || AttributeInput.MULTISELECT.getInput().equals(selectedInput); + + if (isAllowedInput && isAttributeWithoutSource) { + optionsPanel.setVisible(true); + } else { + optionsPanel.setVisible(false); + } + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java index 49de25135..0002115c3 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java @@ -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() diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/GetAttributeOptionPropertiesUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/GetAttributeOptionPropertiesUtil.java new file mode 100644 index 000000000..68473ef89 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/GetAttributeOptionPropertiesUtil.java @@ -0,0 +1,55 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.util; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.jetbrains.annotations.NotNull; + +public final class GetAttributeOptionPropertiesUtil { + public final static String OPTION_VALUE = "Value"; + public final static String OPTION_SORT_ORDER = "Sort Order"; + + private GetAttributeOptionPropertiesUtil() {} + + /** + * Returns sort orders for options. + * + * @param columnsData List + */ + public static Map getSortOrders( + @NotNull final List> columnsData + ) { + final Map sortOrders = new HashMap<>(); + + for (int i = 0; i < columnsData.size(); i++) { + final String sortOrder = columnsData.get(i).get(OPTION_SORT_ORDER); + if (!sortOrder.isEmpty()) { + sortOrders.put(i, sortOrder); + } + } + + return sortOrders; + } + + /** + * Returns options values. + * + * @param columnsData List + */ + public static Map getValues( + @NotNull final List> columnsData + ) { + final Map options = new HashMap<>(); + + for (int i = 0; i < columnsData.size(); i++) { + options.put(i, columnsData.get(i).get(OPTION_VALUE)); + } + + return options; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java index 7f456343e..689193f86 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java @@ -31,7 +31,7 @@ public List mapAttributesByEntityData( final String attributeValue = attributePair.getValue(); attributesWithValues.add( - String.join("=>", attributeKey, attributeValue) + String.join("=>", attributeKey, attributeValue + ",") ); } @@ -41,7 +41,6 @@ public List mapAttributesByEntityData( @SuppressWarnings({"PMD.NullAssignment"}) private Map getMappedAttributes(final ProductEntityData eavEntityData) { final Map mappedAttributes = new HashMap<>(); - mappedAttributes.put(EavAttribute.GROUP.getAttribute(), wrapStringValueForTemplate(eavEntityData.getGroup())); mappedAttributes.put(EavAttribute.TYPE.getAttribute(), @@ -71,6 +70,16 @@ private Map getMappedAttributes(final ProductEntityData eavEntit mappedAttributes.put(EavAttribute.VISIBLE_ON_FRONT.getAttribute(), Boolean.toString(eavEntityData.isVisibleOnFront())); + final String attributeOptions = getMappedOptions( + eavEntityData.getOptions(), + eavEntityData.getOptionsSortOrder() + ); + + if (!attributeOptions.isEmpty()) { + mappedAttributes.put(EavAttribute.OPTION.getAttribute(), + getMappedOptions(eavEntityData.getOptions(), eavEntityData.getOptionsSortOrder())); + } + return mappedAttributes; } @@ -86,4 +95,62 @@ private String getEntitySource(final ProductEntityData eavEntityData) { || eavSource.equals(AttributeSourceModel.NULLABLE_SOURCE.getSource()) ? null : eavSource + "::class"; } + + private String getMappedOptions( + final Map optionValues, + final Map optionSortOrders + ) { + if (optionValues == null || optionValues.isEmpty()) { + return ""; + } + + return "[" + getParsedOptions(optionValues) + + (optionSortOrders == null || optionSortOrders.isEmpty() + ? "->" : "," + getParsedOptionSortOrders(optionSortOrders)) + "]"; + } + + private String getParsedOptions(final Map optionValues) { + final String valueNode = "->" + wrapStringValueForTemplate("value") + " => "; + final StringBuilder optionsContent = new StringBuilder(); + + for (final Integer optionKey : optionValues.keySet()) { + final String optionValue = optionValues.get(optionKey); + + if (optionValue.isEmpty()) { + continue; + } + + optionsContent + .append("->") + .append(wrapStringValueForTemplate("option_" + optionKey)) + .append(" => ") + .append("[") + .append(wrapStringValueForTemplate(optionValue)) + .append("], "); + } + + return valueNode + "[" + optionsContent + "->]"; + } + + private String getParsedOptionSortOrders(final Map optionSortOrders) { + final String orderNode = "->" + wrapStringValueForTemplate("order") + " => "; + final StringBuilder ordersContent = new StringBuilder(); + + for (final Integer optionKey : optionSortOrders.keySet()) { + final String orderValue = optionSortOrders.get(optionKey); + + if (orderValue.isEmpty()) { + continue; + } + + ordersContent + .append("->") + .append(wrapStringValueForTemplate("option_" + optionKey)) + .append(" => ") + .append(orderValue) + .append(","); + } + + return orderNode + "[" + ordersContent + "->]->"; + } } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java index 561353822..a19075813 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java @@ -11,7 +11,7 @@ public enum AttributeSourceModel { CONFIG("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Config"), STORE("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Store"), GENERATE_SOURCE("Custom Source"), - NULLABLE_SOURCE("Set Source Model as null"); + NULLABLE_SOURCE("Without Source Model"); private String source; diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java index 9ac14aa6e..0a636e267 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java @@ -19,7 +19,8 @@ public enum EavAttribute { IS_FILTERABLE_IN_GRID("is_filterable_in_grid"), VISIBLE("visible"), IS_HTML_ALLOWED_ON_FRONT("is_html_allowed_on_front"), - VISIBLE_ON_FRONT("visible_on_front"); + VISIBLE_ON_FRONT("visible_on_front"), + OPTION("option"); private String attribute; diff --git a/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php b/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php new file mode 100644 index 000000000..fbdfba9f7 --- /dev/null +++ b/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php @@ -0,0 +1,107 @@ +moduleDataSetup = $moduleDataSetup; + $this->eavSetupFactory = $eavSetupFactory; + } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } + + /** + * Run code inside patch + * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert + * means run PatchInterface::revert() + * + * If we speak about data, under revert means: $transaction->rollback() + * + * @return $this + */ + public function apply() + { + /** @var EavSetup $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); + + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'attribute_with_options', + [ + 'is_visible_in_grid' => false, + 'is_html_allowed_on_front' => false, + 'visible_on_front' => false, + 'visible' => true, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, + 'label' => 'Attribute With Options', + 'source' => null, + 'type' => 'varchar', + 'is_used_in_grid' => false, + 'required' => false, + 'input' => 'multiselect', + 'is_filterable_in_grid' => false, + 'sort_order' => 10, + 'group' => 'General', + 'option' => [ + 'value' => [ + 'option_0' => ['option1'], + 'option_1' => ['option2'], + 'option_2' => ['option3'], + ] + ], + ] + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java index 9220d35fc..7e2c257ee 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java @@ -9,6 +9,8 @@ import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; +import java.util.HashMap; +import java.util.Map; public class EavAttributeSetupPatchGeneratorTest extends BaseGeneratorTestCase { private final static String MODULE_NAME = "Foo_Bar"; @@ -113,4 +115,44 @@ public void testGenerateFileWithGeneratedSourceModel() { assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile); } + + public void testGenerateFileWithOptions() { + final Project project = myFixture.getProject(); + + final ProductEntityData productEntityData = new ProductEntityData(); + productEntityData.setCode("attribute_with_options"); + productEntityData.setVisibleInGrid(false); + productEntityData.setHtmlAllowedOnFront(false); + productEntityData.setVisibleOnFront(false); + productEntityData.setVisible(true); + productEntityData.setScope(AttributeScope.GLOBAL.getScope()); + productEntityData.setLabel("Attribute With Options"); + productEntityData.setType("varchar"); + productEntityData.setUsedInGrid(false); + productEntityData.setRequired(false); + productEntityData.setInput("multiselect"); + productEntityData.setSource(AttributeSourceModel.NULLABLE_SOURCE.getSource()); + productEntityData.setFilterableInGrid(false); + productEntityData.setSortOrder(10); + productEntityData.setGroup("General"); + + final Map options = new HashMap<>(); + options.put(0, "option1"); + options.put(1, "option2"); + options.put(2, "option3"); + + productEntityData.setOptions(options); + + productEntityData.setDataPatchName("AddAttributeWithOptionsAttribute"); + productEntityData.setModuleName(MODULE_NAME); + + final EavAttributeSetupPatchGenerator setupPatchGenerator = + new EavAttributeSetupPatchGenerator(productEntityData, project); + final PsiFile dataPatchFile = setupPatchGenerator.generate("testGenerateFileWithOptions"); + + final String filePatch = this.getFixturePath("AddAttributeWithOptionsAttribute.php"); + final PsiFile expectedFile = myFixture.configureByFile(filePatch); + + assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile); + } } From 38d9892bb51511bd25589beb3d34945999317b01 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Wed, 14 Apr 2021 20:08:31 +0300 Subject: [PATCH 025/111] Fixed field content --- .../AttributeSourcePanelComponentListener.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourcePanelComponentListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourcePanelComponentListener.java index de00601d7..d2e3ce010 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourcePanelComponentListener.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourcePanelComponentListener.java @@ -31,15 +31,19 @@ public void componentMoved(final ComponentEvent componentEvent) { @Override public void componentShown(final ComponentEvent componentEvent) { + initSetDirectoryFieldValue(); + } + + @Override + public void componentHidden(final ComponentEvent componentEvent) { + initSetDirectoryFieldValue(); + } + + private void initSetDirectoryFieldValue() { final String sourceDirectoryValue = sourceModelDirectoryTexField.getText().trim(); if (sourceDirectoryValue.isEmpty()) { sourceModelDirectoryTexField.setText(SourceModelFile.DEFAULT_DIR); } } - - @Override - public void componentHidden(final ComponentEvent componentEvent) { - // - } } From c995db4666c593c9f360db3b915ae2dfb46756f2 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Sat, 17 Apr 2021 19:29:53 +0300 Subject: [PATCH 026/111] Refactored base eav attribute dialog hierarchy --- resources/META-INF/plugin.xml | 7 +- .../dialog/NewEavAttributeDialog.java | 459 ------------------ .../dialog/NewProductEavAttributeDialog.java | 271 +++++++++++ ... NewProductProductEavAttributeDialog.form} | 80 ++- .../eavattribute/EavAttributeDialog.java | 393 +++++++++++++++ .../ApplyToVisibleListener.java | 8 +- ...AttributeSourcePanelComponentListener.java | 2 +- .../AttributeSourceRelationsItemListener.java | 10 +- .../event/eavdialog/DataPatchNameAdapter.java | 88 ++++ .../EavAttributeInputItemListener.java | 2 +- .../OptionsPanelVisibilityChangeListener.java | 12 +- .../eavdialog/SourceModelNameAdapter.java | 54 +++ .../dialog/util/eavdialog/AttributeUtil.java | 90 ++++ .../NewEavAttributeAction.java | 28 +- .../NewProductEavAttributeAction.java | 29 ++ .../actions/groups/NewEavAttributeGroup.java | 30 ++ 16 files changed, 1023 insertions(+), 540 deletions(-) delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java rename src/com/magento/idea/magento2plugin/actions/generation/dialog/{NewEavAttributeDialog.form => NewProductProductEavAttributeDialog.form} (91%) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java rename src/com/magento/idea/magento2plugin/actions/generation/dialog/event/{ => eavdialog}/ApplyToVisibleListener.java (81%) rename src/com/magento/idea/magento2plugin/actions/generation/dialog/event/{ => eavdialog}/AttributeSourcePanelComponentListener.java (98%) rename src/com/magento/idea/magento2plugin/actions/generation/dialog/event/{ => eavdialog}/AttributeSourceRelationsItemListener.java (77%) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java rename src/com/magento/idea/magento2plugin/actions/generation/dialog/event/{ => eavdialog}/EavAttributeInputItemListener.java (98%) rename src/com/magento/idea/magento2plugin/actions/generation/dialog/event/{ => eavdialog}/OptionsPanelVisibilityChangeListener.java (85%) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/util/eavdialog/AttributeUtil.java rename src/com/magento/idea/magento2plugin/actions/generation/{ => eavattribute}/NewEavAttributeAction.java (63%) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java create mode 100644 src/com/magento/idea/magento2plugin/actions/groups/NewEavAttributeGroup.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index e66ee3fc4..ae0b72970 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -73,10 +73,15 @@ - + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java deleted file mode 100644 index 34a3c73c2..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.java +++ /dev/null @@ -1,459 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.intellij.ui.DocumentAdapter; -import com.magento.idea.magento2plugin.actions.generation.NewEavAttributeAction; -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.AttributeSourcePanelComponentListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.AttributeSourceRelationsItemListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.EavAttributeInputItemListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.OptionsPanelVisibilityChangeListener; -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; -import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.GetAttributeOptionPropertiesUtil; -import com.magento.idea.magento2plugin.magento.files.SourceModelFile; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType; -import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity; -import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; -import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import com.magento.idea.magento2plugin.util.magento.GetProductTypesListUtil; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedList; -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.JTable; -import javax.swing.JTextField; -import javax.swing.KeyStroke; -import javax.swing.event.DocumentEvent; -import org.codehaus.plexus.util.StringUtils; -import org.jetbrains.annotations.NotNull; - -@SuppressWarnings({ - "PMD.TooManyFields", - "PMD.ExcessiveImports", - "PMD.TooManyMethods", - "PMD.UnusedPrivateField" -}) -public class NewEavAttributeDialog extends AbstractDialog { - private final String moduleName; - private JPanel contentPanel; - private JButton buttonOK; - private JButton buttonCancel; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Code"}) - @FieldValidation(rule = RuleRegistry.LOWERCASE, - message = {Lowercase.MESSAGE, "Attribute Code"}) - private JTextField codeTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Label"}) - private JTextField labelTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Group"}) - private JTextField groupTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Data Patch Name"}) - private JTextField dataPatchNameTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) - @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, - message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) - private JTextField sortOrderTextField; - private JComboBox entityType; - private JComboBox inputComboBox; - private JComboBox typeComboBox; - private JComboBox scopeComboBox; - private JComboBox sourceComboBox; - private JCheckBox requiredCheckBox; - private JCheckBox usedInGridGridCheckBox; - private JCheckBox visibleInGridCheckBox; - private JCheckBox filterableInGridCheckBox; - private JCheckBox visibleCheckBox; - private JCheckBox htmlAllowedOnCheckBox; - private JCheckBox visibleOnFrontCheckBox; - private JPanel sourcePanel; - private JPanel customSourceModelPanel; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Source Model Directory"}) - private JTextField sourceModelDirectoryTexField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Source Model Name"}) - private JTextField sourceModelNameTexField; - private JTable optionTable; - private JButton addOptionButton; - private JPanel optionsPanel; - @FieldValidation(rule = RuleRegistry.COMMA_SEPARATED_STRING, - message = {CommaSeparatedStringRule.MESSAGE, "Apply To"}) - private JCheckBox applyToAllProductsCheckBox; - private JPanel applyToPanel; - private JList productsTypesList; - private final Project project; - private final SourceModelData sourceModelData; - private TableGroupWrapper entityPropertiesTableGroupWrapper; - - /** - * Constructor. - * - * @param project Project - * @param directory PsiDirectory - */ - public NewEavAttributeDialog(final Project project, final PsiDirectory directory) { - super(); - - this.project = project; - this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); - this.sourceModelData = new SourceModelData(); - - fillEntityComboBoxes(); - initPropertiesTable(); - setPanelConfiguration(); - addActionListenersForButtons(); - addCancelActionForWindow(); - addCancelActionForEsc(); - addApplyToVisibilityAction(); - fillEntityComboBoxes(); - fillProductsTypesList(); - addDependBetweenInputAndSourceModel(); - addOptionPanelListener(); - setAutocompleteListenerForAttributeCodeField(); - setDefaultSources(); - } - - private void initPropertiesTable() { - final List columns = new LinkedList<>(Arrays.asList( - "Value", - "Sort Order" - )); - // Initialize entity properties Table Group - entityPropertiesTableGroupWrapper = new TableGroupWrapper( - optionTable, - addOptionButton, - columns, - new HashMap<>(), - new HashMap<>() - ); - entityPropertiesTableGroupWrapper.initTableGroup(); - } - - private void fillProductsTypesList() { - final List productTypes = GetProductTypesListUtil.execute(project); - - final DefaultListModel 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( - new EavAttributeInputItemListener(sourceComboBox) - ); - - sourceComboBox.addItemListener( - new AttributeSourceRelationsItemListener(customSourceModelPanel) - ); - - customSourceModelPanel.addComponentListener( - new AttributeSourcePanelComponentListener(sourceModelDirectoryTexField) - ); - } - - @SuppressWarnings("PMD.AccessorMethodGeneration") - private void addOptionPanelListener() { - sourceComboBox.addItemListener( - new OptionsPanelVisibilityChangeListener( - optionsPanel, - inputComboBox - ) - ); - } - - private void setDefaultSources() { - final ComboBoxItemData generateSourceItem = new ComboBoxItemData( - AttributeSourceModel.GENERATE_SOURCE.getSource(), - AttributeSourceModel.GENERATE_SOURCE.getSource() - ); - final ComboBoxItemData defaultSourceItem = new ComboBoxItemData( - AttributeSourceModel.NULLABLE_SOURCE.name(), - AttributeSourceModel.NULLABLE_SOURCE.getSource() - ); - sourceComboBox.addItem(defaultSourceItem); - sourceComboBox.addItem(generateSourceItem); - - sourceComboBox.setSelectedItem(defaultSourceItem); - } - - private void setPanelConfiguration() { - setContentPane(contentPanel); - setModal(true); - getRootPane().setDefaultButton(buttonOK); - } - - private void addActionListenersForButtons() { - buttonOK.addActionListener(e -> onOk()); - buttonCancel.addActionListener(e -> onCancel()); - } - - private void addCancelActionForWindow() { - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - } - - private void addCancelActionForEsc() { - contentPanel.registerKeyboardAction( - event -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); - } - - @SuppressWarnings("PMD.AccessorMethodGeneration") - private void setAutocompleteListenerForAttributeCodeField() { - this.codeTextField.getDocument().addDocumentListener(new DocumentAdapter() { - @Override - protected void textChanged(final @NotNull DocumentEvent event) { - final String attributeCode = codeTextField.getText(); - updateDataPatchFileName(attributeCode); - updateSourceModelName(attributeCode); - } - }); - } - - @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") - private void fillEntityComboBoxes() { - for (final EavEntity entity : EavEntity.values()) { - entityType.addItem( - new ComboBoxItemData(entity.name(), entity.name()) - ); - } - - for (final AttributeType typeValue : AttributeType.values()) { - typeComboBox.addItem( - new ComboBoxItemData(typeValue.getType(), typeValue.getType()) - ); - } - - for (final AttributeInput inputValue : AttributeInput.values()) { - inputComboBox.addItem( - new ComboBoxItemData(inputValue.getInput(), inputValue.getInput()) - ); - } - - for (final AttributeScope globalValue : AttributeScope.values()) { - scopeComboBox.addItem( - new ComboBoxItemData(globalValue.getScope(), globalValue.name()) - ); - } - } - - private void updateDataPatchFileName(final String attributeCode) { - if (attributeCode.isEmpty()) { - dataPatchNameTextField.setText(""); - - return; - } - - final String dataPatchSuffix = "Add"; - final String dataPatchPrefix = "Attribute"; - - final String[] attributeCodeParts = attributeCode.split("_"); - String fileName = ""; - - for (final String fileNamePart : attributeCodeParts) { - fileName = String.join("", fileName, StringUtils.capitalise(fileNamePart)); - } - - dataPatchNameTextField.setText(dataPatchSuffix + fileName + dataPatchPrefix); - } - - private void updateSourceModelName(final String attributeCode) { - - if (attributeCode.isEmpty()) { - sourceModelNameTexField.setText(""); - - return; - } - - final String[] attributeCodeParts = attributeCode.split("_"); - final StringBuilder sourceModelClassName = new StringBuilder(); - - for (final String codePart : attributeCodeParts) { - sourceModelClassName.append(StringUtils.capitalise(codePart)); - } - - sourceModelNameTexField.setText(sourceModelClassName.toString()); - } - - /** - * Open dialog. - * - * @param project Project - * @param directory PsiDirectory - */ - public static void open(final Project project, final PsiDirectory directory) { - final NewEavAttributeDialog dialog = new NewEavAttributeDialog(project, directory); - dialog.pack(); - dialog.centerDialog(dialog); - dialog.setVisible(true); - } - - private void onOk() { - if (!validateFormFields()) { - return; - } - - generateSourceModelFile(); - generateDataPatchFile(); - - setVisible(false); - } - - private void generateSourceModelFile() { - final ComboBoxItemData selectedSource = (ComboBoxItemData) sourceComboBox.getSelectedItem(); - - if (selectedSource == null - || !selectedSource.getText().equals( - AttributeSourceModel.GENERATE_SOURCE.getSource() - )) { - return; - } - - sourceModelData.setModuleName(moduleName); - sourceModelData.setClassName(sourceModelNameTexField.getText().trim()); - sourceModelData.setDirectory(sourceModelDirectoryTexField.getText().trim()); - - new SourceModelGenerator(sourceModelData, project, true) - .generate(NewEavAttributeAction.ACTION_NAME, false); - } - - private void generateDataPatchFile() { - new EavAttributeSetupPatchGenerator( - populateProductEntityData(new ProductEntityData()), - project, - true - ).generate(NewEavAttributeAction.ACTION_NAME, true); - } - - private ProductEntityData populateProductEntityData(final ProductEntityData productEntityData) { - productEntityData.setModuleName(moduleName); - - productEntityData.setDataPatchName(dataPatchNameTextField.getText().trim()); - productEntityData.setGroup(groupTextField.getText().trim()); - productEntityData.setCode(codeTextField.getText().trim()); - productEntityData.setLabel(labelTextField.getText().trim()); - productEntityData.setSortOrder(Integer.parseInt(sortOrderTextField.getText().trim())); - productEntityData.setRequired(requiredCheckBox.isSelected()); - productEntityData.setUsedInGrid(usedInGridGridCheckBox.isSelected()); - productEntityData.setVisibleInGrid(visibleInGridCheckBox.isSelected()); - productEntityData.setFilterableInGrid(filterableInGridCheckBox.isSelected()); - productEntityData.setVisible(visibleCheckBox.isSelected()); - productEntityData.setHtmlAllowedOnFront(htmlAllowedOnCheckBox.isSelected()); - productEntityData.setVisibleOnFront(visibleOnFrontCheckBox.isSelected()); - productEntityData.setType(getAttributeType()); - productEntityData.setInput(getAttributeInput()); - productEntityData.setScope(getAttributeScope()); - productEntityData.setSource(getAttributeSource()); - productEntityData.setOptions(GetAttributeOptionPropertiesUtil.getValues( - entityPropertiesTableGroupWrapper.getColumnsData())); - productEntityData.setOptionsSortOrder(GetAttributeOptionPropertiesUtil.getSortOrders( - entityPropertiesTableGroupWrapper.getColumnsData())); - - if (!applyToAllProductsCheckBox.isSelected()) { - productEntityData.setApplyTo( - String.join(",", productsTypesList.getSelectedValuesList()) - ); - } - - return productEntityData; - } - - private String getAttributeSource() { - final ComboBoxItemData selectedItem = (ComboBoxItemData) sourceComboBox.getSelectedItem(); - - if (selectedItem == null - || selectedItem.getText().equals( - AttributeSourceModel.NULLABLE_SOURCE.getSource() - )) { - return null; - } - - if (selectedItem.getText().equals(AttributeSourceModel.GENERATE_SOURCE.getSource()) - && sourceModelData != null) { - - return "\\" + new SourceModelFile( - sourceModelData.getModuleName(), - sourceModelData.getClassName(), - sourceModelData.getDirectory() - ).getClassFqn(); - } - - return sourceComboBox.getSelectedItem().toString(); - } - - private String getAttributeScope() { - final ComboBoxItemData selectedScope = (ComboBoxItemData) scopeComboBox.getSelectedItem(); - - if (selectedScope != null) { - selectedScope.getKey().trim(); - } - - return AttributeScope.GLOBAL.getScope(); - } - - private String getAttributeInput() { - final ComboBoxItemData selectedAttributeInput = - (ComboBoxItemData) inputComboBox.getSelectedItem(); - - if (selectedAttributeInput != null) { - return selectedAttributeInput.getText().trim(); - } - - return ""; - } - - private String getAttributeType() { - final ComboBoxItemData selectedItem = (ComboBoxItemData) typeComboBox.getSelectedItem(); - - if (selectedItem != null) { - return selectedItem.getText(); - } - - return ""; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java new file mode 100644 index 000000000..b98fed97c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java @@ -0,0 +1,271 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; +import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData; +import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.ApplyToVisibleListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.util.eavdialog.AttributeUtil; +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.util.GetAttributeOptionPropertiesUtil; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; +import com.magento.idea.magento2plugin.util.magento.GetProductTypesListUtil; +import java.util.List; +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.JTextField; + +@SuppressWarnings({ + "PMD.TooManyFields", + "PMD.ExcessiveImports", + "PMD.TooManyMethods", + "PMD.UnusedPrivateField" +}) +public class NewProductEavAttributeDialog extends EavAttributeDialog { + + private final static String ENTITY_NAME = "Product"; + private JPanel contentPanel; + private JButton buttonOK; + private JButton buttonCancel; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Code"}) + @FieldValidation(rule = RuleRegistry.LOWERCASE, + message = {Lowercase.MESSAGE, "Attribute Code"}) + private JTextField codeTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Label"}) + private JTextField labelTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Group"}) + private JTextField groupTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Data Patch Name"}) + private JTextField dataPatchNameTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) + @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, + message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) + private JTextField sortOrderTextField; + private JComboBox inputComboBox; + private JComboBox typeComboBox; + private JComboBox scopeComboBox; + private JComboBox sourceComboBox; + private JCheckBox requiredCheckBox; + private JCheckBox usedInGridGridCheckBox; + private JCheckBox visibleInGridCheckBox; + private JCheckBox filterableInGridCheckBox; + private JCheckBox visibleCheckBox; + private JCheckBox htmlAllowedOnCheckBox; + private JCheckBox visibleOnFrontCheckBox; + private JPanel sourcePanel; + private JPanel customSourceModelPanel; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Source Model Directory"}) + private JTextField sourceModelDirectoryTexField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Source Model Name"}) + private JTextField sourceModelNameTexField; + private JTable optionsTable; + private JButton addNewOptionButton; + private JPanel optionsPanel; + @FieldValidation(rule = RuleRegistry.COMMA_SEPARATED_STRING, + message = {CommaSeparatedStringRule.MESSAGE, "Apply To"}) + private JCheckBox applyToAllProductsCheckBox; + private JPanel applyToPanel; + private JList productsTypesList; + + /** + * Constructor. + * + * @param project Project + * @param directory PsiDirectory + */ + public NewProductEavAttributeDialog( + final Project project, + final PsiDirectory directory, + final String actionName + ) { + super(project, directory, actionName); + } + + @Override + protected void initBaseDialogState() { + super.initBaseDialogState(); + fillAttributeScopeComboBoxes(); + addApplyToVisibilityAction(); + fillProductsTypesList(); + } + + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + protected void fillAttributeScopeComboBoxes() { + for (final AttributeScope globalValue : AttributeScope.values()) { + scopeComboBox.addItem( + new ComboBoxItemData(globalValue.getScope(), globalValue.name()) + ); + } + } + + @Override + protected JPanel getContentPanel() { + return contentPanel; + } + + @Override + protected JButton getButtonOk() { + return buttonOK; + } + + @Override + protected JButton getButtonCancel() { + return buttonCancel; + } + + @Override + protected JComboBox getAttributeTypeCompoBox() { + return typeComboBox; + } + + @Override + protected JComboBox getAttributeInputComboBox() { + return inputComboBox; + } + + @Override + protected JTable getOptionsTable() { + return optionsTable; + } + + @Override + protected JButton getNewOptionButton() { + return addNewOptionButton; + } + + @Override + protected JComboBox getAttributeSourceComboBox() { + return sourceComboBox; + } + + @Override + protected JTextField getAttributeSourceModelNameTexField() { + return sourceModelNameTexField; + } + + @Override + protected JTextField getSourceModelDirectoryTexField() { + return sourceModelDirectoryTexField; + } + + @Override + protected JPanel getAttributeCustomSourceModelPanel() { + return customSourceModelPanel; + } + + @Override + protected JPanel getAttributeOptionsPanel() { + return optionsPanel; + } + + @Override + protected JTextField getAttributeCodeTextField() { + return codeTextField; + } + + @Override + protected JTextField getDataPatchNameTextField() { + return dataPatchNameTextField; + } + + @Override + protected JTextField getSourceModelNameTexField() { + return sourceModelNameTexField; + } + + @Override + protected String getEntityName() { + return ENTITY_NAME; + } + + @Override + protected EavEntityDataInterface getEavEntityData() { + return populateProductEntityData(new ProductEntityData()); + } + + private ProductEntityData populateProductEntityData(final ProductEntityData productEntityData) { + productEntityData.setModuleName(moduleName); + + productEntityData.setDataPatchName(dataPatchNameTextField.getText().trim()); + productEntityData.setGroup(groupTextField.getText().trim()); + productEntityData.setCode(codeTextField.getText().trim()); + productEntityData.setLabel(labelTextField.getText().trim()); + productEntityData.setSortOrder(Integer.parseInt(sortOrderTextField.getText().trim())); + productEntityData.setRequired(requiredCheckBox.isSelected()); + productEntityData.setUsedInGrid(usedInGridGridCheckBox.isSelected()); + productEntityData.setVisibleInGrid(visibleInGridCheckBox.isSelected()); + productEntityData.setFilterableInGrid(filterableInGridCheckBox.isSelected()); + productEntityData.setVisible(visibleCheckBox.isSelected()); + productEntityData.setHtmlAllowedOnFront(htmlAllowedOnCheckBox.isSelected()); + productEntityData.setVisibleOnFront(visibleOnFrontCheckBox.isSelected()); + productEntityData.setType( + AttributeUtil.getBackendTypeBySelectedItem( + (ComboBoxItemData) typeComboBox.getSelectedItem() + ) + ); + productEntityData.setInput( + AttributeUtil.getInputTypeBySelectedItem( + (ComboBoxItemData) inputComboBox.getSelectedItem() + ) + ); + productEntityData.setScope( + AttributeUtil.getScopeClassBySelectedItem( + (ComboBoxItemData) scopeComboBox.getSelectedItem() + ) + ); + productEntityData.setSource( + AttributeUtil.getSourceClassBySelectedItem( + (ComboBoxItemData) sourceComboBox.getSelectedItem(), + sourceModelData + ) + ); + productEntityData.setOptions(GetAttributeOptionPropertiesUtil.getValues( + entityPropertiesTableGroupWrapper.getColumnsData())); + productEntityData.setOptionsSortOrder(GetAttributeOptionPropertiesUtil.getSortOrders( + entityPropertiesTableGroupWrapper.getColumnsData())); + + if (!applyToAllProductsCheckBox.isSelected()) { + productEntityData.setApplyTo( + String.join(",", productsTypesList.getSelectedValuesList()) + ); + } + + return productEntityData; + } + + protected void addApplyToVisibilityAction() { + applyToAllProductsCheckBox.addChangeListener(new ApplyToVisibleListener(applyToPanel)); + } + + private void fillProductsTypesList() { + final List productTypes = GetProductTypesListUtil.execute(project); + + final DefaultListModel listModel = new DefaultListModel<>(); + listModel.addAll(productTypes); + productsTypesList.setModel(listModel); + productsTypesList.setSelectedIndex(0); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductProductEavAttributeDialog.form similarity index 91% rename from src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form rename to src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductProductEavAttributeDialog.form index f324611f7..977e99753 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEavAttributeDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductProductEavAttributeDialog.form @@ -1,9 +1,9 @@ -
+ - + @@ -11,7 +11,7 @@ - + @@ -21,25 +21,9 @@ - - - - - - - - - - - - - - - - - + @@ -49,7 +33,7 @@ - + @@ -57,7 +41,7 @@ - + @@ -67,7 +51,7 @@ - + @@ -77,7 +61,7 @@ - + @@ -85,7 +69,7 @@ - + @@ -93,7 +77,7 @@ - + @@ -103,7 +87,7 @@ - + @@ -113,7 +97,7 @@ - + @@ -121,7 +105,7 @@ - + @@ -131,13 +115,13 @@ - + - + @@ -145,7 +129,7 @@ - + @@ -155,7 +139,7 @@ - + @@ -165,7 +149,7 @@ - + @@ -174,7 +158,7 @@ - + @@ -182,7 +166,7 @@ - + @@ -192,7 +176,7 @@ - + @@ -202,7 +186,7 @@ - + @@ -211,7 +195,7 @@ - + @@ -220,19 +204,19 @@ - + - + - + @@ -243,7 +227,7 @@ - + @@ -275,7 +259,7 @@ - + @@ -324,7 +308,7 @@ - + @@ -334,7 +318,7 @@ - + @@ -437,7 +421,7 @@ - + @@ -447,7 +431,7 @@ - + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java new file mode 100644 index 000000000..a530bb311 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java @@ -0,0 +1,393 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; +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.AbstractDialog; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourcePanelComponentListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourceRelationsItemListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.DataPatchNameAdapter; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.EavAttributeInputItemListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.OptionsPanelVisibilityChangeListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.SourceModelNameAdapter; +import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType; +import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; +import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.KeyStroke; + +@SuppressWarnings({"PMD.TooManyMethods"}) +public abstract class EavAttributeDialog extends AbstractDialog { + + protected String moduleName; + protected Project project; + protected String actionName; + protected TableGroupWrapper entityPropertiesTableGroupWrapper; + protected SourceModelData sourceModelData; + + protected abstract EavEntityDataInterface getEavEntityData(); + + protected abstract JPanel getContentPanel(); + + protected abstract JButton getButtonOk(); + + protected abstract JButton getButtonCancel(); + + protected abstract JComboBox getAttributeTypeCompoBox(); + + protected abstract JComboBox getAttributeInputComboBox(); + + protected abstract JTable getOptionsTable(); + + protected abstract JButton getNewOptionButton(); + + protected abstract JComboBox getAttributeSourceComboBox(); + + protected abstract JTextField getAttributeSourceModelNameTexField(); + + protected abstract JTextField getSourceModelDirectoryTexField(); + + protected abstract JPanel getAttributeCustomSourceModelPanel(); + + protected abstract JPanel getAttributeOptionsPanel(); + + protected abstract JTextField getAttributeCodeTextField(); + + protected abstract JTextField getDataPatchNameTextField(); + + protected abstract JTextField getSourceModelNameTexField(); + + protected abstract String getEntityName(); + + /** + * Constructor. + * + * @param project Project + * @param directory PsiDirectory + * @param actionName String + */ + public EavAttributeDialog( + final Project project, + final PsiDirectory directory, + final String actionName + ) { + super(); + + this.project = project; + this.actionName = actionName; + this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); + this.sourceModelData = new SourceModelData(); + } + + /** + * Open dialog window. + */ + public void open() { + this.initBaseDialogState(); + pack(); + centerDialog(this); + setVisible(true); + } + + protected void initBaseDialogState() { + this.setPanelConfiguration(); + this.fillAttributeTypeComboBox(getAttributeTypeCompoBox()); + this.fillAttributeInputComboBox(getAttributeInputComboBox()); + + this.initPropertiesTable( + new LinkedList<>(Arrays.asList( + "Value", + "Sort Order" + )), + getOptionsTable(), + getNewOptionButton(), + getDefaultColumnsValues(), + getColumnsSources() + ); + + this.addActionListenersForOkButton(getButtonOk()); + this.addActionListenersForOkCancel(getButtonCancel()); + + this.addCancelActionForWindow(); + this.addCancelActionForEsc(); + + this.setAttributeInputComboBoxAction(getAttributeSourceComboBox()); + this.setSourceComboBoxAction(getAttributeSourceComboBox()); + + this.setSourceModelPanelAction( + getAttributeCustomSourceModelPanel(), + getSourceModelDirectoryTexField() + ); + this.addOptionPanelListener( + getAttributeSourceComboBox(), + getAttributeInputComboBox(), + getAttributeOptionsPanel() + ); + this.setDefaultSources(getAttributeSourceComboBox()); + this.setAutocompleteListenerForDataPathNameField( + getAttributeCodeTextField(), + getDataPatchNameTextField() + ); + this.setAutocompleteListenerForSourceModelNameField( + getAttributeCodeTextField(), + getSourceModelNameTexField() + ); + } + + protected void setPanelConfiguration() { + setContentPane(this.getContentPanel()); + setModal(this.isModalWindow()); + getRootPane().setDefaultButton(this.getButtonOk()); + } + + protected boolean isModalWindow() { + return true; + } + + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + protected void fillAttributeTypeComboBox(final JComboBox typeComboBox) { + if (typeComboBox == null) { + return; + } + + for (final AttributeType typeValue : AttributeType.values()) { + typeComboBox.addItem( + new ComboBoxItemData(typeValue.getType(), typeValue.getType()) + ); + } + } + + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + protected void fillAttributeInputComboBox(final JComboBox inputComboBox) { + if (inputComboBox == null) { + return; + } + + for (final AttributeInput inputValue : AttributeInput.values()) { + inputComboBox.addItem( + new ComboBoxItemData(inputValue.getInput(), inputValue.getInput()) + ); + } + } + + protected void initPropertiesTable( + final List columns, + final JTable optionsTable, + final JButton newOptionButton, + final Map defaultColumnsValues, + final Map> columnsSources + + ) { + // Initialize entity properties Table Group + entityPropertiesTableGroupWrapper = new TableGroupWrapper( + optionsTable, + newOptionButton, + columns, + defaultColumnsValues, + columnsSources + ); + entityPropertiesTableGroupWrapper.initTableGroup(); + } + + protected Map getDefaultColumnsValues() { + return new HashMap<>(); + } + + protected Map> getColumnsSources() { + return new HashMap<>(); + } + + protected void addActionListenersForOkButton(final JButton okButton) { + okButton.addActionListener(e -> onOk()); + } + + protected void addActionListenersForOkCancel(final JButton cancelButton) { + cancelButton.addActionListener(e -> onCancel()); + } + + protected void onOk() { + if (!validateFormFields()) { + return; + } + + generateSourceModelFile(); + generateDataPatchFile(); + + setVisible(false); + } + + protected void generateSourceModelFile() { + final ComboBoxItemData selectedSource = + (ComboBoxItemData) getAttributeSourceComboBox().getSelectedItem(); + + if (selectedSource == null + || !selectedSource.getText().equals( + AttributeSourceModel.GENERATE_SOURCE.getSource() + )) { + return; + } + + sourceModelData.setModuleName(moduleName); + sourceModelData.setClassName(getAttributeSourceModelNameTexField().getText().trim()); + sourceModelData.setDirectory(getSourceModelDirectoryTexField().getText().trim()); + + new SourceModelGenerator(sourceModelData, project, true) + .generate(actionName, false); + } + + protected void generateDataPatchFile() { + new EavAttributeSetupPatchGenerator( + getEavEntityData(), + project, + true + ).generate(actionName, true); + } + + protected void addCancelActionForWindow() { + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(final WindowEvent event) { + onCancel(); + } + }); + } + + protected void addCancelActionForEsc() { + getContentPanel().registerKeyboardAction( + event -> onCancel(), + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT + ); + } + + @SuppressWarnings("PMD.AccessorMethodGeneration") + protected void setAttributeInputComboBoxAction( + final JComboBox sourceComboBox + ) { + if (sourceComboBox == null) { + return; + } + + getAttributeInputComboBox().addItemListener( + new EavAttributeInputItemListener(sourceComboBox) + ); + } + + @SuppressWarnings("PMD.AccessorMethodGeneration") + protected void setSourceComboBoxAction(final JComboBox sourceComboBox) { + if (sourceComboBox == null) { + return; + } + + sourceComboBox.addItemListener( + new AttributeSourceRelationsItemListener(getAttributeCustomSourceModelPanel()) + ); + } + + @SuppressWarnings("PMD.AccessorMethodGeneration") + protected void setSourceModelPanelAction( + final JPanel attributeCustomSourceModelPanel, + final JTextField sourceModelDirectoryTexField + ) { + if (attributeCustomSourceModelPanel == null || sourceModelDirectoryTexField == null) { + return; + } + + attributeCustomSourceModelPanel.addComponentListener( + new AttributeSourcePanelComponentListener(sourceModelDirectoryTexField) + ); + } + + @SuppressWarnings("PMD.AccessorMethodGeneration") + protected void addOptionPanelListener( + final JComboBox attributeSourceComboBox, + final JComboBox attributeInputComboBox, + final JPanel attributeOptionsPanel + ) { + if (attributeSourceComboBox == null + || attributeInputComboBox == null + || attributeOptionsPanel == null + ) { + return; + } + + attributeSourceComboBox.addItemListener( + new OptionsPanelVisibilityChangeListener( + attributeOptionsPanel, + attributeInputComboBox + ) + ); + } + + protected void setDefaultSources(final JComboBox sourceComboBox) { + if (sourceComboBox == null) { + return; + } + + final ComboBoxItemData generateSourceItem = new ComboBoxItemData( + AttributeSourceModel.GENERATE_SOURCE.getSource(), + AttributeSourceModel.GENERATE_SOURCE.getSource() + ); + final ComboBoxItemData defaultSourceItem = new ComboBoxItemData( + AttributeSourceModel.NULLABLE_SOURCE.name(), + AttributeSourceModel.NULLABLE_SOURCE.getSource() + ); + + sourceComboBox.addItem(defaultSourceItem); + sourceComboBox.addItem(generateSourceItem); + + sourceComboBox.setSelectedItem(defaultSourceItem); + } + + @SuppressWarnings("PMD.AccessorMethodGeneration") + protected void setAutocompleteListenerForDataPathNameField( + final JTextField mainTextField, + final JTextField dependentTextField + + ) { + if (mainTextField == null || dependentTextField == null) { + return; + } + + mainTextField.getDocument() + .addDocumentListener(new DataPatchNameAdapter(dependentTextField, getEntityName())); + } + + @SuppressWarnings("PMD.AccessorMethodGeneration") + protected void setAutocompleteListenerForSourceModelNameField( + final JTextField mainTextField, + final JTextField dependentTextField + ) { + if (mainTextField == null || dependentTextField == null) { + return; + } + + mainTextField.getDocument() + .addDocumentListener(new SourceModelNameAdapter(dependentTextField)); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/ApplyToVisibleListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/ApplyToVisibleListener.java similarity index 81% rename from src/com/magento/idea/magento2plugin/actions/generation/dialog/event/ApplyToVisibleListener.java rename to src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/ApplyToVisibleListener.java index a60b2d4b8..1b9133e07 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/ApplyToVisibleListener.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/ApplyToVisibleListener.java @@ -3,7 +3,7 @@ * See COPYING.txt for license details. */ -package com.magento.idea.magento2plugin.actions.generation.dialog.event; +package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; import javax.swing.JCheckBox; import javax.swing.JPanel; @@ -23,10 +23,6 @@ public ApplyToVisibleListener(@NotNull final JPanel applyToPanel) { public void stateChanged(final ChangeEvent changeEvent) { final JCheckBox checkBox = (JCheckBox) changeEvent.getSource(); - if (checkBox.isSelected()) { - applyToPanel.setVisible(false); - } else { - applyToPanel.setVisible(true); - } + applyToPanel.setVisible(!checkBox.isSelected()); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourcePanelComponentListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeSourcePanelComponentListener.java similarity index 98% rename from src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourcePanelComponentListener.java rename to src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeSourcePanelComponentListener.java index d2e3ce010..b7d1eaecd 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourcePanelComponentListener.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeSourcePanelComponentListener.java @@ -3,7 +3,7 @@ * See COPYING.txt for license details. */ -package com.magento.idea.magento2plugin.actions.generation.dialog.event; +package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; import com.magento.idea.magento2plugin.magento.files.SourceModelFile; import java.awt.event.ComponentEvent; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourceRelationsItemListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeSourceRelationsItemListener.java similarity index 77% rename from src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourceRelationsItemListener.java rename to src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeSourceRelationsItemListener.java index 986f7ea88..ccf84ceb3 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/AttributeSourceRelationsItemListener.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeSourceRelationsItemListener.java @@ -3,7 +3,7 @@ * See COPYING.txt for license details. */ -package com.magento.idea.magento2plugin.actions.generation.dialog.event; +package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; import java.awt.event.ItemEvent; @@ -21,10 +21,8 @@ public AttributeSourceRelationsItemListener(final JPanel customSourcePanel) { public void itemStateChanged(final ItemEvent itemEvent) { final String selectedSource = itemEvent.getItem().toString(); - if (selectedSource.equals(AttributeSourceModel.GENERATE_SOURCE.getSource())) { - customSourcePanel.setVisible(true); - } else { - customSourcePanel.setVisible(false); - } + customSourcePanel.setVisible( + selectedSource.equals(AttributeSourceModel.GENERATE_SOURCE.getSource()) + ); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java new file mode 100644 index 000000000..68d4be8a9 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java @@ -0,0 +1,88 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; + +import com.intellij.ui.DocumentAdapter; +import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import org.codehaus.plexus.util.StringUtils; +import org.jetbrains.annotations.NotNull; + +public class DataPatchNameAdapter extends DocumentAdapter { + + private static final String NAME_PREFIX = "Add"; + private static final String NAME_SUFFIX = "Attribute"; + private final String entityType; + private final JTextField dataPatchNameTextField; + + /** + * Constructor. + * + * @param dataPatchNameTextField JTextField + */ + public DataPatchNameAdapter(final JTextField dataPatchNameTextField) { + super(); + + this.dataPatchNameTextField = dataPatchNameTextField; + entityType = ""; + } + + /** + * Constructor. + * + * @param dataPatchNameTextField JTextField + * @param entityType String + */ + public DataPatchNameAdapter( + final JTextField dataPatchNameTextField, + final String entityType + ) { + super(); + + this.dataPatchNameTextField = dataPatchNameTextField; + this.entityType = entityType; + } + + @Override + protected void textChanged(@NotNull final DocumentEvent event) { + final Document document = event.getDocument(); + + try { + final String attributeCode = document.getText( + 0, document.getEndPosition().getOffset() + ).trim(); + updateDataPatchFileName(attributeCode); + } catch (BadLocationException badLocationException) { + return; + } + } + + private void updateDataPatchFileName(final String attributeCode) { + if (attributeCode.isEmpty()) { + dataPatchNameTextField.setText(""); + + return; + } + + final String[] attributeCodeParts = attributeCode.split("_"); + String fileName = ""; + + for (final String fileNamePart : attributeCodeParts) { + fileName = String.join("", fileName, StringUtils.capitalise(fileNamePart)); + } + + dataPatchNameTextField.setText( + String.join( + "", + NAME_PREFIX, + fileName, + StringUtils.capitalise(entityType), NAME_SUFFIX + ) + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/EavAttributeInputItemListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/EavAttributeInputItemListener.java similarity index 98% rename from src/com/magento/idea/magento2plugin/actions/generation/dialog/event/EavAttributeInputItemListener.java rename to src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/EavAttributeInputItemListener.java index 038795da9..fbe835fec 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/EavAttributeInputItemListener.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/EavAttributeInputItemListener.java @@ -3,7 +3,7 @@ * See COPYING.txt for license details. */ -package com.magento.idea.magento2plugin.actions.generation.dialog.event; +package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/OptionsPanelVisibilityChangeListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/OptionsPanelVisibilityChangeListener.java similarity index 85% rename from src/com/magento/idea/magento2plugin/actions/generation/dialog/event/OptionsPanelVisibilityChangeListener.java rename to src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/OptionsPanelVisibilityChangeListener.java index c1ff8b062..ffbdd34f9 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/OptionsPanelVisibilityChangeListener.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/OptionsPanelVisibilityChangeListener.java @@ -3,7 +3,7 @@ * See COPYING.txt for license details. */ -package com.magento.idea.magento2plugin.actions.generation.dialog.event; +package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; @@ -16,11 +16,11 @@ public class OptionsPanelVisibilityChangeListener implements ItemListener { private final JPanel optionsPanel; - private final JComboBox inputComboBox; + private final JComboBox inputComboBox; public OptionsPanelVisibilityChangeListener( @NotNull final JPanel optionsPanel, - @NotNull final JComboBox inputComboBox + @NotNull final JComboBox inputComboBox ) { this.optionsPanel = optionsPanel; this.inputComboBox = inputComboBox; @@ -39,10 +39,6 @@ public void itemStateChanged(final ItemEvent itemEvent) { AttributeInput.SELECT.getInput().equals(selectedInput) || AttributeInput.MULTISELECT.getInput().equals(selectedInput); - if (isAllowedInput && isAttributeWithoutSource) { - optionsPanel.setVisible(true); - } else { - optionsPanel.setVisible(false); - } + optionsPanel.setVisible(isAllowedInput && isAttributeWithoutSource); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java new file mode 100644 index 000000000..de3ec4abc --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java @@ -0,0 +1,54 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; + +import com.intellij.ui.DocumentAdapter; +import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import org.codehaus.plexus.util.StringUtils; +import org.jetbrains.annotations.NotNull; + +public class SourceModelNameAdapter extends DocumentAdapter { + + private final JTextField sourceModelNameTexField; + + public SourceModelNameAdapter(final JTextField sourceModelNameTexField) { + super(); + this.sourceModelNameTexField = sourceModelNameTexField; + } + + @Override + protected void textChanged(@NotNull final DocumentEvent event) { + final Document document = event.getDocument(); + try { + final String attributeCode = document.getText( + 0, document.getEndPosition().getOffset() + ).trim(); + updateSourceModelName(attributeCode); + } catch (BadLocationException badLocationException) { + return; + } + } + + private void updateSourceModelName(final String attributeCode) { + if (attributeCode.isEmpty()) { + sourceModelNameTexField.setText(""); + + return; + } + + final String[] attributeCodeParts = attributeCode.split("_"); + final StringBuilder sourceModelClassName = new StringBuilder(); + + for (final String codePart : attributeCodeParts) { + sourceModelClassName.append(StringUtils.capitalise(codePart)); + } + + sourceModelNameTexField.setText(sourceModelClassName.toString()); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/eavdialog/AttributeUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/eavdialog/AttributeUtil.java new file mode 100644 index 000000000..0f9f212b3 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/eavdialog/AttributeUtil.java @@ -0,0 +1,90 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.util.eavdialog; + +import com.magento.idea.magento2plugin.actions.generation.data.SourceModelData; +import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +import com.magento.idea.magento2plugin.magento.files.SourceModelFile; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; + +public final class AttributeUtil { + + private AttributeUtil() {} + + /** + * Return actual source class by selected item. + * + * @param selectedSourceItem ComboBoxItemData + * @param sourceModelData SourceModelData + * @return String + */ + public static String getSourceClassBySelectedItem( + final ComboBoxItemData selectedSourceItem, + final SourceModelData sourceModelData + ) { + if (selectedSourceItem == null + || selectedSourceItem.getText().equals( + AttributeSourceModel.NULLABLE_SOURCE.getSource() + )) { + return null; + } + + if (selectedSourceItem.getText().equals(AttributeSourceModel.GENERATE_SOURCE.getSource()) + && sourceModelData != null) { + + return "\\" + new SourceModelFile( + sourceModelData.getModuleName(), + sourceModelData.getClassName(), + sourceModelData.getDirectory() + ).getClassFqn(); + } + + return selectedSourceItem.toString(); + } + + /** + * Return actual scope class by selected item. + * + * @param selectedScopeItem ComboBoxItemData + * @return String + */ + public static String getScopeClassBySelectedItem(final ComboBoxItemData selectedScopeItem) { + if (selectedScopeItem != null) { + selectedScopeItem.getKey().trim(); + } + + return AttributeScope.GLOBAL.getScope(); + } + + /** + * Return actual input type by selected item. + * + * @param selectedInputItem ComboBoxItemData + * @return String + */ + public static String getInputTypeBySelectedItem(final ComboBoxItemData selectedInputItem) { + if (selectedInputItem != null) { + return selectedInputItem.getText().trim(); + } + + return ""; + } + + /** + * Return actual backend type by selected item. + * + * @param selectedTypeItem ComboBoxItemData + * @return String + */ + public static String getBackendTypeBySelectedItem(final ComboBoxItemData selectedTypeItem) { + if (selectedTypeItem != null) { + return selectedTypeItem.getText(); + } + + return ""; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewEavAttributeAction.java similarity index 63% rename from src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java rename to src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewEavAttributeAction.java index 84766ba40..c2d480193 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/NewEavAttributeAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewEavAttributeAction.java @@ -3,7 +3,7 @@ * See COPYING.txt for license details. */ -package com.magento.idea.magento2plugin.actions.generation; +package com.magento.idea.magento2plugin.actions.generation.eavattribute; import com.intellij.ide.IdeView; import com.intellij.openapi.actionSystem.AnAction; @@ -13,16 +13,17 @@ import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; -import com.magento.idea.magento2plugin.MagentoIcons; -import com.magento.idea.magento2plugin.actions.generation.dialog.NewEavAttributeDialog; +import com.magento.idea.magento2plugin.actions.generation.dialog.NewProductEavAttributeDialog; +import javax.swing.Icon; import org.jetbrains.annotations.NotNull; -public class NewEavAttributeAction extends AnAction { - public static final String ACTION_NAME = "Magento 2 EAV Attribute"; - public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Attribute"; - - public NewEavAttributeAction() { - super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); +public abstract class NewEavAttributeAction extends AnAction { + public NewEavAttributeAction( + final String actionName, + final String actionDescription, + final Icon icon + ) { + super(actionName, actionDescription, icon); } @Override @@ -43,11 +44,18 @@ public void actionPerformed(final @NotNull AnActionEvent event) { return; } - NewEavAttributeDialog.open(project, directory); + final NewProductEavAttributeDialog newProductEavAttributeDialog = + getDialogWindow(project, directory); + newProductEavAttributeDialog.open(); } @Override public boolean isDumbAware() { return false; } + + protected abstract NewProductEavAttributeDialog getDialogWindow( + Project project, + PsiDirectory directory + ); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java new file mode 100644 index 000000000..6c37f324f --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java @@ -0,0 +1,29 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.eavattribute; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.magento.idea.magento2plugin.MagentoIcons; +import com.magento.idea.magento2plugin.actions.generation.dialog.NewProductEavAttributeDialog; + +public class NewProductEavAttributeAction extends NewEavAttributeAction { + + public static final String ACTION_NAME = "Product Attribute"; + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Product Attribute"; + + public NewProductEavAttributeAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); + } + + @Override + protected NewProductEavAttributeDialog getDialogWindow( + final Project project, + final PsiDirectory directory + ) { + return new NewProductEavAttributeDialog(project, directory, ACTION_NAME); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/groups/NewEavAttributeGroup.java b/src/com/magento/idea/magento2plugin/actions/groups/NewEavAttributeGroup.java new file mode 100644 index 000000000..e104d4c18 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/groups/NewEavAttributeGroup.java @@ -0,0 +1,30 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.groups; + +import com.intellij.ide.actions.NonTrivialActionGroup; +import com.intellij.openapi.util.IconLoader; +import com.magento.idea.magento2plugin.MagentoIcons; +import javax.swing.Icon; +import org.jetbrains.annotations.NotNull; + +public class NewEavAttributeGroup extends NonTrivialActionGroup { + + /** + * Group for eav attribute generation actions. + */ + public NewEavAttributeGroup() { + super(); + + this.getTemplatePresentation().setIcon(new IconLoader.LazyIcon() { + @NotNull + @Override + protected Icon compute() { + return MagentoIcons.MODULE; + } + }); + } +} From b8dcda7917aa9d74407c4bc8b12ca25c56aac8cc Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Sun, 18 Apr 2021 19:07:30 +0300 Subject: [PATCH 027/111] Fixed classes after refactoring --- ...buteDialog.form => NewProductEavAttributeDialog.form} | 0 .../generation/eavattribute/NewEavAttributeAction.java | 9 ++++----- .../eavattribute/NewProductEavAttributeAction.java | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) rename src/com/magento/idea/magento2plugin/actions/generation/dialog/{NewProductProductEavAttributeDialog.form => NewProductEavAttributeDialog.form} (100%) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductProductEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form similarity index 100% rename from src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductProductEavAttributeDialog.form rename to src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form diff --git a/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewEavAttributeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewEavAttributeAction.java index c2d480193..698917073 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewEavAttributeAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewEavAttributeAction.java @@ -13,7 +13,7 @@ import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; -import com.magento.idea.magento2plugin.actions.generation.dialog.NewProductEavAttributeDialog; +import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; import javax.swing.Icon; import org.jetbrains.annotations.NotNull; @@ -44,9 +44,8 @@ public void actionPerformed(final @NotNull AnActionEvent event) { return; } - final NewProductEavAttributeDialog newProductEavAttributeDialog = - getDialogWindow(project, directory); - newProductEavAttributeDialog.open(); + final EavAttributeDialog eavAttributeDialog = getDialogWindow(project, directory); + eavAttributeDialog.open(); } @Override @@ -54,7 +53,7 @@ public boolean isDumbAware() { return false; } - protected abstract NewProductEavAttributeDialog getDialogWindow( + protected abstract EavAttributeDialog getDialogWindow( Project project, PsiDirectory directory ); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java index 6c37f324f..1fa44915c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java @@ -9,6 +9,7 @@ import com.intellij.psi.PsiDirectory; import com.magento.idea.magento2plugin.MagentoIcons; import com.magento.idea.magento2plugin.actions.generation.dialog.NewProductEavAttributeDialog; +import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; public class NewProductEavAttributeAction extends NewEavAttributeAction { @@ -20,7 +21,7 @@ public NewProductEavAttributeAction() { } @Override - protected NewProductEavAttributeDialog getDialogWindow( + protected EavAttributeDialog getDialogWindow( final Project project, final PsiDirectory directory ) { From 896ea26ce968805b10636240ed190903e13e9915 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Mon, 19 Apr 2021 12:15:54 +0300 Subject: [PATCH 028/111] Implemented CR recommendation --- .../dialog/NewProductEavAttributeDialog.java | 2 +- .../event/eavdialog/DataPatchNameAdapter.java | 4 +-- .../eavdialog/SourceModelNameAdapter.java | 4 +-- .../util/EavAttributeCodeSeparatorUtil.java | 27 +++++++++++++++++++ .../actions/groups/NewEavAttributeGroup.java | 2 +- 5 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/util/EavAttributeCodeSeparatorUtil.java diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java index b98fed97c..7602cbfff 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java @@ -93,7 +93,7 @@ public class NewProductEavAttributeDialog extends EavAttributeDialog { /** * Constructor. * - * @param project Project + * @param project Project * @param directory PsiDirectory */ public NewProductEavAttributeDialog( diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java index 68d4be8a9..57d9fd7a7 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java @@ -6,6 +6,7 @@ package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; import com.intellij.ui.DocumentAdapter; +import com.magento.idea.magento2plugin.actions.generation.dialog.util.EavAttributeCodeSeparatorUtil; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.text.BadLocationException; @@ -69,10 +70,9 @@ private void updateDataPatchFileName(final String attributeCode) { return; } - final String[] attributeCodeParts = attributeCode.split("_"); String fileName = ""; - for (final String fileNamePart : attributeCodeParts) { + for (final String fileNamePart : EavAttributeCodeSeparatorUtil.execute(attributeCode)) { fileName = String.join("", fileName, StringUtils.capitalise(fileNamePart)); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java index de3ec4abc..18e4e89ee 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java @@ -6,6 +6,7 @@ package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; import com.intellij.ui.DocumentAdapter; +import com.magento.idea.magento2plugin.actions.generation.dialog.util.EavAttributeCodeSeparatorUtil; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.text.BadLocationException; @@ -42,10 +43,9 @@ private void updateSourceModelName(final String attributeCode) { return; } - final String[] attributeCodeParts = attributeCode.split("_"); final StringBuilder sourceModelClassName = new StringBuilder(); - for (final String codePart : attributeCodeParts) { + for (final String codePart : EavAttributeCodeSeparatorUtil.execute(attributeCode)) { sourceModelClassName.append(StringUtils.capitalise(codePart)); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/EavAttributeCodeSeparatorUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/EavAttributeCodeSeparatorUtil.java new file mode 100644 index 000000000..a298cc89c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/EavAttributeCodeSeparatorUtil.java @@ -0,0 +1,27 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.util; + +import org.jetbrains.annotations.NotNull; + +public final class EavAttributeCodeSeparatorUtil { + + public static final String ATTRIBUTE_SEPARATOR = "_"; + + private EavAttributeCodeSeparatorUtil(){} + + /** + * Return separated attribute code. + * + * @param attributeCode String + * @return String[] + */ + @NotNull + public static String[] execute(final String attributeCode) { + return attributeCode.split(ATTRIBUTE_SEPARATOR); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/groups/NewEavAttributeGroup.java b/src/com/magento/idea/magento2plugin/actions/groups/NewEavAttributeGroup.java index e104d4c18..c057e6c22 100644 --- a/src/com/magento/idea/magento2plugin/actions/groups/NewEavAttributeGroup.java +++ b/src/com/magento/idea/magento2plugin/actions/groups/NewEavAttributeGroup.java @@ -14,7 +14,7 @@ public class NewEavAttributeGroup extends NonTrivialActionGroup { /** - * Group for eav attribute generation actions. + * Group for Eav attribute generation actions. */ public NewEavAttributeGroup() { super(); From 424a66b9065dad150a62659eac007a2eb4718265 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Mon, 19 Apr 2021 13:01:13 +0300 Subject: [PATCH 029/111] Renamed util class --- .../dialog/event/eavdialog/DataPatchNameAdapter.java | 4 ++-- .../dialog/event/eavdialog/SourceModelNameAdapter.java | 4 ++-- ...eCodeSeparatorUtil.java => SplitEavAttributeCodeUtil.java} | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) rename src/com/magento/idea/magento2plugin/actions/generation/dialog/util/{EavAttributeCodeSeparatorUtil.java => SplitEavAttributeCodeUtil.java} (84%) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java index 57d9fd7a7..536b1a487 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java @@ -6,7 +6,7 @@ package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; import com.intellij.ui.DocumentAdapter; -import com.magento.idea.magento2plugin.actions.generation.dialog.util.EavAttributeCodeSeparatorUtil; +import com.magento.idea.magento2plugin.actions.generation.dialog.util.SplitEavAttributeCodeUtil; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.text.BadLocationException; @@ -72,7 +72,7 @@ private void updateDataPatchFileName(final String attributeCode) { String fileName = ""; - for (final String fileNamePart : EavAttributeCodeSeparatorUtil.execute(attributeCode)) { + for (final String fileNamePart : SplitEavAttributeCodeUtil.execute(attributeCode)) { fileName = String.join("", fileName, StringUtils.capitalise(fileNamePart)); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java index 18e4e89ee..1128e2ef1 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java @@ -6,7 +6,7 @@ package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; import com.intellij.ui.DocumentAdapter; -import com.magento.idea.magento2plugin.actions.generation.dialog.util.EavAttributeCodeSeparatorUtil; +import com.magento.idea.magento2plugin.actions.generation.dialog.util.SplitEavAttributeCodeUtil; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.text.BadLocationException; @@ -45,7 +45,7 @@ private void updateSourceModelName(final String attributeCode) { final StringBuilder sourceModelClassName = new StringBuilder(); - for (final String codePart : EavAttributeCodeSeparatorUtil.execute(attributeCode)) { + for (final String codePart : SplitEavAttributeCodeUtil.execute(attributeCode)) { sourceModelClassName.append(StringUtils.capitalise(codePart)); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/EavAttributeCodeSeparatorUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/SplitEavAttributeCodeUtil.java similarity index 84% rename from src/com/magento/idea/magento2plugin/actions/generation/dialog/util/EavAttributeCodeSeparatorUtil.java rename to src/com/magento/idea/magento2plugin/actions/generation/dialog/util/SplitEavAttributeCodeUtil.java index a298cc89c..3f70f962c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/EavAttributeCodeSeparatorUtil.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/SplitEavAttributeCodeUtil.java @@ -8,11 +8,11 @@ import org.jetbrains.annotations.NotNull; -public final class EavAttributeCodeSeparatorUtil { +public final class SplitEavAttributeCodeUtil { public static final String ATTRIBUTE_SEPARATOR = "_"; - private EavAttributeCodeSeparatorUtil(){} + private SplitEavAttributeCodeUtil(){} /** * Return separated attribute code. From 6686d97e5fb18cb02449aaac151d98440ceae252 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Mon, 19 Apr 2021 15:15:18 +0300 Subject: [PATCH 030/111] Added category dialog and generation, refactored structure --- resources/META-INF/plugin.xml | 3 +- .../generation/data/CategoryEntityData.java | 202 ++++++++++ .../data/EavEntityDataInterface.java | 65 +++- .../generation/data/ProductEntityData.java | 32 +- .../dialog/NewCategoryEavAttributeDialog.form | 354 ++++++++++++++++++ .../dialog/NewCategoryEavAttributeDialog.java | 235 ++++++++++++ .../dialog/NewProductEavAttributeDialog.java | 62 +-- .../eavattribute/EavAttributeDialog.java | 94 ++++- .../NewCategoryEavAttributeAction.java | 25 ++ .../util/eav/AttributeMapperFactory.java | 2 + .../util/eav/CategoryAttributeMapper.java | 31 ++ .../util/eav/DefaultAttributeMapper.java | 165 ++++++++ .../util/eav/ProductAttributeMapper.java | 178 ++------- .../packages/eav/AttributeBackendModel.java | 21 ++ ...vAttribute.java => AttributeProperty.java} | 9 +- .../magento/packages/eav/EavEntity.java | 3 +- ...ibutePropertySetupPatchGeneratorTest.java} | 2 +- 17 files changed, 1297 insertions(+), 186 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/CategoryEntityData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CategoryAttributeMapper.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeBackendModel.java rename src/com/magento/idea/magento2plugin/magento/packages/eav/{EavAttribute.java => AttributeProperty.java} (81%) rename tests/com/magento/idea/magento2plugin/actions/generation/generator/{EavAttributeSetupPatchGeneratorTest.java => AttributePropertySetupPatchGeneratorTest.java} (99%) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index ae0b72970..f8cfa1663 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -78,7 +78,8 @@ - + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryEntityData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryEntityData.java new file mode 100644 index 000000000..71159a15c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryEntityData.java @@ -0,0 +1,202 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity; +import java.util.Map; + +@SuppressWarnings({"PMD.TooManyFields"}) +public class CategoryEntityData implements EavEntityDataInterface { + private String group; + private String code; + private String type; + private String label; + private String input; + private String source; + private String scope; + private String dataPatchName; + private String namespace; + private String directory; + private String moduleName; + private String backendModel; + private int sortOrder; + private boolean required; + private boolean visible; + private Map options; + private Map optionsSortOrder; + + @Override + public void setCode(final String code) { + this.code = code; + } + + @Override + public void setType(final String type) { + this.type = type; + } + + @Override + public void setLabel(final String label) { + this.label = label; + } + + @Override + public void setInput(final String input) { + this.input = input; + } + + @Override + public void setNamespace(final String namespace) { + this.namespace = namespace; + } + + @Override + public void setModuleName(final String moduleName) { + this.moduleName = moduleName; + } + + @Override + public void setDirectory(final String directory) { + this.directory = directory; + } + + @Override + public void setDataPatchName(final String dataPatchName) { + this.dataPatchName = dataPatchName; + } + + @Override + public void setSource(final String source) { + this.source = source; + } + + @Override + public void setSortOrder(final int sortOrder) { + this.sortOrder = sortOrder; + } + + @Override + public void setOptions(final Map options) { + this.options = options; + } + + @Override + public void setOptionsSortOrder(final Map optionsSortOrder) { + this.optionsSortOrder = optionsSortOrder; + } + + @Override + public void setRequired(final boolean required) { + this.required = required; + } + + @Override + public void setVisible(final boolean visible) { + this.visible = visible; + } + + @Override + public void setBackendModel(final String model) { + this.backendModel = model; + } + + public void setGroup(final String group) { + this.group = group; + } + + public void setScope(final String scope) { + this.scope = scope; + } + + @Override + public String getCode() { + return code; + } + + @Override + public String getType() { + return type; + } + + @Override + public String getLabel() { + return label; + } + + @Override + public String getInput() { + return input; + } + + @Override + public String getNamespace() { + return namespace; + } + + @Override + public String getModuleName() { + return moduleName; + } + + @Override + public String getDirectory() { + return directory; + } + + @Override + public String getDataPatchName() { + return dataPatchName; + } + + @Override + public String getEntityClass() { + return EavEntity.CATEGORY.getEntityClass(); + } + + @Override + public String getSource() { + return source; + } + + @Override + public String getBackendModel() { + return backendModel; + } + + @Override + public int getSortOrder() { + return sortOrder; + } + + @Override + public Map getOptions() { + return options; + } + + @Override + public Map getOptionsSortOrder() { + return optionsSortOrder; + } + + @Override + public boolean isRequired() { + return this.required; + } + + @Override + public boolean isVisible() { + return this.visible; + } + + public String getGroup() { + return group; + } + + public String getScope() { + return scope; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java b/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java index 62ae7a062..85b219b29 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java @@ -1,24 +1,69 @@ package com.magento.idea.magento2plugin.actions.generation.data; +import java.util.Map; + @SuppressWarnings({"PMD.UnnecessaryModifier"}) public interface EavEntityDataInterface { - public String getCode(); - public String getType(); + void setCode(final String code); + + void setType(final String type); + + void setLabel(final String label); + + void setInput(final String input); + + void setNamespace(final String namespace); + + void setModuleName(final String moduleName); + + void setDirectory(final String directory); + + void setDataPatchName(final String dataPatchName); + + void setSource(final String source); + + void setSortOrder(final int sortOrder); + + void setOptions(final Map options); + + void setOptionsSortOrder(final Map optionsSortOrder); + + void setRequired(final boolean required); + + void setVisible(final boolean visible); + + void setBackendModel(final String model); + + String getCode(); + + String getType(); + + String getLabel(); + + String getInput(); + + String getNamespace(); + + String getModuleName(); + + String getDirectory(); + + String getDataPatchName(); - public String getLabel(); + String getEntityClass(); - public String getInput(); + String getSource(); - public String getNamespace(); + String getBackendModel(); - public String getModuleName(); + int getSortOrder(); - public String getDirectory(); + Map getOptions(); - public String getDataPatchName(); + Map getOptionsSortOrder(); - public String getEntityClass(); + boolean isRequired(); - public String getSource(); + boolean isVisible(); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java index 9126beeaa..99ac0b70d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java @@ -9,7 +9,7 @@ import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity; import java.util.Map; -@SuppressWarnings({"PMD.TooManyFields"}) +@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessivePublicCount"}) public class ProductEntityData implements EavEntityDataInterface { private String group; private String code; @@ -19,6 +19,7 @@ public class ProductEntityData implements EavEntityDataInterface { private String source; private String scope; private String applyTo; + private String backendModel; private boolean required; private boolean usedInGrid; private boolean visibleInGrid; @@ -53,22 +54,27 @@ public void setGroup(final String group) { this.group = group; } + @Override public void setCode(final String code) { this.code = code; } + @Override public void setType(final String type) { this.type = type; } + @Override public void setLabel(final String label) { this.label = label; } + @Override public void setInput(final String input) { this.input = input; } + @Override public void setSource(final String source) { this.source = source; } @@ -81,6 +87,7 @@ public void setApplyTo(final String applyTo) { this.applyTo = applyTo; } + @Override public void setRequired(final boolean required) { this.required = required; } @@ -97,10 +104,16 @@ public void setFilterableInGrid(final boolean filterableInGrid) { this.filterableInGrid = filterableInGrid; } + @Override public void setVisible(final boolean visible) { this.visible = visible; } + @Override + public void setBackendModel(final String model) { + this.backendModel = model; + } + public void setHtmlAllowedOnFront(final boolean htmlAllowedOnFront) { this.htmlAllowedOnFront = htmlAllowedOnFront; } @@ -109,38 +122,47 @@ public void setVisibleOnFront(final boolean visibleOnFront) { this.visibleOnFront = visibleOnFront; } + @Override public void setSortOrder(final int sortOrder) { this.sortOrder = sortOrder; } + @Override public void setDataPatchName(final String dataPatchName) { this.dataPatchName = dataPatchName; } + @Override public void setNamespace(final String namespace) { this.namespace = namespace; } + @Override public void setDirectory(final String directory) { this.directory = directory; } + @Override public void setModuleName(final String moduleName) { this.moduleName = moduleName; } + @Override public void setOptions(final Map options) { this.options = options; } + @Override public void setOptionsSortOrder(final Map optionsSortOrder) { this.optionsSortOrder = optionsSortOrder; } + @Override public Map getOptions() { return options; } + @Override public Map getOptionsSortOrder() { return optionsSortOrder; } @@ -203,6 +225,11 @@ public String getSource() { return source; } + @Override + public String getBackendModel() { + return backendModel; + } + public String getScope() { return scope; } @@ -211,6 +238,7 @@ public String getApplyTo() { return applyTo; } + @Override public boolean isRequired() { return required; } @@ -227,6 +255,7 @@ public boolean isFilterableInGrid() { return filterableInGrid; } + @Override public boolean isVisible() { return visible; } @@ -239,6 +268,7 @@ public boolean isVisibleOnFront() { return visibleOnFront; } + @Override public int getSortOrder() { return sortOrder; } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form new file mode 100644 index 000000000..a68a352db --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form @@ -0,0 +1,354 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java new file mode 100644 index 000000000..a69774b7b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java @@ -0,0 +1,235 @@ +package com.magento.idea.magento2plugin.actions.generation.dialog; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.magento.idea.magento2plugin.actions.generation.data.CategoryEntityData; +import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; +import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; +import com.magento.idea.magento2plugin.actions.generation.dialog.util.eavdialog.AttributeUtil; +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.Lowercase; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.JTextField; + +@SuppressWarnings({ + "PMD.TooManyFields", + "PMD.ExcessiveImports", + "PMD.TooManyMethods", + "PMD.UnusedPrivateField" +}) +public class NewCategoryEavAttributeDialog extends EavAttributeDialog { + + private final static String ENTITY_NAME = "Category"; + private JPanel contentPanel; + private JButton buttonOK; + private JButton buttonCancel; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Code"}) + @FieldValidation(rule = RuleRegistry.LOWERCASE, + message = {Lowercase.MESSAGE, "Attribute Code"}) + private JTextField codeTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Label"}) + private JTextField labelTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Group"}) + private JTextField groupTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Data Patch Name"}) + private JTextField dataPatchNameTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) + @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, + message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) + private JTextField sortOrderTextField; + private JComboBox inputComboBox; + private JComboBox typeComboBox; + private JComboBox scopeComboBox; + private JComboBox sourceComboBox; + private JCheckBox requiredCheckBox; + private JCheckBox visibleCheckBox; + private JPanel sourcePanel; + private JPanel customSourceModelPanel; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Source Model Directory"}) + private JTextField sourceModelDirectoryTexField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Source Model Name"}) + private JTextField sourceModelNameTexField; + private JTable optionsTable; + private JButton addNewOptionButton; + private JPanel optionsPanel; + + /** + * Constructor. + * + * @param project Project + * @param directory PsiDirectory + * @param actionName String + */ + public NewCategoryEavAttributeDialog( + final Project project, + final PsiDirectory directory, + final String actionName + ) { + super(project, directory, actionName); + + } + + @Override + protected void initBaseDialogState() { + super.initBaseDialogState(); + fillAttributeScopeComboBoxes(); + } + + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + protected void fillAttributeScopeComboBoxes() { + for (final AttributeScope globalValue : AttributeScope.values()) { + scopeComboBox.addItem( + new ComboBoxItemData(globalValue.getScope(), globalValue.name()) + ); + } + } + + @Override + protected JPanel getContentPanel() { + return contentPanel; + } + + @Override + protected JButton getButtonOk() { + return buttonOK; + } + + @Override + protected JButton getButtonCancel() { + return buttonCancel; + } + + @Override + protected JComboBox getAttributeTypeCompoBox() { + return typeComboBox; + } + + @Override + protected JComboBox getAttributeInputComboBox() { + return inputComboBox; + } + + @Override + protected JTable getOptionsTable() { + return optionsTable; + } + + @Override + protected JButton getNewOptionButton() { + return addNewOptionButton; + } + + @Override + protected JComboBox getAttributeSourceComboBox() { + return sourceComboBox; + } + + @Override + protected JTextField getAttributeSourceModelNameTexField() { + return sourceModelNameTexField; + } + + @Override + protected JTextField getSourceModelDirectoryTexField() { + return sourceModelDirectoryTexField; + } + + @Override + protected JPanel getAttributeCustomSourceModelPanel() { + return customSourceModelPanel; + } + + @Override + protected JPanel getAttributeOptionsPanel() { + return optionsPanel; + } + + @Override + protected JTextField getAttributeCodeTextField() { + return codeTextField; + } + + @Override + protected JTextField getDataPatchNameTextField() { + return dataPatchNameTextField; + } + + @Override + protected JTextField getSourceModelNameTexField() { + return sourceModelNameTexField; + } + + @Override + protected JTextField getAttributeLabelTexField() { + return labelTextField; + } + + @Override + protected JTextField getAttributeSortOrderTextField() { + return sortOrderTextField; + } + + @Override + protected JCheckBox getAttributeRequiredCheckBox() { + return requiredCheckBox; + } + + @Override + protected JCheckBox getAttributeVisibleBox() { + return visibleCheckBox; + } + + @Override + protected String getEntityName() { + return ENTITY_NAME; + } + + @Override + protected EavEntityDataInterface getEavEntityData() { + return populateCategoryEntityData(new CategoryEntityData()); + } + + private CategoryEntityData populateCategoryEntityData(final CategoryEntityData categoryEntityData) { + categoryEntityData.setModuleName(moduleName); + + categoryEntityData.setDataPatchName(getDataPatchName()); + categoryEntityData.setCode(getAttributeCode()); + categoryEntityData.setLabel(getAttributeLabel()); + categoryEntityData.setSortOrder(getAttributeSortOrder()); + categoryEntityData.setRequired(isRequiredAttribute()); + categoryEntityData.setVisible(isVisibleAttribute()); + categoryEntityData.setType(getAttributeBackendType()); + categoryEntityData.setInput(getAttributeInput()); + categoryEntityData.setScope( + AttributeUtil.getScopeClassBySelectedItem( + (ComboBoxItemData) scopeComboBox.getSelectedItem() + ) + ); + categoryEntityData.setSource(getAttributeSource(sourceModelData)); + categoryEntityData.setOptions( + getAttributeOptions(entityPropertiesTableGroupWrapper) + ); + categoryEntityData.setOptionsSortOrder( + getAttributeOptionsSortOrders(entityPropertiesTableGroupWrapper) + ); + + categoryEntityData.setGroup(groupTextField.getText().trim()); + + return categoryEntityData; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java index 7602cbfff..cee8f101b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java @@ -18,7 +18,6 @@ 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.util.GetAttributeOptionPropertiesUtil; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; import com.magento.idea.magento2plugin.util.magento.GetProductTypesListUtil; import java.util.List; @@ -39,7 +38,7 @@ }) public class NewProductEavAttributeDialog extends EavAttributeDialog { - private final static String ENTITY_NAME = "Product"; + private static final String ENTITY_NAME = "Product"; private JPanel contentPanel; private JButton buttonOK; private JButton buttonCancel; @@ -196,6 +195,26 @@ protected JTextField getSourceModelNameTexField() { return sourceModelNameTexField; } + @Override + protected JTextField getAttributeLabelTexField() { + return labelTextField; + } + + @Override + protected JTextField getAttributeSortOrderTextField() { + return sortOrderTextField; + } + + @Override + protected JCheckBox getAttributeRequiredCheckBox() { + return requiredCheckBox; + } + + @Override + protected JCheckBox getAttributeVisibleBox() { + return visibleCheckBox; + } + @Override protected String getEntityName() { return ENTITY_NAME; @@ -209,43 +228,32 @@ protected EavEntityDataInterface getEavEntityData() { private ProductEntityData populateProductEntityData(final ProductEntityData productEntityData) { productEntityData.setModuleName(moduleName); - productEntityData.setDataPatchName(dataPatchNameTextField.getText().trim()); + productEntityData.setDataPatchName(getDataPatchName()); + productEntityData.setCode(getAttributeCode()); + productEntityData.setLabel(getAttributeLabel()); + productEntityData.setSortOrder(getAttributeSortOrder()); + productEntityData.setRequired(isRequiredAttribute()); + productEntityData.setVisible(isVisibleAttribute()); productEntityData.setGroup(groupTextField.getText().trim()); - productEntityData.setCode(codeTextField.getText().trim()); - productEntityData.setLabel(labelTextField.getText().trim()); - productEntityData.setSortOrder(Integer.parseInt(sortOrderTextField.getText().trim())); - productEntityData.setRequired(requiredCheckBox.isSelected()); productEntityData.setUsedInGrid(usedInGridGridCheckBox.isSelected()); productEntityData.setVisibleInGrid(visibleInGridCheckBox.isSelected()); productEntityData.setFilterableInGrid(filterableInGridCheckBox.isSelected()); - productEntityData.setVisible(visibleCheckBox.isSelected()); productEntityData.setHtmlAllowedOnFront(htmlAllowedOnCheckBox.isSelected()); productEntityData.setVisibleOnFront(visibleOnFrontCheckBox.isSelected()); - productEntityData.setType( - AttributeUtil.getBackendTypeBySelectedItem( - (ComboBoxItemData) typeComboBox.getSelectedItem() - ) - ); - productEntityData.setInput( - AttributeUtil.getInputTypeBySelectedItem( - (ComboBoxItemData) inputComboBox.getSelectedItem() - ) - ); + productEntityData.setType(getAttributeBackendType()); + productEntityData.setInput(getAttributeInput()); productEntityData.setScope( AttributeUtil.getScopeClassBySelectedItem( (ComboBoxItemData) scopeComboBox.getSelectedItem() ) ); - productEntityData.setSource( - AttributeUtil.getSourceClassBySelectedItem( - (ComboBoxItemData) sourceComboBox.getSelectedItem(), - sourceModelData - ) + productEntityData.setSource(getAttributeSource(sourceModelData)); + productEntityData.setOptions( + getAttributeOptions(entityPropertiesTableGroupWrapper) + ); + productEntityData.setOptionsSortOrder( + getAttributeOptionsSortOrders(entityPropertiesTableGroupWrapper) ); - productEntityData.setOptions(GetAttributeOptionPropertiesUtil.getValues( - entityPropertiesTableGroupWrapper.getColumnsData())); - productEntityData.setOptionsSortOrder(GetAttributeOptionPropertiesUtil.getSortOrders( - entityPropertiesTableGroupWrapper.getColumnsData())); if (!applyToAllProductsCheckBox.isSelected()) { productEntityData.setApplyTo( diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java index a530bb311..5940e03f2 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java @@ -17,8 +17,10 @@ import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.EavAttributeInputItemListener; import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.OptionsPanelVisibilityChangeListener; import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.SourceModelNameAdapter; +import com.magento.idea.magento2plugin.actions.generation.dialog.util.eavdialog.AttributeUtil; import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.GetAttributeOptionPropertiesUtil; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType; @@ -33,6 +35,7 @@ import java.util.List; import java.util.Map; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JPanel; @@ -40,7 +43,7 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; -@SuppressWarnings({"PMD.TooManyMethods"}) +@SuppressWarnings({"PMD.GodClass", "PMD.TooManyMethods"}) public abstract class EavAttributeDialog extends AbstractDialog { protected String moduleName; @@ -81,6 +84,14 @@ public abstract class EavAttributeDialog extends AbstractDialog { protected abstract JTextField getSourceModelNameTexField(); + protected abstract JTextField getAttributeLabelTexField(); + + protected abstract JTextField getAttributeSortOrderTextField(); + + protected abstract JCheckBox getAttributeRequiredCheckBox(); + + protected abstract JCheckBox getAttributeVisibleBox(); + protected abstract String getEntityName(); /** @@ -390,4 +401,85 @@ protected void setAutocompleteListenerForSourceModelNameField( mainTextField.getDocument() .addDocumentListener(new SourceModelNameAdapter(dependentTextField)); } + + protected String getDataPatchName() { + final JTextField dataPatchNameTextField = getDataPatchNameTextField(); + + return dataPatchNameTextField == null + ? "" : dataPatchNameTextField.getText().trim(); + } + + protected String getAttributeCode() { + final JTextField codeTextField = getAttributeCodeTextField(); + + return codeTextField == null + ? "" : codeTextField.getText().trim(); + } + + protected String getAttributeLabel() { + final JTextField labelTextField = getAttributeLabelTexField(); + + return labelTextField == null + ? "" : labelTextField.getText().trim(); + } + + protected int getAttributeSortOrder() { + final JTextField sortOrderTextField = getAttributeSortOrderTextField(); + + return sortOrderTextField == null + ? 0 : Integer.parseInt(sortOrderTextField.getText().trim()); + } + + protected boolean isRequiredAttribute() { + final JCheckBox requiredCheckBox = getAttributeRequiredCheckBox(); + + return requiredCheckBox != null && requiredCheckBox.isSelected(); + } + + protected boolean isVisibleAttribute() { + final JCheckBox visibleCheckBox = getAttributeVisibleBox(); + + return visibleCheckBox != null && visibleCheckBox.isSelected(); + } + + protected String getAttributeBackendType() { + final JComboBox typeComboBox = getAttributeTypeCompoBox(); + + return AttributeUtil.getBackendTypeBySelectedItem( + (ComboBoxItemData) typeComboBox.getSelectedItem() + ); + } + + protected String getAttributeInput() { + final JComboBox inputComboBox = getAttributeInputComboBox(); + + return AttributeUtil.getInputTypeBySelectedItem( + (ComboBoxItemData) inputComboBox.getSelectedItem() + ); + } + + protected String getAttributeSource(final SourceModelData sourceModelData) { + final JComboBox sourceComboBox = getAttributeSourceComboBox(); + + return AttributeUtil.getSourceClassBySelectedItem( + (ComboBoxItemData) sourceComboBox.getSelectedItem(), + sourceModelData + ); + } + + protected Map getAttributeOptions( + final TableGroupWrapper entityPropertiesTableGroupWrapper + ) { + return GetAttributeOptionPropertiesUtil.getValues( + entityPropertiesTableGroupWrapper.getColumnsData() + ); + } + + protected Map getAttributeOptionsSortOrders( + final TableGroupWrapper entityPropertiesTableGroupWrapper + ) { + return GetAttributeOptionPropertiesUtil.getSortOrders( + entityPropertiesTableGroupWrapper.getColumnsData() + ); + } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java new file mode 100644 index 000000000..1c3bea4d6 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java @@ -0,0 +1,25 @@ +package com.magento.idea.magento2plugin.actions.generation.eavattribute; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.magento.idea.magento2plugin.MagentoIcons; +import com.magento.idea.magento2plugin.actions.generation.dialog.NewCategoryEavAttributeDialog; +import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; + +public class NewCategoryEavAttributeAction extends NewEavAttributeAction { + + public static final String ACTION_NAME = "Category Attribute"; + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Catalog Attribute"; + + public NewCategoryEavAttributeAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); + } + + @Override + protected EavAttributeDialog getDialogWindow( + final Project project, + final PsiDirectory directory + ) { + return new NewCategoryEavAttributeDialog(project, directory, ACTION_NAME); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java index 804cf2b8d..b5d8f102b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java @@ -17,6 +17,8 @@ public class AttributeMapperFactory { public AttributeMapperInterface createByEntityClass(@NotNull final String entityClass) { if (entityClass.equals(EavEntity.PRODUCT.getEntityClass())) { return new ProductAttributeMapper(); + } else if (entityClass.equals(EavEntity.CATEGORY.getEntityClass())) { + return new CategoryAttributeMapper(); } return null; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CategoryAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CategoryAttributeMapper.java new file mode 100644 index 000000000..e51d38782 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CategoryAttributeMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; + +import com.magento.idea.magento2plugin.actions.generation.data.CategoryEntityData; +import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeProperty; +import java.util.Map; + +public class CategoryAttributeMapper extends DefaultAttributeMapper { + @Override + protected Map getMappedAttributes(final EavEntityDataInterface eavEntityData) { + final Map mappedAttributes = super.getMappedAttributes(eavEntityData); + final CategoryEntityData categoryEavEntityData = (CategoryEntityData) eavEntityData; + + mappedAttributes.put( + AttributeProperty.GLOBAL.getProperty(), + categoryEavEntityData.getScope() + ); + mappedAttributes.put( + AttributeProperty.GROUP.getProperty(), + wrapStringValueForTemplate(categoryEavEntityData.getGroup()) + ); + + return mappedAttributes; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java new file mode 100644 index 000000000..1b683a0ec --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java @@ -0,0 +1,165 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; + +import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeBackendModel; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeProperty; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DefaultAttributeMapper implements AttributeMapperInterface { + @Override + public List mapAttributesByEntityData(final EavEntityDataInterface entityData) { + final List attributesWithValues = new ArrayList<>(); + + final Map mappedAttributes = getMappedAttributes(entityData); + + for (final Map.Entry attributePair : mappedAttributes.entrySet()) { + final String attributeKey = "'" + attributePair.getKey() + "'"; + final String attributeValue = attributePair.getValue(); + + attributesWithValues.add( + String.join("=>", attributeKey, attributeValue + ",") + ); + } + + return attributesWithValues; + } + + @SuppressWarnings({"PMD.NullAssignment"}) + protected Map getMappedAttributes(final EavEntityDataInterface eavEntityData) { + final Map mappedAttributes = new HashMap<>(); + mappedAttributes.put( + AttributeProperty.TYPE.getProperty(), + wrapStringValueForTemplate(eavEntityData.getType()) + ); + mappedAttributes.put( + AttributeProperty.LABEL.getProperty(), + wrapStringValueForTemplate(eavEntityData.getLabel()) + ); + mappedAttributes.put( + AttributeProperty.INPUT.getProperty(), + wrapStringValueForTemplate(eavEntityData.getInput()) + ); + mappedAttributes.put( + AttributeProperty.SOURCE.getProperty(), + getEntitySource(eavEntityData) + ); + mappedAttributes.put( + AttributeProperty.REQUIRED.getProperty(), + Boolean.toString(eavEntityData.isRequired()) + ); + mappedAttributes.put( + AttributeProperty.SORT_ORDER.getProperty(), + Integer.toString(eavEntityData.getSortOrder()) + ); + mappedAttributes.put( + AttributeProperty.VISIBLE.getProperty(), + Boolean.toString(eavEntityData.isVisible()) + ); + + final String attributeOptions = getMappedOptions( + eavEntityData.getOptions(), + eavEntityData.getOptionsSortOrder() + ); + + if (!attributeOptions.isEmpty()) { + mappedAttributes.put( + AttributeProperty.OPTION.getProperty(), + getMappedOptions(eavEntityData.getOptions(), eavEntityData.getOptionsSortOrder()) + ); + } + + if (eavEntityData.getInput().equals(AttributeInput.MULTISELECT.getInput())) { + mappedAttributes.put( + AttributeProperty.BACKEND_MODEL.getProperty(), + wrapClassValueForTemplate(AttributeBackendModel.ARRAY.getModel()) + ); + } + + return mappedAttributes; + } + + protected String wrapStringValueForTemplate(final String value) { + return "'" + value + "'"; + } + + protected String wrapClassValueForTemplate(final String value) { + return value + "::class"; + } + + protected String getEntitySource(final EavEntityDataInterface eavEntityData) { + final String eavSource = eavEntityData.getSource(); + + return eavSource == null + || eavSource.equals(AttributeSourceModel.NULLABLE_SOURCE.getSource()) + ? null : wrapClassValueForTemplate(eavSource); + } + + protected String getMappedOptions( + final Map optionValues, + final Map optionSortOrders + ) { + if (optionValues == null || optionValues.isEmpty()) { + return ""; + } + + return "[" + getParsedOptions(optionValues) + + (optionSortOrders == null || optionSortOrders.isEmpty() + ? "->" : "," + getParsedOptionSortOrders(optionSortOrders)) + "]"; + } + + protected String getParsedOptions(final Map optionValues) { + final String valueNode = "->" + wrapStringValueForTemplate("value") + " => "; + final StringBuilder optionsContent = new StringBuilder(); + + for (final Integer optionKey : optionValues.keySet()) { + final String optionValue = optionValues.get(optionKey); + + if (optionValue.isEmpty()) { + continue; + } + + optionsContent + .append("->") + .append(wrapStringValueForTemplate("option_" + optionKey)) + .append(" => ") + .append("[") + .append(wrapStringValueForTemplate(optionValue)) + .append("], "); + } + + return valueNode + "[" + optionsContent + "->]"; + } + + protected String getParsedOptionSortOrders(final Map optionSortOrders) { + final String orderNode = "->" + wrapStringValueForTemplate("order") + " => "; + final StringBuilder ordersContent = new StringBuilder(); + + for (final Integer optionKey : optionSortOrders.keySet()) { + final String orderValue = optionSortOrders.get(optionKey); + + if (orderValue.isEmpty()) { + continue; + } + + ordersContent + .append("->") + .append(wrapStringValueForTemplate("option_" + optionKey)) + .append(" => ") + .append(orderValue) + .append(","); + } + + return orderNode + "[" + ordersContent + "->]->"; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java index 35117a316..943c29580 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java @@ -7,155 +7,53 @@ import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; -import com.magento.idea.magento2plugin.magento.packages.eav.EavAttribute; -import com.sun.istack.NotNull; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeProperty; import java.util.Map; -public class ProductAttributeMapper implements AttributeMapperInterface { - @Override - public List mapAttributesByEntityData( - @NotNull final EavEntityDataInterface entityData - ) { - final ProductEntityData productEntityData = (ProductEntityData) entityData; - - final List attributesWithValues = new ArrayList<>(); - - final Map mappedAttributes = getMappedAttributes(productEntityData); - - for (final Map.Entry attributePair : mappedAttributes.entrySet()) { - final String attributeKey = "'" + attributePair.getKey() + "'"; - final String attributeValue = attributePair.getValue(); - - attributesWithValues.add( - String.join("=>", attributeKey, attributeValue + ",") - ); - } - - return attributesWithValues; - } +public class ProductAttributeMapper extends DefaultAttributeMapper { @SuppressWarnings({"PMD.NullAssignment"}) - private Map getMappedAttributes(final ProductEntityData eavEntityData) { - final Map mappedAttributes = new HashMap<>(); - mappedAttributes.put(EavAttribute.GROUP.getAttribute(), - wrapStringValueForTemplate(eavEntityData.getGroup())); - mappedAttributes.put(EavAttribute.TYPE.getAttribute(), - wrapStringValueForTemplate(eavEntityData.getType())); - mappedAttributes.put(EavAttribute.LABEL.getAttribute(), - wrapStringValueForTemplate(eavEntityData.getLabel())); - mappedAttributes.put(EavAttribute.INPUT.getAttribute(), - wrapStringValueForTemplate(eavEntityData.getInput())); - mappedAttributes.put(EavAttribute.SOURCE.getAttribute(), - getEntitySource(eavEntityData)); - mappedAttributes.put(EavAttribute.REQUIRED.getAttribute(), - Boolean.toString(eavEntityData.isRequired())); - mappedAttributes.put(EavAttribute.SORT_ORDER.getAttribute(), - Integer.toString(eavEntityData.getSortOrder())); - mappedAttributes.put(EavAttribute.GLOBAL.getAttribute(), - eavEntityData.getScope()); - mappedAttributes.put(EavAttribute.IS_USED_IN_GRID.getAttribute(), - Boolean.toString(eavEntityData.isUsedInGrid())); - mappedAttributes.put(EavAttribute.IS_VISIBLE_IN_GRID.getAttribute(), - Boolean.toString(eavEntityData.isVisibleInGrid())); - mappedAttributes.put(EavAttribute.IS_FILTERABLE_IN_GRID.getAttribute(), - Boolean.toString(eavEntityData.isFilterableInGrid())); - mappedAttributes.put(EavAttribute.VISIBLE.getAttribute(), - Boolean.toString(eavEntityData.isVisible())); - mappedAttributes.put(EavAttribute.IS_HTML_ALLOWED_ON_FRONT.getAttribute(), - Boolean.toString(eavEntityData.isHtmlAllowedOnFront())); - mappedAttributes.put(EavAttribute.VISIBLE_ON_FRONT.getAttribute(), - Boolean.toString(eavEntityData.isVisibleOnFront())); + @Override + protected Map getMappedAttributes(final EavEntityDataInterface eavEntityData) { + final Map mappedAttributes = super.getMappedAttributes(eavEntityData); - final String attributeOptions = getMappedOptions( - eavEntityData.getOptions(), - eavEntityData.getOptionsSortOrder() + final ProductEntityData productEavEntityData = (ProductEntityData) eavEntityData; + mappedAttributes.put( + AttributeProperty.GROUP.getProperty(), + wrapStringValueForTemplate(productEavEntityData.getGroup()) + ); + mappedAttributes.put( + AttributeProperty.GLOBAL.getProperty(), + productEavEntityData.getScope() + ); + mappedAttributes.put( + AttributeProperty.IS_USED_IN_GRID.getProperty(), + Boolean.toString(productEavEntityData.isUsedInGrid()) + ); + mappedAttributes.put( + AttributeProperty.IS_VISIBLE_IN_GRID.getProperty(), + Boolean.toString(productEavEntityData.isVisibleInGrid()) + ); + mappedAttributes.put( + AttributeProperty.IS_FILTERABLE_IN_GRID.getProperty(), + Boolean.toString(productEavEntityData.isFilterableInGrid()) + ); + mappedAttributes.put( + AttributeProperty.IS_HTML_ALLOWED_ON_FRONT.getProperty(), + Boolean.toString(productEavEntityData.isHtmlAllowedOnFront()) + ); + mappedAttributes.put( + AttributeProperty.VISIBLE_ON_FRONT.getProperty(), + Boolean.toString(productEavEntityData.isVisibleOnFront()) ); - if (!attributeOptions.isEmpty()) { - mappedAttributes.put(EavAttribute.OPTION.getAttribute(), - getMappedOptions(eavEntityData.getOptions(), eavEntityData.getOptionsSortOrder())); - } - - if (eavEntityData.getApplyTo() != null && !eavEntityData.getApplyTo().isEmpty()) { - mappedAttributes.put(EavAttribute.APPLY_TO.getAttribute(), - wrapStringValueForTemplate(eavEntityData.getApplyTo())); + if (productEavEntityData.getApplyTo() != null && !productEavEntityData.getApplyTo().isEmpty()) { + mappedAttributes.put( + AttributeProperty.APPLY_TO.getProperty(), + wrapStringValueForTemplate(productEavEntityData.getApplyTo()) + ); } return mappedAttributes; } - - private String wrapStringValueForTemplate(final String value) { - return "'" + value + "'"; - } - - - private String getEntitySource(final ProductEntityData eavEntityData) { - final String eavSource = eavEntityData.getSource(); - - return eavSource == null - || eavSource.equals(AttributeSourceModel.NULLABLE_SOURCE.getSource()) - ? null : eavSource + "::class"; - } - - private String getMappedOptions( - final Map optionValues, - final Map optionSortOrders - ) { - if (optionValues == null || optionValues.isEmpty()) { - return ""; - } - - return "[" + getParsedOptions(optionValues) - + (optionSortOrders == null || optionSortOrders.isEmpty() - ? "->" : "," + getParsedOptionSortOrders(optionSortOrders)) + "]"; - } - - private String getParsedOptions(final Map optionValues) { - final String valueNode = "->" + wrapStringValueForTemplate("value") + " => "; - final StringBuilder optionsContent = new StringBuilder(); - - for (final Integer optionKey : optionValues.keySet()) { - final String optionValue = optionValues.get(optionKey); - - if (optionValue.isEmpty()) { - continue; - } - - optionsContent - .append("->") - .append(wrapStringValueForTemplate("option_" + optionKey)) - .append(" => ") - .append("[") - .append(wrapStringValueForTemplate(optionValue)) - .append("], "); - } - - return valueNode + "[" + optionsContent + "->]"; - } - - private String getParsedOptionSortOrders(final Map optionSortOrders) { - final String orderNode = "->" + wrapStringValueForTemplate("order") + " => "; - final StringBuilder ordersContent = new StringBuilder(); - - for (final Integer optionKey : optionSortOrders.keySet()) { - final String orderValue = optionSortOrders.get(optionKey); - - if (orderValue.isEmpty()) { - continue; - } - - ordersContent - .append("->") - .append(wrapStringValueForTemplate("option_" + optionKey)) - .append(" => ") - .append(orderValue) - .append(","); - } - - return orderNode + "[" + ordersContent + "->]->"; - } } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeBackendModel.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeBackendModel.java new file mode 100644 index 000000000..2e9524912 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeBackendModel.java @@ -0,0 +1,21 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.magento.packages.eav; + +public enum AttributeBackendModel { + ARRAY("\\Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\ArrayBackend"); + + private String model; + + AttributeBackendModel(final String model) { + this.model = model; + } + + public String getModel() { + return model; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeProperty.java similarity index 81% rename from src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java rename to src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeProperty.java index acd5ceff9..5804022c5 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavAttribute.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeProperty.java @@ -5,7 +5,7 @@ package com.magento.idea.magento2plugin.magento.packages.eav; -public enum EavAttribute { +public enum AttributeProperty { GROUP("group"), TYPE("type"), LABEL("label"), @@ -21,15 +21,16 @@ public enum EavAttribute { IS_HTML_ALLOWED_ON_FRONT("is_html_allowed_on_front"), VISIBLE_ON_FRONT("visible_on_front"), APPLY_TO("apply_to"), - OPTION("option"); + OPTION("option"), + BACKEND_MODEL("backend"); private String attribute; - EavAttribute(final String attribute) { + AttributeProperty(final String attribute) { this.attribute = attribute; } - public String getAttribute() { + public String getProperty() { return attribute; } } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java index 11cf35df9..cdaa2fd8c 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java @@ -6,7 +6,8 @@ package com.magento.idea.magento2plugin.magento.packages.eav; public enum EavEntity { - PRODUCT("\\Magento\\Catalog\\Model\\Product"); + PRODUCT("\\Magento\\Catalog\\Model\\Product"), + CATEGORY("\\Magento\\Catalog\\Model\\Category"); private String entityClass; diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/AttributePropertySetupPatchGeneratorTest.java similarity index 99% rename from tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java rename to tests/com/magento/idea/magento2plugin/actions/generation/generator/AttributePropertySetupPatchGeneratorTest.java index ea76861ca..eb7970496 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/AttributePropertySetupPatchGeneratorTest.java @@ -12,7 +12,7 @@ import java.util.HashMap; import java.util.Map; -public class EavAttributeSetupPatchGeneratorTest extends BaseGeneratorTestCase { +public class AttributePropertySetupPatchGeneratorTest extends BaseGeneratorTestCase { private final static String MODULE_NAME = "Foo_Bar"; /** From 899b3f96cb4bbcfbe5f47bcc71a0363a6f29bbd3 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Wed, 21 Apr 2021 14:40:06 +0300 Subject: [PATCH 031/111] Added category dialog and generation, refactored code --- ... Category Admin Form XML Decoration.xml.ft | 7 + .../Magento Category Admin Form XML.xml.ft | 4 + .../generation/data/CategoryFormXmlData.java | 44 ++++ .../dialog/NewCategoryEavAttributeDialog.java | 37 ++- .../eavattribute/EavAttributeDialog.java | 27 ++- .../generator/CategoryFormXmlGenerator.java | 217 ++++++++++++++++++ .../GetFormElementByAttributeInputUtil.java | 43 ++++ .../magento/files/CategoryFormXmlFile.java | 44 ++++ .../magento/packages/eav/AttributeInput.java | 34 ++- 9 files changed, 438 insertions(+), 19 deletions(-) create mode 100644 resources/fileTemplates/code/Magento Category Admin Form XML Decoration.xml.ft create mode 100644 resources/fileTemplates/internal/Magento Category Admin Form XML.xml.ft create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/CategoryFormXmlGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/GetFormElementByAttributeInputUtil.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/CategoryFormXmlFile.java diff --git a/resources/fileTemplates/code/Magento Category Admin Form XML Decoration.xml.ft b/resources/fileTemplates/code/Magento Category Admin Form XML Decoration.xml.ft new file mode 100644 index 000000000..09ce53202 --- /dev/null +++ b/resources/fileTemplates/code/Magento Category Admin Form XML Decoration.xml.ft @@ -0,0 +1,7 @@ +#if(${INCLUDE_FIELDSET}) +
+#end + +#if(${INCLUDE_FIELDSET}) +
+#end \ No newline at end of file diff --git a/resources/fileTemplates/internal/Magento Category Admin Form XML.xml.ft b/resources/fileTemplates/internal/Magento Category Admin Form XML.xml.ft new file mode 100644 index 000000000..ffe195975 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Category Admin Form XML.xml.ft @@ -0,0 +1,4 @@ + +
+
diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java new file mode 100644 index 000000000..393152caa --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java @@ -0,0 +1,44 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import org.jetbrains.annotations.NotNull; + +public class CategoryFormXmlData { + private final String fieldSetName; + private final String fieldName; + private final String attributeInput; + private final int sortOrder; + + public CategoryFormXmlData( + @NotNull final String fieldSetName, + @NotNull final String fieldName, + @NotNull final String attributeInput, + @NotNull final int sortOrder + ) { + this.fieldSetName = fieldSetName; + this.fieldName = fieldName; + this.attributeInput = attributeInput; + this.sortOrder = sortOrder; + } + + public String getFieldSetName() { + return fieldSetName; + } + + public String getFieldName() { + return fieldName; + } + + public int getSortOrder() { + return sortOrder; + } + + public String getAttributeInput() { + return attributeInput; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java index a69774b7b..98553d720 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java @@ -3,6 +3,7 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; import com.magento.idea.magento2plugin.actions.generation.data.CategoryEntityData; +import com.magento.idea.magento2plugin.actions.generation.data.CategoryFormXmlData; import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; @@ -11,6 +12,7 @@ import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry; 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.CategoryFormXmlGenerator; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -27,7 +29,7 @@ }) public class NewCategoryEavAttributeDialog extends EavAttributeDialog { - private final static String ENTITY_NAME = "Category"; + private static final String ENTITY_NAME = "Category"; private JPanel contentPanel; private JButton buttonOK; private JButton buttonCancel; @@ -204,7 +206,9 @@ protected EavEntityDataInterface getEavEntityData() { return populateCategoryEntityData(new CategoryEntityData()); } - private CategoryEntityData populateCategoryEntityData(final CategoryEntityData categoryEntityData) { + private CategoryEntityData populateCategoryEntityData( + final CategoryEntityData categoryEntityData + ) { categoryEntityData.setModuleName(moduleName); categoryEntityData.setDataPatchName(getDataPatchName()); @@ -232,4 +236,33 @@ private CategoryEntityData populateCategoryEntityData(final CategoryEntityData c return categoryEntityData; } + + @Override + protected void generateExtraFilesAfterDataPatchGeneration( + final EavEntityDataInterface eavEntityDataInterface + ) { + super.generateExtraFilesAfterDataPatchGeneration(eavEntityDataInterface); + generateCategoryAdminForm((CategoryEntityData) eavEntityDataInterface); + } + + private void generateCategoryAdminForm(final CategoryEntityData categoryEntityData) { + final CategoryFormXmlData categoryFormXmlData = new CategoryFormXmlData( + convertGroupNameToFieldSet(categoryEntityData.getGroup()), + categoryEntityData.getCode(), + categoryEntityData.getInput(), + categoryEntityData.getSortOrder() + ); + + new CategoryFormXmlGenerator( + categoryFormXmlData, + project, + moduleName + ).generate(actionName, false); + } + + private String convertGroupNameToFieldSet(final String groupName) { + final String[] nameParts = groupName.toLowerCase().split(" ");//NOPMD + + return String.join("_", nameParts); + } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java index 5940e03f2..5e4022b39 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java @@ -44,7 +44,7 @@ import javax.swing.KeyStroke; @SuppressWarnings({"PMD.GodClass", "PMD.TooManyMethods"}) -public abstract class EavAttributeDialog extends AbstractDialog { +public abstract class EavAttributeDialog extends AbstractDialog { protected String moduleName; protected Project project; @@ -245,8 +245,11 @@ protected void onOk() { return; } - generateSourceModelFile(); - generateDataPatchFile(); + generateExtraFilesBeforeDataPatchGeneration(); + + final EavEntityDataInterface eavEntityDataInterface = getEavEntityData(); + generateDataPatchFile(eavEntityDataInterface); + generateExtraFilesAfterDataPatchGeneration(eavEntityDataInterface); setVisible(false); } @@ -270,14 +273,22 @@ protected void generateSourceModelFile() { .generate(actionName, false); } - protected void generateDataPatchFile() { + protected void generateDataPatchFile(final EavEntityDataInterface eavEntityDataInterface) { new EavAttributeSetupPatchGenerator( - getEavEntityData(), + eavEntityDataInterface, project, true ).generate(actionName, true); } + protected void generateExtraFilesBeforeDataPatchGeneration() { + generateSourceModelFile(); + } + + protected void generateExtraFilesAfterDataPatchGeneration( + final EavEntityDataInterface eavEntityDataInterface + ) {} + protected void addCancelActionForWindow() { setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @@ -443,7 +454,7 @@ protected boolean isVisibleAttribute() { } protected String getAttributeBackendType() { - final JComboBox typeComboBox = getAttributeTypeCompoBox(); + final JComboBox typeComboBox = getAttributeTypeCompoBox(); return AttributeUtil.getBackendTypeBySelectedItem( (ComboBoxItemData) typeComboBox.getSelectedItem() @@ -451,7 +462,7 @@ protected String getAttributeBackendType() { } protected String getAttributeInput() { - final JComboBox inputComboBox = getAttributeInputComboBox(); + final JComboBox inputComboBox = getAttributeInputComboBox(); return AttributeUtil.getInputTypeBySelectedItem( (ComboBoxItemData) inputComboBox.getSelectedItem() @@ -459,7 +470,7 @@ protected String getAttributeInput() { } protected String getAttributeSource(final SourceModelData sourceModelData) { - final JComboBox sourceComboBox = getAttributeSourceComboBox(); + final JComboBox sourceComboBox = getAttributeSourceComboBox(); return AttributeUtil.getSourceClassBySelectedItem( (ComboBoxItemData) sourceComboBox.getSelectedItem(), diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/CategoryFormXmlGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/CategoryFormXmlGenerator.java new file mode 100644 index 000000000..aaf9e0953 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/CategoryFormXmlGenerator.java @@ -0,0 +1,217 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.command.WriteCommandAction; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.PsiFile; +import com.intellij.psi.codeStyle.CodeStyleManager; +import com.intellij.psi.xml.XmlFile; +import com.intellij.psi.xml.XmlTag; +import com.magento.idea.magento2plugin.actions.generation.data.CategoryFormXmlData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.*; +import com.magento.idea.magento2plugin.bundles.CommonBundle; +import com.magento.idea.magento2plugin.bundles.ValidatorBundle; +import com.magento.idea.magento2plugin.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.CategoryFormXmlFile; +import com.magento.idea.magento2plugin.magento.packages.Areas; +import com.magento.idea.magento2plugin.magento.packages.File; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; +import com.magento.idea.magento2plugin.util.magento.FileBasedIndexUtil; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class CategoryFormXmlGenerator extends FileGenerator { + + private final CategoryFormXmlData categoryFormXmlData; + private final String moduleName; + private final DirectoryGenerator directoryGenerator; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final GetCodeTemplateUtil getCodeTemplateUtil; + private final XmlFilePositionUtil xmlFilePositionUtil; + private final ValidatorBundle validatorBundle; + private final CommonBundle commonBundle; + private boolean allowedFieldsetNodeInclude = true; + + public CategoryFormXmlGenerator( + final @NotNull CategoryFormXmlData categoryFormXmlData, + final @NotNull Project project, + final @NotNull String moduleName + ) { + super(project); + + this.categoryFormXmlData = categoryFormXmlData; + this.moduleName = moduleName; + this.directoryGenerator = DirectoryGenerator.getInstance(); + this.xmlFilePositionUtil = new XmlFilePositionUtil(); + this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); + this.getCodeTemplateUtil = new GetCodeTemplateUtil(project); + this.validatorBundle = new ValidatorBundle(); + this.commonBundle = new CommonBundle(); + } + + @Override + public PsiFile generate(final String actionName) { + final PsiDirectory directory = getFileDirectory(); + + PsiFile categoryAdminFormXmlFile = FileBasedIndexUtil.findModuleViewFile( + CategoryFormXmlFile.FILE_NAME, + Areas.getAreaByString(Areas.adminhtml.name()), + moduleName, + project, + CategoryFormXmlFile.SUB_DIRECTORY + ); + + if (categoryAdminFormXmlFile == null) { + categoryAdminFormXmlFile = fileFromTemplateGenerator.generate( + new CategoryFormXmlFile(), + new Properties(), + directory, + actionName + ); + } + + if (categoryAdminFormXmlFile == null) { + showDeclarationCannotBeCreatedDialog(); + return null; + } + + final XmlTag rootTag = ((XmlFile) categoryAdminFormXmlFile).getRootTag(); + + if (rootTag == null) { + showDeclarationCannotBeCreatedDialog(); + return null; + } + + final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project); + final Document document = psiDocumentManager.getDocument(categoryAdminFormXmlFile); + + + if (document == null) { + showDeclarationCannotBeCreatedDialog(); + return null; + } + + try { + final XmlTag matchedFieldsetByName = findMatchedFieldsetByName( + findFieldsetTagsInRoot(rootTag), + categoryFormXmlData.getFieldSetName() + ); + + allowedFieldsetNodeInclude = matchedFieldsetByName == null; + + writeInFile( + matchedFieldsetByName == null ? rootTag : matchedFieldsetByName, + psiDocumentManager, + document + ); + } catch (IOException e) { + showDeclarationCannotBeCreatedDialog(); + } + + return reformatFile(categoryAdminFormXmlFile); + } + + private void showDeclarationCannotBeCreatedDialog() { + JOptionPane.showMessageDialog( + null, + validatorBundle.message( + "validator.file.cantBeCreated", + "Category Admin Form XML file" + ), + commonBundle.message("common.error"), + JOptionPane.ERROR_MESSAGE + ); + } + + private PsiDirectory getFileDirectory() { + PsiDirectory directory = + new ModuleIndex(project).getModuleDirectoryByModuleName(moduleName); + + for (final String handlerDirectory: CategoryFormXmlFile.DIRECTORY.split(File.separator)) { + directory = directoryGenerator.findOrCreateSubdirectory( + directory, + handlerDirectory + ); + } + return directory; + } + + private void writeInFile( + final XmlTag targetTag, + final PsiDocumentManager psiDocumentManager, + final Document document + ) throws IOException { + final int insertPosition = xmlFilePositionUtil.getEndPositionOfTag(targetTag); + + final String declarationXml = + getCodeTemplateUtil.execute( + CategoryFormXmlFile.DECLARATION_TEMPLATE, + getAttributes() + ); + + WriteCommandAction.runWriteCommandAction(project, () -> { + document.insertString(insertPosition, declarationXml); + psiDocumentManager.commitDocument(document); + }); + } + + private PsiFile reformatFile(final PsiFile categoryAdminFormXmlFile) { + WriteCommandAction.runWriteCommandAction(project, () -> { + CodeStyleManager.getInstance(project).reformat(categoryAdminFormXmlFile); + }); + + return categoryAdminFormXmlFile; + } + + @NotNull + private List findFieldsetTagsInRoot(final XmlTag rootTag) { + final XmlTag[] subTags = rootTag.getSubTags(); + final List fieldsetList = new ArrayList<>(); + + for (final XmlTag subTag: subTags) { + if (subTag.getName().equals(CategoryFormXmlFile.XML_TAG_FIELDSET)) { + fieldsetList.add(subTag); + } + } + return fieldsetList; + } + + @Nullable + private XmlTag findMatchedFieldsetByName(final List fieldsetList, final String fieldsetName) { + for (final XmlTag fieldset: fieldsetList) { + final String attributeValue = fieldset.getAttributeValue(CategoryFormXmlFile.XML_ATTR_FIELDSET_NAME); + if (attributeValue != null && attributeValue.equals(fieldsetName)) { + return fieldset; + } + } + + return null; + } + + @Override + protected void fillAttributes(final Properties attributes) { + attributes.setProperty("FIELDSET_NAME", categoryFormXmlData.getFieldSetName()); + attributes.setProperty("FIELD_NAME", categoryFormXmlData.getFieldName()); + attributes.setProperty("SORT_ORDER", Integer.toString(categoryFormXmlData.getSortOrder())); + attributes.setProperty("FORM_ELEMENT", GetFormElementByAttributeInputUtil.execute( + AttributeInput.getAttributeInputByCode(categoryFormXmlData.getAttributeInput()) + )); + + if (allowedFieldsetNodeInclude) { + attributes.setProperty("INCLUDE_FIELDSET", "include"); + } + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/GetFormElementByAttributeInputUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/GetFormElementByAttributeInputUtil.java new file mode 100644 index 000000000..078ab883f --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/GetFormElementByAttributeInputUtil.java @@ -0,0 +1,43 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; +import com.magento.idea.magento2plugin.magento.packages.uicomponent.FormElementType; + +public final class GetFormElementByAttributeInputUtil { + + private GetFormElementByAttributeInputUtil(){} + + /** + * Returns for available form element by attribute input type. + * + * @param inputType AttributeInput + * @return String + */ + public static String execute(final AttributeInput inputType) { + switch (inputType) { + case TEXT: + return FormElementType.INPUT.getType(); + case TEXTAREA: + return FormElementType.TEXTAREA.getType(); + case BOOLEAN: + case SELECT: + return FormElementType.SELECT.getType(); + case MULTISELECT: + return FormElementType.MULTISELECT.getType(); + case DATE: + return FormElementType.DATE.getType(); + case PRICE: + return FormElementType.PRICE.getType(); + case HIDDEN: + return FormElementType.HIDDEN.getType(); + default: + return ""; + } + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/CategoryFormXmlFile.java b/src/com/magento/idea/magento2plugin/magento/files/CategoryFormXmlFile.java new file mode 100644 index 000000000..ae71b6e58 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/CategoryFormXmlFile.java @@ -0,0 +1,44 @@ +/* + * 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 CategoryFormXmlFile implements ModuleFileInterface { + + public static final String FILE_NAME = "category_form.xml"; + public static final String TEMPLATE = "Magento Category Admin Form XML"; + public static final String DECLARATION_TEMPLATE = "Magento Category Admin Form XML Decoration"; + public static final String DIRECTORY = "view/adminhtml/ui_component"; + public static final String SUB_DIRECTORY = "ui_component"; + + //attributes + public static final String XML_ATTR_FIELDSET_NAME = "name"; + public static final String XML_ATTR_FIELD_NAME = "name"; + public static final String XML_ATTR_FIELD_SORT_ORDER = "sortOrder"; + public static final String XML_ATTR_FIELD_FORM_ELEMENT = "formElement"; + + //tags + public static final String XML_TAG_FIELDSET = "fieldset"; + public static final String XML_TAG_FIELD = "field"; + + @Override + public String getFileName() { + return FILE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return XMLLanguage.INSTANCE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInput.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInput.java index 448b4714a..773b18516 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInput.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInput.java @@ -7,18 +7,13 @@ public enum AttributeInput { TEXT("text"), + TEXTAREA("textarea"), BOOLEAN("boolean"), - MULTISELECT("multiselect"), SELECT("select"), - TEXTAREA("textarea"), - PRICE("price"), + MULTISELECT("multiselect"), DATE("date"), - GALLERY("gallery"), - HIDDEN("hidden"), - IMAGE("image"), - MEDIA_IMAGE("media_image"), - MULTILINE("multiline"), - WEIGHT("weight"); + PRICE("price"), + HIDDEN("hidden"); private String input; @@ -26,7 +21,28 @@ public enum AttributeInput { this.input = input; } + /** + * Return attribute input. + * + * @return String + */ public String getInput() { return this.input; } + + /** + * Return attribute input item by input code. + * + * @param code String + * @return AttributeInput + */ + public static AttributeInput getAttributeInputByCode(final String code) { + for (final AttributeInput attributeInput: values()) { + if (attributeInput.getInput().equals(code)) { + return attributeInput; + } + } + + return null; + } } From 2c06892a40df1971588c20946aead6b6d0b3c1ba Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Wed, 21 Apr 2021 15:28:45 +0300 Subject: [PATCH 032/111] Renamed tests for product eav entity --- .../generateFile/AddTestAttribute.php | 0 .../generateFileWithApplyToAttribute/AddAppliedToAttribute.php | 0 .../AddBooleanInputAttributeAttribute.php | 0 .../AddAttributeWithCustomSourceAttribute.php | 0 .../AddAttributeWithOptionsAttribute.php | 3 ++- ...va => ProductAttributePropertySetupPatchGeneratorTest.java} | 2 +- 6 files changed, 3 insertions(+), 2 deletions(-) rename testData/actions/generation/generator/{EavAttributeSetupPatchGenerator => ProductAttributePropertySetupPatchGenerator}/generateFile/AddTestAttribute.php (100%) rename testData/actions/generation/generator/{EavAttributeSetupPatchGenerator => ProductAttributePropertySetupPatchGenerator}/generateFileWithApplyToAttribute/AddAppliedToAttribute.php (100%) rename testData/actions/generation/generator/{EavAttributeSetupPatchGenerator => ProductAttributePropertySetupPatchGenerator}/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php (100%) rename testData/actions/generation/generator/{EavAttributeSetupPatchGenerator => ProductAttributePropertySetupPatchGenerator}/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php (100%) rename testData/actions/generation/generator/{EavAttributeSetupPatchGenerator => ProductAttributePropertySetupPatchGenerator}/generateFileWithOptions/AddAttributeWithOptionsAttribute.php (96%) rename tests/com/magento/idea/magento2plugin/actions/generation/generator/{AttributePropertySetupPatchGeneratorTest.java => ProductAttributePropertySetupPatchGeneratorTest.java} (98%) diff --git a/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFile/AddTestAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php similarity index 100% rename from testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFile/AddTestAttribute.php rename to testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php diff --git a/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php similarity index 100% rename from testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php rename to testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php diff --git a/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php similarity index 100% rename from testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php rename to testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php diff --git a/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php similarity index 100% rename from testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php rename to testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php diff --git a/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php similarity index 96% rename from testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php rename to testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php index fbdfba9f7..3be8e09ac 100644 --- a/testData/actions/generation/generator/EavAttributeSetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php +++ b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php @@ -92,8 +92,8 @@ public function apply() 'required' => false, 'input' => 'multiselect', 'is_filterable_in_grid' => false, + 'backend' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class, 'sort_order' => 10, - 'group' => 'General', 'option' => [ 'value' => [ 'option_0' => ['option1'], @@ -101,6 +101,7 @@ public function apply() 'option_2' => ['option3'], ] ], + 'group' => 'General', ] ); } diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/AttributePropertySetupPatchGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java similarity index 98% rename from tests/com/magento/idea/magento2plugin/actions/generation/generator/AttributePropertySetupPatchGeneratorTest.java rename to tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java index eb7970496..86ef3ac9c 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/AttributePropertySetupPatchGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java @@ -12,7 +12,7 @@ import java.util.HashMap; import java.util.Map; -public class AttributePropertySetupPatchGeneratorTest extends BaseGeneratorTestCase { +public class ProductAttributePropertySetupPatchGeneratorTest extends BaseGeneratorTestCase { private final static String MODULE_NAME = "Foo_Bar"; /** From 6982520e878bb93e8d21a5012a68f72681bf4dcd Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Wed, 21 Apr 2021 16:12:14 +0300 Subject: [PATCH 033/111] Added test for category attribute generator --- .../generation/data/CategoryFormXmlData.java | 8 +- .../dialog/NewCategoryEavAttributeDialog.java | 8 +- .../AddTestAttributeCategoryAttribute.php | 95 +++++++++++++++++++ .../generateFormFile/category_form.xml | 7 ++ ...ributePropertySetupPatchGeneratorTest.java | 80 ++++++++++++++++ 5 files changed, 190 insertions(+), 8 deletions(-) create mode 100644 testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php create mode 100644 testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFormFile/category_form.xml create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/CategoryAttributePropertySetupPatchGeneratorTest.java diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java index 393152caa..1b4eb4fd2 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java @@ -20,12 +20,18 @@ public CategoryFormXmlData( @NotNull final String attributeInput, @NotNull final int sortOrder ) { - this.fieldSetName = fieldSetName; + this.fieldSetName = convertGroupNameToFieldSet(fieldSetName); this.fieldName = fieldName; this.attributeInput = attributeInput; this.sortOrder = sortOrder; } + private String convertGroupNameToFieldSet(final String groupName) { + final String[] nameParts = groupName.toLowerCase().split(" ");//NOPMD + + return String.join("_", nameParts); + } + public String getFieldSetName() { return fieldSetName; } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java index 98553d720..fd85ca3d0 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java @@ -247,7 +247,7 @@ protected void generateExtraFilesAfterDataPatchGeneration( private void generateCategoryAdminForm(final CategoryEntityData categoryEntityData) { final CategoryFormXmlData categoryFormXmlData = new CategoryFormXmlData( - convertGroupNameToFieldSet(categoryEntityData.getGroup()), + categoryEntityData.getGroup(), categoryEntityData.getCode(), categoryEntityData.getInput(), categoryEntityData.getSortOrder() @@ -259,10 +259,4 @@ private void generateCategoryAdminForm(final CategoryEntityData categoryEntityDa moduleName ).generate(actionName, false); } - - private String convertGroupNameToFieldSet(final String groupName) { - final String[] nameParts = groupName.toLowerCase().split(" ");//NOPMD - - return String.join("_", nameParts); - } } diff --git a/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php b/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php new file mode 100644 index 000000000..d6b864318 --- /dev/null +++ b/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php @@ -0,0 +1,95 @@ +moduleDataSetup = $moduleDataSetup; + $this->eavSetupFactory = $eavSetupFactory; + } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } + + /** + * Run code inside patch + * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert + * means run PatchInterface::revert() + * + * If we speak about data, under revert means: $transaction->rollback() + * + * @return $this + */ + public function apply() + { + /** @var EavSetup $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); + + $eavSetup->addAttribute( + \Magento\Catalog\Model\Category::ENTITY, + 'test_attribute', + [ + 'input' => 'text', + 'visible' => true, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, + 'label' => 'Test Attribute', + 'source' => null, + 'type' => 'static', + 'sort_order' => 10, + 'required' => false, + 'group' => 'Content', + ] + ); + } +} diff --git a/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFormFile/category_form.xml b/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFormFile/category_form.xml new file mode 100644 index 000000000..58c560cfa --- /dev/null +++ b/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFormFile/category_form.xml @@ -0,0 +1,7 @@ + +
+
+ +
+
diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/CategoryAttributePropertySetupPatchGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/CategoryAttributePropertySetupPatchGeneratorTest.java new file mode 100644 index 000000000..98f2d375a --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/CategoryAttributePropertySetupPatchGeneratorTest.java @@ -0,0 +1,80 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.data.CategoryEntityData; +import com.magento.idea.magento2plugin.actions.generation.data.CategoryFormXmlData; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; + +public class CategoryAttributePropertySetupPatchGeneratorTest extends BaseGeneratorTestCase { + + private final static String MODULE_NAME = "Foo_Bar"; + + public void testGenerateFile() { + final Project project = myFixture.getProject(); + + final CategoryEntityData categoryEntityData = new CategoryEntityData(); + categoryEntityData.setCode("test_attribute"); + categoryEntityData.setInput("text"); + categoryEntityData.setVisible(true); + categoryEntityData.setLabel("Test Attribute"); + categoryEntityData.setType("static"); + categoryEntityData.setRequired(false); + categoryEntityData.setGroup("Content"); + categoryEntityData.setSortOrder(10); + categoryEntityData.setScope(AttributeScope.GLOBAL.getScope()); + + categoryEntityData.setDataPatchName("AddTestAttributeCategoryAttribute"); + categoryEntityData.setModuleName(MODULE_NAME); + + + final EavAttributeSetupPatchGenerator setupPatchGenerator = + new EavAttributeSetupPatchGenerator(categoryEntityData, project); + final PsiFile dataPatchFile = setupPatchGenerator.generate("testGenerateFile"); + + final String filePatch = this.getFixturePath("AddTestAttributeCategoryAttribute.php"); + final PsiFile expectedFile = myFixture.configureByFile(filePatch); + + assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile); + } + + public void testGenerateFormFile() { + final Project project = myFixture.getProject(); + + final CategoryEntityData categoryEntityData = new CategoryEntityData(); + categoryEntityData.setCode("test_attribute"); + categoryEntityData.setInput("text"); + categoryEntityData.setVisible(true); + categoryEntityData.setLabel("Test Attribute"); + categoryEntityData.setType("static"); + categoryEntityData.setRequired(false); + categoryEntityData.setGroup("Content"); + categoryEntityData.setSortOrder(10); + categoryEntityData.setScope(AttributeScope.GLOBAL.getScope()); + + categoryEntityData.setDataPatchName("AddTestAttributeCategoryAttribute"); + categoryEntityData.setModuleName(MODULE_NAME); + + final CategoryFormXmlData categoryFormXmlData = new CategoryFormXmlData( + categoryEntityData.getGroup(), + categoryEntityData.getCode(), + categoryEntityData.getInput(), + categoryEntityData.getSortOrder() + ); + + final CategoryFormXmlGenerator categoryFormXmlGenerator = + new CategoryFormXmlGenerator(categoryFormXmlData, project, MODULE_NAME); + final PsiFile categoryForm = categoryFormXmlGenerator.generate("category_form"); + + final String fileCategoryForm = this.getFixturePath("category_form.xml"); + final PsiFile expectedCategoryFile = myFixture.configureByFile(fileCategoryForm); + + assertGeneratedFileIsCorrect(expectedCategoryFile, "src/app/code/Foo/Bar/view/adminhtml/ui_component", categoryForm); + } +} From 66ef88336a64ac808721815eba750f228a8653fb Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Fri, 23 Apr 2021 08:36:18 +0300 Subject: [PATCH 034/111] Refactored and improved eav attribute generations. Moved fields on the forms and changed validation. --- .../dialog/NewCategoryEavAttributeDialog.form | 149 +++++++++++----- .../dialog/NewCategoryEavAttributeDialog.java | 29 +-- .../dialog/NewProductEavAttributeDialog.form | 165 ++++++++++++------ .../dialog/NewProductEavAttributeDialog.java | 30 ++-- .../eavattribute/EavAttributeDialog.java | 39 +++-- .../event/eavdialog/AttributeCodeAdapter.java | 48 +++++ 6 files changed, 326 insertions(+), 134 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeCodeAdapter.java diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form index a68a352db..2c6ecbbee 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form @@ -3,7 +3,7 @@ - + @@ -11,7 +11,7 @@ - + @@ -23,7 +23,7 @@ - + @@ -33,25 +33,15 @@ - + - - - - - - - - - - - + @@ -61,15 +51,7 @@ - - - - - - - - - + @@ -77,7 +59,7 @@ - + @@ -87,7 +69,7 @@ - + @@ -97,7 +79,7 @@ - + @@ -105,7 +87,7 @@ - + @@ -115,7 +97,7 @@ - + @@ -129,7 +111,7 @@
- + @@ -139,7 +121,7 @@ - + @@ -159,19 +141,19 @@ - + - + - + @@ -182,7 +164,7 @@ - + @@ -211,10 +193,10 @@
- + - + @@ -224,14 +206,14 @@ - + - + @@ -241,9 +223,9 @@
- + - + @@ -251,16 +233,97 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java index fd85ca3d0..8a2bfe791 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java @@ -14,12 +14,7 @@ import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; import com.magento.idea.magento2plugin.actions.generation.generator.CategoryFormXmlGenerator; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JPanel; -import javax.swing.JTable; -import javax.swing.JTextField; +import javax.swing.*; @SuppressWarnings({ "PMD.TooManyFields", @@ -62,13 +57,20 @@ public class NewCategoryEavAttributeDialog extends EavAttributeDialog { private JPanel customSourceModelPanel; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Source Model Directory"}) - private JTextField sourceModelDirectoryTexField; + private JTextField sourceModelDirectoryTextField; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Source Model Name"}) - private JTextField sourceModelNameTexField; + private JTextField sourceModelNameTextField; private JTable optionsTable; private JButton addNewOptionButton; private JPanel optionsPanel; + private JLabel codeTextFieldErrorMessage; + private JLabel labelTextFieldErrorMessage; + private JLabel dataPatchNameTextFieldErrorMessage; + private JLabel groupTextFieldErrorMessage; + private JLabel sourceModelDirectoryTextFieldErrorMessage; + private JLabel sourceModelNameTextFieldErrorMessage; + private JLabel sortOrderTextFieldErrorMessage; /** * Constructor. @@ -83,7 +85,6 @@ public NewCategoryEavAttributeDialog( final String actionName ) { super(project, directory, actionName); - } @Override @@ -143,12 +144,12 @@ protected JComboBox getAttributeSourceComboBox() { @Override protected JTextField getAttributeSourceModelNameTexField() { - return sourceModelNameTexField; + return sourceModelNameTextField; } @Override - protected JTextField getSourceModelDirectoryTexField() { - return sourceModelDirectoryTexField; + protected JTextField getSourceModelDirectoryTextField() { + return sourceModelDirectoryTextField; } @Override @@ -172,8 +173,8 @@ protected JTextField getDataPatchNameTextField() { } @Override - protected JTextField getSourceModelNameTexField() { - return sourceModelNameTexField; + protected JTextField getSourceModelNameTextField() { + return sourceModelNameTextField; } @Override diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form index 977e99753..f1062a90b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form @@ -3,7 +3,7 @@ - + @@ -11,7 +11,7 @@ - + @@ -22,36 +22,18 @@ - - - - - - - - - - - - - - - - - - - + - + @@ -61,15 +43,7 @@ - - - - - - - - - + @@ -77,7 +51,7 @@ - + @@ -87,7 +61,7 @@ - + @@ -97,7 +71,7 @@ - + @@ -105,7 +79,7 @@ - + @@ -115,7 +89,7 @@ - + @@ -129,7 +103,7 @@ - + @@ -139,7 +113,7 @@ - + @@ -204,19 +178,19 @@ - + - + - + @@ -227,7 +201,7 @@ - + @@ -256,10 +230,10 @@ - + - + @@ -269,14 +243,14 @@ - + - + @@ -286,9 +260,9 @@
- + - + @@ -296,14 +270,32 @@ - - + + + + + + + + + + + + + + + + + + + + @@ -318,7 +310,7 @@ - + @@ -353,6 +345,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java index cee8f101b..d6c77dad6 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java @@ -21,14 +21,7 @@ import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; import com.magento.idea.magento2plugin.util.magento.GetProductTypesListUtil; import java.util.List; -import javax.swing.DefaultListModel; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JTable; -import javax.swing.JTextField; +import javax.swing.*; @SuppressWarnings({ "PMD.TooManyFields", @@ -76,10 +69,10 @@ public class NewProductEavAttributeDialog extends EavAttributeDialog { private JPanel customSourceModelPanel; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Source Model Directory"}) - private JTextField sourceModelDirectoryTexField; + private JTextField sourceModelDirectoryTextField; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Source Model Name"}) - private JTextField sourceModelNameTexField; + private JTextField sourceModelNameTextField; private JTable optionsTable; private JButton addNewOptionButton; private JPanel optionsPanel; @@ -88,6 +81,13 @@ public class NewProductEavAttributeDialog extends EavAttributeDialog { private JCheckBox applyToAllProductsCheckBox; private JPanel applyToPanel; private JList productsTypesList; + private JLabel labelTextFieldErrorMessage; + private JLabel codeTextFieldErrorMessage; + private JLabel dataPatchNameTextFieldErrorMessage; + private JLabel groupTextFieldErrorMessage; + private JLabel sourceModelDirectoryTextFieldErrorMessage; + private JLabel sourceModelNameTextFieldErrorMessage; + private JLabel sortOrderTextFieldErrorMessage; /** * Constructor. @@ -162,12 +162,12 @@ protected JComboBox getAttributeSourceComboBox() { @Override protected JTextField getAttributeSourceModelNameTexField() { - return sourceModelNameTexField; + return sourceModelNameTextField; } @Override - protected JTextField getSourceModelDirectoryTexField() { - return sourceModelDirectoryTexField; + protected JTextField getSourceModelDirectoryTextField() { + return sourceModelDirectoryTextField; } @Override @@ -191,8 +191,8 @@ protected JTextField getDataPatchNameTextField() { } @Override - protected JTextField getSourceModelNameTexField() { - return sourceModelNameTexField; + protected JTextField getSourceModelNameTextField() { + return sourceModelNameTextField; } @Override diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java index 5e4022b39..b3fb244b9 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java @@ -11,12 +11,7 @@ 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.AbstractDialog; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourcePanelComponentListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourceRelationsItemListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.DataPatchNameAdapter; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.EavAttributeInputItemListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.OptionsPanelVisibilityChangeListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.SourceModelNameAdapter; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.*; import com.magento.idea.magento2plugin.actions.generation.dialog.util.eavdialog.AttributeUtil; import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator; @@ -42,6 +37,7 @@ import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.KeyStroke; +import org.jetbrains.annotations.NotNull; @SuppressWarnings({"PMD.GodClass", "PMD.TooManyMethods"}) public abstract class EavAttributeDialog extends AbstractDialog { @@ -72,7 +68,7 @@ public abstract class EavAttributeDialog extends AbstractDialog { protected abstract JTextField getAttributeSourceModelNameTexField(); - protected abstract JTextField getSourceModelDirectoryTexField(); + protected abstract JTextField getSourceModelDirectoryTextField(); protected abstract JPanel getAttributeCustomSourceModelPanel(); @@ -82,7 +78,7 @@ public abstract class EavAttributeDialog extends AbstractDialog { protected abstract JTextField getDataPatchNameTextField(); - protected abstract JTextField getSourceModelNameTexField(); + protected abstract JTextField getSourceModelNameTextField(); protected abstract JTextField getAttributeLabelTexField(); @@ -121,6 +117,7 @@ public void open() { this.initBaseDialogState(); pack(); centerDialog(this); + setTitle(actionName); setVisible(true); } @@ -151,7 +148,7 @@ protected void initBaseDialogState() { this.setSourceModelPanelAction( getAttributeCustomSourceModelPanel(), - getSourceModelDirectoryTexField() + getSourceModelDirectoryTextField() ); this.addOptionPanelListener( getAttributeSourceComboBox(), @@ -159,13 +156,17 @@ protected void initBaseDialogState() { getAttributeOptionsPanel() ); this.setDefaultSources(getAttributeSourceComboBox()); + this.setAutocompleteListenerForAttributeCodeField( + getAttributeLabelTexField(), + getAttributeCodeTextField() + ); this.setAutocompleteListenerForDataPathNameField( getAttributeCodeTextField(), getDataPatchNameTextField() ); this.setAutocompleteListenerForSourceModelNameField( getAttributeCodeTextField(), - getSourceModelNameTexField() + getSourceModelNameTextField() ); } @@ -241,6 +242,8 @@ protected void addActionListenersForOkCancel(final JButton cancelButton) { } protected void onOk() { + stopOptionsTableEditing(getOptionsTable()); + if (!validateFormFields()) { return; } @@ -267,7 +270,7 @@ protected void generateSourceModelFile() { sourceModelData.setModuleName(moduleName); sourceModelData.setClassName(getAttributeSourceModelNameTexField().getText().trim()); - sourceModelData.setDirectory(getSourceModelDirectoryTexField().getText().trim()); + sourceModelData.setDirectory(getSourceModelDirectoryTextField().getText().trim()); new SourceModelGenerator(sourceModelData, project, true) .generate(actionName, false); @@ -386,6 +389,14 @@ protected void setDefaultSources(final JComboBox sourceComboBo sourceComboBox.setSelectedItem(defaultSourceItem); } + protected void setAutocompleteListenerForAttributeCodeField( + @NotNull final JTextField attributeLabelTextField, + @NotNull final JTextField attributeCodeTextField + ) { + attributeLabelTextField.getDocument() + .addDocumentListener(new AttributeCodeAdapter(attributeCodeTextField)); + } + @SuppressWarnings("PMD.AccessorMethodGeneration") protected void setAutocompleteListenerForDataPathNameField( final JTextField mainTextField, @@ -493,4 +504,10 @@ protected Map getAttributeOptionsSortOrders( entityPropertiesTableGroupWrapper.getColumnsData() ); } + + private void stopOptionsTableEditing(final JTable optionsTable) { + if (optionsTable != null && optionsTable.isEditing()) { + optionsTable.getCellEditor().stopCellEditing(); + } + } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeCodeAdapter.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeCodeAdapter.java new file mode 100644 index 000000000..649b66bbb --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeCodeAdapter.java @@ -0,0 +1,48 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; + +import com.intellij.ui.DocumentAdapter; +import java.util.Locale; +import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import org.jetbrains.annotations.NotNull; + +public class AttributeCodeAdapter extends DocumentAdapter { + + private final JTextField attributeCodeTextField; + + public AttributeCodeAdapter(@NotNull final JTextField attributeCodeTextField) { + super(); + this.attributeCodeTextField = attributeCodeTextField; + } + + @Override + protected void textChanged(final @NotNull DocumentEvent event) { + final Document document = event.getDocument(); + + try { + final String attributeLabel = document.getText( + 0, document.getEndPosition().getOffset() + ).trim(); + attributeCodeTextField.setText( + convertLabelToAttributeCode(attributeLabel) + ); + } catch (BadLocationException badLocationException) { + return; + } + } + + private String convertLabelToAttributeCode(final String attributeLabel) { + final String formattedAttributeLabel = attributeLabel.trim().toLowerCase(Locale.ROOT); + + //replace 2 or more spaces with underscore + return formattedAttributeLabel.replaceAll("^ +| +$|( )+", "_"); + } +} From 0e114f8c791a36c4d5884052cb2a359150620182 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Fri, 23 Apr 2021 09:46:52 +0300 Subject: [PATCH 035/111] Multiple improvements to EAV generators --- ...ento Eav Attribute Data Patch Class.php.ft | 54 ++++++++--------- .../EavAttributeSetupPatchGenerator.java | 7 ++- .../magento/packages/eav/EavEntity.java | 4 +- .../AddTestAttributeCategoryAttribute.php | 56 +++++++++--------- .../generateFile/AddTestAttribute.php | 59 +++++++++---------- .../AddAppliedToAttribute.php | 59 +++++++++---------- .../AddBooleanInputAttributeAttribute.php | 59 +++++++++---------- .../AddAttributeWithCustomSourceAttribute.php | 59 +++++++++---------- .../AddAttributeWithOptionsAttribute.php | 59 +++++++++---------- 9 files changed, 206 insertions(+), 210 deletions(-) diff --git a/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft b/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft index c235baa36..94f5b8bf0 100644 --- a/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft +++ b/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft @@ -23,8 +23,6 @@ class ${CLASS_NAME} implements ${IMPLEMENTS} { private $eavSetupFactory; /** - * AddRecommendedAttribute constructor. - * * @param ${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup * @param ${EAV_SETUP_FACTORY} $eavSetupFactory */ @@ -36,6 +34,32 @@ class ${CLASS_NAME} implements ${IMPLEMENTS} { $this->eavSetupFactory = $eavSetupFactory; } + /** + * Run code inside patch + * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert + * means run PatchInterface::revert() + * + * If we speak about data, under revert means: $transaction->rollback() + * + * @return $this + */ + public function apply() + { + /** @var ${EAV_SETUP} $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); + + $eavSetup->addAttribute( + ${ENTITY_CLASS}::ENTITY, + '${ATTRIBUTE_CODE}', + [ + #set ($attributeSet = ${ATTRIBUTE_SET}) + #foreach ($attribute in $attributeSet.split("->")) + $attribute + #end +] + ); + } + /** * Get array of patches that have to be executed prior to this. * @@ -62,30 +86,4 @@ class ${CLASS_NAME} implements ${IMPLEMENTS} { { return []; } - - /** - * Run code inside patch - * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert - * means run PatchInterface::revert() - * - * If we speak about data, under revert means: $transaction->rollback() - * - * @return $this - */ - public function apply() - { - /** @var ${EAV_SETUP} $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); - - $eavSetup->addAttribute( - ${ENTITY_CLASS}::ENTITY, - '${ATTRIBUTE_CODE}', - [ - #set ($attributeSet = ${ATTRIBUTE_SET}) - #foreach ($attribute in $attributeSet.split("->")) - $attribute - #end -] - ); - } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java index 0002115c3..55b6dc99c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java @@ -68,9 +68,14 @@ protected void fillAttributes(final Properties attributes) { "IMPLEMENTS", DataPatchDependency.DATA_PATCH_INTERFACE.getClassPatch() ) + .append( + "ENTITY_CLASS", + data.getEntityClass() + ) .append( "MODULE_DATA_SETUP_INTERFACE", - DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch()) + DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch() + ) .append( "EAV_SETUP_FACTORY", DataPatchDependency.EAV_SETUP_FACTORY.getClassPatch() diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java index cdaa2fd8c..36f2487cb 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java @@ -6,8 +6,8 @@ package com.magento.idea.magento2plugin.magento.packages.eav; public enum EavEntity { - PRODUCT("\\Magento\\Catalog\\Model\\Product"), - CATEGORY("\\Magento\\Catalog\\Model\\Category"); + PRODUCT("Magento\\Catalog\\Model\\Product"), + CATEGORY("Magento\\Catalog\\Model\\Category"); private String entityClass; diff --git a/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php b/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php index d6b864318..1db511555 100644 --- a/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php +++ b/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php @@ -21,8 +21,6 @@ class AddTestAttributeCategoryAttribute implements DataPatchInterface private $eavSetupFactory; /** - * AddRecommendedAttribute constructor. - * * @param ModuleDataSetupInterface $moduleDataSetup * @param EavSetupFactory $eavSetupFactory */ @@ -35,33 +33,6 @@ public function __construct( $this->eavSetupFactory = $eavSetupFactory; } - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } - /** * Run code inside patch * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert @@ -92,4 +63,31 @@ public function apply() ] ); } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } } diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php index b0793c4e9..d31d7da10 100644 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php +++ b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php @@ -2,6 +2,7 @@ namespace Foo\Bar\Setup\Patch\Data; +use Magento\Catalog\Model\Product; use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\ModuleDataSetupInterface; @@ -21,8 +22,6 @@ class AddTestAttribute implements DataPatchInterface private $eavSetupFactory; /** - * AddRecommendedAttribute constructor. - * * @param ModuleDataSetupInterface $moduleDataSetup * @param EavSetupFactory $eavSetupFactory */ @@ -35,33 +34,6 @@ public function __construct( $this->eavSetupFactory = $eavSetupFactory; } - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } - /** * Run code inside patch * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert @@ -77,7 +49,7 @@ public function apply() $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, + Product::ENTITY, 'test', [ 'is_visible_in_grid' => false, @@ -97,4 +69,31 @@ public function apply() ] ); } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } } diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php index 7efbadc5a..b8a3cafa1 100644 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php +++ b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php @@ -2,6 +2,7 @@ namespace Foo\Bar\Setup\Patch\Data; +use Magento\Catalog\Model\Product; use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\ModuleDataSetupInterface; @@ -21,8 +22,6 @@ class AddAppliedToAttribute implements DataPatchInterface private $eavSetupFactory; /** - * AddRecommendedAttribute constructor. - * * @param ModuleDataSetupInterface $moduleDataSetup * @param EavSetupFactory $eavSetupFactory */ @@ -35,33 +34,6 @@ public function __construct( $this->eavSetupFactory = $eavSetupFactory; } - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } - /** * Run code inside patch * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert @@ -77,7 +49,7 @@ public function apply() $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, + Product::ENTITY, 'applied_to_attribute', [ 'is_visible_in_grid' => false, @@ -98,4 +70,31 @@ public function apply() ] ); } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } } diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php index 5f71e121e..668a7d808 100644 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php +++ b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php @@ -2,6 +2,7 @@ namespace Foo\Bar\Setup\Patch\Data; +use Magento\Catalog\Model\Product; use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\ModuleDataSetupInterface; @@ -21,8 +22,6 @@ class AddBooleanInputAttributeAttribute implements DataPatchInterface private $eavSetupFactory; /** - * AddRecommendedAttribute constructor. - * * @param ModuleDataSetupInterface $moduleDataSetup * @param EavSetupFactory $eavSetupFactory */ @@ -35,33 +34,6 @@ public function __construct( $this->eavSetupFactory = $eavSetupFactory; } - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } - /** * Run code inside patch * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert @@ -77,7 +49,7 @@ public function apply() $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, + Product::ENTITY, 'boolean_input_attribute', [ 'is_visible_in_grid' => false, @@ -97,4 +69,31 @@ public function apply() ] ); } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } } diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php index 9b4ce17a7..7242b836e 100644 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php +++ b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php @@ -2,6 +2,7 @@ namespace Foo\Bar\Setup\Patch\Data; +use Magento\Catalog\Model\Product; use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\ModuleDataSetupInterface; @@ -21,8 +22,6 @@ class AddAttributeWithCustomSourceAttribute implements DataPatchInterface private $eavSetupFactory; /** - * AddRecommendedAttribute constructor. - * * @param ModuleDataSetupInterface $moduleDataSetup * @param EavSetupFactory $eavSetupFactory */ @@ -35,33 +34,6 @@ public function __construct( $this->eavSetupFactory = $eavSetupFactory; } - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } - /** * Run code inside patch * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert @@ -77,7 +49,7 @@ public function apply() $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, + Product::ENTITY, 'attribute_with_custom_source', [ 'is_visible_in_grid' => false, @@ -97,4 +69,31 @@ public function apply() ] ); } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } } diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php index 3be8e09ac..700ae6373 100644 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php +++ b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php @@ -2,6 +2,7 @@ namespace Foo\Bar\Setup\Patch\Data; +use Magento\Catalog\Model\Product; use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\ModuleDataSetupInterface; @@ -21,8 +22,6 @@ class AddAttributeWithOptionsAttribute implements DataPatchInterface private $eavSetupFactory; /** - * AddRecommendedAttribute constructor. - * * @param ModuleDataSetupInterface $moduleDataSetup * @param EavSetupFactory $eavSetupFactory */ @@ -35,33 +34,6 @@ public function __construct( $this->eavSetupFactory = $eavSetupFactory; } - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } - /** * Run code inside patch * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert @@ -77,7 +49,7 @@ public function apply() $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, + Product::ENTITY, 'attribute_with_options', [ 'is_visible_in_grid' => false, @@ -105,4 +77,31 @@ public function apply() ] ); } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } } From 0e512d9e8bcc095124a08713b6234133f7634c60 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Fri, 23 Apr 2021 12:53:05 +0300 Subject: [PATCH 036/111] Fixed code style --- .../dialog/NewCategoryEavAttributeDialog.java | 8 +++++++- .../dialog/NewProductEavAttributeDialog.java | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java index 8a2bfe791..7698d4e55 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java @@ -14,7 +14,13 @@ import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; import com.magento.idea.magento2plugin.actions.generation.generator.CategoryFormXmlGenerator; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; -import javax.swing.*; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.JTextField; @SuppressWarnings({ "PMD.TooManyFields", diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java index d6c77dad6..faba8d9a1 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java @@ -21,7 +21,15 @@ import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; import com.magento.idea.magento2plugin.util.magento.GetProductTypesListUtil; import java.util.List; -import javax.swing.*; +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.JTextField; @SuppressWarnings({ "PMD.TooManyFields", From 5531aab8e2ddd3b8127bbcf33c40576921bd7e3c Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Fri, 23 Apr 2021 12:53:13 +0300 Subject: [PATCH 037/111] Fixed code style --- .../dialog/eavattribute/EavAttributeDialog.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java index b3fb244b9..cdd4daaad 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java @@ -11,7 +11,13 @@ 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.AbstractDialog; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.*; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeCodeAdapter; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourcePanelComponentListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourceRelationsItemListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.DataPatchNameAdapter; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.EavAttributeInputItemListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.OptionsPanelVisibilityChangeListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.SourceModelNameAdapter; import com.magento.idea.magento2plugin.actions.generation.dialog.util.eavdialog.AttributeUtil; import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator; From 8e98626156e010e180dca03b2cc245b23a31fab4 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Mon, 26 Apr 2021 10:55:09 +0300 Subject: [PATCH 038/111] Moved properties in new block --- .../dialog/NewCategoryEavAttributeDialog.form | 90 ++++---- .../dialog/NewProductEavAttributeDialog.form | 200 +++++++++--------- 2 files changed, 153 insertions(+), 137 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form index 2c6ecbbee..09e1bdc5a 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form @@ -23,7 +23,7 @@ - + @@ -33,7 +33,7 @@ - + @@ -41,7 +41,7 @@ - + @@ -51,7 +51,7 @@ - + @@ -59,7 +59,7 @@ - + @@ -69,7 +69,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -87,7 +87,7 @@ - + @@ -97,21 +97,13 @@ - + - - - - - - - - - + @@ -121,7 +113,7 @@ - + @@ -129,31 +121,21 @@ - - - - - - - - - - - + - + - + @@ -164,7 +146,7 @@ - + @@ -196,7 +178,7 @@ - + @@ -263,7 +245,7 @@ - + @@ -273,7 +255,7 @@ - + @@ -281,7 +263,7 @@ - + @@ -290,7 +272,7 @@ - + @@ -299,7 +281,7 @@ - + @@ -308,7 +290,7 @@ - + @@ -317,13 +299,39 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form index f1062a90b..fb8710dee 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form @@ -3,7 +3,7 @@ - + @@ -23,7 +23,7 @@ - + @@ -33,7 +33,7 @@ - + @@ -43,7 +43,7 @@ - + @@ -51,7 +51,7 @@ - + @@ -61,7 +61,7 @@ - + @@ -71,7 +71,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -89,21 +89,13 @@ - + - - - - - - - - - + @@ -113,7 +105,7 @@ - + @@ -121,76 +113,21 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + @@ -201,7 +138,7 @@ - + @@ -233,7 +170,7 @@ - + @@ -298,15 +235,6 @@ - - - - - - - - - @@ -347,7 +275,7 @@ - + @@ -357,7 +285,7 @@ - + @@ -365,7 +293,7 @@ - + @@ -373,7 +301,7 @@ - + @@ -382,7 +310,7 @@ - + @@ -391,7 +319,7 @@ - + @@ -400,7 +328,7 @@ - + @@ -409,13 +337,93 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 54855a96d3bb7e38e3364a79174397733975e617 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Mon, 26 Apr 2021 12:47:43 +0300 Subject: [PATCH 039/111] Adding copyrights --- .../generation/dialog/NewCategoryEavAttributeDialog.java | 5 +++++ .../dialog/event/eavdialog/AttributeCodeAdapter.java | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java index 7698d4e55..494e5c28e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.generation.dialog; import com.intellij.openapi.project.Project; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeCodeAdapter.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeCodeAdapter.java index 649b66bbb..a1143cdd7 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeCodeAdapter.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeCodeAdapter.java @@ -1,7 +1,6 @@ /* * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. - * */ package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; @@ -42,7 +41,6 @@ protected void textChanged(final @NotNull DocumentEvent event) { private String convertLabelToAttributeCode(final String attributeLabel) { final String formattedAttributeLabel = attributeLabel.trim().toLowerCase(Locale.ROOT); - //replace 2 or more spaces with underscore return formattedAttributeLabel.replaceAll("^ +| +$|( )+", "_"); } } From 2f6c738eb91eb2a19b5fac47765f0f5a253192f6 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Thu, 29 Apr 2021 10:34:10 +0300 Subject: [PATCH 040/111] Added customer attribute generation --- resources/META-INF/plugin.xml | 1 + ...omer Eav Attribute Data Patch Class.php.ft | 113 +++++ .../NewCustomerEavAttributeAction.java | 32 ++ .../generation/data/CustomerEntityData.java | 261 ++++++++++ .../dialog/NewCustomerEavAttributeDialog.form | 458 ++++++++++++++++++ .../dialog/NewCustomerEavAttributeDialog.java | 323 ++++++++++++ .../eavattribute/EavAttributeDialog.java | 12 +- .../CustomerEavAttributePatchGenerator.java | 107 ++++ .../EavAttributeSetupPatchGenerator.java | 5 +- .../util/eav/AttributeMapperFactory.java | 2 + .../util/eav/CategoryAttributeMapper.java | 4 + .../util/eav/CustomerAttributeMapper.java | 48 ++ .../util/eav/DefaultAttributeMapper.java | 11 +- .../util/eav/ProductAttributeMapper.java | 7 +- .../CustomerEavAttributeDataPatchFile.java | 43 ++ .../packages/eav/AttributeProperty.java | 5 +- .../magento/packages/eav/CustomerForm.java | 28 ++ .../packages/eav/DataPatchDependency.java | 8 +- .../magento/packages/eav/EavEntity.java | 3 +- 19 files changed, 1453 insertions(+), 18 deletions(-) create mode 100644 resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.ft create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/NewCustomerEavAttributeAction.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/CustomerEntityData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CustomerAttributeMapper.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/CustomerEavAttributeDataPatchFile.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/CustomerForm.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index f8cfa1663..6b63e3c96 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -80,6 +80,7 @@ + diff --git a/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.ft b/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.ft new file mode 100644 index 000000000..069df9b29 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.ft @@ -0,0 +1,113 @@ +moduleDataSetup = $moduleDataSetup; + $this->eavSetupFactory = $eavSetupFactory; + $this->eavConfig = $eavConfig; + } + + /** + * Run code inside patch + * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert + * means run PatchInterface::revert() + * + * If we speak about data, under revert means: $transaction->rollback() + * + * @return $this + */ + public function apply() + { +/** @var ${EAV_SETUP} $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); + + $eavSetup->addAttribute( + ${ENTITY_CLASS}::ENTITY, + '${ATTRIBUTE_CODE}', + [ + #set ($attributeSet = ${ATTRIBUTE_SET}) + #foreach ($attribute in $attributeSet.split("->")) + $attribute + #end +] + ); + + $eavSetup->addAttributeToSet( + ${CUSTOMER_METADATA_INTERFACE}::ENTITY_TYPE_CUSTOMER, + ${CUSTOMER_METADATA_INTERFACE}::ATTRIBUTE_SET_ID_CUSTOMER, + null, + '${ATTRIBUTE_CODE}' + ); + + #if (${CUSTOMER_FORMS}) + $attribute = $this->eavConfig->getAttribute(${ENTITY_CLASS}::ENTITY, '${ATTRIBUTE_CODE}'); + $attribute->setData( + 'used_in_forms', + [${CUSTOMER_FORMS}] + ); + $attribute->save(); + #end + + return $this; + } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/NewCustomerEavAttributeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/NewCustomerEavAttributeAction.java new file mode 100644 index 000000000..6b680b2b3 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/NewCustomerEavAttributeAction.java @@ -0,0 +1,32 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.magento.idea.magento2plugin.MagentoIcons; +import com.magento.idea.magento2plugin.actions.generation.dialog.NewCustomerEavAttributeDialog; +import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; +import com.magento.idea.magento2plugin.actions.generation.eavattribute.NewEavAttributeAction; + +public class NewCustomerEavAttributeAction extends NewEavAttributeAction { + + public static final String ACTION_NAME = "Customer Attribute"; + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Customer Attribute"; + + public NewCustomerEavAttributeAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); + } + + @Override + protected EavAttributeDialog getDialogWindow( + final Project project, + final PsiDirectory directory + ) { + return new NewCustomerEavAttributeDialog(project, directory, ACTION_NAME); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/CustomerEntityData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/CustomerEntityData.java new file mode 100644 index 000000000..bf148c944 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/CustomerEntityData.java @@ -0,0 +1,261 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity; +import java.util.Map; + +@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessivePublicCount"}) +public class CustomerEntityData implements EavEntityDataInterface { + + private String code; + private String type; + private String label; + private String input; + private String namespace; + private String moduleName; + private String directory; + private String dataPatchName; + private String source; + private int sortOrder; + private Map options; + private String model; + private Map optionsSortOrder; + private boolean required; + private boolean visible; + private boolean userDefined; + private boolean useInAdminhtmlCustomerForm; + private boolean useInCustomerAccountCreateForm; + private boolean useInCustomerAccountEditForm; + private boolean usedInGrid; + private boolean visibleInGrid; + private boolean filterableInGrid; + private boolean system; + + @Override + public void setCode(final String code) { + this.code = code; + } + + @Override + public void setType(final String type) { + this.type = type; + } + + @Override + public void setLabel(final String label) { + this.label = label; + } + + @Override + public void setInput(final String input) { + this.input = input; + } + + @Override + public void setNamespace(final String namespace) { + this.namespace = namespace; + } + + @Override + public void setModuleName(final String moduleName) { + this.moduleName = moduleName; + } + + @Override + public void setDirectory(final String directory) { + this.directory = directory; + } + + @Override + public void setDataPatchName(final String dataPatchName) { + this.dataPatchName = dataPatchName; + } + + @Override + public void setSource(final String source) { + this.source = source; + } + + @Override + public void setSortOrder(final int sortOrder) { + this.sortOrder = sortOrder; + } + + @Override + public void setOptions(final Map options) { + this.options = options; + } + + @Override + public void setOptionsSortOrder(final Map optionsSortOrder) { + this.optionsSortOrder = optionsSortOrder; + } + + @Override + public void setRequired(final boolean required) { + this.required = required; + } + + @Override + public void setVisible(final boolean visible) { + this.visible = visible; + } + + @Override + public void setBackendModel(final String model) { + this.model = model; + } + + public void setUserDefined(final boolean userDefined) { + this.userDefined = userDefined; + } + + public void setUseInAdminhtmlCustomerForm(final boolean useInAdminhtmlCustomerForm) { + this.useInAdminhtmlCustomerForm = useInAdminhtmlCustomerForm; + } + + public void setUseInCustomerAccountCreateForm(final boolean useInCustomerAccountCreateForm) { + this.useInCustomerAccountCreateForm = useInCustomerAccountCreateForm; + } + + public void setUseInCustomerAccountEditForm(final boolean useInCustomerAccountEditForm) { + this.useInCustomerAccountEditForm = useInCustomerAccountEditForm; + } + + public void setUsedInGrid(final boolean usedInGrid) { + this.usedInGrid = usedInGrid; + } + + public void setVisibleInGrid(final boolean visibleInGrid) { + this.visibleInGrid = visibleInGrid; + } + + public void setFilterableInGrid(final boolean filterableInGrid) { + this.filterableInGrid = filterableInGrid; + } + + public void setSystem(final boolean system) { + this.system = system; + } + + @Override + public String getCode() { + return code; + } + + @Override + public String getType() { + return type; + } + + @Override + public String getLabel() { + return label; + } + + @Override + public String getInput() { + return input; + } + + @Override + public String getNamespace() { + return namespace; + } + + @Override + public String getModuleName() { + return moduleName; + } + + @Override + public String getDirectory() { + return directory; + } + + @Override + public String getDataPatchName() { + return dataPatchName; + } + + @Override + public String getEntityClass() { + return EavEntity.CUSTOMER.getEntityClass(); + } + + @Override + public String getSource() { + return source; + } + + @Override + public String getBackendModel() { + return null; + } + + @Override + public int getSortOrder() { + return sortOrder; + } + + @Override + public Map getOptions() { + return options; + } + + public String getModel() { + return model; + } + + @Override + public Map getOptionsSortOrder() { + return optionsSortOrder; + } + + @Override + public boolean isRequired() { + return required; + } + + @Override + public boolean isVisible() { + return visible; + } + + public boolean isUserDefined() { + return userDefined; + } + + public boolean isUseInAdminhtmlCustomerForm() { + return useInAdminhtmlCustomerForm; + } + + public boolean isUseInCustomerAccountCreateForm() { + return useInCustomerAccountCreateForm; + } + + public boolean isUseInCustomerAccountEditForm() { + return useInCustomerAccountEditForm; + } + + public boolean isUsedInGrid() { + return usedInGrid; + } + + public boolean isVisibleInGrid() { + return visibleInGrid; + } + + public boolean isFilterableInGrid() { + return filterableInGrid; + } + + public boolean isSystem() { + return system; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form new file mode 100644 index 000000000..32aa56cae --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form @@ -0,0 +1,458 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java new file mode 100644 index 000000000..07daa2f92 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java @@ -0,0 +1,323 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.magento.idea.magento2plugin.actions.generation.data.CustomerEntityData; +import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; +import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; +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.Lowercase; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; +import com.magento.idea.magento2plugin.actions.generation.generator.CustomerEavAttributePatchGenerator; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; +import com.magento.idea.magento2plugin.magento.packages.uicomponent.AvailableSourcesByInput; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.List; +import javax.swing.*; + +@SuppressWarnings({ + "PMD.TooManyFields", + "PMD.ExcessiveImports", + "PMD.TooManyMethods", + "PMD.UnusedPrivateField" +}) +public class NewCustomerEavAttributeDialog extends EavAttributeDialog { + + private static final String ENTITY_NAME = "Customer"; + private JPanel contentPanel; + private JButton buttonOK; + private JButton buttonCancel; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Code"}) + @FieldValidation(rule = RuleRegistry.LOWERCASE, + message = {Lowercase.MESSAGE, "Attribute Code"}) + private JTextField codeTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Label"}) + private JTextField labelTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Data Patch Name"}) + private JTextField dataPatchNameTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) + @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, + message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) + private JTextField sortOrderTextField; + private JComboBox inputComboBox; + private JComboBox typeComboBox; + private JComboBox sourceComboBox; + private JCheckBox requiredCheckBox; + private JCheckBox visibleCheckBox; + private JPanel sourcePanel; + private JPanel customSourceModelPanel; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Source Model Directory"}) + private JTextField sourceModelDirectoryTextField; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, "Source Model Name"}) + private JTextField sourceModelNameTextField; + private JTable optionsTable; + private JButton addNewOptionButton; + private JPanel optionsPanel; + private JLabel codeTextFieldErrorMessage; + private JLabel labelTextFieldErrorMessage; + private JLabel dataPatchNameTextFieldErrorMessage; + private JLabel sourceModelDirectoryTextFieldErrorMessage; + private JLabel sourceModelNameTextFieldErrorMessage; + private JLabel sortOrderTextFieldErrorMessage; + private JCheckBox userDefineCheckBox; + private JCheckBox useInAdminhtmlCustomerCheckBox; + private JCheckBox useInCustomerAccountCreateCheckBox; + private JCheckBox useInCustomerAccountEditCheckBox; + private JCheckBox useInGridCheckBox; + private JCheckBox filterableInGridCheckBox; + private JCheckBox visibleInGridCheckBox; + private JCheckBox systemAttributecheckBox; + + /** + * Constructor. + * + * @param project Project + * @param directory PsiDirectory + * @param actionName String + */ + public NewCustomerEavAttributeDialog( + final Project project, + final PsiDirectory directory, + final String actionName + ) { + super(project, directory, actionName); + } + + @Override + protected JPanel getContentPanel() { + return contentPanel; + } + + @Override + protected JButton getButtonOk() { + return buttonOK; + } + + @Override + protected JButton getButtonCancel() { + return buttonCancel; + } + + @Override + protected JComboBox getAttributeTypeCompoBox() { + return typeComboBox; + } + + @Override + protected JComboBox getAttributeInputComboBox() { + return inputComboBox; + } + + @Override + protected JTable getOptionsTable() { + return optionsTable; + } + + @Override + protected JButton getNewOptionButton() { + return addNewOptionButton; + } + + @Override + protected JComboBox getAttributeSourceComboBox() { + return sourceComboBox; + } + + @Override + protected JTextField getAttributeSourceModelNameTexField() { + return sourceModelNameTextField; + } + + @Override + protected JTextField getSourceModelDirectoryTextField() { + return sourceModelDirectoryTextField; + } + + @Override + protected JPanel getAttributeCustomSourceModelPanel() { + return customSourceModelPanel; + } + + @Override + protected JPanel getAttributeOptionsPanel() { + return optionsPanel; + } + + @Override + protected JTextField getAttributeCodeTextField() { + return codeTextField; + } + + @Override + protected JTextField getDataPatchNameTextField() { + return dataPatchNameTextField; + } + + @Override + protected JTextField getSourceModelNameTextField() { + return sourceModelNameTextField; + } + + @Override + protected JTextField getAttributeLabelTexField() { + return labelTextField; + } + + @Override + protected JTextField getAttributeSortOrderTextField() { + return sortOrderTextField; + } + + @Override + protected JCheckBox getAttributeRequiredCheckBox() { + return requiredCheckBox; + } + + @Override + protected JCheckBox getAttributeVisibleBox() { + return visibleCheckBox; + } + + @Override + protected String getEntityName() { + return ENTITY_NAME; + } + + @Override + protected void generateDataPatchFile(final EavEntityDataInterface eavEntityDataInterface) { + new CustomerEavAttributePatchGenerator( + eavEntityDataInterface, + project, + true + ).generate(actionName, true); + } + + @Override + protected EavEntityDataInterface getEavEntityData() { + return populateCategoryEntityData(new CustomerEntityData()); + } + + private CustomerEntityData populateCategoryEntityData( + final CustomerEntityData customerEntityData + ) { + customerEntityData.setModuleName(moduleName); + customerEntityData.setType(getAttributeBackendType()); + customerEntityData.setDataPatchName(getDataPatchName()); + customerEntityData.setCode(getAttributeCode()); + customerEntityData.setLabel(getAttributeLabel()); + customerEntityData.setSortOrder(getAttributeSortOrder()); + customerEntityData.setRequired(isRequiredAttribute()); + customerEntityData.setVisible(isVisibleAttribute()); + customerEntityData.setInput(getAttributeInput()); + customerEntityData.setSource(getAttributeSource(sourceModelData)); + customerEntityData.setOptions( + getAttributeOptions(entityPropertiesTableGroupWrapper) + ); + customerEntityData.setOptionsSortOrder( + getAttributeOptionsSortOrders(entityPropertiesTableGroupWrapper) + ); + customerEntityData.setUserDefined(userDefineCheckBox.isSelected()); + customerEntityData.setUseInAdminhtmlCustomerForm( + useInAdminhtmlCustomerCheckBox.isSelected() + ); + customerEntityData.setUseInCustomerAccountCreateForm( + useInCustomerAccountCreateCheckBox.isSelected() + ); + customerEntityData.setUseInCustomerAccountEditForm( + useInCustomerAccountEditCheckBox.isSelected() + ); + customerEntityData.setVisibleInGrid(visibleInGridCheckBox.isSelected()); + customerEntityData.setUsedInGrid(useInGridCheckBox.isVisible()); + customerEntityData.setFilterableInGrid(filterableInGridCheckBox.isSelected()); + customerEntityData.setSystem(systemAttributecheckBox.isSelected()); + + return customerEntityData; + } + + @Override + protected void addOptionPanelListener( + final JComboBox attributeSourceComboBox, + final JComboBox attributeInputComboBox, + final JPanel attributeOptionsPanel + ) { + if (attributeSourceComboBox == null + || attributeInputComboBox == null + || attributeOptionsPanel == null + ) { + return; + } + + attributeSourceComboBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(final ItemEvent itemEvent) { + final ComboBoxItemData selectedInputItem = (ComboBoxItemData) attributeInputComboBox.getSelectedItem(); + final String selectedInput = selectedInputItem == null ? "" : selectedInputItem.toString(); + final boolean isAllowedInput = + AttributeInput.SELECT.getInput().equals(selectedInput) + || AttributeInput.MULTISELECT.getInput().equals(selectedInput); + + attributeOptionsPanel.setVisible(isAllowedInput); + } + }); + } + + @Override + protected void setAttributeInputComboBoxAction( + final JComboBox sourceComboBox, + final JComboBox inputComboBox + ) { + if (sourceComboBox == null || inputComboBox == null) { + return; + } + + inputComboBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(final ItemEvent itemEvent) { + final String selectedInput = itemEvent.getItem().toString(); + + final List availableSources = + new AvailableSourcesByInput(selectedInput).getItems(); + sourceComboBox.removeAllItems(); + + if (!selectedInput.equals(AttributeInput.SELECT.getInput()) + || !selectedInput.equals(AttributeInput.MULTISELECT.getInput())) { + final ComboBoxItemData defaultSourceItem = new ComboBoxItemData( + AttributeSourceModel.NULLABLE_SOURCE.name(), + AttributeSourceModel.NULLABLE_SOURCE.getSource() + ); + + sourceComboBox.addItem(defaultSourceItem); + sourceComboBox.setSelectedItem(defaultSourceItem); + } + + if (availableSources.isEmpty()) { + return; + } + + for (final ComboBoxItemData comboBoxItemData : availableSources) { + sourceComboBox.addItem(comboBoxItemData); + + if (comboBoxItemData.getText().equals(AttributeSourceModel.TABLE.getSource())) { + sourceComboBox.setSelectedItem(comboBoxItemData); + } + } + } + }); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java index cdd4daaad..15ab458ad 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java @@ -149,7 +149,10 @@ protected void initBaseDialogState() { this.addCancelActionForWindow(); this.addCancelActionForEsc(); - this.setAttributeInputComboBoxAction(getAttributeSourceComboBox()); + this.setAttributeInputComboBoxAction( + getAttributeSourceComboBox(), + getAttributeInputComboBox() + ); this.setSourceComboBoxAction(getAttributeSourceComboBox()); this.setSourceModelPanelAction( @@ -318,13 +321,14 @@ protected void addCancelActionForEsc() { @SuppressWarnings("PMD.AccessorMethodGeneration") protected void setAttributeInputComboBoxAction( - final JComboBox sourceComboBox + final JComboBox sourceComboBox, + final JComboBox inputComboBox ) { - if (sourceComboBox == null) { + if (sourceComboBox == null || inputComboBox == null) { return; } - getAttributeInputComboBox().addItemListener( + inputComboBox.addItemListener( new EavAttributeInputItemListener(sourceComboBox) ); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java new file mode 100644 index 000000000..a62e954ed --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java @@ -0,0 +1,107 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.CustomerEntityData; +import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.CustomerEavAttributeDataPatchFile; +import com.magento.idea.magento2plugin.magento.packages.eav.CustomerForm; +import com.magento.idea.magento2plugin.magento.packages.eav.DataPatchDependency; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class CustomerEavAttributePatchGenerator extends EavAttributeSetupPatchGenerator { + + private final EavEntityDataInterface data; + + public CustomerEavAttributePatchGenerator( + final @NotNull EavEntityDataInterface data, + final Project project + ) { + this(data, project, true); + } + + /** + * Php file generator constructor. + * + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public CustomerEavAttributePatchGenerator( + final @NotNull EavEntityDataInterface data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(data, project, checkFileAlreadyExists); + this.data = data; + } + + @Override + protected AbstractPhpFile initFile() { + return new CustomerEavAttributeDataPatchFile(data.getModuleName(), data.getDataPatchName()); + } + + @Override + protected void fillAttributes(final Properties attributes) { + super.fillAttributes(attributes); + phpClassTypesBuilder + .append( + "EAV_CONFIG_CLASS", + DataPatchDependency.EAV_CONFIG.getClassPatch() + ) + .append( + "CUSTOMER_METADATA_INTERFACE", + DataPatchDependency.CUSTOMER_METADATA_INTERFACE.getClassPatch() + ); + + final String selectedCustomerForms = getFormsForAttribute((CustomerEntityData) data); + + if (!selectedCustomerForms.isEmpty()) { + phpClassTypesBuilder.appendProperty("CUSTOMER_FORMS", selectedCustomerForms); + } + + phpClassTypesBuilder.mergeProperties(attributes); + + attributes.setProperty( + "USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()) + ); + } + + private String getFormsForAttribute(final CustomerEntityData customerEntityData) { + final List usedInForms = new ArrayList<>(); + + if (customerEntityData.isUseInAdminhtmlCustomerForm()) { + usedInForms.add( + "'" + CustomerForm.ADMINHTML_CUSTOMER.getFormCode() + "'" + ); + } + + if (customerEntityData.isUseInCustomerAccountCreateForm()) { + usedInForms.add( + "'" + CustomerForm.CUSTOMER_ACCOUNT_CREATE.getFormCode() + "'" + ); + } + + if (customerEntityData.isUseInCustomerAccountEditForm()) { + usedInForms.add( + "'" + CustomerForm.CUSTOMER_ACCOUNT_EDIT.getFormCode() + "'" + ); + } + + if (usedInForms.isEmpty()) { + return ""; + } + + return String.join(",", usedInForms); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java index 55b6dc99c..3339abf99 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java @@ -19,7 +19,9 @@ import org.jetbrains.annotations.NotNull; public class EavAttributeSetupPatchGenerator extends PhpFileGenerator { + private final EavEntityDataInterface data; + protected final PhpClassTypesBuilder phpClassTypesBuilder; /** * Constructor. @@ -47,6 +49,7 @@ public EavAttributeSetupPatchGenerator( ) { super(project, checkFileAlreadyExists); this.data = data; + this.phpClassTypesBuilder = new PhpClassTypesBuilder(); } @Override @@ -56,8 +59,6 @@ protected AbstractPhpFile initFile() { @Override protected void fillAttributes(final Properties attributes) { - final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); - phpClassTypesBuilder .appendProperty("CLASS_NAME", data.getDataPatchName()) .appendProperty("NAMESPACE", this.getFile().getNamespace()) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java index b5d8f102b..1d9bf01d5 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java @@ -19,6 +19,8 @@ public AttributeMapperInterface createByEntityClass(@NotNull final String entity return new ProductAttributeMapper(); } else if (entityClass.equals(EavEntity.CATEGORY.getEntityClass())) { return new CategoryAttributeMapper(); + } else if (entityClass.equals(EavEntity.CUSTOMER.getEntityClass())) { + return new CustomerAttributeMapper(); } return null; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CategoryAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CategoryAttributeMapper.java index e51d38782..b291e3e06 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CategoryAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CategoryAttributeMapper.java @@ -17,6 +17,10 @@ protected Map getMappedAttributes(final EavEntityDataInterface e final Map mappedAttributes = super.getMappedAttributes(eavEntityData); final CategoryEntityData categoryEavEntityData = (CategoryEntityData) eavEntityData; + mappedAttributes.put( + AttributeProperty.SORT_ORDER.getProperty(), + Integer.toString(categoryEavEntityData.getSortOrder()) + ); mappedAttributes.put( AttributeProperty.GLOBAL.getProperty(), categoryEavEntityData.getScope() diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CustomerAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CustomerAttributeMapper.java new file mode 100644 index 000000000..73c939f8e --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CustomerAttributeMapper.java @@ -0,0 +1,48 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; + +import com.magento.idea.magento2plugin.actions.generation.data.CustomerEntityData; +import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeProperty; +import java.util.Map; + +public class CustomerAttributeMapper extends DefaultAttributeMapper { + + @Override + protected Map getMappedAttributes(final EavEntityDataInterface eavEntityData) { + final Map mappedAttributes = super.getMappedAttributes(eavEntityData); + final CustomerEntityData customerEntityData = (CustomerEntityData) eavEntityData; + + mappedAttributes.put( + AttributeProperty.POSITION.getProperty(), + Integer.toString(customerEntityData.getSortOrder()) + ); + mappedAttributes.put( + AttributeProperty.USER_DEFINED.getProperty(), + Boolean.toString(customerEntityData.isUserDefined()) + ); + mappedAttributes.put( + AttributeProperty.IS_USED_IN_GRID.getProperty(), + Boolean.toString(customerEntityData.isUsedInGrid()) + ); + mappedAttributes.put( + AttributeProperty.IS_VISIBLE_IN_GRID.getProperty(), + Boolean.toString(customerEntityData.isVisibleInGrid()) + ); + mappedAttributes.put( + AttributeProperty.IS_FILTERABLE_IN_GRID.getProperty(), + Boolean.toString(customerEntityData.isFilterableInGrid()) + ); + mappedAttributes.put( + AttributeProperty.SYSTEM.getProperty(), + Boolean.toString(customerEntityData.isSystem()) + ); + + return mappedAttributes; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java index 1b683a0ec..a8a5fb9cd 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java @@ -9,8 +9,8 @@ import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeBackendModel; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeProperty; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -58,10 +58,6 @@ protected Map getMappedAttributes(final EavEntityDataInterface e AttributeProperty.REQUIRED.getProperty(), Boolean.toString(eavEntityData.isRequired()) ); - mappedAttributes.put( - AttributeProperty.SORT_ORDER.getProperty(), - Integer.toString(eavEntityData.getSortOrder()) - ); mappedAttributes.put( AttributeProperty.VISIBLE.getProperty(), Boolean.toString(eavEntityData.isVisible()) @@ -75,7 +71,10 @@ protected Map getMappedAttributes(final EavEntityDataInterface e if (!attributeOptions.isEmpty()) { mappedAttributes.put( AttributeProperty.OPTION.getProperty(), - getMappedOptions(eavEntityData.getOptions(), eavEntityData.getOptionsSortOrder()) + getMappedOptions( + eavEntityData.getOptions(), + eavEntityData.getOptionsSortOrder() + ) ); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java index 943c29580..4dd4c7265 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java @@ -18,6 +18,10 @@ protected Map getMappedAttributes(final EavEntityDataInterface e final Map mappedAttributes = super.getMappedAttributes(eavEntityData); final ProductEntityData productEavEntityData = (ProductEntityData) eavEntityData; + mappedAttributes.put( + AttributeProperty.SORT_ORDER.getProperty(), + Integer.toString(productEavEntityData.getSortOrder()) + ); mappedAttributes.put( AttributeProperty.GROUP.getProperty(), wrapStringValueForTemplate(productEavEntityData.getGroup()) @@ -47,7 +51,8 @@ protected Map getMappedAttributes(final EavEntityDataInterface e Boolean.toString(productEavEntityData.isVisibleOnFront()) ); - if (productEavEntityData.getApplyTo() != null && !productEavEntityData.getApplyTo().isEmpty()) { + if (productEavEntityData.getApplyTo() != null + && !productEavEntityData.getApplyTo().isEmpty()) { mappedAttributes.put( AttributeProperty.APPLY_TO.getProperty(), wrapStringValueForTemplate(productEavEntityData.getApplyTo()) diff --git a/src/com/magento/idea/magento2plugin/magento/files/CustomerEavAttributeDataPatchFile.java b/src/com/magento/idea/magento2plugin/magento/files/CustomerEavAttributeDataPatchFile.java new file mode 100644 index 000000000..e718f6815 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/CustomerEavAttributeDataPatchFile.java @@ -0,0 +1,43 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.magento.files; + +import org.jetbrains.annotations.NotNull; + +public class CustomerEavAttributeDataPatchFile extends AbstractPhpFile { + public static final String HUMAN_READABLE_NAME = "Customer Eav Attribute Data Patch Class"; + public static final String TEMPLATE = "Magento Customer Eav Attribute Data Patch Class"; + public static final String DEFAULT_DIR = "Setup/Patch/Data"; + + /** + * Abstract php file constructor. + * + * @param moduleName String + * @param className String + */ + public CustomerEavAttributeDataPatchFile( + final @NotNull String moduleName, + final @NotNull String className + ) { + super(moduleName, className); + } + + @Override + public String getDirectory() { + return DEFAULT_DIR; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeProperty.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeProperty.java index 5804022c5..3a2b47200 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeProperty.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeProperty.java @@ -22,7 +22,10 @@ public enum AttributeProperty { VISIBLE_ON_FRONT("visible_on_front"), APPLY_TO("apply_to"), OPTION("option"), - BACKEND_MODEL("backend"); + BACKEND_MODEL("backend"), + USER_DEFINED("user_defined"), + POSITION("position"), + SYSTEM("system"); private String attribute; diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/CustomerForm.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/CustomerForm.java new file mode 100644 index 000000000..b52d55287 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/CustomerForm.java @@ -0,0 +1,28 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.magento.packages.eav; + +public enum CustomerForm { + + ADMINHTML_CHECKOUT("adminhtml_checkout"), + ADMINHTML_CUSTOMER("adminhtml_customer"), + ADMINHTML_CUSTOMER_ADDRESS("adminhtml_customer_address"), + CUSTOMER_ACCOUNT_CREATE("customer_account_create"), + CUSTOMER_ACCOUNT_EDIT("customer_account_edit"), + CUSTOMER_ADDRESS_EDIT("customer_address_edit"), + CUSTOMER_REGISTER_ADDRESS("customer_register_address"); + + private final String formCode; + + CustomerForm(final String formCode) { + this.formCode = formCode; + } + + public String getFormCode() { + return this.formCode; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java index 73f2bf0fa..9ae62b2b9 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java @@ -6,10 +6,12 @@ package com.magento.idea.magento2plugin.magento.packages.eav; public enum DataPatchDependency { - ENV_SETUP("Magento\\Eav\\Setup\\EavSetup"), + CUSTOMER_METADATA_INTERFACE("Magento\\Customer\\Api\\CustomerMetadataInterface"), + DATA_PATCH_INTERFACE("Magento\\Framework\\Setup\\Patch\\DataPatchInterface"), + EAV_CONFIG("Magento\\Eav\\Model\\Config"), EAV_SETUP_FACTORY("Magento\\Eav\\Setup\\EavSetupFactory"), - MODULE_DATA_SETUP_INTERFACE("Magento\\Framework\\Setup\\ModuleDataSetupInterface"), - DATA_PATCH_INTERFACE("Magento\\Framework\\Setup\\Patch\\DataPatchInterface"); + ENV_SETUP("Magento\\Eav\\Setup\\EavSetup"), + MODULE_DATA_SETUP_INTERFACE("Magento\\Framework\\Setup\\ModuleDataSetupInterface"); private String classPatch; diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java index 36f2487cb..ee3e770ea 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java @@ -7,7 +7,8 @@ public enum EavEntity { PRODUCT("Magento\\Catalog\\Model\\Product"), - CATEGORY("Magento\\Catalog\\Model\\Category"); + CATEGORY("Magento\\Catalog\\Model\\Category"), + CUSTOMER("Magento\\Customer\\Model\\Customer"); private String entityClass; From db4da15342e1e5dbc66075ccd233ef70b2eacd1b Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopoov Date: Thu, 29 Apr 2021 12:19:08 +0300 Subject: [PATCH 041/111] Fixed dialog issue, added testes --- .../dialog/NewCustomerEavAttributeDialog.form | 2 +- .../dialog/NewCustomerEavAttributeDialog.java | 6 +- .../AddMultiselectTestCustomerAttribute.php | 129 ++++++++++++++++++ ...tomerAttributeSetupPatchGeneratorTest.java | 55 ++++++++ 4 files changed, 188 insertions(+), 4 deletions(-) create mode 100644 testData/actions/generation/generator/CustomerAttributeSetupPatchGenerator/generateMultiselectAttributeDataPatch/AddMultiselectTestCustomerAttribute.php create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/CustomerAttributeSetupPatchGeneratorTest.java diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form index 32aa56cae..002bf2f32 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form @@ -357,7 +357,7 @@
- + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java index 07daa2f92..315bc44e9 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java @@ -82,7 +82,7 @@ public class NewCustomerEavAttributeDialog extends EavAttributeDialog { private JCheckBox useInGridCheckBox; private JCheckBox filterableInGridCheckBox; private JCheckBox visibleInGridCheckBox; - private JCheckBox systemAttributecheckBox; + private JCheckBox systemAttributeCheckBox; /** * Constructor. @@ -243,9 +243,9 @@ private CustomerEntityData populateCategoryEntityData( useInCustomerAccountEditCheckBox.isSelected() ); customerEntityData.setVisibleInGrid(visibleInGridCheckBox.isSelected()); - customerEntityData.setUsedInGrid(useInGridCheckBox.isVisible()); + customerEntityData.setUsedInGrid(useInGridCheckBox.isSelected()); customerEntityData.setFilterableInGrid(filterableInGridCheckBox.isSelected()); - customerEntityData.setSystem(systemAttributecheckBox.isSelected()); + customerEntityData.setSystem(systemAttributeCheckBox.isSelected()); return customerEntityData; } diff --git a/testData/actions/generation/generator/CustomerAttributeSetupPatchGenerator/generateMultiselectAttributeDataPatch/AddMultiselectTestCustomerAttribute.php b/testData/actions/generation/generator/CustomerAttributeSetupPatchGenerator/generateMultiselectAttributeDataPatch/AddMultiselectTestCustomerAttribute.php new file mode 100644 index 000000000..a2c0972c0 --- /dev/null +++ b/testData/actions/generation/generator/CustomerAttributeSetupPatchGenerator/generateMultiselectAttributeDataPatch/AddMultiselectTestCustomerAttribute.php @@ -0,0 +1,129 @@ +moduleDataSetup = $moduleDataSetup; + $this->eavSetupFactory = $eavSetupFactory; + $this->eavConfig = $eavConfig; + } + + /** + * Run code inside patch + * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert + * means run PatchInterface::revert() + * + * If we speak about data, under revert means: $transaction->rollback() + * + * @return $this + */ + public function apply() + { + /** @var EavSetup $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); + + $eavSetup->addAttribute( + Customer::ENTITY, + 'multiselect_test', + [ + 'is_visible_in_grid' => false, + 'visible' => true, + 'label' => 'Multiselect Test', + 'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class, + 'type' => 'varchar', + 'is_used_in_grid' => false, + 'required' => false, + 'input' => 'multiselect', + 'user_defined' => true, + 'is_filterable_in_grid' => false, + 'system' => false, + 'backend' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class, + 'position' => 10, + 'option' => [ + 'value' => [ + 'option_0' => ['option1'], + 'option_1' => ['option2'], + 'option_2' => ['option3'], + ] + ], + ] + ); + + $eavSetup->addAttributeToSet( + CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, + CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER, + null, + 'multiselect_test' + ); + + $attribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'multiselect_test'); + $attribute->setData( + 'used_in_forms', + ['adminhtml_customer'] + ); + $attribute->save(); + + return $this; + } + + /** + * Get array of patches that have to be executed prior to this. + * + * Example of implementation: + * + * [ + * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, + * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class + * ] + * + * @return string[] + */ + public static function getDependencies() + { + return []; + } + + /** + * Get aliases (previous names) for the patch. + * + * @return string[] + */ + public function getAliases() + { + return []; + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/CustomerAttributeSetupPatchGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/CustomerAttributeSetupPatchGeneratorTest.java new file mode 100644 index 000000000..d89cf31ce --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/CustomerAttributeSetupPatchGeneratorTest.java @@ -0,0 +1,55 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + * + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.data.CustomerEntityData; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType; +import java.util.HashMap; +import java.util.Map; + +public class CustomerAttributeSetupPatchGeneratorTest extends BaseGeneratorTestCase { + + private final static String MODULE_NAME = "Foo_Bar"; + + public void testGenerateMultiselectAttributeDataPatch() { + final Project project = myFixture.getProject(); + + final CustomerEntityData customerEntityData = new CustomerEntityData(); + customerEntityData.setCode("multiselect_test"); + customerEntityData.setLabel("Multiselect Test"); + customerEntityData.setVisible(true); + customerEntityData.setSource(AttributeSourceModel.TABLE.getSource()); + customerEntityData.setType(AttributeType.VARCHAR.getType()); + customerEntityData.setInput(AttributeInput.MULTISELECT.getInput()); + customerEntityData.setUserDefined(true); + customerEntityData.setSortOrder(10); + customerEntityData.setUseInAdminhtmlCustomerForm(true); + + final Map options = new HashMap<>(); + options.put(0, "option1"); + options.put(1, "option2"); + options.put(2, "option3"); + customerEntityData.setOptions(options); + + customerEntityData.setDataPatchName("AddMultiselectTestCustomerAttribute"); + customerEntityData.setModuleName(MODULE_NAME); + + + final CustomerEavAttributePatchGenerator setupPatchGenerator = + new CustomerEavAttributePatchGenerator(customerEntityData, project); + final PsiFile dataPatchFile = setupPatchGenerator.generate("testGenerateMultiselectAttributeDataPatch"); + + final String filePatch = this.getFixturePath("AddMultiselectTestCustomerAttribute.php"); + final PsiFile expectedFile = myFixture.configureByFile(filePatch); + + assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile); + } +} From 077c19a419512ff1e7aff2edcb3106941dcd94e0 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Wed, 5 May 2021 14:54:58 +0300 Subject: [PATCH 042/111] Fixing the scope selection --- .../internal/Magento Eav Attribute Data Patch Class.php.ft | 2 -- .../generation/dialog/util/eavdialog/AttributeUtil.java | 2 +- .../generateFile/AddTestAttributeCategoryAttribute.php | 5 ++--- .../generateFile/AddTestAttribute.php | 2 -- .../AddAppliedToAttribute.php | 2 -- .../AddBooleanInputAttributeAttribute.php | 2 -- .../AddAttributeWithCustomSourceAttribute.php | 2 -- .../AddAttributeWithOptionsAttribute.php | 2 -- 8 files changed, 3 insertions(+), 16 deletions(-) diff --git a/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft b/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft index 94f5b8bf0..7c6813869 100644 --- a/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft +++ b/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft @@ -40,8 +40,6 @@ class ${CLASS_NAME} implements ${IMPLEMENTS} { * means run PatchInterface::revert() * * If we speak about data, under revert means: $transaction->rollback() - * - * @return $this */ public function apply() { diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/eavdialog/AttributeUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/eavdialog/AttributeUtil.java index 0f9f212b3..1199fff64 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/eavdialog/AttributeUtil.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/eavdialog/AttributeUtil.java @@ -54,7 +54,7 @@ public static String getSourceClassBySelectedItem( */ public static String getScopeClassBySelectedItem(final ComboBoxItemData selectedScopeItem) { if (selectedScopeItem != null) { - selectedScopeItem.getKey().trim(); + return selectedScopeItem.getKey().trim(); } return AttributeScope.GLOBAL.getScope(); diff --git a/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php b/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php index 1db511555..0c43f12d0 100644 --- a/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php +++ b/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php @@ -2,6 +2,7 @@ namespace Foo\Bar\Setup\Patch\Data; +use Magento\Catalog\Model\Category; use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\ModuleDataSetupInterface; @@ -39,8 +40,6 @@ public function __construct( * means run PatchInterface::revert() * * If we speak about data, under revert means: $transaction->rollback() - * - * @return $this */ public function apply() { @@ -48,7 +47,7 @@ public function apply() $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); $eavSetup->addAttribute( - \Magento\Catalog\Model\Category::ENTITY, + Category::ENTITY, 'test_attribute', [ 'input' => 'text', diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php index d31d7da10..129a8f068 100644 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php +++ b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php @@ -40,8 +40,6 @@ public function __construct( * means run PatchInterface::revert() * * If we speak about data, under revert means: $transaction->rollback() - * - * @return $this */ public function apply() { diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php index b8a3cafa1..90be38a37 100644 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php +++ b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php @@ -40,8 +40,6 @@ public function __construct( * means run PatchInterface::revert() * * If we speak about data, under revert means: $transaction->rollback() - * - * @return $this */ public function apply() { diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php index 668a7d808..574350b72 100644 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php +++ b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php @@ -40,8 +40,6 @@ public function __construct( * means run PatchInterface::revert() * * If we speak about data, under revert means: $transaction->rollback() - * - * @return $this */ public function apply() { diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php index 7242b836e..2dc15f408 100644 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php +++ b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php @@ -40,8 +40,6 @@ public function __construct( * means run PatchInterface::revert() * * If we speak about data, under revert means: $transaction->rollback() - * - * @return $this */ public function apply() { diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php index 700ae6373..2a1a353ca 100644 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php +++ b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php @@ -40,8 +40,6 @@ public function __construct( * means run PatchInterface::revert() * * If we speak about data, under revert means: $transaction->rollback() - * - * @return $this */ public function apply() { From 94a915a5c104e38b65005fd59c3a82bd3997ae4f Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Tue, 15 Feb 2022 15:39:16 +0300 Subject: [PATCH 043/111] Code review adjustments --- ...Customer Eav Attribute Data Patch Class.php.ft | 13 +++++++++++-- ...stomer Eav Attribute Data Patch Class.php.html | 15 +++++++++++++++ .../generation/data/CustomerEntityData.java | 10 +++++++++- .../dialog/NewCustomerEavAttributeDialog.form | 11 +++++++++-- .../dialog/NewCustomerEavAttributeDialog.java | 9 ++++++++- .../CustomerEavAttributePatchGenerator.java | 6 ++++++ .../EavAttributeSetupPatchGenerator.java | 3 +++ .../magento/packages/eav/DataPatchDependency.java | 3 ++- .../AddMultiselectTestCustomerAttribute.php | 14 ++++++++++++-- 9 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.html diff --git a/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.ft b/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.ft index 069df9b29..52d51a592 100644 --- a/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.ft +++ b/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.ft @@ -26,18 +26,27 @@ class ${CLASS_NAME} implements ${IMPLEMENTS} */ private $eavConfig; + /** + * @var ${ATTRIBUTE_RESOURCE} + */ + private $attributeResource; + /** * @param ${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup * @param ${EAV_SETUP_FACTORY} $eavSetupFactory + * @param ${EAV_CONFIG_CLASS} $eavConfig + * @param ${ATTRIBUTE_RESOURCE} $attributeResource */ public function __construct( ${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup, ${EAV_SETUP_FACTORY} $eavSetupFactory, - ${EAV_CONFIG_CLASS} $eavConfig + ${EAV_CONFIG_CLASS} $eavConfig, + ${ATTRIBUTE_RESOURCE} $attributeResource ) { $this->moduleDataSetup = $moduleDataSetup; $this->eavSetupFactory = $eavSetupFactory; $this->eavConfig = $eavConfig; + $this->attributeResource = $attributeResource; } /** @@ -78,7 +87,7 @@ class ${CLASS_NAME} implements ${IMPLEMENTS} 'used_in_forms', [${CUSTOMER_FORMS}] ); - $attribute->save(); + $this->attributeResource->save($attribute); #end return $this; diff --git a/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.html b/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.html new file mode 100644 index 000000000..0a2028f8b --- /dev/null +++ b/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.html @@ -0,0 +1,15 @@ + + + + +

+ Data patch for the customer EAV attribute +

+
+ + \ No newline at end of file diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/CustomerEntityData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/CustomerEntityData.java index bf148c944..db45bf7c7 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/CustomerEntityData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/CustomerEntityData.java @@ -1,7 +1,6 @@ /* * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. - * */ package com.magento.idea.magento2plugin.actions.generation.data; @@ -29,6 +28,7 @@ public class CustomerEntityData implements EavEntityDataInterface { private boolean visible; private boolean userDefined; private boolean useInAdminhtmlCustomerForm; + private boolean useInAdminhtmlCheckoutForm; private boolean useInCustomerAccountCreateForm; private boolean useInCustomerAccountEditForm; private boolean usedInGrid; @@ -119,6 +119,10 @@ public void setUseInAdminhtmlCustomerForm(final boolean useInAdminhtmlCustomerFo this.useInAdminhtmlCustomerForm = useInAdminhtmlCustomerForm; } + public void setUseInAdminhtmlCheckoutForm(final boolean useInAdminhtmlCheckoutForm) { + this.useInAdminhtmlCheckoutForm = useInAdminhtmlCheckoutForm; + } + public void setUseInCustomerAccountCreateForm(final boolean useInCustomerAccountCreateForm) { this.useInCustomerAccountCreateForm = useInCustomerAccountCreateForm; } @@ -235,6 +239,10 @@ public boolean isUseInAdminhtmlCustomerForm() { return useInAdminhtmlCustomerForm; } + public boolean isUseInAdminhtmlCheckoutForm() { + return useInAdminhtmlCheckoutForm; + } + public boolean isUseInCustomerAccountCreateForm() { return useInCustomerAccountCreateForm; } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form index 002bf2f32..1f26f958e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form @@ -3,11 +3,10 @@ - + - @@ -365,6 +364,14 @@
+ + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java index 315bc44e9..0018e6bab 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java @@ -1,7 +1,6 @@ /* * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. - * */ package com.magento.idea.magento2plugin.actions.generation.dialog; @@ -83,6 +82,7 @@ public class NewCustomerEavAttributeDialog extends EavAttributeDialog { private JCheckBox filterableInGridCheckBox; private JCheckBox visibleInGridCheckBox; private JCheckBox systemAttributeCheckBox; + private JCheckBox useInAdminhtmlCheckoutCheckBox; /** * Constructor. @@ -236,6 +236,9 @@ private CustomerEntityData populateCategoryEntityData( customerEntityData.setUseInAdminhtmlCustomerForm( useInAdminhtmlCustomerCheckBox.isSelected() ); + customerEntityData.setUseInAdminhtmlCheckoutForm( + useInAdminhtmlCheckoutCheckBox.isSelected() + ); customerEntityData.setUseInCustomerAccountCreateForm( useInCustomerAccountCreateCheckBox.isSelected() ); @@ -320,4 +323,8 @@ public void itemStateChanged(final ItemEvent itemEvent) { } }); } + + private void createUIComponents() { + // TODO: place custom component creation code here + } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java index a62e954ed..f67e94fa7 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java @@ -86,6 +86,12 @@ private String getFormsForAttribute(final CustomerEntityData customerEntityData) ); } + if (customerEntityData.isUseInAdminhtmlCheckoutForm()) { + usedInForms.add( + "'" + CustomerForm.ADMINHTML_CHECKOUT.getFormCode() + "'" + ); + } + if (customerEntityData.isUseInCustomerAccountCreateForm()) { usedInForms.add( "'" + CustomerForm.CUSTOMER_ACCOUNT_CREATE.getFormCode() + "'" diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java index 3339abf99..6ac3fd633 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java @@ -76,6 +76,9 @@ protected void fillAttributes(final Properties attributes) { .append( "MODULE_DATA_SETUP_INTERFACE", DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch() + ).append( + "ATTRIBUTE_RESOURCE", + DataPatchDependency.ATTRIBUTE_RESOURCE.getClassPatch() ) .append( "EAV_SETUP_FACTORY", diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java index 9ae62b2b9..aee63c3d9 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java @@ -11,7 +11,8 @@ public enum DataPatchDependency { EAV_CONFIG("Magento\\Eav\\Model\\Config"), EAV_SETUP_FACTORY("Magento\\Eav\\Setup\\EavSetupFactory"), ENV_SETUP("Magento\\Eav\\Setup\\EavSetup"), - MODULE_DATA_SETUP_INTERFACE("Magento\\Framework\\Setup\\ModuleDataSetupInterface"); + MODULE_DATA_SETUP_INTERFACE("Magento\\Framework\\Setup\\ModuleDataSetupInterface"), + ATTRIBUTE_RESOURCE("Magento\\Customer\\Model\\ResourceModel\\Attribute"); private String classPatch; diff --git a/testData/actions/generation/generator/CustomerAttributeSetupPatchGenerator/generateMultiselectAttributeDataPatch/AddMultiselectTestCustomerAttribute.php b/testData/actions/generation/generator/CustomerAttributeSetupPatchGenerator/generateMultiselectAttributeDataPatch/AddMultiselectTestCustomerAttribute.php index a2c0972c0..4757629dd 100644 --- a/testData/actions/generation/generator/CustomerAttributeSetupPatchGenerator/generateMultiselectAttributeDataPatch/AddMultiselectTestCustomerAttribute.php +++ b/testData/actions/generation/generator/CustomerAttributeSetupPatchGenerator/generateMultiselectAttributeDataPatch/AddMultiselectTestCustomerAttribute.php @@ -4,6 +4,7 @@ use Magento\Customer\Api\CustomerMetadataInterface; use Magento\Customer\Model\Customer; +use Magento\Customer\Model\ResourceModel\Attribute; use Magento\Eav\Model\Config; use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; @@ -27,19 +28,28 @@ class AddMultiselectTestCustomerAttribute implements DataPatchInterface */ private $eavConfig; + /** + * @var Attribute + */ + private $attributeResource; + /** * @param ModuleDataSetupInterface $moduleDataSetup * @param EavSetupFactory $eavSetupFactory + * @param Config $eavConfig + * @param Attribute $attributeResource */ public function __construct( ModuleDataSetupInterface $moduleDataSetup, EavSetupFactory $eavSetupFactory, - Config $eavConfig + Config $eavConfig, + Attribute $attributeResource ) { $this->moduleDataSetup = $moduleDataSetup; $this->eavSetupFactory = $eavSetupFactory; $this->eavConfig = $eavConfig; + $this->attributeResource = $attributeResource; } /** @@ -95,7 +105,7 @@ public function apply() 'used_in_forms', ['adminhtml_customer'] ); - $attribute->save(); + $this->attributeResource->save($attribute); return $this; } From 9fc3b44ae04b5a62d0f1455d4237d041552ff652 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Tue, 15 Feb 2022 15:47:55 +0300 Subject: [PATCH 044/111] Try running CI by regex attempt 1 --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 94244ea64..d62a7384f 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -5,7 +5,7 @@ name: Run automated tests on: pull_request: - branches: [ master, 4.3.0-develop ] + branches: [ master, '*-develop', 'mainline*' ] jobs: build-linux: From d7755534f94e23c2162cc1acf4f9ca58ce701b05 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Tue, 15 Feb 2022 16:03:56 +0300 Subject: [PATCH 045/111] Static fixes --- .../dialog/NewCustomerEavAttributeDialog.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java index 0018e6bab..47da9a97b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java @@ -22,7 +22,13 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.List; -import javax.swing.*; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.JTextField; @SuppressWarnings({ "PMD.TooManyFields", @@ -237,7 +243,7 @@ private CustomerEntityData populateCategoryEntityData( useInAdminhtmlCustomerCheckBox.isSelected() ); customerEntityData.setUseInAdminhtmlCheckoutForm( - useInAdminhtmlCheckoutCheckBox.isSelected() + useInAdminhtmlCheckoutCheckBox.isSelected() ); customerEntityData.setUseInCustomerAccountCreateForm( useInCustomerAccountCreateCheckBox.isSelected() @@ -269,8 +275,10 @@ protected void addOptionPanelListener( attributeSourceComboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(final ItemEvent itemEvent) { - final ComboBoxItemData selectedInputItem = (ComboBoxItemData) attributeInputComboBox.getSelectedItem(); - final String selectedInput = selectedInputItem == null ? "" : selectedInputItem.toString(); + final ComboBoxItemData selectedInputItem = + (ComboBoxItemData) attributeInputComboBox.getSelectedItem(); + final String selectedInput = selectedInputItem == null + ? "" : selectedInputItem.toString(); final boolean isAllowedInput = AttributeInput.SELECT.getInput().equals(selectedInput) || AttributeInput.MULTISELECT.getInput().equals(selectedInput); @@ -324,7 +332,7 @@ public void itemStateChanged(final ItemEvent itemEvent) { }); } - private void createUIComponents() { + private void createUIComponents() { //NOPMD - suppressed UnusedPrivateMethod // TODO: place custom component creation code here } } From 2db8e9ef7d00b8f65a02e320d39f2ab581dedcea Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Tue, 15 Feb 2022 16:12:52 +0300 Subject: [PATCH 046/111] Experiment with branch names --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index d62a7384f..a6614457d 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -5,7 +5,7 @@ name: Run automated tests on: pull_request: - branches: [ master, '*-develop', 'mainline*' ] + branches: [ master, 4.3.0-develop, mainline-eav-attr-code-genearators ] jobs: build-linux: From 2a18b003599e5dc4823176d7a0da0264e0b62eef Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Tue, 15 Feb 2022 16:18:18 +0300 Subject: [PATCH 047/111] Experiment with --stacktrace --- .github/workflows/gradle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index a6614457d..5b9960c7c 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -5,7 +5,7 @@ name: Run automated tests on: pull_request: - branches: [ master, 4.3.0-develop, mainline-eav-attr-code-genearators ] + branches: [ master, '*-develop', 'mainline*' ] jobs: build-linux: @@ -104,7 +104,7 @@ jobs: - id: file_changes uses: trilom/file-changes-action@v1.2.4 - name: Run Code Style Check - run: ./gradlew checkstyleCI -i --no-daemon + run: ./gradlew checkstyleCI --stacktrace --no-daemon env: MODIFIED_FILES: ${{ steps.file_changes.outputs.files}} - name: Run PMD Quality Check From db87c3a045181ff35722915de1924d73944bd78d Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Tue, 15 Feb 2022 16:28:29 +0300 Subject: [PATCH 048/111] Experiment with ACTIONS_STEP_DEBUG --- .github/workflows/gradle.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 5b9960c7c..6f92519b8 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -104,9 +104,10 @@ jobs: - id: file_changes uses: trilom/file-changes-action@v1.2.4 - name: Run Code Style Check - run: ./gradlew checkstyleCI --stacktrace --no-daemon + run: ./gradlew checkstyleCI -i --no-daemon env: MODIFIED_FILES: ${{ steps.file_changes.outputs.files}} + ACTIONS_STEP_DEBUG: true - name: Run PMD Quality Check run: ./gradlew pmdCI -i --no-daemon env: From a05a21f12b6ca58dbab04cf8da5ba034e8f0cdd6 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Tue, 15 Feb 2022 17:15:12 +0300 Subject: [PATCH 049/111] Static fixes --- .../CustomerEavAttributePatchGenerator.java | 2 +- .../CustomerAttributeSetupPatchGeneratorTest.java | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java index f67e94fa7..fa80466d0 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java @@ -88,7 +88,7 @@ private String getFormsForAttribute(final CustomerEntityData customerEntityData) if (customerEntityData.isUseInAdminhtmlCheckoutForm()) { usedInForms.add( - "'" + CustomerForm.ADMINHTML_CHECKOUT.getFormCode() + "'" + "'" + CustomerForm.ADMINHTML_CHECKOUT.getFormCode() + "'" ); } diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/CustomerAttributeSetupPatchGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/CustomerAttributeSetupPatchGeneratorTest.java index d89cf31ce..3bc1ea13e 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/CustomerAttributeSetupPatchGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/CustomerAttributeSetupPatchGeneratorTest.java @@ -17,8 +17,11 @@ public class CustomerAttributeSetupPatchGeneratorTest extends BaseGeneratorTestCase { - private final static String MODULE_NAME = "Foo_Bar"; + private static final String MODULE_NAME = "Foo_Bar"; + /** + * Test generating the customer attribute data patch. + */ public void testGenerateMultiselectAttributeDataPatch() { final Project project = myFixture.getProject(); @@ -45,11 +48,17 @@ public void testGenerateMultiselectAttributeDataPatch() { final CustomerEavAttributePatchGenerator setupPatchGenerator = new CustomerEavAttributePatchGenerator(customerEntityData, project); - final PsiFile dataPatchFile = setupPatchGenerator.generate("testGenerateMultiselectAttributeDataPatch"); + final PsiFile dataPatchFile = setupPatchGenerator.generate( + "testGenerateMultiselectAttributeDataPatch" + ); final String filePatch = this.getFixturePath("AddMultiselectTestCustomerAttribute.php"); final PsiFile expectedFile = myFixture.configureByFile(filePatch); - assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile); + assertGeneratedFileIsCorrect( + expectedFile, + "src/app/code/Foo/Bar/Setup/Patch/Data", + dataPatchFile + ); } } From 870497f2fc871f20df90e9579f63ea74e5043eec Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Tue, 15 Feb 2022 17:33:06 +0300 Subject: [PATCH 050/111] Static fixes and test fixes --- .../dialog/eavattribute/EavAttributeDialog.java | 17 ++++++++++------- .../CustomerEavAttributePatchGenerator.java | 6 ++++-- .../EavAttributeSetupPatchGenerator.java | 3 --- .../util/eav/DefaultAttributeMapper.java | 14 ++++++++------ 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java index 15ab458ad..885baff52 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java @@ -45,7 +45,12 @@ import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; -@SuppressWarnings({"PMD.GodClass", "PMD.TooManyMethods"}) +@SuppressWarnings({ + "PMD.GodClass", + "PMD.TooManyMethods", + "PMD.ExcessiveImports", + "PMD.AccessorMethodGeneration" +}) public abstract class EavAttributeDialog extends AbstractDialog { protected String moduleName; @@ -297,6 +302,10 @@ protected void generateExtraFilesBeforeDataPatchGeneration() { generateSourceModelFile(); } + @SuppressWarnings({ + "PMD.EmptyMethodInAbstractClassShouldBeAbstract", + "PMD.UncommentedEmptyMethodBody" + }) protected void generateExtraFilesAfterDataPatchGeneration( final EavEntityDataInterface eavEntityDataInterface ) {} @@ -319,7 +328,6 @@ protected void addCancelActionForEsc() { ); } - @SuppressWarnings("PMD.AccessorMethodGeneration") protected void setAttributeInputComboBoxAction( final JComboBox sourceComboBox, final JComboBox inputComboBox @@ -333,7 +341,6 @@ protected void setAttributeInputComboBoxAction( ); } - @SuppressWarnings("PMD.AccessorMethodGeneration") protected void setSourceComboBoxAction(final JComboBox sourceComboBox) { if (sourceComboBox == null) { return; @@ -344,7 +351,6 @@ protected void setSourceComboBoxAction(final JComboBox sourceC ); } - @SuppressWarnings("PMD.AccessorMethodGeneration") protected void setSourceModelPanelAction( final JPanel attributeCustomSourceModelPanel, final JTextField sourceModelDirectoryTexField @@ -358,7 +364,6 @@ protected void setSourceModelPanelAction( ); } - @SuppressWarnings("PMD.AccessorMethodGeneration") protected void addOptionPanelListener( final JComboBox attributeSourceComboBox, final JComboBox attributeInputComboBox, @@ -407,7 +412,6 @@ protected void setAutocompleteListenerForAttributeCodeField( .addDocumentListener(new AttributeCodeAdapter(attributeCodeTextField)); } - @SuppressWarnings("PMD.AccessorMethodGeneration") protected void setAutocompleteListenerForDataPathNameField( final JTextField mainTextField, final JTextField dependentTextField @@ -421,7 +425,6 @@ protected void setAutocompleteListenerForDataPathNameField( .addDocumentListener(new DataPatchNameAdapter(dependentTextField, getEntityName())); } - @SuppressWarnings("PMD.AccessorMethodGeneration") protected void setAutocompleteListenerForSourceModelNameField( final JTextField mainTextField, final JTextField dependentTextField diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java index fa80466d0..3b441c3ca 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java @@ -57,8 +57,10 @@ protected void fillAttributes(final Properties attributes) { .append( "EAV_CONFIG_CLASS", DataPatchDependency.EAV_CONFIG.getClassPatch() - ) - .append( + ).append( + "ATTRIBUTE_RESOURCE", + DataPatchDependency.ATTRIBUTE_RESOURCE.getClassPatch() + ).append( "CUSTOMER_METADATA_INTERFACE", DataPatchDependency.CUSTOMER_METADATA_INTERFACE.getClassPatch() ); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java index 6ac3fd633..3339abf99 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java @@ -76,9 +76,6 @@ protected void fillAttributes(final Properties attributes) { .append( "MODULE_DATA_SETUP_INTERFACE", DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch() - ).append( - "ATTRIBUTE_RESOURCE", - DataPatchDependency.ATTRIBUTE_RESOURCE.getClassPatch() ) .append( "EAV_SETUP_FACTORY", diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java index a8a5fb9cd..92a1b8374 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java @@ -17,6 +17,8 @@ import java.util.Map; public class DefaultAttributeMapper implements AttributeMapperInterface { + private final static String PHP_DOUBLE_ARROW_OPERATOR = " => "; + @Override public List mapAttributesByEntityData(final EavEntityDataInterface entityData) { final List attributesWithValues = new ArrayList<>(); @@ -118,7 +120,7 @@ protected String getMappedOptions( } protected String getParsedOptions(final Map optionValues) { - final String valueNode = "->" + wrapStringValueForTemplate("value") + " => "; + final String valueNode = "->" + wrapStringValueForTemplate("value") + PHP_DOUBLE_ARROW_OPERATOR; final StringBuilder optionsContent = new StringBuilder(); for (final Integer optionKey : optionValues.keySet()) { @@ -131,8 +133,8 @@ protected String getParsedOptions(final Map optionValues) { optionsContent .append("->") .append(wrapStringValueForTemplate("option_" + optionKey)) - .append(" => ") - .append("[") + .append(PHP_DOUBLE_ARROW_OPERATOR) + .append('[') .append(wrapStringValueForTemplate(optionValue)) .append("], "); } @@ -141,7 +143,7 @@ protected String getParsedOptions(final Map optionValues) { } protected String getParsedOptionSortOrders(final Map optionSortOrders) { - final String orderNode = "->" + wrapStringValueForTemplate("order") + " => "; + final String orderNode = "->" + wrapStringValueForTemplate("order") + PHP_DOUBLE_ARROW_OPERATOR; final StringBuilder ordersContent = new StringBuilder(); for (final Integer optionKey : optionSortOrders.keySet()) { @@ -154,9 +156,9 @@ protected String getParsedOptionSortOrders(final Map optionSort ordersContent .append("->") .append(wrapStringValueForTemplate("option_" + optionKey)) - .append(" => ") + .append(PHP_DOUBLE_ARROW_OPERATOR) .append(orderValue) - .append(","); + .append(','); } return orderNode + "[" + ordersContent + "->]->"; From df550bd2d19feae476211cbe7692319781287c77 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Tue, 15 Feb 2022 17:37:08 +0300 Subject: [PATCH 051/111] Static fixes Checkstyle --- .../generator/CustomerEavAttributePatchGenerator.java | 2 +- .../generator/util/eav/DefaultAttributeMapper.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java index 3b441c3ca..83c5f1450 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java @@ -63,7 +63,7 @@ protected void fillAttributes(final Properties attributes) { ).append( "CUSTOMER_METADATA_INTERFACE", DataPatchDependency.CUSTOMER_METADATA_INTERFACE.getClassPatch() - ); + ); final String selectedCustomerForms = getFormsForAttribute((CustomerEntityData) data); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java index 92a1b8374..d20604111 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java @@ -17,7 +17,7 @@ import java.util.Map; public class DefaultAttributeMapper implements AttributeMapperInterface { - private final static String PHP_DOUBLE_ARROW_OPERATOR = " => "; + private static final String PHP_DOUBLE_ARROW_OPERATOR = " => "; @Override public List mapAttributesByEntityData(final EavEntityDataInterface entityData) { @@ -120,7 +120,8 @@ protected String getMappedOptions( } protected String getParsedOptions(final Map optionValues) { - final String valueNode = "->" + wrapStringValueForTemplate("value") + PHP_DOUBLE_ARROW_OPERATOR; + final String valueNode = "->" + wrapStringValueForTemplate("value") + + PHP_DOUBLE_ARROW_OPERATOR; final StringBuilder optionsContent = new StringBuilder(); for (final Integer optionKey : optionValues.keySet()) { @@ -143,7 +144,8 @@ protected String getParsedOptions(final Map optionValues) { } protected String getParsedOptionSortOrders(final Map optionSortOrders) { - final String orderNode = "->" + wrapStringValueForTemplate("order") + PHP_DOUBLE_ARROW_OPERATOR; + final String orderNode = "->" + wrapStringValueForTemplate("order") + + PHP_DOUBLE_ARROW_OPERATOR; final StringBuilder ordersContent = new StringBuilder(); for (final Integer optionKey : optionSortOrders.keySet()) { From 9d6cebbaee12c3c7634213b56b22c2adab241e82 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Tue, 15 Feb 2022 19:57:18 +0300 Subject: [PATCH 052/111] Fixed copyright --- .../actions/generation/NewCustomerEavAttributeAction.java | 1 - .../generation/generator/CustomerEavAttributePatchGenerator.java | 1 - .../generation/generator/util/eav/CustomerAttributeMapper.java | 1 - .../generation/generator/util/eav/DefaultAttributeMapper.java | 1 - .../magento/files/CustomerEavAttributeDataPatchFile.java | 1 - .../idea/magento2plugin/magento/packages/eav/CustomerForm.java | 1 - .../generator/CustomerAttributeSetupPatchGeneratorTest.java | 1 - 7 files changed, 7 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/NewCustomerEavAttributeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/NewCustomerEavAttributeAction.java index 6b680b2b3..576749b7a 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/NewCustomerEavAttributeAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/NewCustomerEavAttributeAction.java @@ -1,7 +1,6 @@ /* * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. - * */ package com.magento.idea.magento2plugin.actions.generation; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java index 83c5f1450..890be334d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java @@ -1,7 +1,6 @@ /* * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. - * */ package com.magento.idea.magento2plugin.actions.generation.generator; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CustomerAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CustomerAttributeMapper.java index 73c939f8e..fa74a6052 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CustomerAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CustomerAttributeMapper.java @@ -1,7 +1,6 @@ /* * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. - * */ package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java index d20604111..f209305c0 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java @@ -1,7 +1,6 @@ /* * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. - * */ package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; diff --git a/src/com/magento/idea/magento2plugin/magento/files/CustomerEavAttributeDataPatchFile.java b/src/com/magento/idea/magento2plugin/magento/files/CustomerEavAttributeDataPatchFile.java index e718f6815..02a90c03b 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/CustomerEavAttributeDataPatchFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/CustomerEavAttributeDataPatchFile.java @@ -1,7 +1,6 @@ /* * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. - * */ package com.magento.idea.magento2plugin.magento.files; diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/CustomerForm.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/CustomerForm.java index b52d55287..40c7733ff 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/CustomerForm.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/eav/CustomerForm.java @@ -1,7 +1,6 @@ /* * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. - * */ package com.magento.idea.magento2plugin.magento.packages.eav; diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/CustomerAttributeSetupPatchGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/CustomerAttributeSetupPatchGeneratorTest.java index 3bc1ea13e..bcd76c58c 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/CustomerAttributeSetupPatchGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/CustomerAttributeSetupPatchGeneratorTest.java @@ -1,7 +1,6 @@ /* * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. - * */ package com.magento.idea.magento2plugin.actions.generation.generator; From c27e398f98a5af043b0591ee260ba79becc39386 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Fri, 18 Feb 2022 22:21:44 +0300 Subject: [PATCH 053/111] Static fixes --- .../generation/data/CategoryFormXmlData.java | 8 +++ .../data/EavEntityDataInterface.java | 5 ++ .../OptionsPanelVisibilityChangeListener.java | 3 +- .../NewCategoryEavAttributeAction.java | 5 ++ .../generator/CategoryFormXmlGenerator.java | 31 ++++++--- .../GetAttributeOptionPropertiesUtil.java | 4 +- .../util/eav/AttributeMapperInterface.java | 5 ++ .../uicomponent/AvailableSourcesByInput.java | 5 ++ .../reference/js/JsReferenceContributor.java | 18 ++++-- .../stubs/indexes/xml/ProductTypeIndex.java | 13 +++- .../util/magento/GetProductTypesListUtil.java | 10 ++- ...ributePropertySetupPatchGeneratorTest.java | 20 +++++- ...ributePropertySetupPatchGeneratorTest.java | 64 +++++++++++++------ .../generator/SourceModelGeneratorTest.java | 6 +- 14 files changed, 149 insertions(+), 48 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java index 1b4eb4fd2..7598502e3 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java @@ -14,6 +14,14 @@ public class CategoryFormXmlData { private final String attributeInput; private final int sortOrder; + /** + * Category Form data class. + * + * @param fieldSetName name of the fieldset + * @param fieldName field name + * @param attributeInput attribute input + * @param sortOrder sort order + */ public CategoryFormXmlData( @NotNull final String fieldSetName, @NotNull final String fieldName, diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java b/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java index 85b219b29..f25f64f68 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.generation.data; import java.util.Map; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/OptionsPanelVisibilityChangeListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/OptionsPanelVisibilityChangeListener.java index ffbdd34f9..6bc0cab76 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/OptionsPanelVisibilityChangeListener.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/OptionsPanelVisibilityChangeListener.java @@ -30,7 +30,8 @@ public OptionsPanelVisibilityChangeListener( public void itemStateChanged(final ItemEvent itemEvent) { final String selectedSource = itemEvent.getItem().toString(); - final ComboBoxItemData selectedInputItem = (ComboBoxItemData) inputComboBox.getSelectedItem(); + final ComboBoxItemData selectedInputItem = + (ComboBoxItemData) inputComboBox.getSelectedItem(); final String selectedInput = selectedInputItem == null ? "" : selectedInputItem.toString(); final boolean isAttributeWithoutSource = diff --git a/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java index 1c3bea4d6..446247f02 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.generation.eavattribute; import com.intellij.openapi.project.Project; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/CategoryFormXmlGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/CategoryFormXmlGenerator.java index aaf9e0953..bc71ab122 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/CategoryFormXmlGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/CategoryFormXmlGenerator.java @@ -16,7 +16,10 @@ import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.magento.idea.magento2plugin.actions.generation.data.CategoryFormXmlData; -import com.magento.idea.magento2plugin.actions.generation.generator.util.*; +import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.GetCodeTemplateUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.XmlFilePositionUtil; import com.magento.idea.magento2plugin.bundles.CommonBundle; import com.magento.idea.magento2plugin.bundles.ValidatorBundle; import com.magento.idea.magento2plugin.indexes.ModuleIndex; @@ -45,6 +48,13 @@ public class CategoryFormXmlGenerator extends FileGenerator { private final CommonBundle commonBundle; private boolean allowedFieldsetNodeInclude = true; + /** + * Category form XML Generator. + * + * @param categoryFormXmlData Category form data class + * @param project Project + * @param moduleName module name + */ public CategoryFormXmlGenerator( final @NotNull CategoryFormXmlData categoryFormXmlData, final @NotNull Project project, @@ -141,11 +151,11 @@ private PsiDirectory getFileDirectory() { new ModuleIndex(project).getModuleDirectoryByModuleName(moduleName); for (final String handlerDirectory: CategoryFormXmlFile.DIRECTORY.split(File.separator)) { - directory = directoryGenerator.findOrCreateSubdirectory( - directory, - handlerDirectory - ); - } + directory = directoryGenerator.findOrCreateSubdirectory( + directory, + handlerDirectory + ); + } return directory; } @@ -190,9 +200,14 @@ private List findFieldsetTagsInRoot(final XmlTag rootTag) { } @Nullable - private XmlTag findMatchedFieldsetByName(final List fieldsetList, final String fieldsetName) { + private XmlTag findMatchedFieldsetByName( + final List fieldsetList, + final String fieldsetName + ) { for (final XmlTag fieldset: fieldsetList) { - final String attributeValue = fieldset.getAttributeValue(CategoryFormXmlFile.XML_ATTR_FIELDSET_NAME); + final String attributeValue = fieldset.getAttributeValue( + CategoryFormXmlFile.XML_ATTR_FIELDSET_NAME + ); if (attributeValue != null && attributeValue.equals(fieldsetName)) { return fieldset; } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/GetAttributeOptionPropertiesUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/GetAttributeOptionPropertiesUtil.java index 68473ef89..97620041b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/GetAttributeOptionPropertiesUtil.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/GetAttributeOptionPropertiesUtil.java @@ -11,8 +11,8 @@ import org.jetbrains.annotations.NotNull; public final class GetAttributeOptionPropertiesUtil { - public final static String OPTION_VALUE = "Value"; - public final static String OPTION_SORT_ORDER = "Sort Order"; + public static final String OPTION_VALUE = "Value"; + public static final String OPTION_SORT_ORDER = "Sort Order"; private GetAttributeOptionPropertiesUtil() {} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java index 9157acdbb..f6ccb2b4c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; diff --git a/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java b/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java index 1dd0dcc42..f587e0d98 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java @@ -19,6 +19,11 @@ public AvailableSourcesByInput(@NotNull final String input) { this.input = input; } + /** + * Source items getter. + * + * @return List + */ public List getItems() { final List items = new ArrayList<>(); final ComboBoxItemData generateSourceItem = new ComboBoxItemData( diff --git a/src/com/magento/idea/magento2plugin/reference/js/JsReferenceContributor.java b/src/com/magento/idea/magento2plugin/reference/js/JsReferenceContributor.java index 787958e34..8bb196767 100644 --- a/src/com/magento/idea/magento2plugin/reference/js/JsReferenceContributor.java +++ b/src/com/magento/idea/magento2plugin/reference/js/JsReferenceContributor.java @@ -2,21 +2,23 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + package com.magento.idea.magento2plugin.reference.js; +import static com.intellij.patterns.StandardPatterns.string; + import com.intellij.lang.javascript.patterns.JSPatterns; -import com.intellij.psi.*; +import com.intellij.psi.PsiReferenceContributor; +import com.intellij.psi.PsiReferenceRegistrar; import com.magento.idea.magento2plugin.reference.provider.FilePathReferenceProvider; import com.magento.idea.magento2plugin.reference.provider.ModuleNameReferenceProvider; import com.magento.idea.magento2plugin.reference.provider.RequireJsPreferenceReferenceProvider; import com.magento.idea.magento2plugin.util.RegExUtil; import org.jetbrains.annotations.NotNull; -import static com.intellij.patterns.StandardPatterns.string; - public class JsReferenceContributor extends PsiReferenceContributor { @Override - public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { + public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider( JSPatterns.jsLiteralExpression() .withText(string().matches(".*" + RegExUtil.Magento.MODULE_NAME + ".*")), @@ -24,12 +26,16 @@ public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) ); registrar.registerReferenceProvider( - JSPatterns.jsLiteralExpression().withText(string().matches(".*\\W" + RegExUtil.FILE_PATH + ".*")), + JSPatterns.jsLiteralExpression().withText( + string().matches(".*\\W" + RegExUtil.FILE_PATH + ".*") + ), new FilePathReferenceProvider() ); registrar.registerReferenceProvider( - JSPatterns.jsLiteralExpression().withText(string().matches(".*\\W" + RegExUtil.FILE_PATH + ".*")), + JSPatterns.jsLiteralExpression().withText( + string().matches(".*\\W" + RegExUtil.FILE_PATH + ".*") + ), new RequireJsPreferenceReferenceProvider() ); } diff --git a/src/com/magento/idea/magento2plugin/stubs/indexes/xml/ProductTypeIndex.java b/src/com/magento/idea/magento2plugin/stubs/indexes/xml/ProductTypeIndex.java index 93f8820c4..e95cfb414 100644 --- a/src/com/magento/idea/magento2plugin/stubs/indexes/xml/ProductTypeIndex.java +++ b/src/com/magento/idea/magento2plugin/stubs/indexes/xml/ProductTypeIndex.java @@ -10,7 +10,11 @@ import com.intellij.psi.xml.XmlDocument; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; -import com.intellij.util.indexing.*; +import com.intellij.util.indexing.DataIndexer; +import com.intellij.util.indexing.FileBasedIndex; +import com.intellij.util.indexing.FileContent; +import com.intellij.util.indexing.ID; +import com.intellij.util.indexing.ScalarIndexExtension; import com.intellij.util.io.EnumeratorStringDescriptor; import com.intellij.util.io.KeyDescriptor; import com.magento.idea.magento2plugin.magento.files.ProductTypeXml; @@ -20,7 +24,7 @@ import org.jetbrains.annotations.NotNull; public class ProductTypeIndex extends ScalarIndexExtension { - private final static String TEST_DIRECTORY_PATTERN = ".*\\/[Tt]ests?\\/?.*"; + private static final String TEST_DIRECTORY_PATTERN = ".*\\/[Tt]ests?\\/?.*"; private final KeyDescriptor myKeyDescriptor = new EnumeratorStringDescriptor(); public static final ID KEY = ID.create( "com.magento.idea.magento2plugin.stubs.indexes.product_types"); @@ -69,7 +73,9 @@ DataIndexer getIndexer() { private void parseRootTag(final Map map, final XmlTag xmlRootTag) { for (final XmlTag productTypeTag : xmlRootTag.findSubTags(ProductTypeXml.XML_TAG_TYPE)) { - final String productTypeName = productTypeTag.getAttributeValue(ProductTypeXml.XML_ATTRIBUTE_NAME); + final String productTypeName = productTypeTag.getAttributeValue( + ProductTypeXml.XML_ATTRIBUTE_NAME + ); map.put(productTypeName, null); } } @@ -86,6 +92,7 @@ public int getVersion() { } @Override + @SuppressWarnings({"PMD.LiteralsFirstInComparisons"}) public FileBasedIndex.InputFilter getInputFilter() { return file -> file.getFileType() == XmlFileType.INSTANCE diff --git a/src/com/magento/idea/magento2plugin/util/magento/GetProductTypesListUtil.java b/src/com/magento/idea/magento2plugin/util/magento/GetProductTypesListUtil.java index 7638892ef..527759024 100644 --- a/src/com/magento/idea/magento2plugin/util/magento/GetProductTypesListUtil.java +++ b/src/com/magento/idea/magento2plugin/util/magento/GetProductTypesListUtil.java @@ -12,10 +12,16 @@ import java.util.List; import java.util.stream.Collectors; -public final class GetProductTypesListUtil -{ +public final class GetProductTypesListUtil { + private GetProductTypesListUtil() {} + /** + * Product types util. + * + * @param project Project + * @return List + */ public static List execute(final Project project) { final Collection productTypesList = FileBasedIndex.getInstance().getAllKeys(ProductTypeIndex.KEY, project); diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/CategoryAttributePropertySetupPatchGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/CategoryAttributePropertySetupPatchGeneratorTest.java index 98f2d375a..9dcd4093b 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/CategoryAttributePropertySetupPatchGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/CategoryAttributePropertySetupPatchGeneratorTest.java @@ -14,8 +14,11 @@ public class CategoryAttributePropertySetupPatchGeneratorTest extends BaseGeneratorTestCase { - private final static String MODULE_NAME = "Foo_Bar"; + private static final String MODULE_NAME = "Foo_Bar"; + /** + * Tests the generated patch file. + */ public void testGenerateFile() { final Project project = myFixture.getProject(); @@ -41,9 +44,16 @@ public void testGenerateFile() { final String filePatch = this.getFixturePath("AddTestAttributeCategoryAttribute.php"); final PsiFile expectedFile = myFixture.configureByFile(filePatch); - assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile); + assertGeneratedFileIsCorrect( + expectedFile, + "src/app/code/Foo/Bar/Setup/Patch/Data", + dataPatchFile + ); } + /** + * Tests the generated form file. + */ public void testGenerateFormFile() { final Project project = myFixture.getProject(); @@ -75,6 +85,10 @@ public void testGenerateFormFile() { final String fileCategoryForm = this.getFixturePath("category_form.xml"); final PsiFile expectedCategoryFile = myFixture.configureByFile(fileCategoryForm); - assertGeneratedFileIsCorrect(expectedCategoryFile, "src/app/code/Foo/Bar/view/adminhtml/ui_component", categoryForm); + assertGeneratedFileIsCorrect( + expectedCategoryFile, + "src/app/code/Foo/Bar/view/adminhtml/ui_component", + categoryForm + ); } } diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java index 86ef3ac9c..2179fd262 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java @@ -2,6 +2,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + package com.magento.idea.magento2plugin.actions.generation.generator; import com.intellij.openapi.project.Project; @@ -13,7 +14,12 @@ import java.util.Map; public class ProductAttributePropertySetupPatchGeneratorTest extends BaseGeneratorTestCase { - private final static String MODULE_NAME = "Foo_Bar"; + private static final String MODULE_NAME = "Foo_Bar"; + private static final String LABEL = "Test Label"; + private static final String TYPE = "static"; + private static final String SORT_ORDER = 10; + private static final String GROUP = "General"; + private static final String FILE_PATH = "src/app/code/Foo/Bar/Setup/Patch/Data"; /** * Test Data patch for product's eav attribute generator. @@ -28,14 +34,14 @@ public void testGenerateFile() { productEntityData.setVisibleOnFront(false); productEntityData.setVisible(true); productEntityData.setScope(AttributeScope.GLOBAL.getScope()); - productEntityData.setLabel("Test Label"); - productEntityData.setType("static"); + productEntityData.setLabel(LABEL); + productEntityData.setType(TYPE); productEntityData.setUsedInGrid(false); productEntityData.setRequired(false); productEntityData.setInput("text"); productEntityData.setFilterableInGrid(false); - productEntityData.setSortOrder(10); - productEntityData.setGroup("General"); + productEntityData.setSortOrder(SORT_ORDER); + productEntityData.setGroup(GROUP); productEntityData.setDataPatchName("AddTestAttribute"); productEntityData.setModuleName(MODULE_NAME); @@ -47,9 +53,12 @@ public void testGenerateFile() { final String filePatch = this.getFixturePath("AddTestAttribute.php"); final PsiFile expectedFile = myFixture.configureByFile(filePatch); - assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile); + assertGeneratedFileIsCorrect(expectedFile, FILE_PATH, dataPatchFile); } + /** + * Tests the generated file with the boolean source model. + */ public void testGenerateFileWithBooleanSourceModel() { final Project project = myFixture.getProject(); @@ -60,29 +69,34 @@ public void testGenerateFileWithBooleanSourceModel() { productEntityData.setVisibleOnFront(false); productEntityData.setVisible(true); productEntityData.setScope(AttributeScope.GLOBAL.getScope()); - productEntityData.setLabel("Test Label"); - productEntityData.setType("static"); + productEntityData.setLabel(LABEL); + productEntityData.setType(TYPE); productEntityData.setUsedInGrid(false); productEntityData.setRequired(false); productEntityData.setInput("boolean"); productEntityData.setSource(AttributeSourceModel.BOOLEAN.getSource()); productEntityData.setFilterableInGrid(false); - productEntityData.setSortOrder(10); - productEntityData.setGroup("General"); + productEntityData.setSortOrder(SORT_ORDER); + productEntityData.setGroup(GROUP); productEntityData.setDataPatchName("AddBooleanInputAttributeAttribute"); productEntityData.setModuleName(MODULE_NAME); final EavAttributeSetupPatchGenerator setupPatchGenerator = new EavAttributeSetupPatchGenerator(productEntityData, project); - final PsiFile dataPatchFile = setupPatchGenerator.generate("testGenerateFileWithBooleanSourceModel"); + final PsiFile dataPatchFile = setupPatchGenerator.generate( + "testGenerateFileWithBooleanSourceModel" + ); final String filePatch = this.getFixturePath("AddBooleanInputAttributeAttribute.php"); final PsiFile expectedFile = myFixture.configureByFile(filePatch); - assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile); + assertGeneratedFileIsCorrect(expectedFile, FILE_PATH, dataPatchFile); } + /** + * Tests the generated file with the source model. + */ public void testGenerateFileWithGeneratedSourceModel() { final Project project = myFixture.getProject(); @@ -101,21 +115,26 @@ public void testGenerateFileWithGeneratedSourceModel() { productEntityData.setSource("\\Foo\\Bar\\Model\\Source\\AttributeWithCustomSource"); productEntityData.setFilterableInGrid(false); productEntityData.setSortOrder(10); - productEntityData.setGroup("General"); + productEntityData.setGroup(GROUP); productEntityData.setDataPatchName("AddAttributeWithCustomSourceAttribute"); productEntityData.setModuleName(MODULE_NAME); final EavAttributeSetupPatchGenerator setupPatchGenerator = new EavAttributeSetupPatchGenerator(productEntityData, project); - final PsiFile dataPatchFile = setupPatchGenerator.generate("testGenerateFileWithBooleanSourceModel"); + final PsiFile dataPatchFile = setupPatchGenerator.generate( + "testGenerateFileWithBooleanSourceModel" + ); final String filePatch = this.getFixturePath("AddAttributeWithCustomSourceAttribute.php"); final PsiFile expectedFile = myFixture.configureByFile(filePatch); - assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile); + assertGeneratedFileIsCorrect(expectedFile, FILE_PATH, dataPatchFile); } + /** + * Tests file with the `apply to` attribute. + */ public void testGenerateFileWithApplyToAttribute() { final Project project = myFixture.getProject(); @@ -133,7 +152,7 @@ public void testGenerateFileWithApplyToAttribute() { productEntityData.setInput("text"); productEntityData.setFilterableInGrid(false); productEntityData.setSortOrder(10); - productEntityData.setGroup("General"); + productEntityData.setGroup(GROUP); productEntityData.setApplyTo("configurable,simple"); productEntityData.setDataPatchName("AddAppliedToAttribute"); @@ -141,14 +160,19 @@ public void testGenerateFileWithApplyToAttribute() { final EavAttributeSetupPatchGenerator setupPatchGenerator = new EavAttributeSetupPatchGenerator(productEntityData, project); - final PsiFile dataPatchFile = setupPatchGenerator.generate("testGenerateFileWithApplyToAttribute"); + final PsiFile dataPatchFile = setupPatchGenerator.generate( + "testGenerateFileWithApplyToAttribute" + ); final String filePatch = this.getFixturePath("AddAppliedToAttribute.php"); final PsiFile expectedFile = myFixture.configureByFile(filePatch); - assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile); + assertGeneratedFileIsCorrect(expectedFile, FILE_PATH, dataPatchFile); } + /** + * Tests file with options. + */ public void testGenerateFileWithOptions() { final Project project = myFixture.getProject(); @@ -167,7 +191,7 @@ public void testGenerateFileWithOptions() { productEntityData.setSource(AttributeSourceModel.NULLABLE_SOURCE.getSource()); productEntityData.setFilterableInGrid(false); productEntityData.setSortOrder(10); - productEntityData.setGroup("General"); + productEntityData.setGroup(GROUP); final Map options = new HashMap<>(); options.put(0, "option1"); @@ -186,6 +210,6 @@ public void testGenerateFileWithOptions() { final String filePatch = this.getFixturePath("AddAttributeWithOptionsAttribute.php"); final PsiFile expectedFile = myFixture.configureByFile(filePatch); - assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile); + assertGeneratedFileIsCorrect(expectedFile, FILE_PATH, dataPatchFile); } } diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java index 5a53c6a5d..76c059190 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java @@ -10,10 +10,10 @@ import com.magento.idea.magento2plugin.actions.generation.data.SourceModelData; public class SourceModelGeneratorTest extends BaseGeneratorTestCase { - private final static String MODULE_NAME = "Foo_Bar"; + private static final String MODULE_NAME = "Foo_Bar"; /** - * Test source model generation + * Test source model generation. */ public void testGenerateFile() { final Project project = myFixture.getProject(); @@ -36,7 +36,7 @@ public void testGenerateFile() { } /** - * Test source model in custom directory generation + * Test source model in custom directory generation. */ public void testGenerateFileInCustomDirectory() { final Project project = myFixture.getProject(); From 645e5aaecc018343823f84153b31ca10428c309b Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Fri, 18 Feb 2022 22:25:43 +0300 Subject: [PATCH 054/111] Removed a general suppression, used a certain instead --- .../inspections/xml/ObserverDeclarationInspection.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java b/src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java index b38a80a9c..762c5e14d 100644 --- a/src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java +++ b/src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java @@ -3,7 +3,7 @@ * See COPYING.txt for license details. */ -package com.magento.idea.magento2plugin.inspections.xml;//NOPMD +package com.magento.idea.magento2plugin.inspections.xml; import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.codeInspection.ProblemsHolder; @@ -39,7 +39,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -@SuppressWarnings({"PMD.ExcessiveMethodLength", "PMD.NPathComplexity"}) +@SuppressWarnings({ + "PMD.ExcessiveMethodLength", + "PMD.NPathComplexity", + "PMD.ExcessiveImports", +}) public class ObserverDeclarationInspection extends PhpInspection { @NotNull From 3f3a95680ec36201f96a14ee03e6d79ec05ba89e Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Fri, 18 Feb 2022 23:18:01 +0300 Subject: [PATCH 055/111] Fixed test --- .../ProductAttributePropertySetupPatchGeneratorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java index 2179fd262..8e05991c2 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java @@ -17,7 +17,7 @@ public class ProductAttributePropertySetupPatchGeneratorTest extends BaseGenerat private static final String MODULE_NAME = "Foo_Bar"; private static final String LABEL = "Test Label"; private static final String TYPE = "static"; - private static final String SORT_ORDER = 10; + private static final int SORT_ORDER = 10; private static final String GROUP = "General"; private static final String FILE_PATH = "src/app/code/Foo/Bar/Setup/Patch/Data"; From 358f34263b03c688e93897414932bb729bc064f3 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Tue, 1 Mar 2022 18:19:01 +0200 Subject: [PATCH 056/111] 1011: Updated docblock for code generator --- .../internal/Magento CLI Command Class.php.ft | 2 +- .../internal/Magento Collection Class.php.ft | 2 +- .../fileTemplates/internal/Magento Data Model.php.ft | 12 ------------ .../internal/Magento Entity Search Results.php.ft | 9 +++++++-- ...ento Grid Ui Component Action Column Class.php.ft | 7 ++++--- .../internal/Magento Model Class.php.ft | 4 +++- .../internal/Magento Resource Model Class.php.ft | 2 +- ...to UI Component Custom Data Provider Class.php.ft | 8 ++++++-- .../BookBlockActions.php | 7 ++++--- 9 files changed, 27 insertions(+), 26 deletions(-) diff --git a/resources/fileTemplates/internal/Magento CLI Command Class.php.ft b/resources/fileTemplates/internal/Magento CLI Command Class.php.ft index c87eb8da0..3e3096594 100644 --- a/resources/fileTemplates/internal/Magento CLI Command Class.php.ft +++ b/resources/fileTemplates/internal/Magento CLI Command Class.php.ft @@ -12,7 +12,7 @@ use Symfony\Component\Console\Output\OutputInterface; class ${NAME} extends Command { /** - * @inheritDoc + * Initialization of the command */ protected function configure() { diff --git a/resources/fileTemplates/internal/Magento Collection Class.php.ft b/resources/fileTemplates/internal/Magento Collection Class.php.ft index 58a15875e..696c2a186 100644 --- a/resources/fileTemplates/internal/Magento Collection Class.php.ft +++ b/resources/fileTemplates/internal/Magento Collection Class.php.ft @@ -17,7 +17,7 @@ class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implemen protected $_eventPrefix = '${DB_NAME}_collection'; /** - * @inheritdoc + * Initialize resource model */ protected function _construct() { diff --git a/resources/fileTemplates/internal/Magento Data Model.php.ft b/resources/fileTemplates/internal/Magento Data Model.php.ft index 521e4db61..8d3fc33c5 100644 --- a/resources/fileTemplates/internal/Magento Data Model.php.ft +++ b/resources/fileTemplates/internal/Magento Data Model.php.ft @@ -41,17 +41,11 @@ class ${NAME} #if (${EXTENDS})extends ${EXTENDS} #end #if (${IMPLEMENTS} && $has #if(!($foreach.first)) #end - #if ($hasInterface) - /** - * @inheritDoc - */ - #else /** * Getter for $propertyUpperCamel. * * @return $propertyType|null */ - #end public function get$propertyUpperCamel(): ?$propertyType { #if($propertyType == 'string') @@ -62,11 +56,6 @@ class ${NAME} #if (${EXTENDS})extends ${EXTENDS} #end #if (${IMPLEMENTS} && $has #end } - #if ($hasInterface) - /** - * @inheritDoc - */ - #else /** * Setter for $propertyUpperCamel. * @@ -74,7 +63,6 @@ class ${NAME} #if (${EXTENDS})extends ${EXTENDS} #end #if (${IMPLEMENTS} && $has * * @return void */ - #end public function set$propertyUpperCamel(?$propertyType $$propertyLowerCamel): void { $this->setData(self::$propertyUpperSnake, $$propertyLowerCamel); diff --git a/resources/fileTemplates/internal/Magento Entity Search Results.php.ft b/resources/fileTemplates/internal/Magento Entity Search Results.php.ft index bd4b1e096..215f6c031 100644 --- a/resources/fileTemplates/internal/Magento Entity Search Results.php.ft +++ b/resources/fileTemplates/internal/Magento Entity Search Results.php.ft @@ -14,7 +14,10 @@ use $use; class ${CLASS_NAME} extends ${PARENT_CLASS_NAME} implements ${INTERFACE_NAME} { /** - * @inheritDoc + * Set items list. + * + * @param array $items + * @return ${INTERFACE_NAME} */ public function setItems(array $items): ${INTERFACE_NAME} { @@ -22,7 +25,9 @@ class ${CLASS_NAME} extends ${PARENT_CLASS_NAME} implements ${INTERFACE_NAME} } /** - * @inheritDoc + * Get items list. + * + * @return array */ public function getItems(): array { diff --git a/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft b/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft index 5f2757a9c..7c1bcf4e8 100644 --- a/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft +++ b/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft @@ -20,11 +20,9 @@ class ${CLASS_NAME} extends ${PARENT_CLASS} /** * Url paths. - * #@+ */ private const EDIT_URL_PATH = '${EDIT_URL_PATH}'; private const DELETE_URL_PATH = '${DELETE_URL_PATH}'; - /** #@- */ /** * @var ${URL} @@ -55,7 +53,10 @@ class ${CLASS_NAME} extends ${PARENT_CLASS} } /** - * @inheritDoc + * Prepare Data Source + * + * @param array $dataSource + * @return array */ public function prepareDataSource(array $dataSource): array { diff --git a/resources/fileTemplates/internal/Magento Model Class.php.ft b/resources/fileTemplates/internal/Magento Model Class.php.ft index e4ed8d293..70502da7f 100644 --- a/resources/fileTemplates/internal/Magento Model Class.php.ft +++ b/resources/fileTemplates/internal/Magento Model Class.php.ft @@ -17,7 +17,9 @@ class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implemen protected $_eventPrefix = '${DB_NAME}_model'; /** - * @inheritdoc + * Initialize resource + * + * @return void */ protected function _construct() { diff --git a/resources/fileTemplates/internal/Magento Resource Model Class.php.ft b/resources/fileTemplates/internal/Magento Resource Model Class.php.ft index f2a3d580d..4c3852a1c 100644 --- a/resources/fileTemplates/internal/Magento Resource Model Class.php.ft +++ b/resources/fileTemplates/internal/Magento Resource Model Class.php.ft @@ -17,7 +17,7 @@ class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implemen protected $_eventPrefix = '${DB_NAME}_resource_model'; /** - * @inheritdoc + * Init resource model */ protected function _construct() { diff --git a/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft b/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft index 183e69f4f..b7eae12b9 100644 --- a/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft +++ b/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft @@ -76,7 +76,9 @@ class ${CLASS_NAME} extends ${EXTENDS} } /** - * @inheritDoc + * Returns Search result + * + * @return ${SEARCH_RESULT_FACTORY} */ public function getSearchResult() { @@ -119,7 +121,9 @@ class ${CLASS_NAME} extends ${EXTENDS} } #else /** - * @inheritDoc + * Get data. + * + * @return array */ public function getData() { diff --git a/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php b/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php index 383555ecf..7b3362485 100644 --- a/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php +++ b/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php @@ -20,11 +20,9 @@ class BookBlockActions extends Column /** * Url paths. - * #@+ */ private const EDIT_URL_PATH = 'book_book_edit'; private const DELETE_URL_PATH = 'book_book_delete'; - /** #@- */ /** * @var UrlInterface @@ -56,7 +54,10 @@ public function __construct( } /** - * @inheritDoc + * Prepare Data Source + * + * @param array $dataSource + * @return array */ public function prepareDataSource(array $dataSource): array { From 2bd35f670c35b97e8e54708463c3e98b6f6aa568 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Tue, 1 Mar 2022 20:19:11 +0200 Subject: [PATCH 057/111] 1011: Updated testing files --- .../fileTemplates/internal/Magento CLI Command Class.php.ft | 2 ++ .../generateCLICommandClass/TestCLICommandPHPClass.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/fileTemplates/internal/Magento CLI Command Class.php.ft b/resources/fileTemplates/internal/Magento CLI Command Class.php.ft index 3e3096594..23fa1d962 100644 --- a/resources/fileTemplates/internal/Magento CLI Command Class.php.ft +++ b/resources/fileTemplates/internal/Magento CLI Command Class.php.ft @@ -2,7 +2,9 @@ #parse("PHP File Header.php") #if (${NAMESPACE}) + namespace ${NAMESPACE}; + #end use Symfony\Component\Console\Command\Command; diff --git a/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php b/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php index 5ddf71601..3cfa352c1 100644 --- a/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php +++ b/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php @@ -9,7 +9,7 @@ class TestCLICommandPHPClass extends Command { /** - * @inheritDoc + * Initialization of the command */ protected function configure() { From c80e35b504812d4141a8aad907b001e985568720 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Wed, 2 Mar 2022 17:28:23 +0200 Subject: [PATCH 058/111] 1011: Updated testing files --- .../TestCLICommandPHPClass.php | 2 ++ .../generateDataModel/Sample.php | 20 +++++++++++++++---- .../generateFile/TestCollection.php | 2 +- .../Collection.php | 2 +- .../generateFile/TestModel.php | 4 +++- .../Test.php | 4 +++- .../generateFile/TestResourceModel.php | 2 +- .../TestResourceModel.php | 2 +- .../BookSearchResults.php | 9 +++++++-- .../GridDataProvider.php | 4 +++- .../GridDataProvider.php | 4 +++- 11 files changed, 41 insertions(+), 14 deletions(-) diff --git a/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php b/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php index 3cfa352c1..01cba0616 100644 --- a/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php +++ b/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php @@ -1,7 +1,9 @@ Date: Fri, 4 Mar 2022 11:51:50 +0200 Subject: [PATCH 059/111] 1023: initialized mainline branch --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 94244ea64..d62a7384f 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -5,7 +5,7 @@ name: Run automated tests on: pull_request: - branches: [ master, 4.3.0-develop ] + branches: [ master, '*-develop', 'mainline*' ] jobs: build-linux: From 11606af2f6ad0d2e18fc5549b114dbbe4ee54203 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Fri, 4 Mar 2022 19:18:32 +0200 Subject: [PATCH 060/111] 1023: Added additional fields for UCT configuration dialog --- .../settings/UctSettingsService.java | 42 ++++++++++++ .../magento2uct/ui/ConfigurationDialog.form | 66 +++++++++++++++---- .../magento2uct/ui/ConfigurationDialog.java | 52 ++++++++++++--- 3 files changed, 138 insertions(+), 22 deletions(-) diff --git a/src/com/magento/idea/magento2uct/settings/UctSettingsService.java b/src/com/magento/idea/magento2uct/settings/UctSettingsService.java index fb2d24100..4b2e41528 100644 --- a/src/com/magento/idea/magento2uct/settings/UctSettingsService.java +++ b/src/com/magento/idea/magento2uct/settings/UctSettingsService.java @@ -42,6 +42,12 @@ public class UctSettingsService implements PersistentStateComponent - + - + + + - + @@ -20,7 +22,7 @@ - + @@ -28,7 +30,7 @@ - + @@ -43,7 +45,7 @@
- + @@ -58,11 +60,13 @@
- + - + + + @@ -74,13 +78,13 @@ - + - + @@ -89,7 +93,7 @@ - + @@ -97,7 +101,7 @@ - + @@ -105,7 +109,7 @@ - + @@ -116,7 +120,7 @@ - + @@ -124,6 +128,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java b/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java index 039b430ba..390d9741c 100644 --- a/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java +++ b/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java @@ -27,13 +27,7 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Objects; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.KeyStroke; +import javax.swing.*; import org.jetbrains.annotations.NotNull; @SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) @@ -44,6 +38,7 @@ public class ConfigurationDialog extends AbstractDialog { private JCheckBox enable; private LabeledComponent modulePath; + private LabeledComponent additionalPath; private JCheckBox ignoreCurrentVersion; private JComboBox currentVersion; private JComboBox targetVersion; @@ -59,6 +54,9 @@ public class ConfigurationDialog extends AbstractDialog { private JLabel modulePathError;//NOPMD private JLabel enableComment;//NOPMD private JLabel enableCommentPath;//NOPMD + private JCheckBox hasAdditionalPath; + private JLabel additionalPathLabel;//NOPMD + private JLabel additionalPathError;//NOPMD /** * Configuration dialog. @@ -76,6 +74,7 @@ public ConfigurationDialog(final @NotNull Project project) { setTitle(ConfigureUctAction.ACTION_NAME); getRootPane().setDefaultButton(buttonOk); + hasAdditionalPath.addActionListener(event -> refreshAdditionalFields(hasAdditionalPath.isSelected())); buttonOk.addActionListener(event -> onOK()); buttonCancel.addActionListener(event -> onCancel()); @@ -98,6 +97,9 @@ public void windowClosing(final WindowEvent event) { modulePathError.setText(""); modulePathError.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL)); modulePathError.setForeground(new Color(252, 119, 83)); + additionalPathError.setText(""); + additionalPathError.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL)); + additionalPathError.setForeground(new Color(252, 119, 83)); enableComment.setForeground(JBColor.blue); enableCommentPath.setForeground(JBColor.blue); setDefaultValues(); @@ -120,12 +122,18 @@ public static void open(final @NotNull Project project) { */ private void onOK() { modulePathError.setText(""); + additionalPathError.setText(""); if (modulePath.getComponent().getText().isEmpty() || !UctModulePathValidatorUtil.validate(modulePath.getComponent().getText())) { modulePathError.setText("The `Path To Analyse` field is empty or invalid"); return; } + if (additionalPath.getComponent().getText().isEmpty() + || !UctModulePathValidatorUtil.validate(additionalPath.getComponent().getText())) { + additionalPathError.setText("The `Path To Analyse` field is empty or invalid"); + return; + } settingsService.setEnabled(enable.isSelected()); final ComboBoxItemData currentVersionItemData = @@ -155,7 +163,8 @@ private void onOK() { ) ); settingsService.setIgnoreCurrentVersion(ignoreCurrentVersion.isSelected()); - + settingsService.setHasAdditionalPath(hasAdditionalPath.isSelected()); + settingsService.setAdditionalPath(additionalPath.getComponent().getText()); exit(); } @@ -221,6 +230,21 @@ private void setDefaultValues() { } final Boolean shouldIgnore = settingsService.shouldIgnoreCurrentVersion(); ignoreCurrentVersion.setSelected(Objects.requireNonNullElse(shouldIgnore, false)); + + final Boolean isShowAdditionalPath = settingsService.getHasAdditionalPath(); + additionalPath.setEnabled( + Objects.requireNonNullElse(isShowAdditionalPath, false) + ); + + if (settingsService.getAdditionalPath() == null) { + final String basePath = Settings.getMagentoPath(project); + + if (basePath != null) { + additionalPath.getComponent().setText(basePath); + } + } else { + additionalPath.getComponent().setText(settingsService.getAdditionalPath()); + } } /** @@ -271,5 +295,17 @@ private void createUIComponents() { new FileChooserDescriptor(false, true, false, false, false, false) ) ); + + additionalPath = new LabeledComponent<>(); + additionalPath.setComponent(new TextFieldWithBrowseButton()); + additionalPath.getComponent().addBrowseFolderListener( + new TextBrowseFolderListener( + new FileChooserDescriptor(false, true, false, false, false, false) + ) + ); + } + + private void refreshAdditionalFields(final boolean isEnabled) { + additionalPath.setEnabled(isEnabled); } } From a17258a5b128697d2871c2c647ee37719bbde278 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Sat, 5 Mar 2022 19:59:12 +0200 Subject: [PATCH 061/111] 1023: update logic and code style --- .../magento2uct/ui/ConfigurationDialog.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java b/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java index 390d9741c..8ded3e1c6 100644 --- a/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java +++ b/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java @@ -40,6 +40,7 @@ public class ConfigurationDialog extends AbstractDialog { private LabeledComponent modulePath; private LabeledComponent additionalPath; private JCheckBox ignoreCurrentVersion; + private JCheckBox hasAdditionalPath; private JComboBox currentVersion; private JComboBox targetVersion; private JComboBox issueSeverityLevel; @@ -54,7 +55,6 @@ public class ConfigurationDialog extends AbstractDialog { private JLabel modulePathError;//NOPMD private JLabel enableComment;//NOPMD private JLabel enableCommentPath;//NOPMD - private JCheckBox hasAdditionalPath; private JLabel additionalPathLabel;//NOPMD private JLabel additionalPathError;//NOPMD @@ -103,6 +103,7 @@ public void windowClosing(final WindowEvent event) { enableComment.setForeground(JBColor.blue); enableCommentPath.setForeground(JBColor.blue); setDefaultValues(); + refreshAdditionalFields(hasAdditionalPath.isSelected()); } /** @@ -129,8 +130,9 @@ private void onOK() { modulePathError.setText("The `Path To Analyse` field is empty or invalid"); return; } - if (additionalPath.getComponent().getText().isEmpty() - || !UctModulePathValidatorUtil.validate(additionalPath.getComponent().getText())) { + if (hasAdditionalPath.isSelected() && additionalPath.getComponent().getText().isEmpty() + || hasAdditionalPath.isSelected() + && !UctModulePathValidatorUtil.validate(additionalPath.getComponent().getText())) { additionalPathError.setText("The `Path To Analyse` field is empty or invalid"); return; } @@ -232,17 +234,11 @@ private void setDefaultValues() { ignoreCurrentVersion.setSelected(Objects.requireNonNullElse(shouldIgnore, false)); final Boolean isShowAdditionalPath = settingsService.getHasAdditionalPath(); - additionalPath.setEnabled( + hasAdditionalPath.setSelected( Objects.requireNonNullElse(isShowAdditionalPath, false) ); - if (settingsService.getAdditionalPath() == null) { - final String basePath = Settings.getMagentoPath(project); - - if (basePath != null) { - additionalPath.getComponent().setText(basePath); - } - } else { + if (settingsService.getAdditionalPath() != null) { additionalPath.getComponent().setText(settingsService.getAdditionalPath()); } } @@ -307,5 +303,8 @@ private void createUIComponents() { private void refreshAdditionalFields(final boolean isEnabled) { additionalPath.setEnabled(isEnabled); + additionalPath.setVisible(isEnabled); + additionalPathLabel.setVisible(isEnabled); + additionalPathError.setVisible(isEnabled); } } From 98b7d95053c1fa2133339af20b1af5b05cca02c6 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Mon, 7 Mar 2022 14:46:16 +0200 Subject: [PATCH 062/111] 1011: Updated testing files --- .../fileTemplates/internal/Magento CLI Command Class.php.ft | 2 -- .../generateCLICommandClass/TestCLICommandPHPClass.php | 2 -- 2 files changed, 4 deletions(-) diff --git a/resources/fileTemplates/internal/Magento CLI Command Class.php.ft b/resources/fileTemplates/internal/Magento CLI Command Class.php.ft index 23fa1d962..3e3096594 100644 --- a/resources/fileTemplates/internal/Magento CLI Command Class.php.ft +++ b/resources/fileTemplates/internal/Magento CLI Command Class.php.ft @@ -2,9 +2,7 @@ #parse("PHP File Header.php") #if (${NAMESPACE}) - namespace ${NAMESPACE}; - #end use Symfony\Component\Console\Command\Command; diff --git a/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php b/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php index 01cba0616..3cfa352c1 100644 --- a/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php +++ b/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php @@ -1,9 +1,7 @@ Date: Fri, 11 Mar 2022 16:11:57 +0200 Subject: [PATCH 063/111] 1011: Updated docblock for code generator and testing files --- .../fileTemplates/internal/Magento CLI Command Class.php.ft | 4 ++-- .../fileTemplates/internal/Magento Collection Class.php.ft | 2 +- resources/fileTemplates/internal/Magento Data Model.php.ft | 2 +- .../internal/Magento Entity Search Results.php.ft | 1 + .../Magento Grid Ui Component Action Column Class.php.ft | 3 ++- resources/fileTemplates/internal/Magento Model Class.php.ft | 2 +- .../internal/Magento Resource Model Class.php.ft | 2 +- .../Magento UI Component Custom Data Provider Class.php.ft | 2 +- .../generateCLICommandClass/TestCLICommandPHPClass.php | 4 ++-- .../generateDataModelWithoutInterface/Sample.php | 2 +- .../generateGridActionColumnFile/BookBlockActions.php | 3 ++- .../ModuleCollectionGenerator/generateFile/TestCollection.php | 2 +- .../Collection.php | 2 +- .../generator/ModuleModelGenerator/generateFile/TestModel.php | 2 +- .../generateWithTheSameNameForResourceModel/Test.php | 2 +- .../generateFile/TestResourceModel.php | 2 +- .../generateFileWithDtoReference/TestResourceModel.php | 2 +- .../generateSearchResultsFile/BookSearchResults.php | 1 + .../GridDataProvider.php | 2 +- 19 files changed, 23 insertions(+), 19 deletions(-) diff --git a/resources/fileTemplates/internal/Magento CLI Command Class.php.ft b/resources/fileTemplates/internal/Magento CLI Command Class.php.ft index 3e3096594..1958b580f 100644 --- a/resources/fileTemplates/internal/Magento CLI Command Class.php.ft +++ b/resources/fileTemplates/internal/Magento CLI Command Class.php.ft @@ -12,7 +12,7 @@ use Symfony\Component\Console\Output\OutputInterface; class ${NAME} extends Command { /** - * Initialization of the command + * Initialization of the command. */ protected function configure() { @@ -22,7 +22,7 @@ class ${NAME} extends Command } /** - * CLI command description + * CLI command description. * * @param InputInterface $input * @param OutputInterface $output diff --git a/resources/fileTemplates/internal/Magento Collection Class.php.ft b/resources/fileTemplates/internal/Magento Collection Class.php.ft index 696c2a186..14153e67b 100644 --- a/resources/fileTemplates/internal/Magento Collection Class.php.ft +++ b/resources/fileTemplates/internal/Magento Collection Class.php.ft @@ -17,7 +17,7 @@ class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implemen protected $_eventPrefix = '${DB_NAME}_collection'; /** - * Initialize resource model + * Initialize resource model. */ protected function _construct() { diff --git a/resources/fileTemplates/internal/Magento Data Model.php.ft b/resources/fileTemplates/internal/Magento Data Model.php.ft index 8d3fc33c5..f49f33387 100644 --- a/resources/fileTemplates/internal/Magento Data Model.php.ft +++ b/resources/fileTemplates/internal/Magento Data Model.php.ft @@ -19,7 +19,7 @@ class ${NAME} #if (${EXTENDS})extends ${EXTENDS} #end #if (${IMPLEMENTS} && $has { #if (${PROPERTIES} && !$hasInterface) /** - * String constants for property names + * String constants for property names. */ #set ($properties = ${PROPERTIES}) #foreach ($property in $properties.split(",")) diff --git a/resources/fileTemplates/internal/Magento Entity Search Results.php.ft b/resources/fileTemplates/internal/Magento Entity Search Results.php.ft index 215f6c031..2c3e6da01 100644 --- a/resources/fileTemplates/internal/Magento Entity Search Results.php.ft +++ b/resources/fileTemplates/internal/Magento Entity Search Results.php.ft @@ -17,6 +17,7 @@ class ${CLASS_NAME} extends ${PARENT_CLASS_NAME} implements ${INTERFACE_NAME} * Set items list. * * @param array $items + * * @return ${INTERFACE_NAME} */ public function setItems(array $items): ${INTERFACE_NAME} diff --git a/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft b/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft index 7c1bcf4e8..c5f0deb2c 100644 --- a/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft +++ b/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft @@ -53,9 +53,10 @@ class ${CLASS_NAME} extends ${PARENT_CLASS} } /** - * Prepare Data Source + * Prepare Data Source. * * @param array $dataSource + * * @return array */ public function prepareDataSource(array $dataSource): array diff --git a/resources/fileTemplates/internal/Magento Model Class.php.ft b/resources/fileTemplates/internal/Magento Model Class.php.ft index 70502da7f..a5471d7e9 100644 --- a/resources/fileTemplates/internal/Magento Model Class.php.ft +++ b/resources/fileTemplates/internal/Magento Model Class.php.ft @@ -17,7 +17,7 @@ class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implemen protected $_eventPrefix = '${DB_NAME}_model'; /** - * Initialize resource + * Initialize resource. * * @return void */ diff --git a/resources/fileTemplates/internal/Magento Resource Model Class.php.ft b/resources/fileTemplates/internal/Magento Resource Model Class.php.ft index 4c3852a1c..6ff50b4a8 100644 --- a/resources/fileTemplates/internal/Magento Resource Model Class.php.ft +++ b/resources/fileTemplates/internal/Magento Resource Model Class.php.ft @@ -17,7 +17,7 @@ class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implemen protected $_eventPrefix = '${DB_NAME}_resource_model'; /** - * Init resource model + * Init resource model. */ protected function _construct() { diff --git a/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft b/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft index b7eae12b9..ebce8f403 100644 --- a/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft +++ b/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft @@ -76,7 +76,7 @@ class ${CLASS_NAME} extends ${EXTENDS} } /** - * Returns Search result + * Returns Search result. * * @return ${SEARCH_RESULT_FACTORY} */ diff --git a/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php b/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php index 3cfa352c1..51e0cedeb 100644 --- a/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php +++ b/testData/actions/generation/generator/CLICommandClassGenerator/generateCLICommandClass/TestCLICommandPHPClass.php @@ -9,7 +9,7 @@ class TestCLICommandPHPClass extends Command { /** - * Initialization of the command + * Initialization of the command. */ protected function configure() { @@ -19,7 +19,7 @@ protected function configure() } /** - * CLI command description + * CLI command description. * * @param InputInterface $input * @param OutputInterface $output diff --git a/testData/actions/generation/generator/DataModelGenerator/generateDataModelWithoutInterface/Sample.php b/testData/actions/generation/generator/DataModelGenerator/generateDataModelWithoutInterface/Sample.php index 4a7b160b5..f1cf0e634 100644 --- a/testData/actions/generation/generator/DataModelGenerator/generateDataModelWithoutInterface/Sample.php +++ b/testData/actions/generation/generator/DataModelGenerator/generateDataModelWithoutInterface/Sample.php @@ -7,7 +7,7 @@ class Sample extends DataObject { /** - * String constants for property names + * String constants for property names. */ const ID_PROPERTY = "id_property"; const SAMPLE_PROPERTY = "sample_property"; diff --git a/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php b/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php index 7b3362485..331968778 100644 --- a/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php +++ b/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php @@ -54,9 +54,10 @@ public function __construct( } /** - * Prepare Data Source + * Prepare Data Source. * * @param array $dataSource + * * @return array */ public function prepareDataSource(array $dataSource): array diff --git a/testData/actions/generation/generator/ModuleCollectionGenerator/generateFile/TestCollection.php b/testData/actions/generation/generator/ModuleCollectionGenerator/generateFile/TestCollection.php index 1e3dc62a6..93380952c 100644 --- a/testData/actions/generation/generator/ModuleCollectionGenerator/generateFile/TestCollection.php +++ b/testData/actions/generation/generator/ModuleCollectionGenerator/generateFile/TestCollection.php @@ -14,7 +14,7 @@ class TestCollection extends AbstractCollection protected $_eventPrefix = 'my_table_collection'; /** - * Initialize resource model + * Initialize resource model. */ protected function _construct() { diff --git a/testData/actions/generation/generator/ModuleCollectionGenerator/generateWithTheSameNamesForResourceModelAndModel/Collection.php b/testData/actions/generation/generator/ModuleCollectionGenerator/generateWithTheSameNamesForResourceModelAndModel/Collection.php index 4c34624ed..e20f1ca74 100644 --- a/testData/actions/generation/generator/ModuleCollectionGenerator/generateWithTheSameNamesForResourceModelAndModel/Collection.php +++ b/testData/actions/generation/generator/ModuleCollectionGenerator/generateWithTheSameNamesForResourceModelAndModel/Collection.php @@ -14,7 +14,7 @@ class Collection extends AbstractCollection protected $_eventPrefix = 'my_table_collection'; /** - * Initialize resource model + * Initialize resource model. */ protected function _construct() { diff --git a/testData/actions/generation/generator/ModuleModelGenerator/generateFile/TestModel.php b/testData/actions/generation/generator/ModuleModelGenerator/generateFile/TestModel.php index 43440b6aa..821f0cf10 100644 --- a/testData/actions/generation/generator/ModuleModelGenerator/generateFile/TestModel.php +++ b/testData/actions/generation/generator/ModuleModelGenerator/generateFile/TestModel.php @@ -13,7 +13,7 @@ class TestModel extends AbstractModel protected $_eventPrefix = 'my_table_model'; /** - * Initialize resource + * Initialize resource. * * @return void */ diff --git a/testData/actions/generation/generator/ModuleModelGenerator/generateWithTheSameNameForResourceModel/Test.php b/testData/actions/generation/generator/ModuleModelGenerator/generateWithTheSameNameForResourceModel/Test.php index 5d84197fe..a14714e4b 100644 --- a/testData/actions/generation/generator/ModuleModelGenerator/generateWithTheSameNameForResourceModel/Test.php +++ b/testData/actions/generation/generator/ModuleModelGenerator/generateWithTheSameNameForResourceModel/Test.php @@ -13,7 +13,7 @@ class Test extends AbstractModel protected $_eventPrefix = 'my_table_model'; /** - * Initialize resource + * Initialize resource. * * @return void */ diff --git a/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFile/TestResourceModel.php b/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFile/TestResourceModel.php index 99443f261..ff19fb0b2 100644 --- a/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFile/TestResourceModel.php +++ b/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFile/TestResourceModel.php @@ -12,7 +12,7 @@ class TestResourceModel extends AbstractDb protected $_eventPrefix = 'my_table_resource_model'; /** - * Init resource model + * Init resource model. */ protected function _construct() { diff --git a/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFileWithDtoReference/TestResourceModel.php b/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFileWithDtoReference/TestResourceModel.php index 3e16e9533..2188c0b02 100644 --- a/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFileWithDtoReference/TestResourceModel.php +++ b/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFileWithDtoReference/TestResourceModel.php @@ -13,7 +13,7 @@ class TestResourceModel extends AbstractDb protected $_eventPrefix = 'my_table_resource_model'; /** - * Init resource model + * Init resource model. */ protected function _construct() { diff --git a/testData/actions/generation/generator/SearchResultsFilesGenerator/generateSearchResultsFile/BookSearchResults.php b/testData/actions/generation/generator/SearchResultsFilesGenerator/generateSearchResultsFile/BookSearchResults.php index da33ad85f..47ad29fbb 100644 --- a/testData/actions/generation/generator/SearchResultsFilesGenerator/generateSearchResultsFile/BookSearchResults.php +++ b/testData/actions/generation/generator/SearchResultsFilesGenerator/generateSearchResultsFile/BookSearchResults.php @@ -14,6 +14,7 @@ class BookSearchResults extends SearchResults implements BookSearchResultsInterf * Set items list. * * @param array $items + * * @return BookSearchResultsInterface */ public function setItems(array $items): BookSearchResultsInterface diff --git a/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php b/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php index 3fb14e1c9..902628bdf 100644 --- a/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php +++ b/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php @@ -74,7 +74,7 @@ public function __construct( } /** - * Returns Search result + * Returns Search result. * * @return SearchResultFactory */ From 9d94b3b97cef00dc669974340321dd16233fde97 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Mon, 14 Mar 2022 12:49:56 +0200 Subject: [PATCH 064/111] 613: Initialize mainline branch --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 94244ea64..d62a7384f 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -5,7 +5,7 @@ name: Run automated tests on: pull_request: - branches: [ master, 4.3.0-develop ] + branches: [ master, '*-develop', 'mainline*' ] jobs: build-linux: From 9e799accf92cd6bf4f4e3e4464dfa55c8363fd5c Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Mon, 14 Mar 2022 15:37:15 +0200 Subject: [PATCH 065/111] 1023: added functional for addtional scanning files --- .../magento/files/ThemeXml.java | 38 ++++ .../execution/GenerateUctReportCommand.java | 78 +++++++ .../execution/scanner/ThemeFilesScanner.java | 66 ++++++ .../execution/scanner/ThemeScanner.java | 198 ++++++++++++++++++ 4 files changed, 380 insertions(+) create mode 100644 src/com/magento/idea/magento2plugin/magento/files/ThemeXml.java create mode 100644 src/com/magento/idea/magento2uct/execution/scanner/ThemeFilesScanner.java create mode 100644 src/com/magento/idea/magento2uct/execution/scanner/ThemeScanner.java diff --git a/src/com/magento/idea/magento2plugin/magento/files/ThemeXml.java b/src/com/magento/idea/magento2plugin/magento/files/ThemeXml.java new file mode 100644 index 000000000..d02a88b10 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/ThemeXml.java @@ -0,0 +1,38 @@ +/* + * 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 ThemeXml implements ModuleFileInterface { + public static final String FILE_NAME = "theme.xml"; + public static final String TITLE_ELEMENT_NAME = "title"; + public static final String TEMPLATE = "Magento Theme XML"; + private static final ThemeXml INSTANCE = new ThemeXml(); + + /** + * Getter for singleton instance of class. + */ + public static ThemeXml getInstance() { + return INSTANCE; + } + + @Override + public String getFileName() { + return FILE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return XMLLanguage.INSTANCE; + } +} diff --git a/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java b/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java index 2418a8ad9..ad2cd03f4 100644 --- a/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java +++ b/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java @@ -26,6 +26,8 @@ import com.magento.idea.magento2uct.execution.process.OutputWrapper; import com.magento.idea.magento2uct.execution.scanner.ModuleFilesScanner; import com.magento.idea.magento2uct.execution.scanner.ModuleScanner; +import com.magento.idea.magento2uct.execution.scanner.ThemeFilesScanner; +import com.magento.idea.magento2uct.execution.scanner.ThemeScanner; import com.magento.idea.magento2uct.execution.scanner.data.ComponentData; import com.magento.idea.magento2uct.execution.scanner.filter.ExcludeMagentoBundledFilter; import com.magento.idea.magento2uct.inspections.UctInspectionManager; @@ -81,6 +83,7 @@ public void processTerminated(final @NotNull ProcessEvent event) { public void execute() { output.write("Upgrade compatibility tool\n"); final PsiDirectory rootDirectory = getTargetPsiDirectory(); + final PsiDirectory additionalDirectory = getAdditionalTargetPsiDirectory(); if (rootDirectory == null) { output.print( @@ -99,6 +102,10 @@ public void execute() { ); final ReportBuilder reportBuilder = new ReportBuilder(project); final UctReportOutputUtil outputUtil = new UctReportOutputUtil(output); + final ThemeScanner themeScanner = new ThemeScanner( + additionalDirectory, + new ExcludeMagentoBundledFilter() + ); ApplicationManager.getApplication().executeOnPooledThread(() -> { ApplicationManager.getApplication().runReadAction(() -> { @@ -152,6 +159,56 @@ public void execute() { } } } + for (final ComponentData themeComponentData: themeScanner) { + if (process.isProcessTerminated()) { + return; + } + boolean isThemeHeaderPrinted = false; + + for (final PsiFile psiFile : new ThemeFilesScanner(themeComponentData)) { + if (!(psiFile instanceof PhpFile)) { + continue; + } + + final String filename = psiFile.getVirtualFile().getPath(); + final UctInspectionManager inspectionManager = new UctInspectionManager( + project + ); + final UctProblemsHolder fileProblemsHolder = inspectionManager.run(psiFile); + + if (fileProblemsHolder == null) { + continue; + } + + if (fileProblemsHolder.hasResults()) { + if (!isThemeHeaderPrinted) { + outputUtil.printModuleName(themeComponentData.getName()); + isThemeHeaderPrinted = true; + } + outputUtil.printProblemFile(filename); + } + final List problems = SortDescriptorResultsUtil.sort( + FilterDescriptorResultsUtil.filter(fileProblemsHolder) + ); + + for (final ProblemDescriptor descriptor : problems) { + final SupportedIssue issue = fileProblemsHolder.getIssue(descriptor); + + final String errorMessage = descriptor + .getDescriptionTemplate() + .substring(6) + .trim(); + summary.addToSummary(issue.getLevel()); + reportBuilder.addIssue( + descriptor.getLineNumber() + 1, + filename, + errorMessage, + issue + ); + outputUtil.printIssue(descriptor, issue.getCode()); + } + } + } summary.trackProcessFinished(); summary.setProcessedModules(scanner.getModuleCount()); outputUtil.printSummary(summary); @@ -201,4 +258,25 @@ public void execute() { return PsiManager.getInstance(project).findDirectory(targetDirVirtualFile); } + + /** + * Get additional target psi directory. + * + * @return PsiDirectory + */ + private @Nullable PsiDirectory getAdditionalTargetPsiDirectory() { + final String additionalTargetDirPath = settingsService.getAdditionalPath(); + + if (additionalTargetDirPath == null) { + return null; + } + final VirtualFile targetDirVirtualFile + = VfsUtil.findFile(Paths.get(additionalTargetDirPath), false); + + if (targetDirVirtualFile == null) { + return null; + } + + return PsiManager.getInstance(project).findDirectory(targetDirVirtualFile); + } } diff --git a/src/com/magento/idea/magento2uct/execution/scanner/ThemeFilesScanner.java b/src/com/magento/idea/magento2uct/execution/scanner/ThemeFilesScanner.java new file mode 100644 index 000000000..cce12ec54 --- /dev/null +++ b/src/com/magento/idea/magento2uct/execution/scanner/ThemeFilesScanner.java @@ -0,0 +1,66 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.execution.scanner; + +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.jetbrains.php.lang.psi.PhpFile; +import com.magento.idea.magento2uct.execution.scanner.data.ComponentData; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class ThemeFilesScanner implements Iterable { + + private final ComponentData componentData; + private final List files; + + /** + * Module files scanner constructor. + * + * @param componentData ComponentData + */ + public ThemeFilesScanner(final @NotNull ComponentData componentData) { + this.componentData = componentData; + files = new ArrayList<>(); + } + + @Override + public @NotNull Iterator iterator() { + return run().iterator(); + } + + /** + * Collect module files. + * + * @return List[PsiFile] + */ + private List run() { + files.clear(); + collectFilesInDirectoryRecursively(componentData.getDirectory()); + + return files; + } + + /** + * Collect all files in directory recursively. + * + * @param directory PsiDirectory + */ + private void collectFilesInDirectoryRecursively(final @NotNull PsiDirectory directory) { + for (final PsiFile file : directory.getFiles()) { + if (!(file instanceof PhpFile)) { + files.add(file); + } + } + + for (final PsiDirectory subDirectory : directory.getSubdirectories()) { + collectFilesInDirectoryRecursively(subDirectory); + } + } +} diff --git a/src/com/magento/idea/magento2uct/execution/scanner/ThemeScanner.java b/src/com/magento/idea/magento2uct/execution/scanner/ThemeScanner.java new file mode 100644 index 000000000..9b17f61ed --- /dev/null +++ b/src/com/magento/idea/magento2uct/execution/scanner/ThemeScanner.java @@ -0,0 +1,198 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.execution.scanner; + +import com.intellij.json.psi.JsonFile; +import com.intellij.json.psi.JsonObject; +import com.intellij.json.psi.JsonProperty; +import com.intellij.json.psi.JsonValue; +import com.intellij.openapi.util.Pair; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.intellij.psi.xml.XmlFile; +import com.intellij.psi.xml.XmlTag; +import com.magento.idea.magento2plugin.magento.files.ComposerJson; +import com.magento.idea.magento2plugin.magento.files.ThemeXml; +import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2uct.execution.scanner.data.ComponentData; +import com.magento.idea.magento2uct.execution.scanner.filter.ModuleScannerFilter; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +public final class ThemeScanner implements Iterable { + + private static final String FRAMEWORK_LIBRARY_NAME = "magento/framework"; + + private final PsiDirectory rootDirectory; + private final List componentDataList; + private final List filters; + + /** + * Magento 2 module components scanner constructor. + * + * @param rootDirectory PsiDirectory + * @param filters ModuleScannerFilter[] + */ + public ThemeScanner( + final @NotNull PsiDirectory rootDirectory, + final @NotNull ModuleScannerFilter... filters + + ) { + this.rootDirectory = rootDirectory; + this.filters = Arrays.asList(filters); + componentDataList = new ArrayList<>(); + } + + @Override + public @NotNull Iterator iterator() { + return run().iterator(); + } + + /** + * Get found modules qty. + * + * @return int + */ + public int getThemeCount() { + return componentDataList.size(); + } + + /** + * Run scanner. + * + * @return List[ComponentData] + */ + private List run() { + componentDataList.clear(); + findThemeComponent(rootDirectory); + + return componentDataList; + } + + /** + * Look up magento 2 module components. + * + * @param directory PsiDirectory + */ + @SuppressWarnings({ + "PMD.NPathComplexity", + "PMD.CyclomaticComplexity", + "PMD.CognitiveComplexity", + "PMD.AvoidDeeplyNestedIfStmts" + }) + private void findThemeComponent(final @NotNull PsiDirectory directory) { + String name = null; + String composerBasedName = null; + String composerType; + String type = "magento2-theme"; + + for (final PsiFile file : directory.getFiles()) { + if (file instanceof XmlFile && ThemeXml.FILE_NAME.equals(file.getName())) { + final XmlTag rootTag = ((XmlFile) file).getRootTag(); + + if (rootTag != null && rootTag.getSubTags().length > 0) { + final XmlTag themeTag = rootTag.getSubTags()[0]; + name = themeTag.getValue().getText(); + } + break; + } + } + + for (final PsiFile file : directory.getFiles()) { + if (file instanceof JsonFile && ComposerJson.FILE_NAME.equals(file.getName())) { + final Pair meta = scanModuleComposerMeta((JsonFile) file); + composerBasedName = meta.getFirst(); + composerType = meta.getSecond(); + + if (composerBasedName == null || composerType == null) { + return; + } + + if (name == null && FRAMEWORK_LIBRARY_NAME.equals(composerBasedName)) { + name = meta.getFirst(); + type = composerType; + } + + if (!type.equals(composerType) && !"project".equals(composerType)) { + return; + } + break; + } + } + + if (name != null && composerBasedName != null) { + final ComponentData component = new ComponentData( + name, + composerBasedName, + type, + directory + ); + boolean isExcluded = false; + + for (final ModuleScannerFilter filter : filters) { + if (filter.isExcluded(component)) { + isExcluded = true; + break; + } + } + + if (!isExcluded) { + componentDataList.add(component); + } + return; + } + + for (final PsiDirectory subDirectory : directory.getSubdirectories()) { + findThemeComponent(subDirectory); + } + } + + /** + * Scan module metadata from the composer.json file. + * + * @param composerFile JsonFile + * + * @return Pair[String, String] + */ + @SuppressWarnings({ + "PMD.NPathComplexity", + "PMD.CyclomaticComplexity", + "PMD.CognitiveComplexity" + }) + private Pair scanModuleComposerMeta(final JsonFile composerFile) { + final JsonValue topNode = composerFile.getTopLevelValue(); + String name = null; + String type = null; + + if (topNode instanceof JsonObject) { + for (final JsonProperty property : ((JsonObject) topNode).getPropertyList()) { + switch (property.getName()) { + case "name": + if (property.getValue() != null) { + name = property.getValue().getText().replace("\"", ""); + } + break; + case "type": + if (property.getValue() != null) { + type = property.getValue().getText().replace("\"", ""); + } + break; + default: + break; + } + if (name != null && type != null) { + break; + } + } + } + + return new Pair<>(name, type); + } +} From 667f86b8db5523a58c5e82a80976e99a69294a8f Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Mon, 14 Mar 2022 22:25:11 +0200 Subject: [PATCH 066/111] 1023: Removed unnecessary files --- .../magento/files/ThemeXml.java | 38 ---- .../execution/scanner/ThemeFilesScanner.java | 66 ------ .../execution/scanner/ThemeScanner.java | 198 ------------------ 3 files changed, 302 deletions(-) delete mode 100644 src/com/magento/idea/magento2plugin/magento/files/ThemeXml.java delete mode 100644 src/com/magento/idea/magento2uct/execution/scanner/ThemeFilesScanner.java delete mode 100644 src/com/magento/idea/magento2uct/execution/scanner/ThemeScanner.java diff --git a/src/com/magento/idea/magento2plugin/magento/files/ThemeXml.java b/src/com/magento/idea/magento2plugin/magento/files/ThemeXml.java deleted file mode 100644 index d02a88b10..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/ThemeXml.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 ThemeXml implements ModuleFileInterface { - public static final String FILE_NAME = "theme.xml"; - public static final String TITLE_ELEMENT_NAME = "title"; - public static final String TEMPLATE = "Magento Theme XML"; - private static final ThemeXml INSTANCE = new ThemeXml(); - - /** - * Getter for singleton instance of class. - */ - public static ThemeXml getInstance() { - return INSTANCE; - } - - @Override - public String getFileName() { - return FILE_NAME; - } - - @Override - public String getTemplate() { - return TEMPLATE; - } - - @Override - public Language getLanguage() { - return XMLLanguage.INSTANCE; - } -} diff --git a/src/com/magento/idea/magento2uct/execution/scanner/ThemeFilesScanner.java b/src/com/magento/idea/magento2uct/execution/scanner/ThemeFilesScanner.java deleted file mode 100644 index cce12ec54..000000000 --- a/src/com/magento/idea/magento2uct/execution/scanner/ThemeFilesScanner.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2uct.execution.scanner; - -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; -import com.jetbrains.php.lang.psi.PhpFile; -import com.magento.idea.magento2uct.execution.scanner.data.ComponentData; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class ThemeFilesScanner implements Iterable { - - private final ComponentData componentData; - private final List files; - - /** - * Module files scanner constructor. - * - * @param componentData ComponentData - */ - public ThemeFilesScanner(final @NotNull ComponentData componentData) { - this.componentData = componentData; - files = new ArrayList<>(); - } - - @Override - public @NotNull Iterator iterator() { - return run().iterator(); - } - - /** - * Collect module files. - * - * @return List[PsiFile] - */ - private List run() { - files.clear(); - collectFilesInDirectoryRecursively(componentData.getDirectory()); - - return files; - } - - /** - * Collect all files in directory recursively. - * - * @param directory PsiDirectory - */ - private void collectFilesInDirectoryRecursively(final @NotNull PsiDirectory directory) { - for (final PsiFile file : directory.getFiles()) { - if (!(file instanceof PhpFile)) { - files.add(file); - } - } - - for (final PsiDirectory subDirectory : directory.getSubdirectories()) { - collectFilesInDirectoryRecursively(subDirectory); - } - } -} diff --git a/src/com/magento/idea/magento2uct/execution/scanner/ThemeScanner.java b/src/com/magento/idea/magento2uct/execution/scanner/ThemeScanner.java deleted file mode 100644 index 9b17f61ed..000000000 --- a/src/com/magento/idea/magento2uct/execution/scanner/ThemeScanner.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2uct.execution.scanner; - -import com.intellij.json.psi.JsonFile; -import com.intellij.json.psi.JsonObject; -import com.intellij.json.psi.JsonProperty; -import com.intellij.json.psi.JsonValue; -import com.intellij.openapi.util.Pair; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; -import com.intellij.psi.xml.XmlFile; -import com.intellij.psi.xml.XmlTag; -import com.magento.idea.magento2plugin.magento.files.ComposerJson; -import com.magento.idea.magento2plugin.magento.files.ThemeXml; -import com.magento.idea.magento2plugin.magento.packages.Package; -import com.magento.idea.magento2uct.execution.scanner.data.ComponentData; -import com.magento.idea.magento2uct.execution.scanner.filter.ModuleScannerFilter; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -public final class ThemeScanner implements Iterable { - - private static final String FRAMEWORK_LIBRARY_NAME = "magento/framework"; - - private final PsiDirectory rootDirectory; - private final List componentDataList; - private final List filters; - - /** - * Magento 2 module components scanner constructor. - * - * @param rootDirectory PsiDirectory - * @param filters ModuleScannerFilter[] - */ - public ThemeScanner( - final @NotNull PsiDirectory rootDirectory, - final @NotNull ModuleScannerFilter... filters - - ) { - this.rootDirectory = rootDirectory; - this.filters = Arrays.asList(filters); - componentDataList = new ArrayList<>(); - } - - @Override - public @NotNull Iterator iterator() { - return run().iterator(); - } - - /** - * Get found modules qty. - * - * @return int - */ - public int getThemeCount() { - return componentDataList.size(); - } - - /** - * Run scanner. - * - * @return List[ComponentData] - */ - private List run() { - componentDataList.clear(); - findThemeComponent(rootDirectory); - - return componentDataList; - } - - /** - * Look up magento 2 module components. - * - * @param directory PsiDirectory - */ - @SuppressWarnings({ - "PMD.NPathComplexity", - "PMD.CyclomaticComplexity", - "PMD.CognitiveComplexity", - "PMD.AvoidDeeplyNestedIfStmts" - }) - private void findThemeComponent(final @NotNull PsiDirectory directory) { - String name = null; - String composerBasedName = null; - String composerType; - String type = "magento2-theme"; - - for (final PsiFile file : directory.getFiles()) { - if (file instanceof XmlFile && ThemeXml.FILE_NAME.equals(file.getName())) { - final XmlTag rootTag = ((XmlFile) file).getRootTag(); - - if (rootTag != null && rootTag.getSubTags().length > 0) { - final XmlTag themeTag = rootTag.getSubTags()[0]; - name = themeTag.getValue().getText(); - } - break; - } - } - - for (final PsiFile file : directory.getFiles()) { - if (file instanceof JsonFile && ComposerJson.FILE_NAME.equals(file.getName())) { - final Pair meta = scanModuleComposerMeta((JsonFile) file); - composerBasedName = meta.getFirst(); - composerType = meta.getSecond(); - - if (composerBasedName == null || composerType == null) { - return; - } - - if (name == null && FRAMEWORK_LIBRARY_NAME.equals(composerBasedName)) { - name = meta.getFirst(); - type = composerType; - } - - if (!type.equals(composerType) && !"project".equals(composerType)) { - return; - } - break; - } - } - - if (name != null && composerBasedName != null) { - final ComponentData component = new ComponentData( - name, - composerBasedName, - type, - directory - ); - boolean isExcluded = false; - - for (final ModuleScannerFilter filter : filters) { - if (filter.isExcluded(component)) { - isExcluded = true; - break; - } - } - - if (!isExcluded) { - componentDataList.add(component); - } - return; - } - - for (final PsiDirectory subDirectory : directory.getSubdirectories()) { - findThemeComponent(subDirectory); - } - } - - /** - * Scan module metadata from the composer.json file. - * - * @param composerFile JsonFile - * - * @return Pair[String, String] - */ - @SuppressWarnings({ - "PMD.NPathComplexity", - "PMD.CyclomaticComplexity", - "PMD.CognitiveComplexity" - }) - private Pair scanModuleComposerMeta(final JsonFile composerFile) { - final JsonValue topNode = composerFile.getTopLevelValue(); - String name = null; - String type = null; - - if (topNode instanceof JsonObject) { - for (final JsonProperty property : ((JsonObject) topNode).getPropertyList()) { - switch (property.getName()) { - case "name": - if (property.getValue() != null) { - name = property.getValue().getText().replace("\"", ""); - } - break; - case "type": - if (property.getValue() != null) { - type = property.getValue().getText().replace("\"", ""); - } - break; - default: - break; - } - if (name != null && type != null) { - break; - } - } - } - - return new Pair<>(name, type); - } -} From 6228b9044b63d212215dc9a41fdd18dd75712c0b Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Tue, 15 Mar 2022 12:10:25 +0200 Subject: [PATCH 067/111] 1023: Added support of the theme component --- .../magento/packages/ComponentType.java | 3 +- .../execution/GenerateUctReportCommand.java | 103 ++------ .../magento2uct/execution/output/Summary.java | 19 ++ .../execution/output/UctReportOutputUtil.java | 1 + .../execution/scanner/ModuleScanner.java | 228 +++++++++++------- .../execution/scanner/data/ComponentData.java | 11 +- .../settings/UctSettingsService.java | 8 +- 7 files changed, 192 insertions(+), 181 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/magento/packages/ComponentType.java b/src/com/magento/idea/magento2plugin/magento/packages/ComponentType.java index edcfa91bd..9d9d9faf7 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/ComponentType.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/ComponentType.java @@ -10,7 +10,8 @@ @SuppressWarnings({"PMD.FieldNamingConventions"}) public enum ComponentType { module, - theme; + theme, + library; /** * Get component type by value. diff --git a/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java b/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java index ad2cd03f4..61082ec91 100644 --- a/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java +++ b/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java @@ -26,8 +26,6 @@ import com.magento.idea.magento2uct.execution.process.OutputWrapper; import com.magento.idea.magento2uct.execution.scanner.ModuleFilesScanner; import com.magento.idea.magento2uct.execution.scanner.ModuleScanner; -import com.magento.idea.magento2uct.execution.scanner.ThemeFilesScanner; -import com.magento.idea.magento2uct.execution.scanner.ThemeScanner; import com.magento.idea.magento2uct.execution.scanner.data.ComponentData; import com.magento.idea.magento2uct.execution.scanner.filter.ExcludeMagentoBundledFilter; import com.magento.idea.magento2uct.inspections.UctInspectionManager; @@ -37,6 +35,7 @@ import com.magento.idea.magento2uct.util.inspection.FilterDescriptorResultsUtil; import com.magento.idea.magento2uct.util.inspection.SortDescriptorResultsUtil; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.List; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -82,8 +81,7 @@ public void processTerminated(final @NotNull ProcessEvent event) { @SuppressWarnings({"PMD.ExcessiveMethodLength", "PMD.AvoidInstantiatingObjectsInLoops"}) public void execute() { output.write("Upgrade compatibility tool\n"); - final PsiDirectory rootDirectory = getTargetPsiDirectory(); - final PsiDirectory additionalDirectory = getAdditionalTargetPsiDirectory(); + final PsiDirectory rootDirectory = getTargetPsiDirectory(settingsService.getModulePath()); if (rootDirectory == null) { output.print( @@ -92,8 +90,21 @@ public void execute() { process.destroyProcess(); return; } + final List directoriesToScan = new ArrayList<>(); + directoriesToScan.add(rootDirectory); + + if (settingsService.getHasAdditionalPath()) { + final PsiDirectory additionalDirectory = getTargetPsiDirectory( + settingsService.getAdditionalPath() + ); + + if (additionalDirectory != null) { + directoriesToScan.add(additionalDirectory); + } + } + final ModuleScanner scanner = new ModuleScanner( - rootDirectory, + directoriesToScan, new ExcludeMagentoBundledFilter() ); final Summary summary = new Summary( @@ -102,10 +113,6 @@ public void execute() { ); final ReportBuilder reportBuilder = new ReportBuilder(project); final UctReportOutputUtil outputUtil = new UctReportOutputUtil(output); - final ThemeScanner themeScanner = new ThemeScanner( - additionalDirectory, - new ExcludeMagentoBundledFilter() - ); ApplicationManager.getApplication().executeOnPooledThread(() -> { ApplicationManager.getApplication().runReadAction(() -> { @@ -159,58 +166,9 @@ public void execute() { } } } - for (final ComponentData themeComponentData: themeScanner) { - if (process.isProcessTerminated()) { - return; - } - boolean isThemeHeaderPrinted = false; - - for (final PsiFile psiFile : new ThemeFilesScanner(themeComponentData)) { - if (!(psiFile instanceof PhpFile)) { - continue; - } - - final String filename = psiFile.getVirtualFile().getPath(); - final UctInspectionManager inspectionManager = new UctInspectionManager( - project - ); - final UctProblemsHolder fileProblemsHolder = inspectionManager.run(psiFile); - - if (fileProblemsHolder == null) { - continue; - } - - if (fileProblemsHolder.hasResults()) { - if (!isThemeHeaderPrinted) { - outputUtil.printModuleName(themeComponentData.getName()); - isThemeHeaderPrinted = true; - } - outputUtil.printProblemFile(filename); - } - final List problems = SortDescriptorResultsUtil.sort( - FilterDescriptorResultsUtil.filter(fileProblemsHolder) - ); - - for (final ProblemDescriptor descriptor : problems) { - final SupportedIssue issue = fileProblemsHolder.getIssue(descriptor); - - final String errorMessage = descriptor - .getDescriptionTemplate() - .substring(6) - .trim(); - summary.addToSummary(issue.getLevel()); - reportBuilder.addIssue( - descriptor.getLineNumber() + 1, - filename, - errorMessage, - issue - ); - outputUtil.printIssue(descriptor, issue.getCode()); - } - } - } summary.trackProcessFinished(); summary.setProcessedModules(scanner.getModuleCount()); + summary.setProcessedThemes(scanner.getThemeCount()); outputUtil.printSummary(summary); if (summary.getProcessedModules() == 0) { @@ -242,11 +200,11 @@ public void execute() { /** * Get target psi directory. * + * @param targetDirPath String + * * @return PsiDirectory */ - private @Nullable PsiDirectory getTargetPsiDirectory() { - final String targetDirPath = settingsService.getModulePath(); - + private @Nullable PsiDirectory getTargetPsiDirectory(final String targetDirPath) { if (targetDirPath == null) { return null; } @@ -258,25 +216,4 @@ public void execute() { return PsiManager.getInstance(project).findDirectory(targetDirVirtualFile); } - - /** - * Get additional target psi directory. - * - * @return PsiDirectory - */ - private @Nullable PsiDirectory getAdditionalTargetPsiDirectory() { - final String additionalTargetDirPath = settingsService.getAdditionalPath(); - - if (additionalTargetDirPath == null) { - return null; - } - final VirtualFile targetDirVirtualFile - = VfsUtil.findFile(Paths.get(additionalTargetDirPath), false); - - if (targetDirVirtualFile == null) { - return null; - } - - return PsiManager.getInstance(project).findDirectory(targetDirVirtualFile); - } } diff --git a/src/com/magento/idea/magento2uct/execution/output/Summary.java b/src/com/magento/idea/magento2uct/execution/output/Summary.java index 1c7f5b954..470fddf69 100644 --- a/src/com/magento/idea/magento2uct/execution/output/Summary.java +++ b/src/com/magento/idea/magento2uct/execution/output/Summary.java @@ -18,6 +18,7 @@ public class Summary { private final SupportedVersion installedVersion; private final SupportedVersion targetVersion; private int processedModules; + private int processedThemes; private long processStartedTime; private long processEndedTime; private int phpWarnings; @@ -74,6 +75,24 @@ public void setProcessedModules(final int processedModules) { this.processedModules = processedModules; } + /** + * Get processed theme qty. + * + * @return int + */ + public int getProcessedThemes() { + return processedThemes; + } + + /** + * Set processed theme qty. + * + * @param processedThemes int + */ + public void setProcessedThemes(final int processedThemes) { + this.processedThemes = processedThemes; + } + /** * Track time before process is started. */ diff --git a/src/com/magento/idea/magento2uct/execution/output/UctReportOutputUtil.java b/src/com/magento/idea/magento2uct/execution/output/UctReportOutputUtil.java index cd370f81f..a304e2440 100644 --- a/src/com/magento/idea/magento2uct/execution/output/UctReportOutputUtil.java +++ b/src/com/magento/idea/magento2uct/execution/output/UctReportOutputUtil.java @@ -95,6 +95,7 @@ public void printSummary(final Summary summary) { summaryMap.put("Adobe Commerce version", summary.getTargetVersion()); summaryMap.put("Running time", summary.getProcessRunningTime()); summaryMap.put("Checked modules", String.valueOf(summary.getProcessedModules())); + summaryMap.put("Checked themes", String.valueOf(summary.getProcessedThemes())); summaryMap.put("Total warnings found", String.valueOf(summary.getPhpWarnings())); summaryMap.put("Total errors found", String.valueOf(summary.getPhpErrors())); summaryMap.put("Total critical errors found", diff --git a/src/com/magento/idea/magento2uct/execution/scanner/ModuleScanner.java b/src/com/magento/idea/magento2uct/execution/scanner/ModuleScanner.java index 8ced9c569..9665b017e 100644 --- a/src/com/magento/idea/magento2uct/execution/scanner/ModuleScanner.java +++ b/src/com/magento/idea/magento2uct/execution/scanner/ModuleScanner.java @@ -11,12 +11,17 @@ import com.intellij.json.psi.JsonValue; import com.intellij.openapi.util.Pair; import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; -import com.intellij.psi.xml.XmlFile; -import com.intellij.psi.xml.XmlTag; +import com.intellij.psi.util.PsiTreeUtil; +import com.jetbrains.php.lang.psi.PhpFile; +import com.jetbrains.php.lang.psi.elements.ClassConstantReference; +import com.jetbrains.php.lang.psi.elements.MethodReference; +import com.jetbrains.php.lang.psi.elements.StringLiteralExpression; +import com.jetbrains.php.lang.psi.elements.impl.ClassConstImpl; import com.magento.idea.magento2plugin.magento.files.ComposerJson; -import com.magento.idea.magento2plugin.magento.files.ModuleXml; -import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.magento.files.RegistrationPhp; +import com.magento.idea.magento2plugin.magento.packages.ComponentType; import com.magento.idea.magento2uct.execution.scanner.data.ComponentData; import com.magento.idea.magento2uct.execution.scanner.filter.ModuleScannerFilter; import java.util.ArrayList; @@ -27,11 +32,11 @@ public final class ModuleScanner implements Iterable { - private static final String FRAMEWORK_LIBRARY_NAME = "magento/framework"; - - private final PsiDirectory rootDirectory; + private final List rootDirectories; private final List componentDataList; private final List filters; + private int modulesQty; + private int themesQty; /** * Magento 2 module components scanner constructor. @@ -44,9 +49,25 @@ public ModuleScanner( final @NotNull ModuleScannerFilter... filters ) { - this.rootDirectory = rootDirectory; + this(List.of(rootDirectory), filters); + } + + /** + * Magento 2 module components scanner constructor. + * + * @param directories List[PsiDirectory] + * @param filters ModuleScannerFilter[] + */ + public ModuleScanner( + final List directories, + final @NotNull ModuleScannerFilter... filters + + ) { + this.rootDirectories = new ArrayList<>(directories); this.filters = Arrays.asList(filters); componentDataList = new ArrayList<>(); + modulesQty = 0; + themesQty = 0; } @Override @@ -60,7 +81,16 @@ public ModuleScanner( * @return int */ public int getModuleCount() { - return componentDataList.size(); + return modulesQty; + } + + /** + * Get found themes qty. + * + * @return int + */ + public int getThemeCount() { + return themesQty; } /** @@ -70,7 +100,10 @@ public int getModuleCount() { */ private List run() { componentDataList.clear(); - findModuleComponent(rootDirectory); + + for (final PsiDirectory rootDirectory : rootDirectories) { + findModuleComponent(rootDirectory); + } return componentDataList; } @@ -89,68 +122,51 @@ private List run() { private void findModuleComponent(final @NotNull PsiDirectory directory) { String name = null; String composerBasedName = null; - String composerType; - String type = "magento2-module"; - - for (final PsiDirectory subDirectory : directory.getSubdirectories()) { - if (Package.moduleBaseAreaDir.equals(subDirectory.getName())) { - for (final PsiFile file : subDirectory.getFiles()) { - if (file instanceof XmlFile && ModuleXml.FILE_NAME.equals(file.getName())) { - final XmlTag rootTag = ((XmlFile) file).getRootTag(); - - if (rootTag != null && rootTag.getSubTags().length > 0) { - final XmlTag moduleTag = rootTag.getSubTags()[0]; - name = moduleTag.getAttributeValue("name"); - } - break; - } - } - break; - } - } + ComponentType type = null; - for (final PsiFile file : directory.getFiles()) { - if (file instanceof JsonFile && ComposerJson.FILE_NAME.equals(file.getName())) { - final Pair meta = scanModuleComposerMeta((JsonFile) file); - composerBasedName = meta.getFirst(); - composerType = meta.getSecond(); + final PsiFile registration = directory.findFile(RegistrationPhp.FILE_NAME); - if (composerBasedName == null || composerType == null) { - return; - } - - if (name == null && FRAMEWORK_LIBRARY_NAME.equals(composerBasedName)) { - name = meta.getFirst(); - type = composerType; - } + if (registration instanceof PhpFile) { + final Pair registrationMeta = scanRegistrationMeta( + (PhpFile) registration + ); - if (!type.equals(composerType) && !"project".equals(composerType)) { - return; - } - break; + if (registrationMeta != null) { + name = registrationMeta.getFirst(); + type = registrationMeta.getSecond(); } - } - if (name != null) { - final ComponentData component = new ComponentData( - name, - composerBasedName, - type, - directory - ); - boolean isExcluded = false; + if (name != null) { + final PsiFile composerFile = directory.findFile(ComposerJson.FILE_NAME); - for (final ModuleScannerFilter filter : filters) { - if (filter.isExcluded(component)) { - isExcluded = true; - break; + if (composerFile instanceof JsonFile) { + composerBasedName = getComposerComponentName((JsonFile) composerFile); + } + final ComponentData component = new ComponentData( + name, + composerBasedName, + type, + directory + ); + boolean isExcluded = false; + + for (final ModuleScannerFilter filter : filters) { + if (filter.isExcluded(component)) { + isExcluded = true; + break; + } } - } - if (!isExcluded) { - componentDataList.add(component); + if (!isExcluded) { + if (component.getType().equals(ComponentType.theme)) { + themesQty++; + } else { + modulesQty++; + } + componentDataList.add(component); + } + return; } - return; } for (final PsiDirectory subDirectory : directory.getSubdirectories()) { @@ -159,44 +175,80 @@ private void findModuleComponent(final @NotNull PsiDirectory directory) { } /** - * Scan module metadata from the composer.json file. + * Scan module name from the composer.json file. * * @param composerFile JsonFile * - * @return Pair[String, String] + * @return String */ - @SuppressWarnings({ - "PMD.NPathComplexity", - "PMD.CyclomaticComplexity", - "PMD.CognitiveComplexity" - }) - private Pair scanModuleComposerMeta(final JsonFile composerFile) { + private String getComposerComponentName(final JsonFile composerFile) { final JsonValue topNode = composerFile.getTopLevelValue(); String name = null; - String type = null; if (topNode instanceof JsonObject) { for (final JsonProperty property : ((JsonObject) topNode).getPropertyList()) { - switch (property.getName()) { - case "name": - if (property.getValue() != null) { - name = property.getValue().getText().replace("\"", ""); - } - break; - case "type": - if (property.getValue() != null) { - type = property.getValue().getText().replace("\"", ""); - } - break; - default: - break; - } - if (name != null && type != null) { + if ("name".equals(property.getName())) { + if (property.getValue() != null) { + name = property.getValue().getText().replace("\"", ""); + } break; } } } - return new Pair<>(name, type); + return name; + } + + private Pair scanRegistrationMeta(final PhpFile registrationFile) { + for (final MethodReference reference + : PsiTreeUtil.findChildrenOfType(registrationFile, MethodReference.class)) { + + if (!RegistrationPhp.REGISTER_METHOD_NAME.equals(reference.getName())) { + continue; + } + final PsiElement typeHolder = reference.getParameter(0); + final PsiElement nameHolder = reference.getParameter(1); + + if (typeHolder == null || nameHolder == null) { + return null; + } + final String type = unwrapParameterValue(typeHolder); + final String name = unwrapParameterValue(nameHolder); + + if (name == null || type == null) { + return null; + } + final ComponentType resolvedType = ComponentType.getByValue(type); + + if (resolvedType == null) { + return null; + } + + return new Pair<>(name, resolvedType); + } + + return null; + } + + private String unwrapParameterValue(final @NotNull PsiElement parameterValue) { + if (parameterValue instanceof ClassConstantReference) { + final PsiElement resolvedValue = ((ClassConstantReference) parameterValue).resolve(); + + if (!(resolvedValue instanceof ClassConstImpl)) { + return null; + } + final ClassConstImpl resolvedConst = (ClassConstImpl) resolvedValue; + final PsiElement value = resolvedConst.getDefaultValue(); + + if (value == null) { + return null; + } + + return unwrapParameterValue(value); + } else if (parameterValue instanceof StringLiteralExpression) { + return ((StringLiteralExpression) parameterValue).getContents(); + } + + return null; } } diff --git a/src/com/magento/idea/magento2uct/execution/scanner/data/ComponentData.java b/src/com/magento/idea/magento2uct/execution/scanner/data/ComponentData.java index 1c1980b38..9d6d7ffee 100644 --- a/src/com/magento/idea/magento2uct/execution/scanner/data/ComponentData.java +++ b/src/com/magento/idea/magento2uct/execution/scanner/data/ComponentData.java @@ -6,13 +6,14 @@ package com.magento.idea.magento2uct.execution.scanner.data; import com.intellij.psi.PsiDirectory; +import com.magento.idea.magento2plugin.magento.packages.ComponentType; import org.jetbrains.annotations.NotNull; public class ComponentData { private final String name; private final String composerName; - private final String type; + private final ComponentType type; private final PsiDirectory directory; /** @@ -20,13 +21,13 @@ public class ComponentData { * * @param name String * @param composerName String - * @param type String + * @param type ComponentType * @param directory PsiDirectory */ public ComponentData( final @NotNull String name, final String composerName, - final @NotNull String type, + final @NotNull ComponentType type, final @NotNull PsiDirectory directory ) { this.name = name; @@ -56,9 +57,9 @@ public String getComposerName() { /** * Get component type. * - * @return String + * @return ComponentType */ - public String getType() { + public ComponentType getType() { return type; } diff --git a/src/com/magento/idea/magento2uct/settings/UctSettingsService.java b/src/com/magento/idea/magento2uct/settings/UctSettingsService.java index 4b2e41528..dea0e0b5c 100644 --- a/src/com/magento/idea/magento2uct/settings/UctSettingsService.java +++ b/src/com/magento/idea/magento2uct/settings/UctSettingsService.java @@ -257,7 +257,7 @@ public void setIgnoreCurrentVersion(final boolean ignoreCurrentVersion) { } /** - * Set if show additional path + * Set if show additional path. * * @param hasAdditionalPath boolean */ @@ -266,12 +266,12 @@ public void setHasAdditionalPath(final boolean hasAdditionalPath) { } /** - * Check if show additional path + * Check if show additional path. * * @return boolean */ - public @Nullable Boolean getHasAdditionalPath() { - return hasAdditionalPath; + public @NotNull Boolean getHasAdditionalPath() { + return hasAdditionalPath != null && hasAdditionalPath; } /** From 6f24218d292930b1070ab1132dda42a624ec60ec Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Tue, 15 Mar 2022 12:38:01 +0200 Subject: [PATCH 068/111] 1023: Added phtml files support --- .../execution/GenerateUctReportCommand.java | 4 +- .../execution/output/UctReportOutputUtil.java | 19 +++++++-- .../inspections/UctInspectionManager.java | 40 +++++++++---------- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java b/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java index 61082ec91..ecec26ccb 100644 --- a/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java +++ b/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java @@ -139,7 +139,7 @@ public void execute() { if (fileProblemsHolder.hasResults()) { if (!isModuleHeaderPrinted) { - outputUtil.printModuleName(componentData.getName()); + outputUtil.printModuleName(componentData); isModuleHeaderPrinted = true; } outputUtil.printProblemFile(filename); @@ -171,7 +171,7 @@ public void execute() { summary.setProcessedThemes(scanner.getThemeCount()); outputUtil.printSummary(summary); - if (summary.getProcessedModules() == 0) { + if (summary.getProcessedModules() == 0 && summary.getProcessedThemes() == 0) { process.destroyProcess(); return; } diff --git a/src/com/magento/idea/magento2uct/execution/output/UctReportOutputUtil.java b/src/com/magento/idea/magento2uct/execution/output/UctReportOutputUtil.java index a304e2440..704aa2816 100644 --- a/src/com/magento/idea/magento2uct/execution/output/UctReportOutputUtil.java +++ b/src/com/magento/idea/magento2uct/execution/output/UctReportOutputUtil.java @@ -8,8 +8,10 @@ import com.intellij.codeInspection.ProblemDescriptor; import com.magento.idea.magento2uct.bundles.UctInspectionBundle; import com.magento.idea.magento2uct.execution.process.OutputWrapper; +import com.magento.idea.magento2uct.execution.scanner.data.ComponentData; import com.magento.idea.magento2uct.packages.SupportedIssue; import java.util.LinkedHashMap; +import java.util.Locale; import java.util.Map; import org.jetbrains.annotations.NotNull; @@ -31,10 +33,19 @@ public UctReportOutputUtil(final @NotNull OutputWrapper output) { /** * Print module name header. * - * @param moduleName String + * @param componentData ComponentData */ - public void printModuleName(final @NotNull String moduleName) { - final String moduleNameLine = "Module Name: ".concat(moduleName); + public void printModuleName(final @NotNull ComponentData componentData) { + final String componentType = componentData.getType().toString(); + final String componentTypeFormatted = componentType + .substring(0, 1) + .toUpperCase(new Locale("en","EN")) + .concat(componentType.substring(1)); + + final String moduleNameLine = componentTypeFormatted + .concat(" Name: ") + .concat(componentData.getName()); + stdout.print("\n\n" + stdout.wrapInfo(moduleNameLine).concat("\n")); stdout.print(stdout.wrapInfo("-".repeat(moduleNameLine.length())).concat("\n")); } @@ -81,7 +92,7 @@ public void printIssue(final @NotNull ProblemDescriptor descriptor, final int co */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public void printSummary(final Summary summary) { - if (summary.getProcessedModules() == 0) { + if (summary.getProcessedModules() == 0 && summary.getProcessedThemes() == 0) { stdout.print(stdout.wrapInfo("Couldn't find modules to analyse").concat("\n")); return; } diff --git a/src/com/magento/idea/magento2uct/inspections/UctInspectionManager.java b/src/com/magento/idea/magento2uct/inspections/UctInspectionManager.java index df1f69ee1..093530835 100644 --- a/src/com/magento/idea/magento2uct/inspections/UctInspectionManager.java +++ b/src/com/magento/idea/magento2uct/inspections/UctInspectionManager.java @@ -52,11 +52,6 @@ public UctInspectionManager(final @NotNull Project project) { if (!(psiFile instanceof PhpFile)) { return null; } - final PhpClass phpClass = GetFirstClassOfFile.getInstance().execute((PhpFile) psiFile); - - if (phpClass == null) { - return null; - } final UctProblemsHolder problemsHolder = new UctProblemsHolder( InspectionManager.getInstance(project), psiFile, @@ -64,7 +59,7 @@ public UctInspectionManager(final @NotNull Project project) { ); final List visitors = SupportedIssue.getVisitors(problemsHolder); - for (final PsiElement element : collectElements(phpClass)) { + for (final PsiElement element : collectElements(psiFile)) { for (final PsiElementVisitor visitor : visitors) { element.accept(visitor); } @@ -76,26 +71,31 @@ public UctInspectionManager(final @NotNull Project project) { /** * Collect elements for PHP based inspections. * - * @param phpClass PhpClass + * @param psiFile PsiFile * * @return List[PsiElement] */ - private List collectElements(final @NotNull PhpClass phpClass) { + private List collectElements(final @NotNull PsiFile psiFile) { final List elements = new LinkedList<>(); - elements.add(phpClass); - final PhpPsiElement scopeForUseOperator = PhpCodeInsightUtil.findScopeForUseOperator( - phpClass - ); - if (scopeForUseOperator != null) { - elements.addAll(PhpCodeInsightUtil.collectImports(scopeForUseOperator)); + final PhpClass phpClass = GetFirstClassOfFile.getInstance().execute((PhpFile) psiFile); + + if (phpClass != null) { + elements.add(phpClass); + final PhpPsiElement scopeForUseOperator = PhpCodeInsightUtil.findScopeForUseOperator( + phpClass + ); + + if (scopeForUseOperator != null) { + elements.addAll(PhpCodeInsightUtil.collectImports(scopeForUseOperator)); + } + elements.addAll(Arrays.asList(phpClass.getOwnFields())); } - elements.addAll(PsiTreeUtil.findChildrenOfType(phpClass, ClassConstantReference.class)); - elements.addAll(Arrays.asList(phpClass.getOwnFields())); - elements.addAll(PsiTreeUtil.findChildrenOfType(phpClass, MethodReference.class)); - elements.addAll(PsiTreeUtil.findChildrenOfType(phpClass, AssignmentExpression.class)); - elements.addAll(PsiTreeUtil.findChildrenOfType(phpClass, ClassReference.class)); - elements.addAll(PsiTreeUtil.findChildrenOfType(phpClass, FieldReference.class)); + elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, ClassConstantReference.class)); + elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, MethodReference.class)); + elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, AssignmentExpression.class)); + elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, ClassReference.class)); + elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, FieldReference.class)); return elements; } From 47d4cdcff3c9e8a3457fa2ce4c72149a57409646 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Tue, 15 Mar 2022 12:47:06 +0200 Subject: [PATCH 069/111] 1023: Added themes count into the json report --- .../magento/idea/magento2uct/execution/output/ReportBuilder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/magento/idea/magento2uct/execution/output/ReportBuilder.java b/src/com/magento/idea/magento2uct/execution/output/ReportBuilder.java index b48a0775d..fd6a0734e 100644 --- a/src/com/magento/idea/magento2uct/execution/output/ReportBuilder.java +++ b/src/com/magento/idea/magento2uct/execution/output/ReportBuilder.java @@ -163,6 +163,7 @@ public JsonFile build() { + "installedVersion\": \"" + summary.getInstalledVersion() + "\"," + "\"AdobeCommerceVersion\": \"" + summary.getTargetVersion() + "\"," + "\"checkedModules\": " + summary.getProcessedModules() + "," + + "\"checkedThemes\": " + summary.getProcessedThemes() + "," + "\"runningTime\": \"" + summary.getProcessRunningTime() + "\"," + "\"totalWarnings\": " + summary.getPhpWarnings() + "," + "\"totalErrors\": " + summary.getPhpErrors() + "," From 3b2e39b911700c154f00053e64e68e1c8b97bff1 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Tue, 15 Mar 2022 12:59:54 +0200 Subject: [PATCH 070/111] 1023: Code refactoring --- .github/workflows/gradle.yml | 2 +- .../idea/magento2uct/ui/ConfigurationDialog.java | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index d62a7384f..94244ea64 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -5,7 +5,7 @@ name: Run automated tests on: pull_request: - branches: [ master, '*-develop', 'mainline*' ] + branches: [ master, 4.3.0-develop ] jobs: build-linux: diff --git a/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java b/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java index 8ded3e1c6..e9bb8b6a2 100644 --- a/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java +++ b/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java @@ -27,7 +27,13 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Objects; -import javax.swing.*; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; @SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) @@ -40,7 +46,7 @@ public class ConfigurationDialog extends AbstractDialog { private LabeledComponent modulePath; private LabeledComponent additionalPath; private JCheckBox ignoreCurrentVersion; - private JCheckBox hasAdditionalPath; + private JCheckBox hasAdditionalPath;//NOPMD private JComboBox currentVersion; private JComboBox targetVersion; private JComboBox issueSeverityLevel; @@ -74,7 +80,8 @@ public ConfigurationDialog(final @NotNull Project project) { setTitle(ConfigureUctAction.ACTION_NAME); getRootPane().setDefaultButton(buttonOk); - hasAdditionalPath.addActionListener(event -> refreshAdditionalFields(hasAdditionalPath.isSelected())); + hasAdditionalPath.addActionListener(event -> + refreshAdditionalFields(hasAdditionalPath.isSelected())); buttonOk.addActionListener(event -> onOK()); buttonCancel.addActionListener(event -> onCancel()); @@ -121,6 +128,7 @@ public static void open(final @NotNull Project project) { /** * Save configuration. */ + @SuppressWarnings("PMD.CyclomaticComplexity") private void onOK() { modulePathError.setText(""); additionalPathError.setText(""); From 7d8d0729f1c01e12e7e531c2d8a1034cc9972873 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Tue, 15 Mar 2022 13:11:23 +0200 Subject: [PATCH 071/111] 1023: Code refactoring --- .../idea/magento2uct/execution/output/UctReportOutputUtil.java | 2 +- .../idea/magento2uct/execution/scanner/ModuleScanner.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2uct/execution/output/UctReportOutputUtil.java b/src/com/magento/idea/magento2uct/execution/output/UctReportOutputUtil.java index 28a7a3664..30dc30496 100644 --- a/src/com/magento/idea/magento2uct/execution/output/UctReportOutputUtil.java +++ b/src/com/magento/idea/magento2uct/execution/output/UctReportOutputUtil.java @@ -91,7 +91,7 @@ public void printIssue(final @NotNull ProblemDescriptor descriptor, final int co * @param summary Summary * @param platformName String */ - @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + @SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops", "PMD.CyclomaticComplexity"}) public void printSummary(final Summary summary, final String platformName) { if (summary.getProcessedModules() == 0 && summary.getProcessedThemes() == 0) { stdout.print(stdout.wrapInfo("Couldn't find modules to analyse").concat("\n")); diff --git a/src/com/magento/idea/magento2uct/execution/scanner/ModuleScanner.java b/src/com/magento/idea/magento2uct/execution/scanner/ModuleScanner.java index 9665b017e..a5432138b 100644 --- a/src/com/magento/idea/magento2uct/execution/scanner/ModuleScanner.java +++ b/src/com/magento/idea/magento2uct/execution/scanner/ModuleScanner.java @@ -199,6 +199,7 @@ private String getComposerComponentName(final JsonFile composerFile) { return name; } + @SuppressWarnings("PMD.AvoidBranchingStatementAsLastInLoop") private Pair scanRegistrationMeta(final PhpFile registrationFile) { for (final MethodReference reference : PsiTreeUtil.findChildrenOfType(registrationFile, MethodReference.class)) { From b71ea51f06bf868ced61f843a043b37c2b835ee6 Mon Sep 17 00:00:00 2001 From: Alexandr Tereshkov Date: Wed, 16 Mar 2022 19:12:41 +0300 Subject: [PATCH 072/111] 613-diff-overridden-template --- resources/META-INF/plugin.xml | 3 + .../comparator/CompareTemplateAction.java | 149 ++++++++++++++++++ .../idea/magento2plugin/util/RegExUtil.java | 5 + 3 files changed, 157 insertions(+) create mode 100644 src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index b0cc5b59f..4d03e93b0 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -130,6 +130,9 @@ + + + Date: Wed, 16 Mar 2022 19:26:39 +0300 Subject: [PATCH 073/111] 613-diff-overridden-template --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index d62a7384f..94244ea64 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -5,7 +5,7 @@ name: Run automated tests on: pull_request: - branches: [ master, '*-develop', 'mainline*' ] + branches: [ master, 4.3.0-develop ] jobs: build-linux: From 756c8f409d1aca9299de9e1294340899123f5135 Mon Sep 17 00:00:00 2001 From: Alexandr Tereshkov Date: Thu, 17 Mar 2022 08:14:07 +0300 Subject: [PATCH 074/111] code style --- .../comparator/CompareTemplateAction.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java b/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java index eabacf1c5..d020c0bcf 100644 --- a/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java +++ b/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java @@ -1,3 +1,8 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + package com.magento.idea.magento2plugin.actions.comparator; import com.intellij.diff.DiffContentFactory; @@ -25,6 +30,7 @@ import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; + import java.nio.file.Path; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -72,7 +78,8 @@ public void update(final @NotNull AnActionEvent event) { final String fullPath = selectedFile.getPath(); final String area = getArea(fullPath); final String originalModuleName = getOriginalModuleName(project, psiFile); - final PsiDirectory originalModuleDirectory = new ModuleIndex(project).getModuleDirectoryByModuleName(originalModuleName); + final PsiDirectory originalModuleDirectory = + new ModuleIndex(project).getModuleDirectoryByModuleName(originalModuleName); if (originalModuleDirectory == null || area == null @@ -123,9 +130,11 @@ private String getOriginalModuleName(Project project, PsiFile psiFile) { } @NotNull - private MutableDiffRequestChain createMutableChainFromFiles(@Nullable Project project, - @NotNull VirtualFile file1, - @NotNull VirtualFile file2) { + private MutableDiffRequestChain createMutableChainFromFiles( + @Nullable Project project, + @NotNull VirtualFile file1, + @NotNull VirtualFile file2 + ) { DiffContentFactory contentFactory = DiffContentFactory.getInstance(); DiffRequestFactory requestFactory = DiffRequestFactory.getInstance(); From 2a675e4d7e8618fbd2a9ea075223074a3d5d2c9f Mon Sep 17 00:00:00 2001 From: Alexandr Tereshkov Date: Thu, 17 Mar 2022 08:34:53 +0300 Subject: [PATCH 075/111] code style --- .../actions/comparator/CompareTemplateAction.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java b/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java index d020c0bcf..aeadbd771 100644 --- a/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java +++ b/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java @@ -28,12 +28,11 @@ import com.magento.idea.magento2plugin.util.RegExUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; import org.apache.commons.lang3.StringUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - import java.nio.file.Path; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class CompareTemplateAction extends AnAction { From 7858e9a68c4a3738dbc5ea2434ac905043c9b353 Mon Sep 17 00:00:00 2001 From: Alexandr Tereshkov Date: Thu, 17 Mar 2022 08:38:49 +0300 Subject: [PATCH 076/111] code style --- .../actions/comparator/CompareTemplateAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java b/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java index aeadbd771..ffb836c5e 100644 --- a/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java +++ b/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java @@ -27,10 +27,10 @@ import com.magento.idea.magento2plugin.project.Settings; import com.magento.idea.magento2plugin.util.RegExUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import org.apache.commons.lang3.StringUtils; import java.nio.file.Path; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; From ecc5da48c937db9fefa0a4c22bf0262751987128 Mon Sep 17 00:00:00 2001 From: Alexandr Tereshkov Date: Thu, 17 Mar 2022 08:52:29 +0300 Subject: [PATCH 077/111] code style --- .../comparator/CompareTemplateAction.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java b/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java index ffb836c5e..6508410ad 100644 --- a/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java +++ b/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java @@ -65,7 +65,7 @@ public void update(final @NotNull AnActionEvent event) { return; } final PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE); - selectedFile = psiFile != null ? psiFile.getVirtualFile() : null; + selectedFile = psiFile != null ? psiFile.getVirtualFile() : null;//NOPMD if (selectedFile != null && !PHTML_EXTENSION.equals(selectedFile.getExtension()) @@ -103,15 +103,15 @@ public void update(final @NotNull AnActionEvent event) { } @Override - public void actionPerformed(@NotNull AnActionEvent e) { - Project project = e.getProject(); - DiffRequestChain chain = createMutableChainFromFiles(project, selectedFile, originalFile); + public void actionPerformed(final @NotNull AnActionEvent event) { + final Project project = event.getProject(); + final DiffRequestChain chain = createMutableChainFromFiles(project, selectedFile, originalFile); DiffManager.getInstance().showDiff(project, chain, DiffDialogHints.DEFAULT); } @Nullable - private String getArea(String fullPath) { + private String getArea(final String fullPath) { final Pattern pattern = Pattern.compile(RegExUtil.ViewArea.AREA); final Matcher matcher = pattern.matcher(fullPath); String areaName = null; @@ -122,7 +122,7 @@ private String getArea(String fullPath) { return areaName; } - private String getOriginalModuleName(Project project, PsiFile psiFile) { + private String getOriginalModuleName(final Project project, final PsiFile psiFile) { final PsiDirectory directory = psiFile.getContainingDirectory(); return GetModuleNameByDirectoryUtil.execute(directory, project); @@ -130,17 +130,17 @@ private String getOriginalModuleName(Project project, PsiFile psiFile) { @NotNull private MutableDiffRequestChain createMutableChainFromFiles( - @Nullable Project project, - @NotNull VirtualFile file1, - @NotNull VirtualFile file2 + final @Nullable Project project, + final @NotNull VirtualFile file1, + final @NotNull VirtualFile file2 ) { - DiffContentFactory contentFactory = DiffContentFactory.getInstance(); - DiffRequestFactory requestFactory = DiffRequestFactory.getInstance(); + final DiffContentFactory contentFactory = DiffContentFactory.getInstance(); + final DiffRequestFactory requestFactory = DiffRequestFactory.getInstance(); - DiffContent content1 = contentFactory.create(project, file1); - DiffContent content2 = contentFactory.create(project, file2); + final DiffContent content1 = contentFactory.create(project, file1); + final DiffContent content2 = contentFactory.create(project, file2); - MutableDiffRequestChain chain = BlankDiffWindowUtil.createBlankDiffRequestChain( + final MutableDiffRequestChain chain = BlankDiffWindowUtil.createBlankDiffRequestChain( (DocumentContent)content1, (DocumentContent)content2, null From bf340149c1062a64f2f8624bd11f9cb2911c022d Mon Sep 17 00:00:00 2001 From: Alexandr Tereshkov Date: Thu, 17 Mar 2022 08:56:10 +0300 Subject: [PATCH 078/111] code style --- .../actions/comparator/CompareTemplateAction.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java b/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java index 6508410ad..e09e024a8 100644 --- a/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java +++ b/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java @@ -105,7 +105,8 @@ public void update(final @NotNull AnActionEvent event) { @Override public void actionPerformed(final @NotNull AnActionEvent event) { final Project project = event.getProject(); - final DiffRequestChain chain = createMutableChainFromFiles(project, selectedFile, originalFile); + final DiffRequestChain chain = + createMutableChainFromFiles(project, selectedFile, originalFile); DiffManager.getInstance().showDiff(project, chain, DiffDialogHints.DEFAULT); } From af5f3e98cc932836384b9ce87b069abff7f7a7d6 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 17 Mar 2022 09:50:21 +0200 Subject: [PATCH 079/111] 1030: Adding configuration files support for the UCT feature --- resources/META-INF/plugin.xml | 15 +++ .../UsedDeprecatedTypeInConfig.html | 6 + .../UsedNonExistentTypeInConfig.html | 6 + resources/uct/bundle/inspection.properties | 2 + .../xml/ModuleConfigFileInspection.java | 106 ++++++++++++++++++ .../xml/UsedDeprecatedTypeInConfig.java | 46 ++++++++ .../xml/UsedNonExistentTypeInConfig.java | 46 ++++++++ .../magento2uct/packages/SupportedIssue.java | 28 +++++ .../util/php/FqnValidatorUtil.java | 53 +++++++++ .../util/php/MagentoTypeEscapeUtil.java | 21 ++++ .../versioning/VersionStateManager.java | 17 ++- .../indexes/data/ExistenceStateIndex.java | 11 ++ 12 files changed, 356 insertions(+), 1 deletion(-) create mode 100644 resources/inspectionDescriptions/UsedDeprecatedTypeInConfig.html create mode 100644 resources/inspectionDescriptions/UsedNonExistentTypeInConfig.html create mode 100644 src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java create mode 100644 src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedTypeInConfig.java create mode 100644 src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentTypeInConfig.java create mode 100644 src/com/magento/idea/magento2uct/util/php/FqnValidatorUtil.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index b0cc5b59f..a909a243b 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -537,6 +537,21 @@ enabledByDefault="false" level="WARNING" implementationClass="com.magento.idea.magento2uct.inspections.php.api.CalledNonInterfaceMethod"/> + + + diff --git a/resources/inspectionDescriptions/UsedDeprecatedTypeInConfig.html b/resources/inspectionDescriptions/UsedDeprecatedTypeInConfig.html new file mode 100644 index 000000000..7a699ff79 --- /dev/null +++ b/resources/inspectionDescriptions/UsedDeprecatedTypeInConfig.html @@ -0,0 +1,6 @@ + + +

[1134] Using Magento 2 @deprecated type: consider using Magento Open Source|Adobe Commerce type marked as @api instead.

+ + + diff --git a/resources/inspectionDescriptions/UsedNonExistentTypeInConfig.html b/resources/inspectionDescriptions/UsedNonExistentTypeInConfig.html new file mode 100644 index 000000000..a96cb06c0 --- /dev/null +++ b/resources/inspectionDescriptions/UsedNonExistentTypeInConfig.html @@ -0,0 +1,6 @@ + + +

[1110] The used type is no longer present in the codebase.

+ + + diff --git a/resources/uct/bundle/inspection.properties b/resources/uct/bundle/inspection.properties index 14dd91065..e95eb276f 100644 --- a/resources/uct/bundle/inspection.properties +++ b/resources/uct/bundle/inspection.properties @@ -38,6 +38,8 @@ inspection.displayName.ExtendedNonApiClass=Extended non Magento 2 API class inspection.displayName.InheritedNonApiInterface=Inherited non Magento 2 API interface inspection.displayName.PossibleDependencyOnImplDetails=Possible dependency on implementation details inspection.displayName.CalledNonInterfaceMethod=Called non-interface method +inspection.displayName.UsedNonExistentTypeInConfig=Used non-existent Magento 2 type in the configuration file +inspection.displayName.UsedDeprecatedTypeInConfig=Used deprecated Magento 2 type in the configuration file customCode.warnings.deprecated.1131=[1131] Extended class ''{0}'' that is @deprecated in the ''{1}'' customCode.warnings.deprecated.1132=[1132] Imported class ''{0}'' that is @deprecated in the ''{1}'' customCode.warnings.deprecated.1134=[1134] Used class ''{0}'' that is @deprecated in the ''{1}'' diff --git a/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java b/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java new file mode 100644 index 000000000..478229424 --- /dev/null +++ b/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java @@ -0,0 +1,106 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.inspections.xml; + +import com.intellij.codeInspection.InspectionManager; +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.codeInspection.XmlSuppressableInspectionTool; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.psi.xml.XmlToken; +import com.intellij.psi.xml.XmlTokenType; +import com.magento.idea.magento2uct.settings.UctSettingsService; +import com.magento.idea.magento2uct.versioning.VersionStateManager; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +abstract class ModuleConfigFileInspection extends XmlSuppressableInspectionTool { + + private final String[] supportedFiles = new String[]{ + "di.xml", + "system.xml", + "events.xml", + "extension_attributes.xml", + "webapi.xml", + "communication.xml", + "queue_consumer.xml", + "crontab.xml", + "indexer.xml", + "mview.xml", + "product_types.xml", + "widget.xml", + }; + + @Override + public @Nullable ProblemDescriptor[] checkFile( + final @NotNull PsiFile file, + final @NotNull InspectionManager manager, + final boolean isOnTheFly + ) { + final Project project = file.getProject(); + final UctSettingsService settings = UctSettingsService.getInstance(project); + + if (!settings.isEnabled()) { + return getEmptyResult(); + } + + if (Arrays.stream(supportedFiles).noneMatch(name -> name.equals(file.getName()))) { + return getEmptyResult(); + } + final List allowedTokenTypes = new ArrayList<>(); + allowedTokenTypes.add(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN); + allowedTokenTypes.add(XmlTokenType.XML_DATA_CHARACTERS); + + final List descriptors = new ArrayList<>(); + + for (final XmlToken token : PsiTreeUtil.findChildrenOfType(file, XmlToken.class)) { + if (!allowedTokenTypes.contains(token.getTokenType())) { + continue; + } + final String fqn = token.getText().trim(); + + if (!VersionStateManager.getInstance(project).isPresentInCodebase(fqn)) { + continue; + } + // Inspection logic. + doInspection(fqn, token, manager, isOnTheFly, descriptors); + } + + return descriptors.toArray(new ProblemDescriptor[0]); + } + + /** + * Implement this method to specify inspection logic. + * + * @param fqn String + * @param target PsiElement + * @param manager InspectionManager + * @param isOnTheFly boolean + * @param descriptors List[ProblemDescriptor] + */ + protected abstract void doInspection( + final @NotNull String fqn, + final @NotNull PsiElement target, + final @NotNull InspectionManager manager, + final boolean isOnTheFly, + final @NotNull List descriptors + ); + + /** + * Retrieves an empty result. + * + * @return ProblemDescriptor[] + */ + private ProblemDescriptor[] getEmptyResult() { + return new ProblemDescriptor[0]; + } +} diff --git a/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedTypeInConfig.java b/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedTypeInConfig.java new file mode 100644 index 000000000..e535afeb0 --- /dev/null +++ b/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedTypeInConfig.java @@ -0,0 +1,46 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.inspections.xml; + +import com.intellij.codeInspection.InspectionManager; +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.codeInspection.ProblemHighlightType; +import com.intellij.psi.PsiElement; +import com.magento.idea.magento2uct.packages.SupportedIssue; +import com.magento.idea.magento2uct.versioning.VersionStateManager; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public class UsedDeprecatedTypeInConfig extends ModuleConfigFileInspection { + + @Override + protected void doInspection( + final @NotNull String fqn, + final @NotNull PsiElement target, + final @NotNull InspectionManager manager, + final boolean isOnTheFly, + final @NotNull List descriptors + ) { + if (VersionStateManager.getInstance(manager.getProject()).isDeprecated(fqn)) { + final String message = SupportedIssue.USED_DEPRECATED_TYPE_IN_CONFIG.getMessage( + fqn, + VersionStateManager.getInstance( + manager.getProject() + ).getDeprecatedInVersion(fqn) + ); + + final ProblemDescriptor descriptor = manager.createProblemDescriptor( + target, + message, + null, + ProblemHighlightType.WARNING, + isOnTheFly, + false + ); + descriptors.add(descriptor); + } + } +} diff --git a/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentTypeInConfig.java b/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentTypeInConfig.java new file mode 100644 index 000000000..4c3bca379 --- /dev/null +++ b/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentTypeInConfig.java @@ -0,0 +1,46 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.inspections.xml; + +import com.intellij.codeInspection.InspectionManager; +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.codeInspection.ProblemHighlightType; +import com.intellij.psi.PsiElement; +import com.magento.idea.magento2uct.packages.SupportedIssue; +import com.magento.idea.magento2uct.versioning.VersionStateManager; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public class UsedNonExistentTypeInConfig extends ModuleConfigFileInspection { + + @Override + protected void doInspection( + final @NotNull String fqn, + final @NotNull PsiElement target, + final @NotNull InspectionManager manager, + final boolean isOnTheFly, + final @NotNull List descriptors + ) { + if (!VersionStateManager.getInstance(manager.getProject()).isExists(fqn)) { + final String message = SupportedIssue.USED_NON_EXISTENT_TYPE_IN_CONFIG.getMessage( + fqn, + VersionStateManager.getInstance( + manager.getProject() + ).getRemovedInVersion(fqn) + ); + + final ProblemDescriptor descriptor = manager.createProblemDescriptor( + target, + message, + null, + ProblemHighlightType.ERROR, + isOnTheFly, + false + ); + descriptors.add(descriptor); + } + } +} diff --git a/src/com/magento/idea/magento2uct/packages/SupportedIssue.java b/src/com/magento/idea/magento2uct/packages/SupportedIssue.java index e0771622f..50a43d150 100644 --- a/src/com/magento/idea/magento2uct/packages/SupportedIssue.java +++ b/src/com/magento/idea/magento2uct/packages/SupportedIssue.java @@ -7,6 +7,7 @@ import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.psi.PsiElementVisitor; +import com.jetbrains.php.lang.psi.PhpFile; import com.magento.idea.magento2uct.bundles.UctInspectionBundle; import com.magento.idea.magento2uct.inspections.UctProblemsHolder; import com.magento.idea.magento2uct.inspections.php.api.CalledNonApiMethod; @@ -45,7 +46,10 @@ import com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentConstant; import com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentProperty; import com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentType; +import com.magento.idea.magento2uct.inspections.xml.UsedDeprecatedTypeInConfig; +import com.magento.idea.magento2uct.inspections.xml.UsedNonExistentTypeInConfig; import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import org.jetbrains.annotations.Nullable; @@ -268,6 +272,18 @@ public enum SupportedIssue { IssueSeverityLevel.ERROR, "customCode.errors.api.1449", CalledNonInterfaceMethod.class + ), + USED_NON_EXISTENT_TYPE_IN_CONFIG( + 1110, + IssueSeverityLevel.CRITICAL, + "customCode.critical.existence.1110", + UsedNonExistentTypeInConfig.class + ), + USED_DEPRECATED_TYPE_IN_CONFIG( + 1134, + IssueSeverityLevel.WARNING, + "customCode.warnings.deprecated.1134", + UsedDeprecatedTypeInConfig.class ); private final int code; @@ -377,6 +393,18 @@ public static List getVisitors( return visitors; } + /** + * Get supported file types. + * + * @return List + */ + public static List> getSupportedFileTypes() { + final List> types = new ArrayList<>(); + types.add(PhpFile.class); + + return types; + } + /** * Build inspection visitor for file. * diff --git a/src/com/magento/idea/magento2uct/util/php/FqnValidatorUtil.java b/src/com/magento/idea/magento2uct/util/php/FqnValidatorUtil.java new file mode 100644 index 000000000..a7f753bf4 --- /dev/null +++ b/src/com/magento/idea/magento2uct/util/php/FqnValidatorUtil.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.util.php; + +import com.intellij.openapi.project.Project; +import com.jetbrains.php.PhpIndex; +import com.jetbrains.php.lang.psi.elements.PhpClass; +import java.util.Collection; +import java.util.regex.Matcher; +import org.jetbrains.annotations.NotNull; + +public final class FqnValidatorUtil { + + private FqnValidatorUtil() {} + + /** + * Check if provided string is a valid FQN. + * + * @param fqnCandidate String + * @param project Project + * + * @return boolean + */ + public static boolean validate( + final @NotNull String fqnCandidate, + final @NotNull Project project + ) { + String safeFqn = MagentoTypeEscapeUtil.escapeProperty(fqnCandidate); + + if (isFactoryOrProxy(safeFqn)) { + safeFqn = MagentoTypeEscapeUtil.escape(safeFqn); + } + final Collection classes = PhpIndex.getInstance(project).getAnyByFQN(safeFqn); + + return !classes.isEmpty(); + } + + /** + * Check if provided FQN is a Factory or Proxy. + * + * @param fqn String + * + * @return boolean + */ + private static boolean isFactoryOrProxy(final @NotNull String fqn) { + final Matcher matcher = MagentoTypeEscapeUtil.FACTORY_PROXY_TYPE_PATTERN.matcher(fqn); + + return matcher.find(); + } +} diff --git a/src/com/magento/idea/magento2uct/util/php/MagentoTypeEscapeUtil.java b/src/com/magento/idea/magento2uct/util/php/MagentoTypeEscapeUtil.java index ce910cea9..42802e519 100644 --- a/src/com/magento/idea/magento2uct/util/php/MagentoTypeEscapeUtil.java +++ b/src/com/magento/idea/magento2uct/util/php/MagentoTypeEscapeUtil.java @@ -15,6 +15,8 @@ public final class MagentoTypeEscapeUtil { = "(Factory|\\\\Proxy|Factory\\\\Proxy)($|\\.)"; public static final Pattern FACTORY_PROXY_TYPE_PATTERN = Pattern.compile(FACTORY_PROXY_TYPE_REGEX, Pattern.MULTILINE); + public static final String PHP_PROPERTY_REFERENCE_SEPARATOR = "::"; + public static final String JAVA_PROPERTY_REFERENCE_SEPARATOR = "."; private MagentoTypeEscapeUtil() { } @@ -43,4 +45,23 @@ private MagentoTypeEscapeUtil() { return typeFqn.equals(result) ? typeFqn : result; } + + /** + * Replace PHP property reference separator with the Intellij based separator. + * + * @param typeFqn String + * + * @return String + */ + public static @NotNull String escapeProperty(final @NotNull String typeFqn) { + if (typeFqn.contains(PHP_PROPERTY_REFERENCE_SEPARATOR) + && typeFqn.split(PHP_PROPERTY_REFERENCE_SEPARATOR).length == 1) { + return typeFqn.replace( + PHP_PROPERTY_REFERENCE_SEPARATOR, + JAVA_PROPERTY_REFERENCE_SEPARATOR + ); + } + + return typeFqn; + } } diff --git a/src/com/magento/idea/magento2uct/versioning/VersionStateManager.java b/src/com/magento/idea/magento2uct/versioning/VersionStateManager.java index aa89ea5ca..3ddf8d3cb 100644 --- a/src/com/magento/idea/magento2uct/versioning/VersionStateManager.java +++ b/src/com/magento/idea/magento2uct/versioning/VersionStateManager.java @@ -52,6 +52,19 @@ public static synchronized VersionStateManager getInstance( return instance; } + /** + * Checks if specified FQN was/is in the MBE/VBE. + * + * @param fqn String + * + * @return boolean + */ + public synchronized boolean isPresentInCodebase(final @NotNull String fqn) { + String safeFqn = MagentoTypeEscapeUtil.escapeProperty(escapeFqn(fqn)); + + return existenceStateIndex.isPresentInCodebase(safeFqn); + } + /** * Check if specified FQN exists in the deprecation index. * @@ -215,6 +228,8 @@ private void compute(final VersionStateIndex index) { * @return String */ private String escapeFqn(final @NotNull String fqn) { - return MagentoTypeEscapeUtil.escape(fqn); + return MagentoTypeEscapeUtil.escape( + fqn.trim().charAt(0) == '\\' ? fqn.trim() : '\\' + fqn.trim() + ); } } diff --git a/src/com/magento/idea/magento2uct/versioning/indexes/data/ExistenceStateIndex.java b/src/com/magento/idea/magento2uct/versioning/indexes/data/ExistenceStateIndex.java index 25d677a57..d382baccc 100644 --- a/src/com/magento/idea/magento2uct/versioning/indexes/data/ExistenceStateIndex.java +++ b/src/com/magento/idea/magento2uct/versioning/indexes/data/ExistenceStateIndex.java @@ -66,6 +66,17 @@ public synchronized boolean has(final @NotNull String fqn) { return !changelog.containsKey(fqn); } + /** + * Checks if specified FQN was/is in the MBE/VBE. + * + * @param fqn String + * + * @return boolean + */ + public synchronized boolean isPresentInCodebase(final @NotNull String fqn) { + return changelog.containsKey(fqn); + } + /** * Get version for specified FQN from prepared changelog. * From e126871af44c3746f2498eef020a958a7afbfb30 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 17 Mar 2022 11:18:50 +0200 Subject: [PATCH 080/111] 1011: code refactoring --- .../fileTemplates/internal/Magento Collection Class.php.ft | 2 +- .../Magento Grid Ui Component Action Column Class.php.ft | 2 +- resources/fileTemplates/internal/Magento Model Class.php.ft | 2 +- .../fileTemplates/internal/Magento Resource Model Class.php.ft | 2 +- .../Magento UI Component Custom Data Provider Class.php.ft | 2 +- .../generateGridActionColumnFile/BookBlockActions.php | 2 +- .../ModuleCollectionGenerator/generateFile/TestCollection.php | 2 +- .../Collection.php | 2 +- .../generator/ModuleModelGenerator/generateFile/TestModel.php | 2 +- .../generateWithTheSameNameForResourceModel/Test.php | 2 +- .../generateFile/TestResourceModel.php | 2 +- .../generateFileWithDtoReference/TestResourceModel.php | 2 +- .../GridDataProvider.php | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/resources/fileTemplates/internal/Magento Collection Class.php.ft b/resources/fileTemplates/internal/Magento Collection Class.php.ft index 14153e67b..c7eb58a11 100644 --- a/resources/fileTemplates/internal/Magento Collection Class.php.ft +++ b/resources/fileTemplates/internal/Magento Collection Class.php.ft @@ -17,7 +17,7 @@ class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implemen protected $_eventPrefix = '${DB_NAME}_collection'; /** - * Initialize resource model. + * Initialize collection model. */ protected function _construct() { diff --git a/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft b/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft index c5f0deb2c..79dc781ca 100644 --- a/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft +++ b/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft @@ -53,7 +53,7 @@ class ${CLASS_NAME} extends ${PARENT_CLASS} } /** - * Prepare Data Source. + * Prepare data source. * * @param array $dataSource * diff --git a/resources/fileTemplates/internal/Magento Model Class.php.ft b/resources/fileTemplates/internal/Magento Model Class.php.ft index a5471d7e9..91d2333bd 100644 --- a/resources/fileTemplates/internal/Magento Model Class.php.ft +++ b/resources/fileTemplates/internal/Magento Model Class.php.ft @@ -17,7 +17,7 @@ class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implemen protected $_eventPrefix = '${DB_NAME}_model'; /** - * Initialize resource. + * Initialize magento model. * * @return void */ diff --git a/resources/fileTemplates/internal/Magento Resource Model Class.php.ft b/resources/fileTemplates/internal/Magento Resource Model Class.php.ft index 6ff50b4a8..f3ec78818 100644 --- a/resources/fileTemplates/internal/Magento Resource Model Class.php.ft +++ b/resources/fileTemplates/internal/Magento Resource Model Class.php.ft @@ -17,7 +17,7 @@ class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implemen protected $_eventPrefix = '${DB_NAME}_resource_model'; /** - * Init resource model. + * Initialize resource model. */ protected function _construct() { diff --git a/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft b/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft index ebce8f403..b435459b2 100644 --- a/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft +++ b/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft @@ -76,7 +76,7 @@ class ${CLASS_NAME} extends ${EXTENDS} } /** - * Returns Search result. + * Returns searching result. * * @return ${SEARCH_RESULT_FACTORY} */ diff --git a/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php b/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php index 331968778..357366f19 100644 --- a/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php +++ b/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php @@ -54,7 +54,7 @@ public function __construct( } /** - * Prepare Data Source. + * Prepare data source. * * @param array $dataSource * diff --git a/testData/actions/generation/generator/ModuleCollectionGenerator/generateFile/TestCollection.php b/testData/actions/generation/generator/ModuleCollectionGenerator/generateFile/TestCollection.php index 93380952c..fb80e01be 100644 --- a/testData/actions/generation/generator/ModuleCollectionGenerator/generateFile/TestCollection.php +++ b/testData/actions/generation/generator/ModuleCollectionGenerator/generateFile/TestCollection.php @@ -14,7 +14,7 @@ class TestCollection extends AbstractCollection protected $_eventPrefix = 'my_table_collection'; /** - * Initialize resource model. + * Initialize collection model. */ protected function _construct() { diff --git a/testData/actions/generation/generator/ModuleCollectionGenerator/generateWithTheSameNamesForResourceModelAndModel/Collection.php b/testData/actions/generation/generator/ModuleCollectionGenerator/generateWithTheSameNamesForResourceModelAndModel/Collection.php index e20f1ca74..102b6124c 100644 --- a/testData/actions/generation/generator/ModuleCollectionGenerator/generateWithTheSameNamesForResourceModelAndModel/Collection.php +++ b/testData/actions/generation/generator/ModuleCollectionGenerator/generateWithTheSameNamesForResourceModelAndModel/Collection.php @@ -14,7 +14,7 @@ class Collection extends AbstractCollection protected $_eventPrefix = 'my_table_collection'; /** - * Initialize resource model. + * Initialize collection model. */ protected function _construct() { diff --git a/testData/actions/generation/generator/ModuleModelGenerator/generateFile/TestModel.php b/testData/actions/generation/generator/ModuleModelGenerator/generateFile/TestModel.php index 821f0cf10..fc228bd1d 100644 --- a/testData/actions/generation/generator/ModuleModelGenerator/generateFile/TestModel.php +++ b/testData/actions/generation/generator/ModuleModelGenerator/generateFile/TestModel.php @@ -13,7 +13,7 @@ class TestModel extends AbstractModel protected $_eventPrefix = 'my_table_model'; /** - * Initialize resource. + * Initialize magento model. * * @return void */ diff --git a/testData/actions/generation/generator/ModuleModelGenerator/generateWithTheSameNameForResourceModel/Test.php b/testData/actions/generation/generator/ModuleModelGenerator/generateWithTheSameNameForResourceModel/Test.php index a14714e4b..ea07e0a3a 100644 --- a/testData/actions/generation/generator/ModuleModelGenerator/generateWithTheSameNameForResourceModel/Test.php +++ b/testData/actions/generation/generator/ModuleModelGenerator/generateWithTheSameNameForResourceModel/Test.php @@ -13,7 +13,7 @@ class Test extends AbstractModel protected $_eventPrefix = 'my_table_model'; /** - * Initialize resource. + * Initialize magento model. * * @return void */ diff --git a/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFile/TestResourceModel.php b/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFile/TestResourceModel.php index ff19fb0b2..483df77ca 100644 --- a/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFile/TestResourceModel.php +++ b/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFile/TestResourceModel.php @@ -12,7 +12,7 @@ class TestResourceModel extends AbstractDb protected $_eventPrefix = 'my_table_resource_model'; /** - * Init resource model. + * Initialize resource model. */ protected function _construct() { diff --git a/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFileWithDtoReference/TestResourceModel.php b/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFileWithDtoReference/TestResourceModel.php index 2188c0b02..01726ed42 100644 --- a/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFileWithDtoReference/TestResourceModel.php +++ b/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFileWithDtoReference/TestResourceModel.php @@ -13,7 +13,7 @@ class TestResourceModel extends AbstractDb protected $_eventPrefix = 'my_table_resource_model'; /** - * Init resource model. + * Initialize resource model. */ protected function _construct() { diff --git a/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php b/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php index 902628bdf..514896290 100644 --- a/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php +++ b/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php @@ -74,7 +74,7 @@ public function __construct( } /** - * Returns Search result. + * Returns searching result. * * @return SearchResultFactory */ From fb7224b924090d8ef99d7d7c04ee227dd041006c Mon Sep 17 00:00:00 2001 From: silinmykola Date: Thu, 17 Mar 2022 10:55:28 +0200 Subject: [PATCH 081/111] 1026-Change overwrite templates feature --- resources/META-INF/plugin.xml | 5 +- ....java => OverrideLayoutInThemeAction.java} | 43 ++--- .../OverrideTemplateInThemeAction.java | 97 ++++++++++++ ...nTheme.form => OverrideLayoutInTheme.form} | 2 +- ....java => OverrideLayoutInThemeDialog.java} | 48 ++++-- .../dialog/OverrideTemplateInThemeDialog.form | 90 +++++++++++ .../dialog/OverrideTemplateInThemeDialog.java | 149 ++++++++++++++++++ .../generator/OverrideInThemeGenerator.java | 128 +++++---------- .../OverrideLayoutInThemeGenerator.java | 117 ++++++++++++++ .../OverrideTemplateInThemeGenerator.java | 98 ++++++++++++ .../magento/files/LayoutXml.java | 1 + 11 files changed, 658 insertions(+), 120 deletions(-) rename src/com/magento/idea/magento2plugin/actions/generation/{OverrideInThemeAction.java => OverrideLayoutInThemeAction.java} (62%) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/OverrideTemplateInThemeAction.java rename src/com/magento/idea/magento2plugin/actions/generation/dialog/{OverrideInTheme.form => OverrideLayoutInTheme.form} (99%) rename src/com/magento/idea/magento2plugin/actions/generation/dialog/{OverrideInThemeDialog.java => OverrideLayoutInThemeDialog.java} (69%) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.form create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideLayoutInThemeGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideTemplateInThemeGenerator.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index b0cc5b59f..4a25accac 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -118,7 +118,10 @@ - + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/OverrideInThemeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/OverrideLayoutInThemeAction.java similarity index 62% rename from src/com/magento/idea/magento2plugin/actions/generation/OverrideInThemeAction.java rename to src/com/magento/idea/magento2plugin/actions/generation/OverrideLayoutInThemeAction.java index 85a77e67a..496ad3466 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/OverrideInThemeAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/OverrideLayoutInThemeAction.java @@ -5,28 +5,29 @@ package com.magento.idea.magento2plugin.actions.generation; +import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.magento.idea.magento2plugin.MagentoIcons; -import com.magento.idea.magento2plugin.actions.generation.dialog.OverrideInThemeDialog; +import com.magento.idea.magento2plugin.actions.generation.dialog.OverrideLayoutInThemeDialog; +import com.magento.idea.magento2plugin.magento.files.LayoutXml; +import com.magento.idea.magento2plugin.magento.files.UiComponentGridXmlFile; import com.magento.idea.magento2plugin.magento.packages.ComponentType; import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.project.Settings; -import com.magento.idea.magento2plugin.util.magento.GetComponentNameByDirectoryUtil; -import com.magento.idea.magento2plugin.util.magento.GetComponentTypeByNameUtil; +import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; import org.jetbrains.annotations.NotNull; -public class OverrideInThemeAction extends DumbAwareAction { +public class OverrideLayoutInThemeAction extends AnAction { - public static final String ACTION_NAME = "Override this template in a project theme"; - public static final String ACTION_DESCRIPTION = "Override in project theme"; + public static final String ACTION_NAME = "Override this layout in a project theme"; + public static final String ACTION_DESCRIPTION = "Override layout in project theme"; private PsiFile psiFile; - public OverrideInThemeAction() { + public OverrideLayoutInThemeAction() { super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); } @@ -60,15 +61,22 @@ private boolean isOverrideAllowed(final VirtualFile file, final Project project) return false; } - boolean isAllowed = false; + if (!UiComponentGridXmlFile.FILE_EXTENSION + .equals(psiFile.getVirtualFile().getExtension())) { + return false; + } - final String componentType = GetComponentTypeByNameUtil.execute( - GetComponentNameByDirectoryUtil.execute(psiFile.getContainingDirectory(), project) - ); + if (!LayoutXml.PARENT_DIR.equals(psiFile.getContainingDirectory().getName()) + && !LayoutXml.PAGE_LAYOUT_DIR.equals(psiFile.getContainingDirectory().getName())) { + return false; + } + boolean isAllowed = false; + final GetMagentoModuleUtil.MagentoModuleData moduleData = + GetMagentoModuleUtil.getByContext(psiFile.getContainingDirectory(), project); - if (componentType.equals(ComponentType.module.toString())) { + if (moduleData.getType().equals(ComponentType.module)) { isAllowed = file.getPath().contains(Package.moduleViewDir); - } else if (componentType.equals(ComponentType.theme.toString())) { + } else if (moduleData.getType().equals(ComponentType.theme)) { isAllowed = true; } @@ -82,11 +90,6 @@ private void setStatus(final AnActionEvent event, final boolean status) { @Override public void actionPerformed(final @NotNull AnActionEvent event) { - OverrideInThemeDialog.open(event.getProject(), this.psiFile); - } - - @Override - public boolean isDumbAware() { - return false; + OverrideLayoutInThemeDialog.open(event.getProject(), this.psiFile); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/OverrideTemplateInThemeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/OverrideTemplateInThemeAction.java new file mode 100644 index 000000000..de15db9e5 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/OverrideTemplateInThemeAction.java @@ -0,0 +1,97 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.MagentoIcons; +import com.magento.idea.magento2plugin.actions.CopyMagentoPath; +import com.magento.idea.magento2plugin.actions.generation.dialog.OverrideTemplateInThemeDialog; +import com.magento.idea.magento2plugin.magento.packages.ComponentType; +import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.project.Settings; +import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; +import org.jetbrains.annotations.NotNull; + +public class OverrideTemplateInThemeAction extends AnAction { + + public static final String ACTION_NAME = "Override this in a project theme"; + public static final String ACTION_TEMPLATE_DESCRIPTION = "Override template in project theme"; + public static final String ACTION_STYLES_DESCRIPTION = "Override styles in project theme"; + public static final String LESS_FILE_EXTENSION = "less"; + private PsiFile psiFile; + + public OverrideTemplateInThemeAction() { + super(ACTION_NAME, ACTION_TEMPLATE_DESCRIPTION, MagentoIcons.MODULE); + } + + /** + * Action entry point. + * + * @param event AnActionEvent + */ + @Override + public void update(final @NotNull AnActionEvent event) { + boolean status = false; + final Project project = event.getData(PlatformDataKeys.PROJECT); + psiFile = event.getData(PlatformDataKeys.PSI_FILE); + + if (Settings.isEnabled(project)) { + try { + status = isOverrideAllowed( + psiFile.getVirtualFile(), + project + ); + } catch (NullPointerException e) { //NOPMD + // Ignore + } + } + + this.setStatus(event, status); + } + + private boolean isOverrideAllowed(final VirtualFile file, final Project project) { + if (file.isDirectory()) { + return false; + } + final String fileExtension = psiFile.getVirtualFile().getExtension(); + + if (!CopyMagentoPath.PHTML_EXTENSION.equals(fileExtension) + && !LESS_FILE_EXTENSION.equals(fileExtension)) { + return false; + } + boolean isAllowed = false; + final GetMagentoModuleUtil.MagentoModuleData moduleData = + GetMagentoModuleUtil.getByContext(psiFile.getContainingDirectory(), project); + + if (moduleData.getType().equals(ComponentType.module)) { + isAllowed = file.getPath().contains(Package.moduleViewDir); + } else if (moduleData.getType().equals(ComponentType.theme)) { + isAllowed = true; + } + + return isAllowed; + } + + private void setStatus(final AnActionEvent event, final boolean status) { + event.getPresentation().setVisible(status); + event.getPresentation().setEnabled(status); + } + + @Override + public void actionPerformed(final @NotNull AnActionEvent event) { + OverrideTemplateInThemeDialog.open(event.getProject(), this.psiFile); + } + + @Override + public boolean isDumbAware() { + return false; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideInTheme.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInTheme.form similarity index 99% rename from src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideInTheme.form rename to src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInTheme.form index 392e93cac..6f7e2862f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideInTheme.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInTheme.form @@ -1,5 +1,5 @@ -
+ diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideInThemeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java similarity index 69% rename from src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideInThemeDialog.java rename to src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java index 01d11059c..7a74392fe 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideInThemeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java @@ -6,14 +6,18 @@ package com.magento.idea.magento2plugin.actions.generation.dialog; import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; -import com.magento.idea.magento2plugin.actions.generation.OverrideInThemeAction; +import com.magento.idea.magento2plugin.actions.generation.OverrideLayoutInThemeAction; 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.NotEmptyRule; -import com.magento.idea.magento2plugin.actions.generation.generator.OverrideInThemeGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.OverrideLayoutInThemeGenerator; import com.magento.idea.magento2plugin.indexes.ModuleIndex; import com.magento.idea.magento2plugin.magento.packages.Areas; +import com.magento.idea.magento2plugin.magento.packages.ComponentType; +import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; @@ -28,7 +32,7 @@ import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; -public class OverrideInThemeDialog extends AbstractDialog { +public class OverrideLayoutInThemeDialog extends AbstractDialog { @NotNull private final Project project; private final PsiFile psiFile; @@ -50,7 +54,7 @@ public class OverrideInThemeDialog extends AbstractDialog { * @param project Project * @param psiFile PsiFile */ - public OverrideInThemeDialog(final @NotNull Project project, final PsiFile psiFile) { + public OverrideLayoutInThemeDialog(final @NotNull Project project, final PsiFile psiFile) { super(); this.project = project; @@ -58,7 +62,7 @@ public OverrideInThemeDialog(final @NotNull Project project, final PsiFile psiFi setContentPane(contentPane); setModal(true); - setTitle(OverrideInThemeAction.ACTION_DESCRIPTION); + setTitle(OverrideLayoutInThemeAction.ACTION_DESCRIPTION); getRootPane().setDefaultButton(buttonOK); fillThemeOptions(); @@ -97,10 +101,10 @@ private void onExtend() { private void onOK() { if (validateFormFields()) { - final OverrideInThemeGenerator overrideInThemeGenerator = - new OverrideInThemeGenerator(project); + final OverrideLayoutInThemeGenerator overrideLayoutInThemeGenerator = + new OverrideLayoutInThemeGenerator(project); - overrideInThemeGenerator.execute(psiFile, this.getTheme(), this.isOverride()); + overrideLayoutInThemeGenerator.execute(psiFile, this.getTheme(), this.isOverride()); } exit(); } @@ -125,18 +129,38 @@ public boolean isOverride() { * @param psiFile PsiFile */ public static void open(final @NotNull Project project, final PsiFile psiFile) { - final OverrideInThemeDialog dialog = new OverrideInThemeDialog(project, psiFile); + final OverrideLayoutInThemeDialog dialog = + new OverrideLayoutInThemeDialog(project, psiFile); dialog.pack(); dialog.centerDialog(dialog); dialog.setVisible(true); } private void fillThemeOptions() { - final String area = psiFile.getVirtualFile().getPath().split("view/")[1].split("/")[0]; - final List themeNames = new ModuleIndex(project).getEditableThemeNames(); + final GetMagentoModuleUtil.MagentoModuleData moduleData = + GetMagentoModuleUtil.getByContext(psiFile.getContainingDirectory(), project); + + if (moduleData == null) { + return; + } + String area = ""; // NOPMD; + + if (moduleData.getType().equals(ComponentType.module)) { + final PsiDirectory viewDir = moduleData.getViewDir(); + if (viewDir == null) { + return; + } + final String filePath = psiFile.getVirtualFile().getPath(); + final String relativePath = filePath.replace(viewDir.getVirtualFile().getPath(), ""); + area = relativePath.split(Package.V_FILE_SEPARATOR)[1]; + } else { + area = moduleData.getName().split(Package.V_FILE_SEPARATOR)[0]; + } + final List themeNames = new ModuleIndex(project).getEditableThemeNames(); for (final String themeName : themeNames) { - if (Areas.base.toString().equals(area) || themeName.split("/")[0].equals(area)) { + if (Areas.base.toString().equals(area) + || themeName.split(Package.V_FILE_SEPARATOR)[0].equals(area)) { theme.addItem(themeName); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.form new file mode 100644 index 000000000..598e8eb48 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.form @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java new file mode 100644 index 000000000..2ed15ba32 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java @@ -0,0 +1,149 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.CopyMagentoPath; +import com.magento.idea.magento2plugin.actions.generation.OverrideTemplateInThemeAction; +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.NotEmptyRule; +import com.magento.idea.magento2plugin.actions.generation.generator.OverrideTemplateInThemeGenerator; +import com.magento.idea.magento2plugin.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.packages.Areas; +import com.magento.idea.magento2plugin.magento.packages.ComponentType; +import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.List; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.KeyStroke; +import org.jetbrains.annotations.NotNull; + +public class OverrideTemplateInThemeDialog extends AbstractDialog { + @NotNull + private final Project project; + private final PsiFile psiFile; + private JPanel contentPane; + private JButton buttonOK; + private JButton buttonCancel; + private JLabel selectTheme; //NOPMD + private static final String THEME_NAME = "target theme"; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, THEME_NAME}) + private JComboBox theme; + + /** + * Constructor. + * + * @param project Project + * @param psiFile PsiFile + */ + public OverrideTemplateInThemeDialog(final @NotNull Project project, final PsiFile psiFile) { + super(); + + this.project = project; + this.psiFile = psiFile; + + setContentPane(contentPane); + setModal(true); + + if (CopyMagentoPath.PHTML_EXTENSION.equals(psiFile.getVirtualFile().getExtension())) { + setTitle(OverrideTemplateInThemeAction.ACTION_TEMPLATE_DESCRIPTION); + } else { + setTitle(OverrideTemplateInThemeAction.ACTION_STYLES_DESCRIPTION); + } + getRootPane().setDefaultButton(buttonOK); + fillThemeOptions(); + + buttonOK.addActionListener((final ActionEvent event) -> onOK()); + buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); + + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(final WindowEvent event) { + onCancel(); + } + }); + + contentPane.registerKeyboardAction( + (final ActionEvent event) -> onCancel(), + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT + ); + + addComponentListener(new FocusOnAFieldListener(() -> theme.requestFocusInWindow())); + } + + private void onOK() { + if (validateFormFields()) { + final OverrideTemplateInThemeGenerator overrideInThemeGenerator = + new OverrideTemplateInThemeGenerator(project); + + overrideInThemeGenerator.execute(psiFile, this.getTheme()); + } + exit(); + } + + public String getTheme() { + return this.theme.getSelectedItem().toString(); + } + + /** + * Open popup. + * + * @param project Project + * @param psiFile PsiFile + */ + public static void open(final @NotNull Project project, final PsiFile psiFile) { + final OverrideTemplateInThemeDialog dialog = + new OverrideTemplateInThemeDialog(project, psiFile); + dialog.pack(); + dialog.centerDialog(dialog); + dialog.setVisible(true); + } + + private void fillThemeOptions() { + final GetMagentoModuleUtil.MagentoModuleData moduleData = + GetMagentoModuleUtil.getByContext(psiFile.getContainingDirectory(), project); + + if (moduleData == null) { + return; + } + String area = ""; // NOPMD + + if (moduleData.getType().equals(ComponentType.module)) { + final PsiDirectory viewDir = moduleData.getViewDir(); + + if (viewDir == null) { + return; + } + final String filePath = psiFile.getVirtualFile().getPath(); + final String relativePath = filePath.replace(viewDir.getVirtualFile().getPath(), ""); + area = relativePath.split(Package.V_FILE_SEPARATOR)[1]; + } else { + area = moduleData.getName().split(Package.V_FILE_SEPARATOR)[0]; + } + final List themeNames = new ModuleIndex(project).getEditableThemeNames(); + for (final String themeName : themeNames) { + if (Areas.base.toString().equals(area) + || themeName.split(Package.V_FILE_SEPARATOR)[0].equals(area)) { + theme.addItem(themeName); + } + } + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java index 94f092bb2..27437a5a3 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java @@ -5,105 +5,68 @@ package com.magento.idea.magento2plugin.actions.generation.generator; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; -import com.maddyhome.idea.copyright.actions.UpdateCopyrightProcessor; import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; import com.magento.idea.magento2plugin.bundles.ValidatorBundle; -import com.magento.idea.magento2plugin.indexes.ModuleIndex; import com.magento.idea.magento2plugin.magento.packages.Areas; -import com.magento.idea.magento2plugin.magento.packages.ComponentType; import com.magento.idea.magento2plugin.util.RegExUtil; -import com.magento.idea.magento2plugin.util.magento.GetComponentNameByDirectoryUtil; -import com.magento.idea.magento2plugin.util.magento.GetComponentTypeByNameUtil; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.regex.Pattern; public class OverrideInThemeGenerator { - private final ValidatorBundle validatorBundle; - private final Project project; + public final ValidatorBundle validatorBundle; + public final Project project; + + /** + * OverrideInThemeGenerator constructor. + * + * @param project Project + */ public OverrideInThemeGenerator(final Project project) { this.project = project; this.validatorBundle = new ValidatorBundle(); } /** - * Action entry point. + * Get target directory. + * + * @param directory PsiDirectory + * @param pathComponents String[] * - * @param baseFile PsiFile - * @param themeName String - * @param isOverride boolean + * @return PsiDirectory */ - public void execute(final PsiFile baseFile, final String themeName, final boolean isOverride) { - final String componentType = GetComponentTypeByNameUtil.execute( - GetComponentNameByDirectoryUtil - .execute(baseFile.getContainingDirectory(), project)); - - List pathComponents; - if (componentType.equals(ComponentType.module.toString())) { - pathComponents = getModulePathComponents( - baseFile, - GetComponentNameByDirectoryUtil.execute( - baseFile.getContainingDirectory(), - project - ) - ); - if (isOverride) { - pathComponents.add("override"); - pathComponents.add("base"); - } - } else if (componentType.equals(ComponentType.theme.toString())) { - pathComponents = getThemePathComponents(baseFile); - } else { - return; - } - - final ModuleIndex moduleIndex = new ModuleIndex(project); - PsiDirectory directory = moduleIndex.getModuleDirectoryByModuleName(themeName); - - if (directory == null) { - return; - } - directory = getTargetDirectory(directory, pathComponents); + public static PsiDirectory getTargetDirectory( + PsiDirectory directory, //NOPMD + final List pathComponents + ) { + PsiDirectory result = directory; + PsiDirectory tempDirectory = directory; + final DirectoryGenerator generator = DirectoryGenerator.getInstance(); - if (directory.findFile(baseFile.getName()) != null) { - JBPopupFactory.getInstance() - .createMessage( - validatorBundle.message("validator.file.alreadyExists", baseFile.getName()) - ) - .showCenteredInCurrentWindow(project); - directory.findFile(baseFile.getName()).navigate(true); - return; + for (final String directoryName : pathComponents) { + result = generator.findOrCreateSubdirectory(tempDirectory, directoryName); + tempDirectory = result; } - final PsiDirectory finalDirectory = directory; - ApplicationManager.getApplication().runWriteAction(() -> { - finalDirectory.copyFileFrom(baseFile.getName(), baseFile); - }); - - final PsiFile newFile = directory.findFile(baseFile.getName()); - assert newFile != null; - final Module module = ModuleUtilCore.findModuleForPsiElement(newFile); - final UpdateCopyrightProcessor processor = new UpdateCopyrightProcessor( - project, - module, - newFile - ); - processor.run(); - - newFile.navigate(true); + return result; } - private List getModulePathComponents(final PsiFile file, final String componentName) { + /** + * Gt module path components. + * + * @param file PsiFile + * @param componentName String + * @return String[] + */ + public static List getModulePathComponents( + final PsiFile file, + final String componentName) { final List pathComponents = new ArrayList<>(); PsiDirectory parent = file.getParent(); while (!parent.getName().equals(Areas.frontend.toString()) @@ -119,7 +82,14 @@ private List getModulePathComponents(final PsiFile file, final String co return pathComponents; } - private List getThemePathComponents(final PsiFile file) { + /** + * Get theme path components. + * + * @param file PsiFile + * + * @return String[] + */ + public static List getThemePathComponents(final PsiFile file) { final List pathComponents = new ArrayList<>(); final Pattern pattern = Pattern.compile(RegExUtil.Magento.MODULE_NAME); @@ -133,18 +103,4 @@ private List getThemePathComponents(final PsiFile file) { return pathComponents; } - - private PsiDirectory getTargetDirectory( - PsiDirectory directory, //NOPMD - final List pathComponents - ) { - PsiDirectory result = directory; - final DirectoryGenerator generator = DirectoryGenerator.getInstance(); - - for (final String directoryName : pathComponents) { - result = generator.findOrCreateSubdirectory(directory, directoryName); - } - - return result; - } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideLayoutInThemeGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideLayoutInThemeGenerator.java new file mode 100644 index 000000000..e33282011 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideLayoutInThemeGenerator.java @@ -0,0 +1,117 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleUtilCore; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.maddyhome.idea.copyright.actions.UpdateCopyrightProcessor; +import com.magento.idea.magento2plugin.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.packages.ComponentType; +import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.util.magento.GetComponentNameByDirectoryUtil; +import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; +import java.util.List; + +public class OverrideLayoutInThemeGenerator extends OverrideInThemeGenerator { + + /** + * OverrideLayoutInThemeGenerator constructor. + * + * @param project Project + */ + public OverrideLayoutInThemeGenerator(final Project project) { + super(project); + } + + /** + * Action entry point. + * + * @param baseFile PsiFile + * @param themeName String + * @param isOverride boolean + */ + public void execute( + final PsiFile baseFile, + final String themeName, + final boolean isOverride) { + final GetMagentoModuleUtil.MagentoModuleData moduleData = + GetMagentoModuleUtil.getByContext(baseFile.getContainingDirectory(), project); + + if (moduleData == null) { + return; + } + + List pathComponents; + if (moduleData.getType().equals(ComponentType.module)) { + pathComponents = getModulePathComponents( + baseFile, + GetComponentNameByDirectoryUtil.execute( + baseFile.getContainingDirectory(), + project + ) + ); + if (isOverride) { + pathComponents.add("override"); + pathComponents.add("base"); + } + } else if (moduleData.getType().equals(ComponentType.theme)) { + pathComponents = getThemePathComponents(baseFile); + + if (isOverride) { + pathComponents.add("override"); + pathComponents.add("theme"); + final String[] parentThemeName = + moduleData.getName().split(Package.V_FILE_SEPARATOR); + pathComponents.add(parentThemeName[1]); + pathComponents.add(parentThemeName[2]); + } + } else { + return; + } + + final ModuleIndex moduleIndex = new ModuleIndex(project); + PsiDirectory directory = moduleIndex.getModuleDirectoryByModuleName(themeName); + + if (directory == null) { + return; + } + directory = getTargetDirectory(directory, pathComponents); + + if (directory.findFile(baseFile.getName()) != null) { + JBPopupFactory.getInstance() + .createMessage( + validatorBundle.message( + "validator.file.alreadyExists", + baseFile.getName()) + ) + .showCenteredInCurrentWindow(project); + directory.findFile(baseFile.getName()).navigate(true); + return; + } + + final PsiDirectory finalDirectory = directory; + ApplicationManager.getApplication().runWriteAction(() -> { + finalDirectory.copyFileFrom(baseFile.getName(), baseFile); + }); + + final PsiFile newFile = directory.findFile(baseFile.getName()); + assert newFile != null; + final Module module = ModuleUtilCore.findModuleForPsiElement(newFile); + final UpdateCopyrightProcessor processor = new UpdateCopyrightProcessor( + project, + module, + newFile + ); + processor.run(); + + newFile.navigate(true); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideTemplateInThemeGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideTemplateInThemeGenerator.java new file mode 100644 index 000000000..f2e76d0ca --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideTemplateInThemeGenerator.java @@ -0,0 +1,98 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleUtilCore; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.maddyhome.idea.copyright.actions.UpdateCopyrightProcessor; +import com.magento.idea.magento2plugin.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.packages.ComponentType; +import com.magento.idea.magento2plugin.util.magento.GetComponentNameByDirectoryUtil; +import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; +import java.util.List; + +public class OverrideTemplateInThemeGenerator extends OverrideInThemeGenerator { + + /** + * OverrideTemplateInThemeGenerator constructor. + * + * @param project Project + */ + public OverrideTemplateInThemeGenerator(final Project project) { + super(project); + } + + /** + * Action entry point. + * + * @param baseFile PsiFile + * @param themeName String + */ + public void execute(final PsiFile baseFile, final String themeName) { + + final GetMagentoModuleUtil.MagentoModuleData moduleData = + GetMagentoModuleUtil.getByContext(baseFile.getContainingDirectory(), project); + + if (moduleData == null) { + return; + } + + List pathComponents; + if (moduleData.getType().equals(ComponentType.module)) { + pathComponents = getModulePathComponents( + baseFile, + GetComponentNameByDirectoryUtil.execute( + baseFile.getContainingDirectory(), + project + ) + ); + } else if (moduleData.getType().equals(ComponentType.theme)) { + pathComponents = getThemePathComponents(baseFile); + } else { + return; + } + + final ModuleIndex moduleIndex = new ModuleIndex(project); + PsiDirectory directory = moduleIndex.getModuleDirectoryByModuleName(themeName); + + if (directory == null) { + return; + } + directory = getTargetDirectory(directory, pathComponents); + + if (directory.findFile(baseFile.getName()) != null) { + JBPopupFactory.getInstance() + .createMessage( + validatorBundle.message("validator.file.alreadyExists", baseFile.getName()) + ) + .showCenteredInCurrentWindow(project); + directory.findFile(baseFile.getName()).navigate(true); + return; + } + + final PsiDirectory finalDirectory = directory; + ApplicationManager.getApplication().runWriteAction(() -> { + finalDirectory.copyFileFrom(baseFile.getName(), baseFile); + }); + + final PsiFile newFile = directory.findFile(baseFile.getName()); + assert newFile != null; + final Module module = ModuleUtilCore.findModuleForPsiElement(newFile); + final UpdateCopyrightProcessor processor = new UpdateCopyrightProcessor( + project, + module, + newFile + ); + processor.run(); + + newFile.navigate(true); + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/LayoutXml.java b/src/com/magento/idea/magento2plugin/magento/files/LayoutXml.java index cfe0910a8..df887fd87 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/LayoutXml.java +++ b/src/com/magento/idea/magento2plugin/magento/files/LayoutXml.java @@ -22,6 +22,7 @@ public class LayoutXml implements ModuleFileInterface { public static final String XML_ATTRIBUTE_TEMPLATE = "template"; public static final String ARGUMENTS_TEMPLATE = "Magento Module Class Arguments In Xml"; public static final String PARENT_DIR = "layout"; + public static final String PAGE_LAYOUT_DIR = "page_layout"; public static final String NAME_ATTRIBUTE = "name"; public static final String CONTENT_CONTAINER_NAME = "content"; From be1d5134ded8ee396dbd01bbab44062d4cfa4095 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 17 Mar 2022 16:09:00 +0200 Subject: [PATCH 082/111] 613: Bug fixing, code refactoring --- .../comparator/CompareTemplateAction.java | 120 ++++++++---------- .../comparator/util/DiffRequestChainUtil.java | 55 ++++++++ .../idea/magento2plugin/util/RegExUtil.java | 5 - .../util/magento/area/AreaResolverUtil.java | 59 +++++++++ 4 files changed, 166 insertions(+), 73 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/comparator/util/DiffRequestChainUtil.java create mode 100644 src/com/magento/idea/magento2plugin/util/magento/area/AreaResolverUtil.java diff --git a/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java b/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java index e09e024a8..bef91821f 100644 --- a/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java +++ b/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java @@ -5,15 +5,9 @@ package com.magento.idea.magento2plugin.actions.comparator; -import com.intellij.diff.DiffContentFactory; import com.intellij.diff.DiffDialogHints; import com.intellij.diff.DiffManager; -import com.intellij.diff.DiffRequestFactory; -import com.intellij.diff.actions.BlankDiffWindowUtil; -import com.intellij.diff.actions.impl.MutableDiffRequestChain; import com.intellij.diff.chains.DiffRequestChain; -import com.intellij.diff.contents.DiffContent; -import com.intellij.diff.contents.DocumentContent; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.PlatformDataKeys; @@ -23,28 +17,28 @@ import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; import com.magento.idea.magento2plugin.MagentoIcons; +import com.magento.idea.magento2plugin.actions.comparator.util.DiffRequestChainUtil; import com.magento.idea.magento2plugin.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.packages.Areas; import com.magento.idea.magento2plugin.project.Settings; -import com.magento.idea.magento2plugin.util.RegExUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; +import com.magento.idea.magento2plugin.util.magento.area.AreaResolverUtil; import java.nio.file.Path; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class CompareTemplateAction extends AnAction { - public static final String ACTION_NAME = "Compare Template with Original"; - public static final String ACTION_DESCRIPTION = "Compare Template with Original"; + public static final String ACTION_NAME = "Compare overridden template with the original one"; + public static final String ACTION_DESCRIPTION = "The Magento 2 overridden template comparing"; private static final String PHTML_EXTENSION = "phtml"; protected VirtualFile selectedFile; protected VirtualFile originalFile; /** - * Inject constructor argument action constructor. + * Compare template action constructor. */ public CompareTemplateAction() { super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); @@ -52,107 +46,97 @@ public CompareTemplateAction() { /** * Updates the state of action. + * + * @param event AnActionEvent */ + @SuppressWarnings("PMD.NPathComplexity") @Override public void update(final @NotNull AnActionEvent event) { + setStatus(event, false); final Project project = event.getData(PlatformDataKeys.PROJECT); + if (project == null) { return; } if (!Settings.isEnabled(project)) { - this.setStatus(event, false); return; } final PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE); - selectedFile = psiFile != null ? psiFile.getVirtualFile() : null;//NOPMD - if (selectedFile != null - && !PHTML_EXTENSION.equals(selectedFile.getExtension()) - ) { - this.setStatus(event, false); + if (psiFile == null) { + return; + } + final VirtualFile targetFileCandidate = psiFile.getVirtualFile(); + + if (targetFileCandidate == null) { + return; + } + + if (!PHTML_EXTENSION.equals(targetFileCandidate.getExtension())) { return; } + final Areas area = AreaResolverUtil.getForFileInCustomTheme(targetFileCandidate); - final String fullPath = selectedFile.getPath(); - final String area = getArea(fullPath); + if (area == null) { + return; + } final String originalModuleName = getOriginalModuleName(project, psiFile); final PsiDirectory originalModuleDirectory = new ModuleIndex(project).getModuleDirectoryByModuleName(originalModuleName); - if (originalModuleDirectory == null - || area == null - ) { - this.setStatus(event, false); + if (originalModuleDirectory == null) { return; } - final String originalFilePath = originalModuleDirectory.getVirtualFile().getPath() + "/view/" + area - + StringUtils.substringAfter(fullPath, originalModuleName); + + StringUtils.substringAfter(targetFileCandidate.getPath(), originalModuleName); - originalFile = VfsUtil.findFile(Path.of(originalFilePath), false); + final VirtualFile origFileCandidate = VfsUtil.findFile(Path.of(originalFilePath), false); - if (originalFile != null) { - this.setStatus(event, true); + if (origFileCandidate == null) { return; } - - this.setStatus(event, false); + selectedFile = targetFileCandidate; + originalFile = origFileCandidate; + this.setStatus(event, true); } @Override public void actionPerformed(final @NotNull AnActionEvent event) { final Project project = event.getProject(); - final DiffRequestChain chain = - createMutableChainFromFiles(project, selectedFile, originalFile); - - DiffManager.getInstance().showDiff(project, chain, DiffDialogHints.DEFAULT); - } - @Nullable - private String getArea(final String fullPath) { - final Pattern pattern = Pattern.compile(RegExUtil.ViewArea.AREA); - final Matcher matcher = pattern.matcher(fullPath); - String areaName = null; - if (matcher.find()) { - areaName = matcher.group(1); + if (project == null || selectedFile == null || originalFile == null) { + return; } + final DiffRequestChain chain = DiffRequestChainUtil.createMutableChain( + project, + selectedFile, + originalFile + ); - return areaName; + if (chain == null) { + return; + } + DiffManager.getInstance().showDiff( + project, + chain, + DiffDialogHints.DEFAULT + ); } - private String getOriginalModuleName(final Project project, final PsiFile psiFile) { + private @Nullable String getOriginalModuleName( + final @NotNull Project project, + final @NotNull PsiFile psiFile + ) { final PsiDirectory directory = psiFile.getContainingDirectory(); return GetModuleNameByDirectoryUtil.execute(directory, project); } - @NotNull - private MutableDiffRequestChain createMutableChainFromFiles( - final @Nullable Project project, - final @NotNull VirtualFile file1, - final @NotNull VirtualFile file2 - ) { - final DiffContentFactory contentFactory = DiffContentFactory.getInstance(); - final DiffRequestFactory requestFactory = DiffRequestFactory.getInstance(); - - final DiffContent content1 = contentFactory.create(project, file1); - final DiffContent content2 = contentFactory.create(project, file2); - - final MutableDiffRequestChain chain = BlankDiffWindowUtil.createBlankDiffRequestChain( - (DocumentContent)content1, - (DocumentContent)content2, - null - ); - chain.setWindowTitle(requestFactory.getTitle(file1, file2)); - - return chain; - } - private void setStatus(final AnActionEvent event, final boolean status) { event.getPresentation().setVisible(status); event.getPresentation().setEnabled(status); } -} \ No newline at end of file +} diff --git a/src/com/magento/idea/magento2plugin/actions/comparator/util/DiffRequestChainUtil.java b/src/com/magento/idea/magento2plugin/actions/comparator/util/DiffRequestChainUtil.java new file mode 100644 index 000000000..428fcdff0 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/comparator/util/DiffRequestChainUtil.java @@ -0,0 +1,55 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.comparator.util; + +import com.intellij.diff.DiffContentFactory; +import com.intellij.diff.DiffRequestFactory; +import com.intellij.diff.actions.BlankDiffWindowUtil; +import com.intellij.diff.actions.impl.MutableDiffRequestChain; +import com.intellij.diff.contents.DiffContent; +import com.intellij.diff.contents.DocumentContent; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public final class DiffRequestChainUtil { + + private DiffRequestChainUtil() {} + + /** + * Create mutable chain for files comparing. + * + * @param project Project + * @param targetFile VirtualFile + * @param baseFile VirtualFile + * + * @return MutableDiffRequestChain + */ + public static @Nullable MutableDiffRequestChain createMutableChain( + final @NotNull Project project, + final @NotNull VirtualFile targetFile, + final @NotNull VirtualFile baseFile + ) { + final DiffContentFactory contentFactory = DiffContentFactory.getInstance(); + final DiffContent targetContent = contentFactory.create(project, targetFile); + final DiffContent baseContent = contentFactory.create(project, baseFile); + + if (!(targetContent instanceof DocumentContent) + || !(baseContent instanceof DocumentContent)) { + return null; + } + + final MutableDiffRequestChain chain = BlankDiffWindowUtil.createBlankDiffRequestChain( + (DocumentContent) targetContent, + (DocumentContent) baseContent, + null + ); + chain.setWindowTitle(DiffRequestFactory.getInstance().getTitle(targetFile, baseFile)); + + return chain; + } +} diff --git a/src/com/magento/idea/magento2plugin/util/RegExUtil.java b/src/com/magento/idea/magento2plugin/util/RegExUtil.java index 75b2e7331..2603d8b4b 100644 --- a/src/com/magento/idea/magento2plugin/util/RegExUtil.java +++ b/src/com/magento/idea/magento2plugin/util/RegExUtil.java @@ -107,9 +107,4 @@ public static class CustomTheme { public static final String MODULE_NAME = "app\\/design\\/(adminhtml|frontend)\\/\\w*\\/\\w*\\/\\w*"; } - - public static class ViewArea { - public static final String AREA = - "\\/(adminhtml|frontend)\\/"; - } } diff --git a/src/com/magento/idea/magento2plugin/util/magento/area/AreaResolverUtil.java b/src/com/magento/idea/magento2plugin/util/magento/area/AreaResolverUtil.java new file mode 100644 index 000000000..db1bab75e --- /dev/null +++ b/src/com/magento/idea/magento2plugin/util/magento/area/AreaResolverUtil.java @@ -0,0 +1,59 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.util.magento.area; + +import com.intellij.openapi.vfs.VirtualFile; +import com.magento.idea.magento2plugin.magento.packages.Areas; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public final class AreaResolverUtil { + + private static final String CUSTOM_THEME_AREA = "\\/design\\/(adminhtml|frontend)\\/"; + private static final String MODULE_AREA = + "\\/view\\/(adminhtml|frontend|base|crontab|webapi_rest|webapi_soap|graphql)\\/"; + + private AreaResolverUtil() {} + + /** + * Get Magento 2 area for the specified file (file should be in the custom theme). + * + * @param virtualFile VirtualFile + * + * @return Areas or null if file does not belong to the custom (editable) theme. + */ + public static @Nullable Areas getForFileInCustomTheme(final @NotNull VirtualFile virtualFile) { + return getArea(virtualFile.getPath(), CUSTOM_THEME_AREA); + } + + /** + * Get Magento 2 area for the specified file (file should be in the Magento 2 module). + * + * @param virtualFile VirtualFile + * + * @return Areas or null if file does not belong to the Magento 2 module. + */ + public static @Nullable Areas getForFileInModule(final @NotNull VirtualFile virtualFile) { + return getArea(virtualFile.getPath(), MODULE_AREA); + } + + private static @Nullable Areas getArea( + final @NotNull String filePath, + final @NotNull String searchingRegex + ) { + final Pattern pattern = Pattern.compile(searchingRegex); + final Matcher matcher = pattern.matcher(filePath); + String areaName = null; + + if (matcher.find()) { + areaName = matcher.group(1); + } + + return areaName == null ? null : Areas.getAreaByString(areaName); + } +} From 2806588cc4377f5ab66560d84543e806595acdf3 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 17 Mar 2022 16:17:22 +0200 Subject: [PATCH 083/111] 613: Bug fixing --- .../magento2plugin/indexes/ModuleIndex.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/indexes/ModuleIndex.java b/src/com/magento/idea/magento2plugin/indexes/ModuleIndex.java index e87fcbb31..072f90e29 100644 --- a/src/com/magento/idea/magento2plugin/indexes/ModuleIndex.java +++ b/src/com/magento/idea/magento2plugin/indexes/ModuleIndex.java @@ -12,6 +12,7 @@ import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiManager; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.util.SlowOperations; import com.intellij.util.indexing.FileBasedIndex; import com.jetbrains.php.lang.PhpFileType; import com.magento.idea.magento2plugin.magento.packages.Package; @@ -116,6 +117,7 @@ private List getNames( * Returns PSI directory of the certain module. * * @param moduleName String + * * @return PsiDirectory */ public @Nullable PsiDirectory getModuleDirectoryByModuleName(final String moduleName) { @@ -124,14 +126,20 @@ private List getNames( } final FileBasedIndex index = FileBasedIndex .getInstance(); - - final Collection files = index.getContainingFiles( - ModuleNameIndex.KEY, - moduleName, - GlobalSearchScope.getScopeRestrictedByFileTypes( - GlobalSearchScope.allScope(project), - PhpFileType.INSTANCE - )); + final Collection files = new ArrayList<>(); + + SlowOperations.allowSlowOperations(() -> { + files.addAll( + index.getContainingFiles( + ModuleNameIndex.KEY, + moduleName, + GlobalSearchScope.getScopeRestrictedByFileTypes( + GlobalSearchScope.allScope(project), + PhpFileType.INSTANCE + ) + ) + ); + }); if (files.isEmpty()) { return null; From 4cee5c5be02ec010db1f5513185dcc23d1dfc006 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 17 Mar 2022 17:33:19 +0200 Subject: [PATCH 084/111] 613: Code refactoring --- .../magento2plugin/actions/comparator/CompareTemplateAction.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java b/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java index bef91821f..715cbf101 100644 --- a/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java +++ b/src/com/magento/idea/magento2plugin/actions/comparator/CompareTemplateAction.java @@ -82,6 +82,7 @@ public void update(final @NotNull AnActionEvent event) { return; } final String originalModuleName = getOriginalModuleName(project, psiFile); + final PsiDirectory originalModuleDirectory = new ModuleIndex(project).getModuleDirectoryByModuleName(originalModuleName); From 606ec3724dde762b7b2dc3694914673e970a62fb Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Thu, 17 Mar 2022 21:19:40 +0200 Subject: [PATCH 085/111] 1031: remove deprecated FilenameIndex#getVirtualFilesByName method usage --- .../reference/provider/FilePathReferenceProvider.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/reference/provider/FilePathReferenceProvider.java b/src/com/magento/idea/magento2plugin/reference/provider/FilePathReferenceProvider.java index 4d44459b8..5f756327d 100644 --- a/src/com/magento/idea/magento2plugin/reference/provider/FilePathReferenceProvider.java +++ b/src/com/magento/idea/magento2plugin/reference/provider/FilePathReferenceProvider.java @@ -117,7 +117,6 @@ private Collection getFiles(@NotNull PsiElement element) if (fileName.matches(".*\\.\\w+$")) { // extension presents files = FilenameIndex.getVirtualFilesByName( - element.getProject(), fileName, GlobalSearchScope.allScope(element.getProject()) ); From 4ee8434910729be50c51c8ce67a2a3ffe98bcbb2 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Thu, 17 Mar 2022 22:11:51 +0200 Subject: [PATCH 086/111] 1031: code style --- .../provider/FilePathReferenceProvider.java | 58 ++++++++++++------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/reference/provider/FilePathReferenceProvider.java b/src/com/magento/idea/magento2plugin/reference/provider/FilePathReferenceProvider.java index 5f756327d..4265b4e97 100644 --- a/src/com/magento/idea/magento2plugin/reference/provider/FilePathReferenceProvider.java +++ b/src/com/magento/idea/magento2plugin/reference/provider/FilePathReferenceProvider.java @@ -2,11 +2,16 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + package com.magento.idea.magento2plugin.reference.provider; import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.vfs.*; -import com.intellij.psi.*; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiManager; +import com.intellij.psi.PsiReference; +import com.intellij.psi.PsiReferenceProvider; import com.intellij.psi.search.FilenameIndex; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.ProcessingContext; @@ -16,14 +21,20 @@ import com.magento.idea.magento2plugin.reference.provider.util.GetModuleSourceFilesUtil; import com.magento.idea.magento2plugin.reference.xml.PolyVariantReferenceBase; import gnu.trove.THashMap; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; import org.jetbrains.annotations.NotNull; -import java.util.*; public class FilePathReferenceProvider extends PsiReferenceProvider { @NotNull @Override - public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { + public PsiReference[] getReferencesByElement( + @NotNull PsiElement element, + @NotNull ProcessingContext context + ) { List psiReferences = new ArrayList<>(); @@ -56,7 +67,8 @@ public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNu continue; } String rootPathUrl = fileUrl.substring(0, fileUrl.indexOf(filePath)); - String[] relativePathParts = fileUrl.substring(fileUrl.indexOf(filePath)).split("/"); + String[] relativePathParts + = fileUrl.substring(fileUrl.indexOf(filePath)).split("/"); if (!currentPathIsBuilt) { currentPath = currentPath.isEmpty() @@ -73,13 +85,15 @@ public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNu ? psiManager.findDirectory(currentVf) : psiManager.findFile(currentVf); if (null != psiElement) { + final int currentPathIndex = currentPath.lastIndexOf("/") == -1 + ? 0 : currentPath.lastIndexOf("/") + 1; TextRange pathRange = new TextRange( - origValue.indexOf(filePath) - + (currentPath.lastIndexOf("/") == -1 ? 0 : currentPath.lastIndexOf("/") + 1), - origValue.indexOf(filePath) - + (currentPath.lastIndexOf("/") == -1 ? 0 : currentPath.lastIndexOf("/") + 1) - + pathPart.length() + origValue.indexOf(filePath) + + currentPathIndex, + origValue.indexOf(filePath) + + currentPathIndex + + pathPart.length() ); if (!psiPathElements.containsKey(pathRange)) { @@ -94,17 +108,18 @@ public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNu } if (psiPathElements.size() > 0) { - psiPathElements.forEach(((textRange, psiElements) -> - psiReferences.add(new PolyVariantReferenceBase(element, textRange, psiElements)) - )); + psiPathElements.forEach((textRange, psiElements) -> + psiReferences.add( + new PolyVariantReferenceBase(element, textRange, psiElements) + ) + ); } } return psiReferences.toArray(new PsiReference[psiReferences.size()]); } - private Collection getFiles(@NotNull PsiElement element) - { + private Collection getFiles(@NotNull PsiElement element) { Collection files = new ArrayList<>(); String filePath = GetFilePathUtil.getInstance().execute(element.getText()); @@ -123,7 +138,8 @@ private Collection getFiles(@NotNull PsiElement element) files.removeIf(f -> !f.getPath().endsWith(filePath)); // filter by module - Collection vfs = GetModuleSourceFilesUtil.getInstance().execute(element.getText(), element.getProject()); + Collection vfs = GetModuleSourceFilesUtil.getInstance() + .execute(element.getText(), element.getProject()); if (null != vfs) { files.removeIf(f -> { for (VirtualFile vf : vfs) { @@ -136,11 +152,12 @@ private Collection getFiles(@NotNull PsiElement element) } } else if (isModuleNamePresent(element)) { // extension absent - Collection vfs = GetModuleSourceFilesUtil.getInstance().execute(element.getText(), element.getProject()); + Collection vfs = GetModuleSourceFilesUtil.getInstance() + .execute(element.getText(), element.getProject()); if (null != vfs) { for (VirtualFile vf : vfs) { - Collection vfChildren = GetAllSubFilesOfVirtualFileUtil. - getInstance().execute(vf); + Collection vfChildren = GetAllSubFilesOfVirtualFileUtil + .getInstance().execute(vf); if (null != vfChildren) { vfChildren.removeIf(f -> { if (!f.isDirectory()) { @@ -160,8 +177,7 @@ private Collection getFiles(@NotNull PsiElement element) return files; } - private boolean isModuleNamePresent(@NotNull PsiElement element) - { + private boolean isModuleNamePresent(@NotNull PsiElement element) { return GetModuleNameUtil.getInstance().execute(element.getText()) != null; } } From 22ed1c24c338064f088d0183c0ef406724aecfa5 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 18 Mar 2022 13:19:35 +0200 Subject: [PATCH 087/111] 1026: Code refactoring --- .../generation/OverrideFileInThemeAction.java | 105 ++++++++++++++++++ .../OverrideLayoutInThemeAction.java | 74 ++++-------- .../OverrideTemplateInThemeAction.java | 74 +++--------- .../dialog/OverrideLayoutInThemeDialog.java | 66 +++++------ .../dialog/OverrideTemplateInThemeDialog.java | 43 +++---- .../generator/OverrideInThemeGenerator.java | 24 ++-- .../OverrideLayoutInThemeGenerator.java | 5 +- .../util/magento/GetMagentoModuleUtil.java | 6 +- 8 files changed, 219 insertions(+), 178 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/OverrideFileInThemeAction.java diff --git a/src/com/magento/idea/magento2plugin/actions/generation/OverrideFileInThemeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/OverrideFileInThemeAction.java new file mode 100644 index 000000000..ff7323d45 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/OverrideFileInThemeAction.java @@ -0,0 +1,105 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.magento.packages.ComponentType; +import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.project.Settings; +import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; +import javax.swing.Icon; +import org.jetbrains.annotations.NotNull; + +public abstract class OverrideFileInThemeAction extends AnAction { + + protected PsiFile psiFile; + + /** + * Override file in theme action constructor. + * + * @param actionName String + * @param actionDescription String + * @param module Icon + */ + public OverrideFileInThemeAction( + final String actionName, + final String actionDescription, + final Icon module + ) { + super(actionName, actionDescription, module); + } + + /** + * Action entry point. + * + * @param event AnActionEvent + */ + @Override + public void update(final @NotNull AnActionEvent event) { + setStatus(event, false); + final Project project = event.getData(PlatformDataKeys.PROJECT); + final PsiFile targetFile = event.getData(PlatformDataKeys.PSI_FILE); + + if (project == null || targetFile == null) { + return; + } + + if (Settings.isEnabled(project) && isOverrideAllowed(targetFile, project)) { + setStatus(event, true); + psiFile = targetFile; + } + } + + /** + * Implement this method to specify if override allowed for particular file types. + * + * @param file PsiFile + * @param project Project + * + * @return boolean + */ + protected abstract boolean isOverrideAllowed( + final @NotNull PsiFile file, + final @NotNull Project project + ); + + /** + * Check if file has a path specific to the Magento 2 module or theme. + * + * @param file PsiFile + * @param project Project + * + * @return boolean + */ + protected boolean isFileInModuleOrTheme( + final @NotNull PsiFile file, + final @NotNull Project project + ) { + final GetMagentoModuleUtil.MagentoModuleData moduleData = + GetMagentoModuleUtil.getByContext(file.getContainingDirectory(), project); + + if (moduleData == null) { + return false; + } + final VirtualFile virtualFile = file.getVirtualFile(); + + if (moduleData.getType().equals(ComponentType.module)) { + return virtualFile.getPath().contains("/" + Package.moduleViewDir + "/"); + } else { + return moduleData.getType().equals(ComponentType.theme); + } + } + + private void setStatus(final AnActionEvent event, final boolean status) { + event.getPresentation().setVisible(status); + event.getPresentation().setEnabled(status); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/OverrideLayoutInThemeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/OverrideLayoutInThemeAction.java index 496ad3466..e37abacaf 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/OverrideLayoutInThemeAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/OverrideLayoutInThemeAction.java @@ -5,91 +5,55 @@ package com.magento.idea.magento2plugin.actions.generation; -import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; +import com.intellij.psi.xml.XmlFile; import com.magento.idea.magento2plugin.MagentoIcons; import com.magento.idea.magento2plugin.actions.generation.dialog.OverrideLayoutInThemeDialog; import com.magento.idea.magento2plugin.magento.files.LayoutXml; -import com.magento.idea.magento2plugin.magento.files.UiComponentGridXmlFile; -import com.magento.idea.magento2plugin.magento.packages.ComponentType; -import com.magento.idea.magento2plugin.magento.packages.Package; -import com.magento.idea.magento2plugin.project.Settings; -import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; import org.jetbrains.annotations.NotNull; -public class OverrideLayoutInThemeAction extends AnAction { +public class OverrideLayoutInThemeAction extends OverrideFileInThemeAction { public static final String ACTION_NAME = "Override this layout in a project theme"; public static final String ACTION_DESCRIPTION = "Override layout in project theme"; - private PsiFile psiFile; public OverrideLayoutInThemeAction() { super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); } - /** - * Action entry point. - * - * @param event AnActionEvent - */ @Override - public void update(final @NotNull AnActionEvent event) { - boolean status = false; - final Project project = event.getData(PlatformDataKeys.PROJECT); - psiFile = event.getData(PlatformDataKeys.PSI_FILE); + public void actionPerformed(final @NotNull AnActionEvent event) { + final Project project = event.getProject(); - if (Settings.isEnabled(project)) { - try { - status = isOverrideAllowed( - psiFile.getVirtualFile(), - project - ); - } catch (NullPointerException e) { //NOPMD - // Ignore - } + if (project == null || psiFile == null) { + return; } - - this.setStatus(event, status); + OverrideLayoutInThemeDialog.open(project, psiFile); } - private boolean isOverrideAllowed(final VirtualFile file, final Project project) { - if (file.isDirectory()) { - return false; - } + @Override + protected boolean isOverrideAllowed( + final @NotNull PsiFile file, + final @NotNull Project project + ) { + final VirtualFile virtualFile = file.getVirtualFile(); - if (!UiComponentGridXmlFile.FILE_EXTENSION - .equals(psiFile.getVirtualFile().getExtension())) { + if (virtualFile == null || virtualFile.isDirectory()) { return false; } - if (!LayoutXml.PARENT_DIR.equals(psiFile.getContainingDirectory().getName()) - && !LayoutXml.PAGE_LAYOUT_DIR.equals(psiFile.getContainingDirectory().getName())) { + if (!(file instanceof XmlFile)) { return false; } - boolean isAllowed = false; - final GetMagentoModuleUtil.MagentoModuleData moduleData = - GetMagentoModuleUtil.getByContext(psiFile.getContainingDirectory(), project); - if (moduleData.getType().equals(ComponentType.module)) { - isAllowed = file.getPath().contains(Package.moduleViewDir); - } else if (moduleData.getType().equals(ComponentType.theme)) { - isAllowed = true; + if (!LayoutXml.PARENT_DIR.equals(file.getContainingDirectory().getName()) + && !LayoutXml.PAGE_LAYOUT_DIR.equals(file.getContainingDirectory().getName())) { + return false; } - return isAllowed; - } - - private void setStatus(final AnActionEvent event, final boolean status) { - event.getPresentation().setVisible(status); - event.getPresentation().setEnabled(status); - } - - @Override - public void actionPerformed(final @NotNull AnActionEvent event) { - OverrideLayoutInThemeDialog.open(event.getProject(), this.psiFile); + return isFileInModuleOrTheme(file, project); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/OverrideTemplateInThemeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/OverrideTemplateInThemeAction.java index de15db9e5..325ac90ca 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/OverrideTemplateInThemeAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/OverrideTemplateInThemeAction.java @@ -5,93 +5,53 @@ package com.magento.idea.magento2plugin.actions.generation; -import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.magento.idea.magento2plugin.MagentoIcons; import com.magento.idea.magento2plugin.actions.CopyMagentoPath; import com.magento.idea.magento2plugin.actions.generation.dialog.OverrideTemplateInThemeDialog; -import com.magento.idea.magento2plugin.magento.packages.ComponentType; -import com.magento.idea.magento2plugin.magento.packages.Package; -import com.magento.idea.magento2plugin.project.Settings; -import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; import org.jetbrains.annotations.NotNull; -public class OverrideTemplateInThemeAction extends AnAction { +public class OverrideTemplateInThemeAction extends OverrideFileInThemeAction { - public static final String ACTION_NAME = "Override this in a project theme"; + public static final String ACTION_NAME = "Override this file in a project theme"; public static final String ACTION_TEMPLATE_DESCRIPTION = "Override template in project theme"; public static final String ACTION_STYLES_DESCRIPTION = "Override styles in project theme"; public static final String LESS_FILE_EXTENSION = "less"; - private PsiFile psiFile; public OverrideTemplateInThemeAction() { super(ACTION_NAME, ACTION_TEMPLATE_DESCRIPTION, MagentoIcons.MODULE); } - /** - * Action entry point. - * - * @param event AnActionEvent - */ @Override - public void update(final @NotNull AnActionEvent event) { - boolean status = false; - final Project project = event.getData(PlatformDataKeys.PROJECT); - psiFile = event.getData(PlatformDataKeys.PSI_FILE); + public void actionPerformed(final @NotNull AnActionEvent event) { + final Project project = event.getProject(); - if (Settings.isEnabled(project)) { - try { - status = isOverrideAllowed( - psiFile.getVirtualFile(), - project - ); - } catch (NullPointerException e) { //NOPMD - // Ignore - } + if (project == null || psiFile == null) { + return; } - - this.setStatus(event, status); + OverrideTemplateInThemeDialog.open(project, psiFile); } - private boolean isOverrideAllowed(final VirtualFile file, final Project project) { - if (file.isDirectory()) { + @Override + protected boolean isOverrideAllowed( + final @NotNull PsiFile file, + final @NotNull Project project + ) { + final VirtualFile virtualFile = file.getVirtualFile(); + + if (virtualFile == null || virtualFile.isDirectory()) { return false; } - final String fileExtension = psiFile.getVirtualFile().getExtension(); + final String fileExtension = virtualFile.getExtension(); if (!CopyMagentoPath.PHTML_EXTENSION.equals(fileExtension) && !LESS_FILE_EXTENSION.equals(fileExtension)) { return false; } - boolean isAllowed = false; - final GetMagentoModuleUtil.MagentoModuleData moduleData = - GetMagentoModuleUtil.getByContext(psiFile.getContainingDirectory(), project); - - if (moduleData.getType().equals(ComponentType.module)) { - isAllowed = file.getPath().contains(Package.moduleViewDir); - } else if (moduleData.getType().equals(ComponentType.theme)) { - isAllowed = true; - } - - return isAllowed; - } - private void setStatus(final AnActionEvent event, final boolean status) { - event.getPresentation().setVisible(status); - event.getPresentation().setEnabled(status); - } - - @Override - public void actionPerformed(final @NotNull AnActionEvent event) { - OverrideTemplateInThemeDialog.open(event.getProject(), this.psiFile); - } - - @Override - public boolean isDumbAware() { - return false; + return isFileInModuleOrTheme(file, project); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java index 7a74392fe..727f1363d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java @@ -33,14 +33,15 @@ import org.jetbrains.annotations.NotNull; public class OverrideLayoutInThemeDialog extends AbstractDialog { - @NotNull - private final Project project; + + private static final String THEME_NAME = "target theme"; + + private final @NotNull Project project; private final PsiFile psiFile; private JPanel contentPane; private JButton buttonOK; private JButton buttonCancel; private JLabel selectTheme; //NOPMD - private static final String THEME_NAME = "target theme"; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, THEME_NAME}) @@ -54,7 +55,10 @@ public class OverrideLayoutInThemeDialog extends AbstractDialog { * @param project Project * @param psiFile PsiFile */ - public OverrideLayoutInThemeDialog(final @NotNull Project project, final PsiFile psiFile) { + public OverrideLayoutInThemeDialog( + final @NotNull Project project, + final @NotNull PsiFile psiFile + ) { super(); this.project = project; @@ -89,14 +93,18 @@ public void windowClosing(final WindowEvent event) { addComponentListener(new FocusOnAFieldListener(() -> theme.requestFocusInWindow())); } - private void onOverride() { - this.radioButtonOverride.setSelected(true); - this.radioButtonExtend.setSelected(false); - } - - private void onExtend() { - this.radioButtonOverride.setSelected(false); - this.radioButtonExtend.setSelected(true); + /** + * Open popup. + * + * @param project Project + * @param psiFile PsiFile + */ + public static void open(final @NotNull Project project, final @NotNull PsiFile psiFile) { + final OverrideLayoutInThemeDialog dialog = + new OverrideLayoutInThemeDialog(project, psiFile); + dialog.pack(); + dialog.centerDialog(dialog); + dialog.setVisible(true); } private void onOK() { @@ -104,36 +112,27 @@ private void onOK() { final OverrideLayoutInThemeGenerator overrideLayoutInThemeGenerator = new OverrideLayoutInThemeGenerator(project); - overrideLayoutInThemeGenerator.execute(psiFile, this.getTheme(), this.isOverride()); + overrideLayoutInThemeGenerator.execute(psiFile, getTheme(), isOverride()); + exit(); } - exit(); } - public String getTheme() { + private String getTheme() { return this.theme.getSelectedItem().toString(); } - /** - * Is Override. - * - * @return boolean - */ - public boolean isOverride() { + private boolean isOverride() { return this.radioButtonOverride.isSelected(); } - /** - * Open popup. - * - * @param project Project - * @param psiFile PsiFile - */ - public static void open(final @NotNull Project project, final PsiFile psiFile) { - final OverrideLayoutInThemeDialog dialog = - new OverrideLayoutInThemeDialog(project, psiFile); - dialog.pack(); - dialog.centerDialog(dialog); - dialog.setVisible(true); + private void onOverride() { + this.radioButtonOverride.setSelected(true); + this.radioButtonExtend.setSelected(false); + } + + private void onExtend() { + this.radioButtonOverride.setSelected(false); + this.radioButtonExtend.setSelected(true); } private void fillThemeOptions() { @@ -158,6 +157,7 @@ private void fillThemeOptions() { area = moduleData.getName().split(Package.V_FILE_SEPARATOR)[0]; } final List themeNames = new ModuleIndex(project).getEditableThemeNames(); + for (final String themeName : themeNames) { if (Areas.base.toString().equals(area) || themeName.split(Package.V_FILE_SEPARATOR)[0].equals(area)) { diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java index 2ed15ba32..31920f0e4 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java @@ -33,14 +33,15 @@ import org.jetbrains.annotations.NotNull; public class OverrideTemplateInThemeDialog extends AbstractDialog { - @NotNull - private final Project project; + + private static final String THEME_NAME = "target theme"; + + private final @NotNull Project project; private final PsiFile psiFile; private JPanel contentPane; private JButton buttonOK; private JButton buttonCancel; private JLabel selectTheme; //NOPMD - private static final String THEME_NAME = "target theme"; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, THEME_NAME}) @@ -52,7 +53,10 @@ public class OverrideTemplateInThemeDialog extends AbstractDialog { * @param project Project * @param psiFile PsiFile */ - public OverrideTemplateInThemeDialog(final @NotNull Project project, final PsiFile psiFile) { + public OverrideTemplateInThemeDialog( + final @NotNull Project project, + final @NotNull PsiFile psiFile + ) { super(); this.project = project; @@ -89,27 +93,13 @@ public void windowClosing(final WindowEvent event) { addComponentListener(new FocusOnAFieldListener(() -> theme.requestFocusInWindow())); } - private void onOK() { - if (validateFormFields()) { - final OverrideTemplateInThemeGenerator overrideInThemeGenerator = - new OverrideTemplateInThemeGenerator(project); - - overrideInThemeGenerator.execute(psiFile, this.getTheme()); - } - exit(); - } - - public String getTheme() { - return this.theme.getSelectedItem().toString(); - } - /** * Open popup. * * @param project Project * @param psiFile PsiFile */ - public static void open(final @NotNull Project project, final PsiFile psiFile) { + public static void open(final @NotNull Project project, final @NotNull PsiFile psiFile) { final OverrideTemplateInThemeDialog dialog = new OverrideTemplateInThemeDialog(project, psiFile); dialog.pack(); @@ -117,6 +107,20 @@ public static void open(final @NotNull Project project, final PsiFile psiFile) { dialog.setVisible(true); } + private void onOK() { + if (validateFormFields()) { + final OverrideTemplateInThemeGenerator overrideInThemeGenerator = + new OverrideTemplateInThemeGenerator(project); + + overrideInThemeGenerator.execute(psiFile, this.getTheme()); + exit(); + } + } + + private String getTheme() { + return this.theme.getSelectedItem().toString(); + } + private void fillThemeOptions() { final GetMagentoModuleUtil.MagentoModuleData moduleData = GetMagentoModuleUtil.getByContext(psiFile.getContainingDirectory(), project); @@ -139,6 +143,7 @@ private void fillThemeOptions() { area = moduleData.getName().split(Package.V_FILE_SEPARATOR)[0]; } final List themeNames = new ModuleIndex(project).getEditableThemeNames(); + for (final String themeName : themeNames) { if (Areas.base.toString().equals(area) || themeName.split(Package.V_FILE_SEPARATOR)[0].equals(area)) { diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java index 27437a5a3..21dc171a0 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java @@ -17,11 +17,10 @@ import java.util.List; import java.util.regex.Pattern; -public class OverrideInThemeGenerator { +public abstract class OverrideInThemeGenerator { - public final ValidatorBundle validatorBundle; - - public final Project project; + protected final Project project; + protected final ValidatorBundle validatorBundle; /** * OverrideInThemeGenerator constructor. @@ -37,12 +36,12 @@ public OverrideInThemeGenerator(final Project project) { * Get target directory. * * @param directory PsiDirectory - * @param pathComponents String[] + * @param pathComponents List[String] * * @return PsiDirectory */ - public static PsiDirectory getTargetDirectory( - PsiDirectory directory, //NOPMD + protected PsiDirectory getTargetDirectory( + final PsiDirectory directory, final List pathComponents ) { PsiDirectory result = directory; @@ -62,13 +61,16 @@ public static PsiDirectory getTargetDirectory( * * @param file PsiFile * @param componentName String - * @return String[] + * + * @return List[String] */ - public static List getModulePathComponents( + protected List getModulePathComponents( final PsiFile file, - final String componentName) { + final String componentName + ) { final List pathComponents = new ArrayList<>(); PsiDirectory parent = file.getParent(); + while (!parent.getName().equals(Areas.frontend.toString()) && !parent.getName().equals(Areas.adminhtml.toString()) && !parent.getName().equals(Areas.base.toString()) @@ -89,7 +91,7 @@ public static List getModulePathComponents( * * @return String[] */ - public static List getThemePathComponents(final PsiFile file) { + protected List getThemePathComponents(final PsiFile file) { final List pathComponents = new ArrayList<>(); final Pattern pattern = Pattern.compile(RegExUtil.Magento.MODULE_NAME); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideLayoutInThemeGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideLayoutInThemeGenerator.java index e33282011..9654c88f9 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideLayoutInThemeGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideLayoutInThemeGenerator.java @@ -41,15 +41,16 @@ public OverrideLayoutInThemeGenerator(final Project project) { public void execute( final PsiFile baseFile, final String themeName, - final boolean isOverride) { + final boolean isOverride + ) { final GetMagentoModuleUtil.MagentoModuleData moduleData = GetMagentoModuleUtil.getByContext(baseFile.getContainingDirectory(), project); if (moduleData == null) { return; } - List pathComponents; + if (moduleData.getType().equals(ComponentType.module)) { pathComponents = getModulePathComponents( baseFile, diff --git a/src/com/magento/idea/magento2plugin/util/magento/GetMagentoModuleUtil.java b/src/com/magento/idea/magento2plugin/util/magento/GetMagentoModuleUtil.java index 503844a89..f1218c26b 100644 --- a/src/com/magento/idea/magento2plugin/util/magento/GetMagentoModuleUtil.java +++ b/src/com/magento/idea/magento2plugin/util/magento/GetMagentoModuleUtil.java @@ -10,6 +10,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.SlowOperations; import com.jetbrains.php.lang.psi.elements.ClassConstantReference; import com.jetbrains.php.lang.psi.elements.MethodReference; import com.jetbrains.php.lang.psi.elements.StringLiteralExpression; @@ -108,7 +109,10 @@ private static PsiFile getModuleRegistrationFile( private static String parseParameterValue(final PsiElement valueHolder) { if (valueHolder instanceof ClassConstantReference) { - final PsiElement resolved = ((ClassConstantReference) valueHolder).resolve(); + final ClassConstantReference constantReference = (ClassConstantReference) valueHolder; + final PsiElement resolved = SlowOperations.allowSlowOperations( + constantReference::resolve + ); if (!(resolved instanceof ClassConstImpl)) { return null; From 5e10bcd2c7333b551986462ce562e81f174e2d63 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 18 Mar 2022 13:28:48 +0200 Subject: [PATCH 088/111] 1026: Code refactoring --- .../actions/generation/generator/OverrideInThemeGenerator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java index 21dc171a0..b13e93030 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.regex.Pattern; +@SuppressWarnings("PMD.AbstractClassWithoutAbstractMethod") public abstract class OverrideInThemeGenerator { protected final Project project; From 23d1931ea38c80fbf7393d6c9bfba20fbd1cdac9 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 18 Mar 2022 15:49:26 +0200 Subject: [PATCH 089/111] UCT-1030: Added config files support --- .../execution/GenerateUctReportCommand.java | 3 -- .../execution/scanner/ModuleFilesScanner.java | 9 +++-- .../inspections/UctInspectionManager.java | 39 +++++++++++-------- .../xml/ModuleConfigFileInspection.java | 24 +++++++++++- .../xml/UsedDeprecatedTypeInConfig.java | 8 ++++ .../xml/UsedNonExistentTypeInConfig.java | 8 ++++ .../magento2uct/packages/SupportedIssue.java | 2 + 7 files changed, 69 insertions(+), 24 deletions(-) diff --git a/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java b/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java index d12aec9f5..4f08468e9 100644 --- a/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java +++ b/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java @@ -135,9 +135,6 @@ public void execute() { boolean isModuleHeaderPrinted = false; for (final PsiFile psiFile : new ModuleFilesScanner(componentData)) { - if (!(psiFile instanceof PhpFile)) { - continue; - } final String filename = psiFile.getVirtualFile().getPath(); final UctInspectionManager inspectionManager = new UctInspectionManager( project diff --git a/src/com/magento/idea/magento2uct/execution/scanner/ModuleFilesScanner.java b/src/com/magento/idea/magento2uct/execution/scanner/ModuleFilesScanner.java index 1f158a173..90f703bad 100644 --- a/src/com/magento/idea/magento2uct/execution/scanner/ModuleFilesScanner.java +++ b/src/com/magento/idea/magento2uct/execution/scanner/ModuleFilesScanner.java @@ -7,8 +7,8 @@ import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; -import com.jetbrains.php.lang.psi.PhpFile; import com.magento.idea.magento2uct.execution.scanner.data.ComponentData; +import com.magento.idea.magento2uct.packages.SupportedIssue; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -53,9 +53,12 @@ private List run() { */ private void collectFilesInDirectoryRecursively(final @NotNull PsiDirectory directory) { for (final PsiFile file : directory.getFiles()) { - if (file instanceof PhpFile) { - files.add(file); + if (SupportedIssue.getSupportedFileTypes().stream().noneMatch( + clazz -> clazz.isInstance(file)) + ) { + continue; } + files.add(file); } for (final PsiDirectory subDirectory : directory.getSubdirectories()) { diff --git a/src/com/magento/idea/magento2uct/inspections/UctInspectionManager.java b/src/com/magento/idea/magento2uct/inspections/UctInspectionManager.java index 093530835..2938e11ad 100644 --- a/src/com/magento/idea/magento2uct/inspections/UctInspectionManager.java +++ b/src/com/magento/idea/magento2uct/inspections/UctInspectionManager.java @@ -11,6 +11,7 @@ import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.psi.xml.XmlFile; import com.jetbrains.php.codeInsight.PhpCodeInsightUtil; import com.jetbrains.php.lang.psi.PhpFile; import com.jetbrains.php.lang.psi.elements.AssignmentExpression; @@ -49,7 +50,9 @@ public UctInspectionManager(final @NotNull Project project) { * @return ProblemsHolder */ public @Nullable UctProblemsHolder run(final PsiFile psiFile) { - if (!(psiFile instanceof PhpFile)) { + if (SupportedIssue.getSupportedFileTypes().stream().noneMatch( + clazz -> clazz.isInstance(psiFile)) + ) { return null; } final UctProblemsHolder problemsHolder = new UctProblemsHolder( @@ -78,25 +81,29 @@ public UctInspectionManager(final @NotNull Project project) { private List collectElements(final @NotNull PsiFile psiFile) { final List elements = new LinkedList<>(); - final PhpClass phpClass = GetFirstClassOfFile.getInstance().execute((PhpFile) psiFile); + if (psiFile instanceof PhpFile) { + final PhpClass phpClass = GetFirstClassOfFile.getInstance().execute((PhpFile) psiFile); - if (phpClass != null) { - elements.add(phpClass); - final PhpPsiElement scopeForUseOperator = PhpCodeInsightUtil.findScopeForUseOperator( - phpClass - ); + if (phpClass != null) { + elements.add(phpClass); + final PhpPsiElement scopeForUseOperator = PhpCodeInsightUtil + .findScopeForUseOperator(phpClass); - if (scopeForUseOperator != null) { - elements.addAll(PhpCodeInsightUtil.collectImports(scopeForUseOperator)); + if (scopeForUseOperator != null) { + elements.addAll(PhpCodeInsightUtil.collectImports(scopeForUseOperator)); + } + elements.addAll(Arrays.asList(phpClass.getOwnFields())); } - elements.addAll(Arrays.asList(phpClass.getOwnFields())); - } - elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, ClassConstantReference.class)); - elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, MethodReference.class)); - elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, AssignmentExpression.class)); - elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, ClassReference.class)); - elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, FieldReference.class)); + elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, ClassConstantReference.class)); + elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, MethodReference.class)); + elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, AssignmentExpression.class)); + elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, ClassReference.class)); + elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, FieldReference.class)); + } else if (psiFile instanceof XmlFile) { + elements.add(psiFile); + } + return elements; } } diff --git a/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java b/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java index 478229424..91945ab4a 100644 --- a/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java +++ b/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java @@ -7,9 +7,11 @@ import com.intellij.codeInspection.InspectionManager; import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.codeInspection.ProblemsHolder; import com.intellij.codeInspection.XmlSuppressableInspectionTool; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.PsiFile; import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.PsiTreeUtil; @@ -39,6 +41,17 @@ abstract class ModuleConfigFileInspection extends XmlSuppressableInspectionTool "product_types.xml", "widget.xml", }; + private ProblemsHolder problemsHolder; + + @Override + public @NotNull PsiElementVisitor buildVisitor( + final @NotNull ProblemsHolder holder, + final boolean isOnTheFly + ) { + problemsHolder = holder; + + return super.buildVisitor(holder, isOnTheFly); + } @Override public @Nullable ProblemDescriptor[] checkFile( @@ -48,8 +61,9 @@ abstract class ModuleConfigFileInspection extends XmlSuppressableInspectionTool ) { final Project project = file.getProject(); final UctSettingsService settings = UctSettingsService.getInstance(project); + final ProblemsHolder holder = getProblemsHolder(); - if (!settings.isEnabled()) { + if (!settings.isEnabled() || holder == null) { return getEmptyResult(); } @@ -72,7 +86,7 @@ abstract class ModuleConfigFileInspection extends XmlSuppressableInspectionTool continue; } // Inspection logic. - doInspection(fqn, token, manager, isOnTheFly, descriptors); + doInspection(fqn, token, manager, holder, isOnTheFly, descriptors); } return descriptors.toArray(new ProblemDescriptor[0]); @@ -84,6 +98,7 @@ abstract class ModuleConfigFileInspection extends XmlSuppressableInspectionTool * @param fqn String * @param target PsiElement * @param manager InspectionManager + * @param holder ProblemsHolder * @param isOnTheFly boolean * @param descriptors List[ProblemDescriptor] */ @@ -91,10 +106,15 @@ protected abstract void doInspection( final @NotNull String fqn, final @NotNull PsiElement target, final @NotNull InspectionManager manager, + final @NotNull ProblemsHolder holder, final boolean isOnTheFly, final @NotNull List descriptors ); + private @Nullable ProblemsHolder getProblemsHolder() { + return problemsHolder; + } + /** * Retrieves an empty result. * diff --git a/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedTypeInConfig.java b/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedTypeInConfig.java index e535afeb0..794a4be1c 100644 --- a/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedTypeInConfig.java +++ b/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedTypeInConfig.java @@ -8,7 +8,9 @@ import com.intellij.codeInspection.InspectionManager; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ProblemHighlightType; +import com.intellij.codeInspection.ProblemsHolder; import com.intellij.psi.PsiElement; +import com.magento.idea.magento2uct.inspections.UctProblemsHolder; import com.magento.idea.magento2uct.packages.SupportedIssue; import com.magento.idea.magento2uct.versioning.VersionStateManager; import java.util.List; @@ -21,6 +23,7 @@ protected void doInspection( final @NotNull String fqn, final @NotNull PsiElement target, final @NotNull InspectionManager manager, + final @NotNull ProblemsHolder holder, final boolean isOnTheFly, final @NotNull List descriptors ) { @@ -32,6 +35,11 @@ protected void doInspection( ).getDeprecatedInVersion(fqn) ); + if (holder instanceof UctProblemsHolder) { + ((UctProblemsHolder) holder).setIssue( + SupportedIssue.USED_DEPRECATED_TYPE_IN_CONFIG + ); + } final ProblemDescriptor descriptor = manager.createProblemDescriptor( target, message, diff --git a/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentTypeInConfig.java b/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentTypeInConfig.java index 4c3bca379..13aaac616 100644 --- a/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentTypeInConfig.java +++ b/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentTypeInConfig.java @@ -8,7 +8,9 @@ import com.intellij.codeInspection.InspectionManager; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ProblemHighlightType; +import com.intellij.codeInspection.ProblemsHolder; import com.intellij.psi.PsiElement; +import com.magento.idea.magento2uct.inspections.UctProblemsHolder; import com.magento.idea.magento2uct.packages.SupportedIssue; import com.magento.idea.magento2uct.versioning.VersionStateManager; import java.util.List; @@ -21,6 +23,7 @@ protected void doInspection( final @NotNull String fqn, final @NotNull PsiElement target, final @NotNull InspectionManager manager, + final @NotNull ProblemsHolder holder, final boolean isOnTheFly, final @NotNull List descriptors ) { @@ -32,6 +35,11 @@ protected void doInspection( ).getRemovedInVersion(fqn) ); + if (holder instanceof UctProblemsHolder) { + ((UctProblemsHolder) holder).setIssue( + SupportedIssue.USED_NON_EXISTENT_TYPE_IN_CONFIG + ); + } final ProblemDescriptor descriptor = manager.createProblemDescriptor( target, message, diff --git a/src/com/magento/idea/magento2uct/packages/SupportedIssue.java b/src/com/magento/idea/magento2uct/packages/SupportedIssue.java index 50a43d150..df2922715 100644 --- a/src/com/magento/idea/magento2uct/packages/SupportedIssue.java +++ b/src/com/magento/idea/magento2uct/packages/SupportedIssue.java @@ -7,6 +7,7 @@ import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.xml.XmlFile; import com.jetbrains.php.lang.psi.PhpFile; import com.magento.idea.magento2uct.bundles.UctInspectionBundle; import com.magento.idea.magento2uct.inspections.UctProblemsHolder; @@ -401,6 +402,7 @@ public static List getVisitors( public static List> getSupportedFileTypes() { final List> types = new ArrayList<>(); types.add(PhpFile.class); + types.add(XmlFile.class); return types; } From bbcabf3bdd36242edb61d8b9a779072ae8056f0b Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 18 Mar 2022 17:39:15 +0200 Subject: [PATCH 090/111] 1030: Extended fqn escaping and references analysis --- .../inspections/UctProblemsHolder.java | 1 - .../util/php/FqnValidatorUtil.java | 53 ---------------- .../util/php/MagentoReferenceUtil.java | 63 +++++++++++++++++++ .../util/php/MagentoTypeEscapeUtil.java | 12 ++-- .../versioning/VersionStateManager.java | 6 +- .../indexes/data/ExistenceStateIndex.java | 9 ++- 6 files changed, 77 insertions(+), 67 deletions(-) delete mode 100644 src/com/magento/idea/magento2uct/util/php/FqnValidatorUtil.java create mode 100644 src/com/magento/idea/magento2uct/util/php/MagentoReferenceUtil.java diff --git a/src/com/magento/idea/magento2uct/inspections/UctProblemsHolder.java b/src/com/magento/idea/magento2uct/inspections/UctProblemsHolder.java index 0f11a8149..6f0afd2ed 100644 --- a/src/com/magento/idea/magento2uct/inspections/UctProblemsHolder.java +++ b/src/com/magento/idea/magento2uct/inspections/UctProblemsHolder.java @@ -74,7 +74,6 @@ public void registerProblem(final @NotNull ProblemDescriptor problemDescriptor) // if problem has been added successfully if (problemCount != getMyProblems().size()) { myProblemCodes.put(problemDescriptor, issue); - issue = null;//NOPMD } } diff --git a/src/com/magento/idea/magento2uct/util/php/FqnValidatorUtil.java b/src/com/magento/idea/magento2uct/util/php/FqnValidatorUtil.java deleted file mode 100644 index a7f753bf4..000000000 --- a/src/com/magento/idea/magento2uct/util/php/FqnValidatorUtil.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2uct.util.php; - -import com.intellij.openapi.project.Project; -import com.jetbrains.php.PhpIndex; -import com.jetbrains.php.lang.psi.elements.PhpClass; -import java.util.Collection; -import java.util.regex.Matcher; -import org.jetbrains.annotations.NotNull; - -public final class FqnValidatorUtil { - - private FqnValidatorUtil() {} - - /** - * Check if provided string is a valid FQN. - * - * @param fqnCandidate String - * @param project Project - * - * @return boolean - */ - public static boolean validate( - final @NotNull String fqnCandidate, - final @NotNull Project project - ) { - String safeFqn = MagentoTypeEscapeUtil.escapeProperty(fqnCandidate); - - if (isFactoryOrProxy(safeFqn)) { - safeFqn = MagentoTypeEscapeUtil.escape(safeFqn); - } - final Collection classes = PhpIndex.getInstance(project).getAnyByFQN(safeFqn); - - return !classes.isEmpty(); - } - - /** - * Check if provided FQN is a Factory or Proxy. - * - * @param fqn String - * - * @return boolean - */ - private static boolean isFactoryOrProxy(final @NotNull String fqn) { - final Matcher matcher = MagentoTypeEscapeUtil.FACTORY_PROXY_TYPE_PATTERN.matcher(fqn); - - return matcher.find(); - } -} diff --git a/src/com/magento/idea/magento2uct/util/php/MagentoReferenceUtil.java b/src/com/magento/idea/magento2uct/util/php/MagentoReferenceUtil.java new file mode 100644 index 000000000..d35c443a7 --- /dev/null +++ b/src/com/magento/idea/magento2uct/util/php/MagentoReferenceUtil.java @@ -0,0 +1,63 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.util.php; + +import com.intellij.openapi.util.text.StringUtil; +import org.jetbrains.annotations.NotNull; + +public final class MagentoReferenceUtil { + + public static final String PHP_REFERENCE_SEPARATOR = "::"; + + private MagentoReferenceUtil() { + } + + /** + * Check if reference looks like a PHP reference. + * + * @param referenceCandidate String + * + * @return boolean + */ + public static boolean isReference(final @NotNull String referenceCandidate) { + return referenceCandidate.contains(PHP_REFERENCE_SEPARATOR) + && referenceCandidate.split(PHP_REFERENCE_SEPARATOR).length == 2; + } + + /** + * Check if reference looks like a PHP method reference. + * + * @param referenceCandidate String + * + * @return boolean + */ + public static boolean isMethodReference(final @NotNull String referenceCandidate) { + if (isReference(referenceCandidate)) { + final String referencePart = referenceCandidate.split(PHP_REFERENCE_SEPARATOR)[1]; + + return StringUtil.isJavaIdentifier(referencePart); + } + + return false; + } + + /** + * Check if reference looks like a PHP constant reference. + * + * @param referenceCandidate String + * + * @return boolean + */ + public static boolean isConstantReference(final @NotNull String referenceCandidate) { + if (isReference(referenceCandidate)) { + final String referencePart = referenceCandidate.split(PHP_REFERENCE_SEPARATOR)[1]; + + return StringUtil.isUpperCase(referencePart); + } + + return false; + } +} diff --git a/src/com/magento/idea/magento2uct/util/php/MagentoTypeEscapeUtil.java b/src/com/magento/idea/magento2uct/util/php/MagentoTypeEscapeUtil.java index 42802e519..d938b07c8 100644 --- a/src/com/magento/idea/magento2uct/util/php/MagentoTypeEscapeUtil.java +++ b/src/com/magento/idea/magento2uct/util/php/MagentoTypeEscapeUtil.java @@ -15,8 +15,7 @@ public final class MagentoTypeEscapeUtil { = "(Factory|\\\\Proxy|Factory\\\\Proxy)($|\\.)"; public static final Pattern FACTORY_PROXY_TYPE_PATTERN = Pattern.compile(FACTORY_PROXY_TYPE_REGEX, Pattern.MULTILINE); - public static final String PHP_PROPERTY_REFERENCE_SEPARATOR = "::"; - public static final String JAVA_PROPERTY_REFERENCE_SEPARATOR = "."; + public static final String JAVA_REFERENCE_SEPARATOR = "."; private MagentoTypeEscapeUtil() { } @@ -43,7 +42,7 @@ private MagentoTypeEscapeUtil() { result = result.substring(0, begin) + result.substring(end); } - return typeFqn.equals(result) ? typeFqn : result; + return typeFqn.equals(result) ? escapeProperty(typeFqn) : escapeProperty(result); } /** @@ -54,11 +53,10 @@ private MagentoTypeEscapeUtil() { * @return String */ public static @NotNull String escapeProperty(final @NotNull String typeFqn) { - if (typeFqn.contains(PHP_PROPERTY_REFERENCE_SEPARATOR) - && typeFqn.split(PHP_PROPERTY_REFERENCE_SEPARATOR).length == 1) { + if (MagentoReferenceUtil.isReference(typeFqn)) { return typeFqn.replace( - PHP_PROPERTY_REFERENCE_SEPARATOR, - JAVA_PROPERTY_REFERENCE_SEPARATOR + MagentoReferenceUtil.PHP_REFERENCE_SEPARATOR, + JAVA_REFERENCE_SEPARATOR ); } diff --git a/src/com/magento/idea/magento2uct/versioning/VersionStateManager.java b/src/com/magento/idea/magento2uct/versioning/VersionStateManager.java index 3ddf8d3cb..f6d493177 100644 --- a/src/com/magento/idea/magento2uct/versioning/VersionStateManager.java +++ b/src/com/magento/idea/magento2uct/versioning/VersionStateManager.java @@ -17,6 +17,7 @@ import java.util.List; import org.jetbrains.annotations.NotNull; +@SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel") public final class VersionStateManager { private static VersionStateManager instance; @@ -35,7 +36,6 @@ public final class VersionStateManager { * * @return VersionStateManager */ - @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel") public static synchronized VersionStateManager getInstance( final @NotNull Project project ) { //NOPMD @@ -60,9 +60,7 @@ public static synchronized VersionStateManager getInstance( * @return boolean */ public synchronized boolean isPresentInCodebase(final @NotNull String fqn) { - String safeFqn = MagentoTypeEscapeUtil.escapeProperty(escapeFqn(fqn)); - - return existenceStateIndex.isPresentInCodebase(safeFqn); + return existenceStateIndex.isPresentInCodebase(escapeFqn(fqn)); } /** diff --git a/src/com/magento/idea/magento2uct/versioning/indexes/data/ExistenceStateIndex.java b/src/com/magento/idea/magento2uct/versioning/indexes/data/ExistenceStateIndex.java index d382baccc..14813bf9a 100644 --- a/src/com/magento/idea/magento2uct/versioning/indexes/data/ExistenceStateIndex.java +++ b/src/com/magento/idea/magento2uct/versioning/indexes/data/ExistenceStateIndex.java @@ -16,11 +16,14 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import org.jetbrains.annotations.NotNull; +@SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel") public class ExistenceStateIndex implements VersionStateIndex { private static final String RESOURCE_DIR = "existence"; @@ -28,6 +31,7 @@ public class ExistenceStateIndex implements VersionStateIndex { private final Map> versioningData; private final Map targetVersionData; private final Map changelog; + private final Set codebase; private String projectBasePath; /** @@ -37,6 +41,7 @@ public ExistenceStateIndex() { versioningData = new LinkedHashMap<>(); targetVersionData = new HashMap<>(); changelog = new HashMap<>(); + codebase = new HashSet<>(); } /** @@ -55,7 +60,6 @@ public void setProjectBasePath(final @NotNull String projectBasePath) { * * @return boolean */ - @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel") public synchronized boolean has(final @NotNull String fqn) { groupLoadedData(); @@ -74,7 +78,7 @@ public synchronized boolean has(final @NotNull String fqn) { * @return boolean */ public synchronized boolean isPresentInCodebase(final @NotNull String fqn) { - return changelog.containsKey(fqn); + return codebase.contains(fqn); } /** @@ -198,6 +202,7 @@ private void groupLoadedData() { ); targetVersionData.putAll(gatheredData.getFirst()); changelog.putAll(gatheredData.getSecond()); + codebase.addAll(VersioningDataOperationsUtil.unionVersionData(versioningData).keySet()); } } } From bb097d0746cf7610178ef416a89d7c238135aa38 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Fri, 18 Mar 2022 18:29:32 +0200 Subject: [PATCH 091/111] 1031: code style --- .../provider/FilePathReferenceProvider.java | 86 ++++++++++--------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/reference/provider/FilePathReferenceProvider.java b/src/com/magento/idea/magento2plugin/reference/provider/FilePathReferenceProvider.java index 4265b4e97..fc3b53808 100644 --- a/src/com/magento/idea/magento2plugin/reference/provider/FilePathReferenceProvider.java +++ b/src/com/magento/idea/magento2plugin/reference/provider/FilePathReferenceProvider.java @@ -1,4 +1,4 @@ -/** +/* * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ @@ -29,45 +29,50 @@ public class FilePathReferenceProvider extends PsiReferenceProvider { + @SuppressWarnings({ + "PMD.CognitiveComplexity", + "PMD.CyclomaticComplexity", + "PMD.NPathComplexity", + "PMD.AvoidInstantiatingObjectsInLoops" + }) @NotNull @Override public PsiReference[] getReferencesByElement( - @NotNull PsiElement element, - @NotNull ProcessingContext context + @NotNull final PsiElement element, + @NotNull final ProcessingContext context ) { + final String origValue = element.getText(); - List psiReferences = new ArrayList<>(); - - String origValue = element.getText(); - - String filePath = GetFilePathUtil.getInstance().execute(origValue); + final String filePath = GetFilePathUtil.getInstance().execute(origValue); if (null == filePath) { return PsiReference.EMPTY_ARRAY; } // Find all files based on provided path - Collection files = getFiles(element); - if (!(files.size() > 0)) { + final Collection files = getFiles(element); + + if (files.isEmpty()) { return PsiReference.EMPTY_ARRAY; } + final PsiManager psiManager = PsiManager.getInstance(element.getProject()); - PsiManager psiManager = PsiManager.getInstance(element.getProject()); + final List psiReferences = new ArrayList<>(); String currentPath = ""; - String[] pathParts = filePath.split("/"); + final String[] pathParts = filePath.split("/"); for (int i = 0; i < pathParts.length; i++) { - String pathPart = pathParts[i]; + final String pathPart = pathParts[i]; Boolean currentPathIsBuilt = false; - Map> psiPathElements = new THashMap<>(); + final Map> psiPathElements = new THashMap<>(); - for (VirtualFile file : files) { - String fileUrl = file.getUrl(); + for (final VirtualFile file : files) { + final String fileUrl = file.getUrl(); if (!fileUrl.contains(filePath)) { continue; } - String rootPathUrl = fileUrl.substring(0, fileUrl.indexOf(filePath)); - String[] relativePathParts + final String rootPathUrl = fileUrl.substring(0, fileUrl.indexOf(filePath)); + final String[] relativePathParts = fileUrl.substring(fileUrl.indexOf(filePath)).split("/"); if (!currentPathIsBuilt) { @@ -77,18 +82,18 @@ public PsiReference[] getReferencesByElement( currentPathIsBuilt = true; } - VirtualFile currentVf = VirtualFileManager.getInstance() + final VirtualFile currentVf = VirtualFileManager.getInstance() .findFileByUrl(rootPathUrl.concat(currentPath)); if (null != currentVf) { - PsiElement psiElement = currentVf.isDirectory() + final PsiElement psiElement = currentVf.isDirectory() ? psiManager.findDirectory(currentVf) : psiManager.findFile(currentVf); if (null != psiElement) { - final int currentPathIndex = currentPath.lastIndexOf("/") == -1 - ? 0 : currentPath.lastIndexOf("/") + 1; + final int currentPathIndex = currentPath.lastIndexOf('/') == -1 + ? 0 : currentPath.lastIndexOf('/') + 1; - TextRange pathRange = new TextRange( + final TextRange pathRange = new TextRange( origValue.indexOf(filePath) + currentPathIndex, origValue.indexOf(filePath) @@ -96,18 +101,18 @@ public PsiReference[] getReferencesByElement( + pathPart.length() ); - if (!psiPathElements.containsKey(pathRange)) { - List list = new ArrayList<>(); + if (psiPathElements.containsKey(pathRange)) { + psiPathElements.get(pathRange).add(psiElement); + } else { + final List list = new ArrayList<>(); list.add(psiElement); psiPathElements.put(pathRange, list); - } else { - psiPathElements.get(pathRange).add(psiElement); } } } } - if (psiPathElements.size() > 0) { + if (!psiPathElements.isEmpty()) { psiPathElements.forEach((textRange, psiElements) -> psiReferences.add( new PolyVariantReferenceBase(element, textRange, psiElements) @@ -116,18 +121,19 @@ public PsiReference[] getReferencesByElement( } } - return psiReferences.toArray(new PsiReference[psiReferences.size()]); + return psiReferences.toArray(new PsiReference[0]); } - private Collection getFiles(@NotNull PsiElement element) { + @SuppressWarnings("PMD.CognitiveComplexity") + private Collection getFiles(final @NotNull PsiElement element) { Collection files = new ArrayList<>(); - String filePath = GetFilePathUtil.getInstance().execute(element.getText()); + final String filePath = GetFilePathUtil.getInstance().execute(element.getText()); if (null == filePath) { return files; } - String fileName = filePath.substring(filePath.lastIndexOf("/") + 1); + final String fileName = filePath.substring(filePath.lastIndexOf('/') + 1); if (fileName.matches(".*\\.\\w+$")) { // extension presents @@ -138,11 +144,11 @@ private Collection getFiles(@NotNull PsiElement element) { files.removeIf(f -> !f.getPath().endsWith(filePath)); // filter by module - Collection vfs = GetModuleSourceFilesUtil.getInstance() + final Collection vfs = GetModuleSourceFilesUtil.getInstance() .execute(element.getText(), element.getProject()); if (null != vfs) { files.removeIf(f -> { - for (VirtualFile vf : vfs) { + for (final VirtualFile vf : vfs) { if (f.getPath().startsWith(vf.getPath().concat("/"))) { return false; } @@ -152,16 +158,16 @@ private Collection getFiles(@NotNull PsiElement element) { } } else if (isModuleNamePresent(element)) { // extension absent - Collection vfs = GetModuleSourceFilesUtil.getInstance() + final Collection vfs = GetModuleSourceFilesUtil.getInstance() .execute(element.getText(), element.getProject()); if (null != vfs) { - for (VirtualFile vf : vfs) { - Collection vfChildren = GetAllSubFilesOfVirtualFileUtil + for (final VirtualFile vf : vfs) { + final Collection vfChildren = GetAllSubFilesOfVirtualFileUtil .getInstance().execute(vf); if (null != vfChildren) { vfChildren.removeIf(f -> { - if (!f.isDirectory()) { - String ext = f.getExtension(); + if (!f.isDirectory()) { //NOPMD + final String ext = f.getExtension(); if (null != ext) { return !f.getPath().endsWith(filePath.concat(".").concat(ext)); } @@ -177,7 +183,7 @@ private Collection getFiles(@NotNull PsiElement element) { return files; } - private boolean isModuleNamePresent(@NotNull PsiElement element) { + private boolean isModuleNamePresent(final @NotNull PsiElement element) { return GetModuleNameUtil.getInstance().execute(element.getText()) != null; } } From c5818ecdf45cecc2514815372662884200824bb0 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Sat, 19 Mar 2022 11:45:07 +0200 Subject: [PATCH 092/111] 1030: Extended xml file inspection coverage --- resources/META-INF/plugin.xml | 28 +++++++++ .../UsedDeprecatedConstantInConfig.html | 6 ++ .../UsedDeprecatedMethodInConfig.html | 6 ++ .../UsedNonExistentConstantInConfig.html | 6 ++ .../UsedNonExistentMethodInConfig.html | 6 ++ resources/uct/bundle/inspection.properties | 4 ++ .../xml/ModuleConfigFileInspection.java | 1 + .../xml/UsedDeprecatedConstantInConfig.java | 58 +++++++++++++++++++ .../xml/UsedDeprecatedMethodInConfig.java | 58 +++++++++++++++++++ .../xml/UsedDeprecatedTypeInConfig.java | 4 ++ .../xml/UsedNonExistentConstantInConfig.java | 58 +++++++++++++++++++ .../xml/UsedNonExistentMethodInConfig.java | 58 +++++++++++++++++++ .../xml/UsedNonExistentTypeInConfig.java | 4 ++ .../magento2uct/packages/SupportedIssue.java | 28 +++++++++ .../util/php/MagentoReferenceUtil.java | 5 +- 15 files changed, 328 insertions(+), 2 deletions(-) create mode 100644 resources/inspectionDescriptions/UsedDeprecatedConstantInConfig.html create mode 100644 resources/inspectionDescriptions/UsedDeprecatedMethodInConfig.html create mode 100644 resources/inspectionDescriptions/UsedNonExistentConstantInConfig.html create mode 100644 resources/inspectionDescriptions/UsedNonExistentMethodInConfig.html create mode 100644 src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedConstantInConfig.java create mode 100644 src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedMethodInConfig.java create mode 100644 src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentConstantInConfig.java create mode 100644 src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentMethodInConfig.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 545ac7e40..cbe6f445f 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -558,6 +558,34 @@ enabledByDefault="true" level="ERROR" implementationClass="com.magento.idea.magento2uct.inspections.xml.UsedDeprecatedTypeInConfig"/> + + + + diff --git a/resources/inspectionDescriptions/UsedDeprecatedConstantInConfig.html b/resources/inspectionDescriptions/UsedDeprecatedConstantInConfig.html new file mode 100644 index 000000000..5b1db6efc --- /dev/null +++ b/resources/inspectionDescriptions/UsedDeprecatedConstantInConfig.html @@ -0,0 +1,6 @@ + + +

[1234] Using Magento 2 @deprecated constant: consider using Magento Open Source|Adobe Commerce constant marked as @api instead.

+ + + diff --git a/resources/inspectionDescriptions/UsedDeprecatedMethodInConfig.html b/resources/inspectionDescriptions/UsedDeprecatedMethodInConfig.html new file mode 100644 index 000000000..cb9b0f668 --- /dev/null +++ b/resources/inspectionDescriptions/UsedDeprecatedMethodInConfig.html @@ -0,0 +1,6 @@ + + +

[1439] Using Magento 2 @deprecated method: this method will be removed in upcoming versions. Consider relying on methods declared in API interfaces instead.

+ + + diff --git a/resources/inspectionDescriptions/UsedNonExistentConstantInConfig.html b/resources/inspectionDescriptions/UsedNonExistentConstantInConfig.html new file mode 100644 index 000000000..aaaf1516e --- /dev/null +++ b/resources/inspectionDescriptions/UsedNonExistentConstantInConfig.html @@ -0,0 +1,6 @@ + + +

[1214] The used constant is no longer present in the codebase.

+ + + diff --git a/resources/inspectionDescriptions/UsedNonExistentMethodInConfig.html b/resources/inspectionDescriptions/UsedNonExistentMethodInConfig.html new file mode 100644 index 000000000..b539bd50a --- /dev/null +++ b/resources/inspectionDescriptions/UsedNonExistentMethodInConfig.html @@ -0,0 +1,6 @@ + + +

[1410] The used method is no longer present in the codebase.

+ + + diff --git a/resources/uct/bundle/inspection.properties b/resources/uct/bundle/inspection.properties index e95eb276f..9fd84c5d9 100644 --- a/resources/uct/bundle/inspection.properties +++ b/resources/uct/bundle/inspection.properties @@ -40,6 +40,10 @@ inspection.displayName.PossibleDependencyOnImplDetails=Possible dependency on im inspection.displayName.CalledNonInterfaceMethod=Called non-interface method inspection.displayName.UsedNonExistentTypeInConfig=Used non-existent Magento 2 type in the configuration file inspection.displayName.UsedDeprecatedTypeInConfig=Used deprecated Magento 2 type in the configuration file +inspection.displayName.UsedDeprecatedConstantInConfig=Used deprecated Magento 2 constant in the configuration file +inspection.displayName.UsedDeprecatedMethodInConfig=Used deprecated Magento 2 method in the configuration file +inspection.displayName.UsedNonExistentConstantInConfig=Used non-existent Magento 2 constant in the configuration file +inspection.displayName.UsedNonExistentMethodInConfig=Used non-existent Magento 2 method in the configuration file customCode.warnings.deprecated.1131=[1131] Extended class ''{0}'' that is @deprecated in the ''{1}'' customCode.warnings.deprecated.1132=[1132] Imported class ''{0}'' that is @deprecated in the ''{1}'' customCode.warnings.deprecated.1134=[1134] Used class ''{0}'' that is @deprecated in the ''{1}'' diff --git a/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java b/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java index 91945ab4a..62ff42b39 100644 --- a/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java +++ b/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java @@ -17,6 +17,7 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlToken; import com.intellij.psi.xml.XmlTokenType; +import com.jetbrains.php.lang.PhpLangUtil; import com.magento.idea.magento2uct.settings.UctSettingsService; import com.magento.idea.magento2uct.versioning.VersionStateManager; import java.util.ArrayList; diff --git a/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedConstantInConfig.java b/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedConstantInConfig.java new file mode 100644 index 000000000..3a67ad75b --- /dev/null +++ b/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedConstantInConfig.java @@ -0,0 +1,58 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.inspections.xml; + +import com.intellij.codeInspection.InspectionManager; +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.codeInspection.ProblemHighlightType; +import com.intellij.codeInspection.ProblemsHolder; +import com.intellij.psi.PsiElement; +import com.magento.idea.magento2uct.inspections.UctProblemsHolder; +import com.magento.idea.magento2uct.packages.SupportedIssue; +import com.magento.idea.magento2uct.util.php.MagentoReferenceUtil; +import com.magento.idea.magento2uct.versioning.VersionStateManager; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public class UsedDeprecatedConstantInConfig extends ModuleConfigFileInspection { + + @Override + protected void doInspection( + final @NotNull String fqn, + final @NotNull PsiElement target, + final @NotNull InspectionManager manager, + final @NotNull ProblemsHolder holder, + final boolean isOnTheFly, + final @NotNull List descriptors + ) { + if (!MagentoReferenceUtil.isConstantReference(fqn)) { + return; + } + if (VersionStateManager.getInstance(manager.getProject()).isDeprecated(fqn)) { + final String message = SupportedIssue.USED_DEPRECATED_CONSTANT_IN_CONFIG.getMessage( + fqn, + VersionStateManager.getInstance( + manager.getProject() + ).getDeprecatedInVersion(fqn) + ); + + if (holder instanceof UctProblemsHolder) { + ((UctProblemsHolder) holder).setIssue( + SupportedIssue.USED_DEPRECATED_CONSTANT_IN_CONFIG + ); + } + final ProblemDescriptor descriptor = manager.createProblemDescriptor( + target, + message, + null, + ProblemHighlightType.WARNING, + isOnTheFly, + false + ); + descriptors.add(descriptor); + } + } +} diff --git a/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedMethodInConfig.java b/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedMethodInConfig.java new file mode 100644 index 000000000..ea36967f9 --- /dev/null +++ b/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedMethodInConfig.java @@ -0,0 +1,58 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.inspections.xml; + +import com.intellij.codeInspection.InspectionManager; +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.codeInspection.ProblemHighlightType; +import com.intellij.codeInspection.ProblemsHolder; +import com.intellij.psi.PsiElement; +import com.magento.idea.magento2uct.inspections.UctProblemsHolder; +import com.magento.idea.magento2uct.packages.SupportedIssue; +import com.magento.idea.magento2uct.util.php.MagentoReferenceUtil; +import com.magento.idea.magento2uct.versioning.VersionStateManager; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public class UsedDeprecatedMethodInConfig extends ModuleConfigFileInspection { + + @Override + protected void doInspection( + final @NotNull String fqn, + final @NotNull PsiElement target, + final @NotNull InspectionManager manager, + final @NotNull ProblemsHolder holder, + final boolean isOnTheFly, + final @NotNull List descriptors + ) { + if (!MagentoReferenceUtil.isMethodReference(fqn)) { + return; + } + if (VersionStateManager.getInstance(manager.getProject()).isDeprecated(fqn)) { + final String message = SupportedIssue.USED_DEPRECATED_METHOD_IN_CONFIG.getMessage( + fqn, + VersionStateManager.getInstance( + manager.getProject() + ).getDeprecatedInVersion(fqn) + ); + + if (holder instanceof UctProblemsHolder) { + ((UctProblemsHolder) holder).setIssue( + SupportedIssue.USED_DEPRECATED_METHOD_IN_CONFIG + ); + } + final ProblemDescriptor descriptor = manager.createProblemDescriptor( + target, + message, + null, + ProblemHighlightType.WARNING, + isOnTheFly, + false + ); + descriptors.add(descriptor); + } + } +} diff --git a/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedTypeInConfig.java b/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedTypeInConfig.java index 794a4be1c..7c10df123 100644 --- a/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedTypeInConfig.java +++ b/src/com/magento/idea/magento2uct/inspections/xml/UsedDeprecatedTypeInConfig.java @@ -12,6 +12,7 @@ import com.intellij.psi.PsiElement; import com.magento.idea.magento2uct.inspections.UctProblemsHolder; import com.magento.idea.magento2uct.packages.SupportedIssue; +import com.magento.idea.magento2uct.util.php.MagentoReferenceUtil; import com.magento.idea.magento2uct.versioning.VersionStateManager; import java.util.List; import org.jetbrains.annotations.NotNull; @@ -27,6 +28,9 @@ protected void doInspection( final boolean isOnTheFly, final @NotNull List descriptors ) { + if (MagentoReferenceUtil.isReference(fqn)) { + return; + } if (VersionStateManager.getInstance(manager.getProject()).isDeprecated(fqn)) { final String message = SupportedIssue.USED_DEPRECATED_TYPE_IN_CONFIG.getMessage( fqn, diff --git a/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentConstantInConfig.java b/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentConstantInConfig.java new file mode 100644 index 000000000..d6ce2de1a --- /dev/null +++ b/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentConstantInConfig.java @@ -0,0 +1,58 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.inspections.xml; + +import com.intellij.codeInspection.InspectionManager; +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.codeInspection.ProblemHighlightType; +import com.intellij.codeInspection.ProblemsHolder; +import com.intellij.psi.PsiElement; +import com.magento.idea.magento2uct.inspections.UctProblemsHolder; +import com.magento.idea.magento2uct.packages.SupportedIssue; +import com.magento.idea.magento2uct.util.php.MagentoReferenceUtil; +import com.magento.idea.magento2uct.versioning.VersionStateManager; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public class UsedNonExistentConstantInConfig extends ModuleConfigFileInspection { + + @Override + protected void doInspection( + final @NotNull String fqn, + final @NotNull PsiElement target, + final @NotNull InspectionManager manager, + final @NotNull ProblemsHolder holder, + final boolean isOnTheFly, + final @NotNull List descriptors + ) { + if (!MagentoReferenceUtil.isConstantReference(fqn)) { + return; + } + if (!VersionStateManager.getInstance(manager.getProject()).isExists(fqn)) { + final String message = SupportedIssue.USED_NON_EXISTENT_CONSTANT_IN_CONFIG.getMessage( + fqn, + VersionStateManager.getInstance( + manager.getProject() + ).getRemovedInVersion(fqn) + ); + + if (holder instanceof UctProblemsHolder) { + ((UctProblemsHolder) holder).setIssue( + SupportedIssue.USED_NON_EXISTENT_CONSTANT_IN_CONFIG + ); + } + final ProblemDescriptor descriptor = manager.createProblemDescriptor( + target, + message, + null, + ProblemHighlightType.ERROR, + isOnTheFly, + false + ); + descriptors.add(descriptor); + } + } +} diff --git a/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentMethodInConfig.java b/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentMethodInConfig.java new file mode 100644 index 000000000..40b806060 --- /dev/null +++ b/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentMethodInConfig.java @@ -0,0 +1,58 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.inspections.xml; + +import com.intellij.codeInspection.InspectionManager; +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.codeInspection.ProblemHighlightType; +import com.intellij.codeInspection.ProblemsHolder; +import com.intellij.psi.PsiElement; +import com.magento.idea.magento2uct.inspections.UctProblemsHolder; +import com.magento.idea.magento2uct.packages.SupportedIssue; +import com.magento.idea.magento2uct.util.php.MagentoReferenceUtil; +import com.magento.idea.magento2uct.versioning.VersionStateManager; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public class UsedNonExistentMethodInConfig extends ModuleConfigFileInspection { + + @Override + protected void doInspection( + final @NotNull String fqn, + final @NotNull PsiElement target, + final @NotNull InspectionManager manager, + final @NotNull ProblemsHolder holder, + final boolean isOnTheFly, + final @NotNull List descriptors + ) { + if (!MagentoReferenceUtil.isMethodReference(fqn)) { + return; + } + if (!VersionStateManager.getInstance(manager.getProject()).isExists(fqn)) { + final String message = SupportedIssue.USED_NON_EXISTENT_METHOD_IN_CONFIG.getMessage( + fqn, + VersionStateManager.getInstance( + manager.getProject() + ).getRemovedInVersion(fqn) + ); + + if (holder instanceof UctProblemsHolder) { + ((UctProblemsHolder) holder).setIssue( + SupportedIssue.USED_NON_EXISTENT_METHOD_IN_CONFIG + ); + } + final ProblemDescriptor descriptor = manager.createProblemDescriptor( + target, + message, + null, + ProblemHighlightType.ERROR, + isOnTheFly, + false + ); + descriptors.add(descriptor); + } + } +} diff --git a/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentTypeInConfig.java b/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentTypeInConfig.java index 13aaac616..059084ce7 100644 --- a/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentTypeInConfig.java +++ b/src/com/magento/idea/magento2uct/inspections/xml/UsedNonExistentTypeInConfig.java @@ -12,6 +12,7 @@ import com.intellij.psi.PsiElement; import com.magento.idea.magento2uct.inspections.UctProblemsHolder; import com.magento.idea.magento2uct.packages.SupportedIssue; +import com.magento.idea.magento2uct.util.php.MagentoReferenceUtil; import com.magento.idea.magento2uct.versioning.VersionStateManager; import java.util.List; import org.jetbrains.annotations.NotNull; @@ -27,6 +28,9 @@ protected void doInspection( final boolean isOnTheFly, final @NotNull List descriptors ) { + if (MagentoReferenceUtil.isReference(fqn)) { + return; + } if (!VersionStateManager.getInstance(manager.getProject()).isExists(fqn)) { final String message = SupportedIssue.USED_NON_EXISTENT_TYPE_IN_CONFIG.getMessage( fqn, diff --git a/src/com/magento/idea/magento2uct/packages/SupportedIssue.java b/src/com/magento/idea/magento2uct/packages/SupportedIssue.java index df2922715..004d50f10 100644 --- a/src/com/magento/idea/magento2uct/packages/SupportedIssue.java +++ b/src/com/magento/idea/magento2uct/packages/SupportedIssue.java @@ -47,7 +47,11 @@ import com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentConstant; import com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentProperty; import com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentType; +import com.magento.idea.magento2uct.inspections.xml.UsedDeprecatedConstantInConfig; +import com.magento.idea.magento2uct.inspections.xml.UsedDeprecatedMethodInConfig; import com.magento.idea.magento2uct.inspections.xml.UsedDeprecatedTypeInConfig; +import com.magento.idea.magento2uct.inspections.xml.UsedNonExistentConstantInConfig; +import com.magento.idea.magento2uct.inspections.xml.UsedNonExistentMethodInConfig; import com.magento.idea.magento2uct.inspections.xml.UsedNonExistentTypeInConfig; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -285,6 +289,30 @@ public enum SupportedIssue { IssueSeverityLevel.WARNING, "customCode.warnings.deprecated.1134", UsedDeprecatedTypeInConfig.class + ), + USED_DEPRECATED_CONSTANT_IN_CONFIG( + 1234, + IssueSeverityLevel.WARNING, + "customCode.warnings.deprecated.1234", + UsedDeprecatedConstantInConfig.class + ), + USED_DEPRECATED_METHOD_IN_CONFIG( + 1439, + IssueSeverityLevel.WARNING, + "customCode.warnings.deprecated.1439", + UsedDeprecatedMethodInConfig.class + ), + USED_NON_EXISTENT_CONSTANT_IN_CONFIG( + 1214, + IssueSeverityLevel.WARNING, + "customCode.critical.existence.1214", + UsedNonExistentConstantInConfig.class + ), + USED_NON_EXISTENT_METHOD_IN_CONFIG( + 1410, + IssueSeverityLevel.WARNING, + "customCode.critical.existence.1410", + UsedNonExistentMethodInConfig.class ); private final int code; diff --git a/src/com/magento/idea/magento2uct/util/php/MagentoReferenceUtil.java b/src/com/magento/idea/magento2uct/util/php/MagentoReferenceUtil.java index d35c443a7..d01faa7a1 100644 --- a/src/com/magento/idea/magento2uct/util/php/MagentoReferenceUtil.java +++ b/src/com/magento/idea/magento2uct/util/php/MagentoReferenceUtil.java @@ -38,7 +38,8 @@ public static boolean isMethodReference(final @NotNull String referenceCandidate if (isReference(referenceCandidate)) { final String referencePart = referenceCandidate.split(PHP_REFERENCE_SEPARATOR)[1]; - return StringUtil.isJavaIdentifier(referencePart); + return StringUtil.isJavaIdentifier(referencePart) + && !isConstantReference(referenceCandidate); } return false; @@ -55,7 +56,7 @@ public static boolean isConstantReference(final @NotNull String referenceCandida if (isReference(referenceCandidate)) { final String referencePart = referenceCandidate.split(PHP_REFERENCE_SEPARATOR)[1]; - return StringUtil.isUpperCase(referencePart); + return StringUtil.isUpperCase(referencePart.replace("_", "")); } return false; From 22071d7f8c619caea2c4af1312806de2690cf6aa Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Sat, 19 Mar 2022 12:14:13 +0200 Subject: [PATCH 093/111] 1030: Code refactoring --- resources/META-INF/plugin.xml | 41 ++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index cbe6f445f..0a16d3401 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -544,46 +544,47 @@ level="WARNING" implementationClass="com.magento.idea.magento2uct.inspections.php.api.CalledNonInterfaceMethod"/> - + + From 1d24a8fc797303e96c31a663b116c1097e2136cb Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Sat, 19 Mar 2022 12:50:03 +0200 Subject: [PATCH 094/111] 1030: Added theme xml files support --- .../xml/ModuleConfigFileInspection.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java b/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java index 62ff42b39..89e674907 100644 --- a/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java +++ b/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java @@ -10,6 +10,7 @@ import com.intellij.codeInspection.ProblemsHolder; import com.intellij.codeInspection.XmlSuppressableInspectionTool; import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.PsiFile; @@ -17,17 +18,20 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlToken; import com.intellij.psi.xml.XmlTokenType; -import com.jetbrains.php.lang.PhpLangUtil; import com.magento.idea.magento2uct.settings.UctSettingsService; import com.magento.idea.magento2uct.versioning.VersionStateManager; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; abstract class ModuleConfigFileInspection extends XmlSuppressableInspectionTool { + private static final String LAYOUT_FILE_REGEX = "\\/(layout|ui_component)\\/.*\\.xml"; + private static final Pattern LAYOUT_FILE_PATTERN = Pattern.compile(LAYOUT_FILE_REGEX); + private final String[] supportedFiles = new String[]{ "di.xml", "system.xml", @@ -68,7 +72,8 @@ abstract class ModuleConfigFileInspection extends XmlSuppressableInspectionTool return getEmptyResult(); } - if (Arrays.stream(supportedFiles).noneMatch(name -> name.equals(file.getName()))) { + if (Arrays.stream(supportedFiles).noneMatch(name -> name.equals(file.getName())) + && !isLayoutFile(file)) { return getEmptyResult(); } final List allowedTokenTypes = new ArrayList<>(); @@ -124,4 +129,14 @@ protected abstract void doInspection( private ProblemDescriptor[] getEmptyResult() { return new ProblemDescriptor[0]; } + + private boolean isLayoutFile(final @NotNull PsiFile file) { + final VirtualFile virtualFile = file.getVirtualFile(); + + if (virtualFile == null) { + return false; + } + + return LAYOUT_FILE_PATTERN.matcher(virtualFile.getPath()).find(); + } } From ffcea950d5438773060af17d61231bfec61a050a Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Sat, 19 Mar 2022 12:50:50 +0200 Subject: [PATCH 095/111] 1030: Code refactoring --- .../magento2uct/inspections/xml/ModuleConfigFileInspection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java b/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java index 89e674907..f4d77bfad 100644 --- a/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java +++ b/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java @@ -32,7 +32,7 @@ abstract class ModuleConfigFileInspection extends XmlSuppressableInspectionTool private static final String LAYOUT_FILE_REGEX = "\\/(layout|ui_component)\\/.*\\.xml"; private static final Pattern LAYOUT_FILE_PATTERN = Pattern.compile(LAYOUT_FILE_REGEX); - private final String[] supportedFiles = new String[]{ + private final String[] supportedFiles = { "di.xml", "system.xml", "events.xml", From 688d5896ffb82fca2eb5f5a16345c6e3a2d3fafe Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Sat, 19 Mar 2022 13:06:19 +0200 Subject: [PATCH 096/111] 1030: Code refactoring --- .../idea/magento2uct/execution/GenerateUctReportCommand.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java b/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java index 4f08468e9..99a3f52c9 100644 --- a/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java +++ b/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java @@ -20,7 +20,6 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; -import com.jetbrains.php.lang.psi.PhpFile; import com.magento.idea.magento2plugin.util.magento.MagentoVersionUtil; import com.magento.idea.magento2uct.execution.output.ReportBuilder; import com.magento.idea.magento2uct.execution.output.Summary; From af4b9c0616b811aa67fed085644feaa9a471bb13 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Wed, 23 Mar 2022 20:36:50 +0200 Subject: [PATCH 097/111] 1035: removed deprecated Function#getReturnType --- .../util/FillTextBufferWithPluginMethods.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/util/FillTextBufferWithPluginMethods.java b/src/com/magento/idea/magento2plugin/actions/generation/util/FillTextBufferWithPluginMethods.java index 93cbc58c6..9bfc1187f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/util/FillTextBufferWithPluginMethods.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/util/FillTextBufferWithPluginMethods.java @@ -13,6 +13,7 @@ import com.jetbrains.php.lang.psi.elements.Parameter; import com.jetbrains.php.lang.psi.elements.PhpReturnType; import com.magento.idea.magento2plugin.actions.generation.data.code.PluginMethodData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; import com.magento.idea.magento2plugin.actions.generation.references.PhpClassReferenceResolver; import com.magento.idea.magento2plugin.util.php.PhpTypeMetadataParserUtil; import java.util.ArrayList; @@ -55,19 +56,19 @@ public void execute( final PsiElement targetClass = (PsiElement) pluginMethod.getTargetMethod() .getUserData(targetClassKey); resolver.processElement(targetClass); - PhpReturnType returnType = targetMethod.getReturnType(); + final String returnTypeFqn = PhpTypeMetadataParserUtil.getMethodReturnType(targetMethod); - if (returnType == null && returnTypeFqn != null) { - returnType = PhpPsiElementFactory.createReturnType( + if (returnTypeFqn != null && PhpClassGeneratorUtil.isValidFqn(returnTypeFqn)) { + final PhpReturnType returnType = PhpPsiElementFactory.createReturnType( pluginMethod.getTargetMethod().getProject(), returnTypeFqn ); - } - if (returnType != null) { - resolver.processElement(returnType); + if (returnType != null) { + resolver.processElement(returnType); + } } textBuf.append('\n'); From 8d52fd18d7af825ee11c36b4c10c72309d7d911d Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 24 Mar 2022 12:35:46 +0200 Subject: [PATCH 098/111] 1035: Code refactoring --- .../util/FillTextBufferWithPluginMethods.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/util/FillTextBufferWithPluginMethods.java b/src/com/magento/idea/magento2plugin/actions/generation/util/FillTextBufferWithPluginMethods.java index 9bfc1187f..fc3cb28b6 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/util/FillTextBufferWithPluginMethods.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/util/FillTextBufferWithPluginMethods.java @@ -11,7 +11,6 @@ import com.jetbrains.php.lang.psi.PhpPsiElementFactory; import com.jetbrains.php.lang.psi.elements.Method; import com.jetbrains.php.lang.psi.elements.Parameter; -import com.jetbrains.php.lang.psi.elements.PhpReturnType; import com.magento.idea.magento2plugin.actions.generation.data.code.PluginMethodData; import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; import com.magento.idea.magento2plugin.actions.generation.references.PhpClassReferenceResolver; @@ -57,18 +56,18 @@ public void execute( .getUserData(targetClassKey); resolver.processElement(targetClass); - final String returnTypeFqn = - PhpTypeMetadataParserUtil.getMethodReturnType(targetMethod); + final String returnTypeCandidate = PhpTypeMetadataParserUtil.getMethodReturnType( + targetMethod + ); - if (returnTypeFqn != null && PhpClassGeneratorUtil.isValidFqn(returnTypeFqn)) { - final PhpReturnType returnType = PhpPsiElementFactory.createReturnType( - pluginMethod.getTargetMethod().getProject(), - returnTypeFqn + if (returnTypeCandidate != null + && PhpClassGeneratorUtil.isValidFqn(returnTypeCandidate)) { + resolver.processElement( + PhpPsiElementFactory.createReturnType( + pluginMethod.getTargetMethod().getProject(), + returnTypeCandidate + ) ); - - if (returnType != null) { - resolver.processElement(returnType); - } } textBuf.append('\n'); From 709db24f23284baf25def525a2a3fc67ae08b665 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 24 Mar 2022 13:13:53 +0200 Subject: [PATCH 099/111] 984: Filtered generated folder from reference resolving results --- resources/META-INF/plugin.xml | 2 + .../php/MagentoProxyDeclarationFilter.java | 53 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/com/magento/idea/magento2plugin/lang/php/MagentoProxyDeclarationFilter.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index f6af41125..6cf1e6eba 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -617,5 +617,7 @@ + + diff --git a/src/com/magento/idea/magento2plugin/lang/php/MagentoProxyDeclarationFilter.java b/src/com/magento/idea/magento2plugin/lang/php/MagentoProxyDeclarationFilter.java new file mode 100644 index 000000000..81acc6a3b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/lang/php/MagentoProxyDeclarationFilter.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.lang.php; + +import com.intellij.openapi.util.registry.Registry; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.util.containers.ContainerUtil; +import com.jetbrains.php.lang.psi.PhpMultipleDeclarationFilter; +import com.jetbrains.php.lang.psi.elements.PhpNamedElement; +import com.magento.idea.magento2plugin.project.Settings; +import java.util.Collection; +import org.jetbrains.annotations.NotNull; + +public class MagentoProxyDeclarationFilter implements PhpMultipleDeclarationFilter { + + @SuppressWarnings({"PMD.CognitiveComplexity", "PMD.ConfusingTernary"}) + @Override + public Collection filter( + final @NotNull PsiElement psiElement, + final Collection candidates + ) { + if (!Settings.isEnabled(psiElement.getProject())) { + return candidates; + } else if (!Registry.is("php.use.multiproject.ref.resolver", true)) { + return candidates; + } else if (candidates.size() == 1) { // NOPMD + return candidates; + } else if (psiElement.getContainingFile() == null) { + return candidates; + } else { + return ContainerUtil.filter(candidates, + (candidate) -> { + final PsiFile file = candidate.getContainingFile(); + + if (file == null) { + return false; + } + final VirtualFile virtualFile = file.getVirtualFile(); + + if (virtualFile == null) { + return false; + } + + return !virtualFile.getPath().contains("/generated/"); + }); + } + } +} From feedf152b7d6a4e3fa9f474fefd67c47ffbe169d Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 24 Mar 2022 13:35:34 +0200 Subject: [PATCH 100/111] 984: Code refactoring after code review --- .../php/MagentoProxyDeclarationFilter.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/lang/php/MagentoProxyDeclarationFilter.java b/src/com/magento/idea/magento2plugin/lang/php/MagentoProxyDeclarationFilter.java index 81acc6a3b..86705b138 100644 --- a/src/com/magento/idea/magento2plugin/lang/php/MagentoProxyDeclarationFilter.java +++ b/src/com/magento/idea/magento2plugin/lang/php/MagentoProxyDeclarationFilter.java @@ -32,22 +32,22 @@ public Collection filter( return candidates; } else if (psiElement.getContainingFile() == null) { return candidates; - } else { - return ContainerUtil.filter(candidates, - (candidate) -> { - final PsiFile file = candidate.getContainingFile(); - - if (file == null) { - return false; - } - final VirtualFile virtualFile = file.getVirtualFile(); - - if (virtualFile == null) { - return false; - } - - return !virtualFile.getPath().contains("/generated/"); - }); } + + return ContainerUtil.filter(candidates, + (candidate) -> { + final PsiFile file = candidate.getContainingFile(); + + if (file == null) { + return false; + } + final VirtualFile virtualFile = file.getVirtualFile(); + + if (virtualFile == null) { + return false; + } + + return !virtualFile.getPath().contains("/generated/"); + }); } } From 1c84ee481fa22bd7abeb7b2157ef83e3d4c54fa7 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 24 Mar 2022 17:38:41 +0200 Subject: [PATCH 101/111] 614: Provided file path references for JS:STRING_LITERAL psi elements in the js files --- .../reference/js/JsReferenceContributor.java | 32 +++++++++++++++---- .../idea/magento2plugin/util/RegExUtil.java | 7 ++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/reference/js/JsReferenceContributor.java b/src/com/magento/idea/magento2plugin/reference/js/JsReferenceContributor.java index 787958e34..36d67c60e 100644 --- a/src/com/magento/idea/magento2plugin/reference/js/JsReferenceContributor.java +++ b/src/com/magento/idea/magento2plugin/reference/js/JsReferenceContributor.java @@ -1,35 +1,53 @@ -/** +/* * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + package com.magento.idea.magento2plugin.reference.js; +import static com.intellij.patterns.StandardPatterns.string; +import static com.magento.idea.magento2plugin.util.RegExUtil.JsRegex; + +import com.intellij.lang.javascript.JSTokenTypes; +import com.intellij.lang.javascript.JavascriptLanguage; import com.intellij.lang.javascript.patterns.JSPatterns; -import com.intellij.psi.*; +import com.intellij.patterns.PlatformPatterns; +import com.intellij.psi.PsiReferenceContributor; +import com.intellij.psi.PsiReferenceRegistrar; import com.magento.idea.magento2plugin.reference.provider.FilePathReferenceProvider; import com.magento.idea.magento2plugin.reference.provider.ModuleNameReferenceProvider; import com.magento.idea.magento2plugin.reference.provider.RequireJsPreferenceReferenceProvider; import com.magento.idea.magento2plugin.util.RegExUtil; import org.jetbrains.annotations.NotNull; -import static com.intellij.patterns.StandardPatterns.string; - public class JsReferenceContributor extends PsiReferenceContributor { + @Override - public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { + public void registerReferenceProviders(final @NotNull PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider( JSPatterns.jsLiteralExpression() .withText(string().matches(".*" + RegExUtil.Magento.MODULE_NAME + ".*")), new ModuleNameReferenceProvider() ); + // Targets property value -> {test: 'Sandbox_Test/js/test'} registrar.registerReferenceProvider( - JSPatterns.jsLiteralExpression().withText(string().matches(".*\\W" + RegExUtil.FILE_PATH + ".*")), + JSPatterns.jsLiteralExpression() + .withText(string().matches(JsRegex.FILE_PATH)), + new FilePathReferenceProvider() + ); + + // Targets property key (JS:STRING_LITERAL) -> {'Sandbox_Test/js/test': true} + registrar.registerReferenceProvider( + PlatformPatterns.psiElement(JSTokenTypes.STRING_LITERAL) + .withText(string().matches(JsRegex.FILE_PATH)) + .withLanguage(JavascriptLanguage.INSTANCE), new FilePathReferenceProvider() ); registrar.registerReferenceProvider( - JSPatterns.jsLiteralExpression().withText(string().matches(".*\\W" + RegExUtil.FILE_PATH + ".*")), + JSPatterns.jsLiteralExpression() + .withText(string().matches(".*\\W" + RegExUtil.FILE_PATH + ".*")), new RequireJsPreferenceReferenceProvider() ); } diff --git a/src/com/magento/idea/magento2plugin/util/RegExUtil.java b/src/com/magento/idea/magento2plugin/util/RegExUtil.java index 2603d8b4b..17dd76d9d 100644 --- a/src/com/magento/idea/magento2plugin/util/RegExUtil.java +++ b/src/com/magento/idea/magento2plugin/util/RegExUtil.java @@ -103,6 +103,13 @@ public static class XmlRegex { "\\\\?" + PhpRegex.FQN + "(" + CLASS_MEMBER_NAME + ")?.*"; } + public static class JsRegex { + + // Targets paths like `'Sandbox_Test/js/test'` + public static final String FILE_PATH + = "(\\W{1}[A-Z][a-zA-Z0-9]+_[A-Z][a-zA-Z0-9]+[\\/\\w*-]{1,}\\W{1})"; + } + public static class CustomTheme { public static final String MODULE_NAME = "app\\/design\\/(adminhtml|frontend)\\/\\w*\\/\\w*\\/\\w*"; From db73a4ce075a79dc69727ec19cdea75519d0a999 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 24 Mar 2022 18:00:05 +0200 Subject: [PATCH 102/111] 614: Code refactoring --- .../js/RequireJsReferenceRegistrarTest.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/tests/com/magento/idea/magento2plugin/reference/js/RequireJsReferenceRegistrarTest.java b/tests/com/magento/idea/magento2plugin/reference/js/RequireJsReferenceRegistrarTest.java index 666b3b35d..195c927cf 100644 --- a/tests/com/magento/idea/magento2plugin/reference/js/RequireJsReferenceRegistrarTest.java +++ b/tests/com/magento/idea/magento2plugin/reference/js/RequireJsReferenceRegistrarTest.java @@ -2,34 +2,45 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + package com.magento.idea.magento2plugin.reference.js; public class RequireJsReferenceRegistrarTest extends ReferenceJsFixtureTestCase { + private static final String FIXTURE_PATH = "test.js"; + + /** + * Mapped parameters should have reference to file. + */ public void testMappedInjectionParameterMustHaveReference() { - String filePath = this.getFixturePath("test.js"); - myFixture.configureByFile(filePath); + myFixture.configureByFile(getFixturePath(FIXTURE_PATH)); assertHasReferenceToFile("app/code/Foo/Bar/view/frontend/web/js/file.js"); } + /** + * Path parameters should have reference to file. + */ public void testPathInjectionParameterMustHaveReference() { - String filePath = this.getFixturePath("test.js"); - myFixture.configureByFile(filePath); + myFixture.configureByFile(getFixturePath(FIXTURE_PATH)); assertHasReferenceToFile("app/code/Foo/Bar/view/frontend/web/js/file2.js"); } + /** + * The Magento resource file path parameters should have reference to file. + */ public void testFileInjectionParameterMustHaveReference() { - String filePath = this.getFixturePath("test.js"); - myFixture.configureByFile(filePath); + myFixture.configureByFile(getFixturePath(FIXTURE_PATH)); assertHasReferenceToFile("app/code/Foo/Bar/view/frontend/web/js/file.js"); } + /** + * Lib resource parameters should have reference to file. + */ public void testLibInjectionParameterMustHaveReference() { - String filePath = this.getFixturePath("test.js"); - myFixture.configureByFile(filePath); + myFixture.configureByFile(getFixturePath(FIXTURE_PATH)); assertHasReferenceToFile("/lib/web/testjs.js"); } From 1f094cb9356d3d635b26efc0d1e4db2e1e077bb4 Mon Sep 17 00:00:00 2001 From: silinmykola Date: Thu, 24 Mar 2022 18:52:18 +0200 Subject: [PATCH 103/111] fix overrite for js and css files --- .../internal/Require Config JS File.js.ft | 2 + .../internal/Require Config JS File.js.html | 20 ++++ .../OverrideTemplateInThemeAction.java | 24 +++-- .../dialog/OverrideTemplateInThemeDialog.java | 43 +++++--- .../generator/OverrideInThemeGenerator.java | 51 +++++++-- .../OverrideTemplateInThemeGenerator.java | 36 ++++--- .../js/RequireJsConfigGenerator.java | 51 +++++++++ .../magento/files/RequireConfigJsFile.java | 33 ++++++ .../magento/packages/OverridableFileType.java | 102 ++++++++++++++++++ 9 files changed, 314 insertions(+), 48 deletions(-) create mode 100644 resources/fileTemplates/internal/Require Config JS File.js.ft create mode 100644 resources/fileTemplates/internal/Require Config JS File.js.html create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/js/RequireJsConfigGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/RequireConfigJsFile.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/OverridableFileType.java diff --git a/resources/fileTemplates/internal/Require Config JS File.js.ft b/resources/fileTemplates/internal/Require Config JS File.js.ft new file mode 100644 index 000000000..2238246bd --- /dev/null +++ b/resources/fileTemplates/internal/Require Config JS File.js.ft @@ -0,0 +1,2 @@ +var config = { +} diff --git a/resources/fileTemplates/internal/Require Config JS File.js.html b/resources/fileTemplates/internal/Require Config JS File.js.html new file mode 100644 index 000000000..f958bd890 --- /dev/null +++ b/resources/fileTemplates/internal/Require Config JS File.js.html @@ -0,0 +1,20 @@ + + + + +

+ All configuration is done in the requirejs-config.js file. It has a single root object config which contains + the configuration options described below. All the configuration settings are optional and are used only when required. +

+

+ Read more about requirejs-config.js in the + DevDocs. +

+
+ + \ No newline at end of file diff --git a/src/com/magento/idea/magento2plugin/actions/generation/OverrideTemplateInThemeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/OverrideTemplateInThemeAction.java index 325ac90ca..302015cc1 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/OverrideTemplateInThemeAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/OverrideTemplateInThemeAction.java @@ -10,16 +10,19 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.magento.idea.magento2plugin.MagentoIcons; -import com.magento.idea.magento2plugin.actions.CopyMagentoPath; import com.magento.idea.magento2plugin.actions.generation.dialog.OverrideTemplateInThemeDialog; +import com.magento.idea.magento2plugin.magento.packages.OverridableFileType; +import com.magento.idea.magento2plugin.magento.packages.Package; +import java.util.Arrays; import org.jetbrains.annotations.NotNull; public class OverrideTemplateInThemeAction extends OverrideFileInThemeAction { public static final String ACTION_NAME = "Override this file in a project theme"; - public static final String ACTION_TEMPLATE_DESCRIPTION = "Override template in project theme"; - public static final String ACTION_STYLES_DESCRIPTION = "Override styles in project theme"; - public static final String LESS_FILE_EXTENSION = "less"; + public static final String ACTION_TEMPLATE_DESCRIPTION = + "Override template file in project theme"; + public static final String ACTION_STYLES_DESCRIPTION = "Override styles file in project theme"; + public static final String ACTION_JS_DESCRIPTION = "Override javascript file in project theme"; public OverrideTemplateInThemeAction() { super(ACTION_NAME, ACTION_TEMPLATE_DESCRIPTION, MagentoIcons.MODULE); @@ -47,11 +50,18 @@ protected boolean isOverrideAllowed( } final String fileExtension = virtualFile.getExtension(); - if (!CopyMagentoPath.PHTML_EXTENSION.equals(fileExtension) - && !LESS_FILE_EXTENSION.equals(fileExtension)) { + if (!OverridableFileType.getOverwritableFileExtensions().contains(fileExtension)) { return false; } - return isFileInModuleOrTheme(file, project); + if (OverridableFileType.isFileJS(fileExtension) + && !virtualFile.getCanonicalPath().contains(Package.libWebRoot) + && !Arrays.asList(virtualFile.getCanonicalPath() + .split(Package.V_FILE_SEPARATOR)).contains("web")) { + return false; + } + + return OverridableFileType.isFileJS(fileExtension) + || isFileInModuleOrTheme(file, project); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java index 31920f0e4..a0dde4de8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java @@ -8,7 +8,6 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; -import com.magento.idea.magento2plugin.actions.CopyMagentoPath; import com.magento.idea.magento2plugin.actions.generation.OverrideTemplateInThemeAction; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry; @@ -17,6 +16,7 @@ import com.magento.idea.magento2plugin.indexes.ModuleIndex; import com.magento.idea.magento2plugin.magento.packages.Areas; import com.magento.idea.magento2plugin.magento.packages.ComponentType; +import com.magento.idea.magento2plugin.magento.packages.OverridableFileType; import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; import java.awt.event.ActionEvent; @@ -65,9 +65,12 @@ public OverrideTemplateInThemeDialog( setContentPane(contentPane); setModal(true); - if (CopyMagentoPath.PHTML_EXTENSION.equals(psiFile.getVirtualFile().getExtension())) { + final String fileType = psiFile.getVirtualFile().getExtension(); + if (OverridableFileType.isFilePhtml(fileType)) { setTitle(OverrideTemplateInThemeAction.ACTION_TEMPLATE_DESCRIPTION); - } else { + } else if (OverridableFileType.isFileJS(fileType)) { + setTitle(OverrideTemplateInThemeAction.ACTION_JS_DESCRIPTION); + } else if (OverridableFileType.isFileStyle(fileType)) { setTitle(OverrideTemplateInThemeAction.ACTION_STYLES_DESCRIPTION); } getRootPane().setDefaultButton(buttonOK); @@ -121,27 +124,37 @@ private String getTheme() { return this.theme.getSelectedItem().toString(); } + @SuppressWarnings("PMD.CognitiveComplexity") private void fillThemeOptions() { final GetMagentoModuleUtil.MagentoModuleData moduleData = GetMagentoModuleUtil.getByContext(psiFile.getContainingDirectory(), project); - - if (moduleData == null) { - return; - } String area = ""; // NOPMD - if (moduleData.getType().equals(ComponentType.module)) { - final PsiDirectory viewDir = moduleData.getViewDir(); - - if (viewDir == null) { + if (moduleData == null) { + if (psiFile.getVirtualFile().getExtension() + .equals(OverridableFileType.JS.getType())) { + area = "base"; + } else { return; } - final String filePath = psiFile.getVirtualFile().getPath(); - final String relativePath = filePath.replace(viewDir.getVirtualFile().getPath(), ""); - area = relativePath.split(Package.V_FILE_SEPARATOR)[1]; } else { - area = moduleData.getName().split(Package.V_FILE_SEPARATOR)[0]; + if (moduleData.getType().equals(ComponentType.module)) { + final PsiDirectory viewDir = moduleData.getViewDir(); + + if (viewDir == null) { + return; + } + final String filePath = psiFile.getVirtualFile().getPath(); + final String relativePath = filePath.replace( + viewDir.getVirtualFile().getPath(), + "" + ); + area = relativePath.split(Package.V_FILE_SEPARATOR)[1]; + } else { + area = moduleData.getName().split(Package.V_FILE_SEPARATOR)[0]; + } } + final List themeNames = new ModuleIndex(project).getEditableThemeNames(); for (final String themeName : themeNames) { diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java index b13e93030..4e5512b04 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideInThemeGenerator.java @@ -11,11 +11,13 @@ import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; import com.magento.idea.magento2plugin.bundles.ValidatorBundle; import com.magento.idea.magento2plugin.magento.packages.Areas; +import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.util.RegExUtil; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.regex.Pattern; +import java.util.stream.Collectors; @SuppressWarnings("PMD.AbstractClassWithoutAbstractMethod") public abstract class OverrideInThemeGenerator { @@ -45,16 +47,12 @@ protected PsiDirectory getTargetDirectory( final PsiDirectory directory, final List pathComponents ) { - PsiDirectory result = directory; - PsiDirectory tempDirectory = directory; final DirectoryGenerator generator = DirectoryGenerator.getInstance(); - for (final String directoryName : pathComponents) { - result = generator.findOrCreateSubdirectory(tempDirectory, directoryName); - tempDirectory = result; - } - - return result; + return generator.findOrCreateSubdirectories( + directory, + pathComponents.stream().collect(Collectors.joining(File.separator)) + ); } /** @@ -97,11 +95,42 @@ protected List getThemePathComponents(final PsiFile file) { final Pattern pattern = Pattern.compile(RegExUtil.Magento.MODULE_NAME); PsiDirectory parent = file.getParent(); - do { + boolean isLib = true; + for (final String filePart : parent.toString().split("/")) { + if (Pattern.matches(String.valueOf(pattern), filePart)) { + isLib = false; + } + } + + if (isLib) { + pathComponents.addAll(getLibPathComponets(file)); + } else { + do { + pathComponents.add(parent.getName()); + parent = parent.getParent(); + } while (!pattern.matcher(parent.getName()).find()); + pathComponents.add(parent.getName()); + Collections.reverse(pathComponents); + } + + return pathComponents; + } + + /** + * Get file path to lib. + * + * @param file PsiFile + * @return List + */ + protected List getLibPathComponets(final PsiFile file) { + final List pathComponents = new ArrayList<>(); + PsiDirectory parent = file.getParent(); + + while (!"web".equals(parent.getName())) { pathComponents.add(parent.getName()); parent = parent.getParent(); - } while (!pattern.matcher(parent.getName()).find()); - pathComponents.add(parent.getName()); + } + pathComponents.add("web"); Collections.reverse(pathComponents); return pathComponents; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideTemplateInThemeGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideTemplateInThemeGenerator.java index f2e76d0ca..6520bc601 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideTemplateInThemeGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/OverrideTemplateInThemeGenerator.java @@ -15,6 +15,7 @@ import com.maddyhome.idea.copyright.actions.UpdateCopyrightProcessor; import com.magento.idea.magento2plugin.indexes.ModuleIndex; import com.magento.idea.magento2plugin.magento.packages.ComponentType; +import com.magento.idea.magento2plugin.magento.packages.OverridableFileType; import com.magento.idea.magento2plugin.util.magento.GetComponentNameByDirectoryUtil; import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; import java.util.List; @@ -40,24 +41,29 @@ public void execute(final PsiFile baseFile, final String themeName) { final GetMagentoModuleUtil.MagentoModuleData moduleData = GetMagentoModuleUtil.getByContext(baseFile.getContainingDirectory(), project); + List pathComponents; if (moduleData == null) { - return; - } - - List pathComponents; - if (moduleData.getType().equals(ComponentType.module)) { - pathComponents = getModulePathComponents( - baseFile, - GetComponentNameByDirectoryUtil.execute( - baseFile.getContainingDirectory(), - project - ) - ); - } else if (moduleData.getType().equals(ComponentType.theme)) { - pathComponents = getThemePathComponents(baseFile); + if (baseFile.getVirtualFile().getExtension().equals(OverridableFileType.JS.getType())) { + pathComponents = getLibPathComponets(baseFile); + } else { + return; + } } else { - return; + + if (moduleData.getType().equals(ComponentType.module)) { + pathComponents = getModulePathComponents( + baseFile, + GetComponentNameByDirectoryUtil.execute( + baseFile.getContainingDirectory(), + project + ) + ); + } else if (moduleData.getType().equals(ComponentType.theme)) { + pathComponents = getThemePathComponents(baseFile); + } else { + return; + } } final ModuleIndex moduleIndex = new ModuleIndex(project); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/js/RequireJsConfigGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/js/RequireJsConfigGenerator.java new file mode 100644 index 000000000..7df2d3c08 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/js/RequireJsConfigGenerator.java @@ -0,0 +1,51 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.js; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.generator.FileGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; +import com.magento.idea.magento2plugin.magento.files.RequireConfigJsFile; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + + +public class RequireJsConfigGenerator extends FileGenerator { + + private final PsiDirectory directory; + + public RequireJsConfigGenerator( + final @NotNull Project project, + final @NotNull PsiDirectory directory + ) { + super(project); + this.directory = directory; + } + + @Override + public PsiFile generate(final @NotNull String actionName) { + final RequireConfigJsFile file = new RequireConfigJsFile(); + PsiFile configFile = directory.findFile(file.getFileName()); + + if (configFile == null) { + final FileFromTemplateGenerator generator = new FileFromTemplateGenerator(project); + configFile = generator.generate( + file, + new Properties(), + directory, + actionName + ); + } + + return configFile; + } + + @SuppressWarnings("PMD.UncommentedEmptyMethodBody") + @Override + protected void fillAttributes(final Properties attributes) {} +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/RequireConfigJsFile.java b/src/com/magento/idea/magento2plugin/magento/files/RequireConfigJsFile.java new file mode 100644 index 000000000..86659aa05 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/RequireConfigJsFile.java @@ -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.javascript.JavascriptLanguage; + +public class RequireConfigJsFile implements ModuleFileInterface { + + public static final String TEMPLATE = "Require Config JS File"; + public static final String FILE_NAME = "requirejs-config.js"; + + public static final String MAP_PROPERTY = "map"; + public static final String ASTERISK_PROPERTY = "*"; + + @Override + public String getFileName() { + return FILE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return JavascriptLanguage.INSTANCE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/OverridableFileType.java b/src/com/magento/idea/magento2plugin/magento/packages/OverridableFileType.java new file mode 100644 index 000000000..41347d2a9 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/OverridableFileType.java @@ -0,0 +1,102 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.packages; + +import java.util.ArrayList; +import java.util.List; + +public enum OverridableFileType { + + CSS("css"), + LESS("less"), + JS("js"), + PHTML("phtml"); + + private final String filetype; + + /** + * Overridable File Type constructor. + * + * @param filetype String + */ + OverridableFileType(final String filetype) { + this.filetype = filetype; + } + + /** + * Get overridable file type. + * + * @return String + */ + public String getType() { + return filetype; + } + + /** + * Checks if file extension is js. + * + * @param filetype String + * @return boolean + */ + public static Boolean isFileJS(final String filetype) { + return filetype.equals(OverridableFileType.JS.getType()); + } + + /** + * Checks is file extension is phtml. + * + * @param fileType String + * @return Boolean + */ + public static Boolean isFilePhtml(final String fileType) { + return fileType.equals(OverridableFileType.PHTML.getType()); + } + + /** + * Checks is file extension is less or css. + * @param fileType String + * @return Boolean + */ + public static Boolean isFileStyle(final String fileType) { + Boolean result = false; + final List fileStyleTypes = getStyleFileTypes(); + for (final String styleType : fileStyleTypes) { + if (styleType.equals(fileType)) { + result = true; + } + } + + return result; + } + + /** + * Get overridable file extensions. + * @return List + */ + public static List getOverwritableFileExtensions() { + final List fileTypes = new ArrayList<>(); + + fileTypes.add(OverridableFileType.CSS.getType()); + fileTypes.add(OverridableFileType.LESS.getType()); + fileTypes.add(OverridableFileType.PHTML.getType()); + fileTypes.add(OverridableFileType.JS.getType()); + + return fileTypes; + } + + /** + * Returns styles file extensions. + * @return List + */ + public static List getStyleFileTypes() { + final List styleFileTypes = new ArrayList<>(); + + styleFileTypes.add(OverridableFileType.CSS.getType()); + styleFileTypes.add(OverridableFileType.LESS.getType()); + + return styleFileTypes; + } +} From 18ab51d2eb8b2a90da61d2127e8162418db9dd61 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Fri, 25 Mar 2022 09:50:30 +0200 Subject: [PATCH 104/111] Fixed path suggestion --- .../idea/magento2plugin/project/SettingsForm.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/project/SettingsForm.java b/src/com/magento/idea/magento2plugin/project/SettingsForm.java index 6bd5386c3..55f747bf6 100644 --- a/src/com/magento/idea/magento2plugin/project/SettingsForm.java +++ b/src/com/magento/idea/magento2plugin/project/SettingsForm.java @@ -18,6 +18,7 @@ import com.magento.idea.magento2plugin.indexes.IndexManager; import com.magento.idea.magento2plugin.init.ConfigurationManager; import com.magento.idea.magento2plugin.magento.packages.MagentoComponentManager; +import com.magento.idea.magento2plugin.project.util.GetProjectBasePath; import com.magento.idea.magento2plugin.project.validator.SettingsFormValidator; import com.magento.idea.magento2plugin.util.magento.MagentoVersionUtil; import java.awt.event.MouseAdapter; @@ -197,13 +198,22 @@ private void addPathListener() { "Magento Root Directory", "Choose Magento root directory", this.magentoPath, - null, + project, descriptor, TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT ) { @Nullable @Override protected VirtualFile getInitialFile() { + + final String text = getComponentText(); + if (text.length() == 0) { + final VirtualFile file = GetProjectBasePath.execute(project); + if (file != null) { + return file; + } + } + return super.getInitialFile(); } }; From 1c515b8a689894031f8edb6abd0250c6f82eef1c Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Fri, 25 Mar 2022 10:15:34 +0200 Subject: [PATCH 105/111] Fixed adobe icon --- resources/META-INF/pluginIcon.svg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/META-INF/pluginIcon.svg b/resources/META-INF/pluginIcon.svg index 564f534c2..511dfcb73 100644 --- a/resources/META-INF/pluginIcon.svg +++ b/resources/META-INF/pluginIcon.svg @@ -1,7 +1,7 @@ - + + fill="#ffd700"/> \ No newline at end of file From 6956d714f2e4118e0e27f403e25a2f8eddb83bc3 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Fri, 25 Mar 2022 10:21:47 +0200 Subject: [PATCH 106/111] Fixed adobe icon 2 --- resources/META-INF/pluginIcon.svg | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/resources/META-INF/pluginIcon.svg b/resources/META-INF/pluginIcon.svg index 511dfcb73..2f02d0e39 100644 --- a/resources/META-INF/pluginIcon.svg +++ b/resources/META-INF/pluginIcon.svg @@ -1,7 +1,9 @@ - + + fill="#fff"/> + + \ No newline at end of file From 945bcdad51891367965467d5b5e92ccf475f18d1 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Fri, 25 Mar 2022 10:24:45 +0200 Subject: [PATCH 107/111] Code style fix --- resources/META-INF/pluginIcon.svg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/META-INF/pluginIcon.svg b/resources/META-INF/pluginIcon.svg index 2f02d0e39..28a1797c4 100644 --- a/resources/META-INF/pluginIcon.svg +++ b/resources/META-INF/pluginIcon.svg @@ -4,6 +4,6 @@ - - + + \ No newline at end of file From df473c99522234afc0c4c7fffca6aec23914914d Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 25 Mar 2022 11:42:23 +0200 Subject: [PATCH 108/111] 614: Added test coverage --- .../requirejs-config.js | 9 ++++ .../reference/BaseReferenceTestCase.java | 47 ++++++++++++++++++- .../js/RequireJsReferenceRegistrarTest.java | 15 ++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 testData/reference/js/RequireJsReferenceRegistrar/filePathInMixinDeclarationMustHaveReference/requirejs-config.js diff --git a/testData/reference/js/RequireJsReferenceRegistrar/filePathInMixinDeclarationMustHaveReference/requirejs-config.js b/testData/reference/js/RequireJsReferenceRegistrar/filePathInMixinDeclarationMustHaveReference/requirejs-config.js new file mode 100644 index 000000000..f4f72ba67 --- /dev/null +++ b/testData/reference/js/RequireJsReferenceRegistrar/filePathInMixinDeclarationMustHaveReference/requirejs-config.js @@ -0,0 +1,9 @@ +var config = { + config: { + mixins: { + 'Magento_Checkout/js/view/shipping': { + 'Foo_Bar/js/file': true + } + } + } +} diff --git a/tests/com/magento/idea/magento2plugin/reference/BaseReferenceTestCase.java b/tests/com/magento/idea/magento2plugin/reference/BaseReferenceTestCase.java index 560e685bb..4f50d8333 100644 --- a/tests/com/magento/idea/magento2plugin/reference/BaseReferenceTestCase.java +++ b/tests/com/magento/idea/magento2plugin/reference/BaseReferenceTestCase.java @@ -9,11 +9,13 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiReference; +import com.intellij.psi.PsiReferenceProvider; import com.intellij.psi.ResolveResult; import com.intellij.psi.impl.file.PsiDirectoryImpl; import com.intellij.psi.xml.XmlAttributeValue; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; +import com.intellij.util.ProcessingContext; import com.jetbrains.php.lang.psi.elements.Method; import com.jetbrains.php.lang.psi.elements.Parameter; import com.jetbrains.php.lang.psi.elements.ParameterList; @@ -21,6 +23,10 @@ import com.magento.idea.magento2plugin.inspections.BaseInspectionsTestCase; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.reference.xml.PolyVariantReferenceBase; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import org.jetbrains.annotations.Nullable; @SuppressWarnings({ @@ -36,6 +42,7 @@ protected void setUp() throws Exception { myFixture.setTestDataPath(testDataFolderPath); } + @SuppressWarnings("PMD.CognitiveComplexity") protected void assertHasReferenceToXmlAttributeValue(final String reference) { final PsiElement element = getElementFromCaret(); for (final PsiReference psiReference: element.getReferences()) { @@ -70,6 +77,7 @@ protected void assertHasReferenceToXmlAttributeValue(final String reference) { fail(String.format(referenceNotFound, reference)); } + @SuppressWarnings("PMD.CognitiveComplexity") protected void assertHasReferenceToXmlTag(final String tagName) { final PsiElement element = getElementFromCaret(); for (final PsiReference psiReference: element.getReferences()) { @@ -106,7 +114,40 @@ protected void assertHasReferenceToXmlTag(final String tagName) { protected void assertHasReferenceToFile(final String reference) { final PsiElement element = getElementFromCaret(); - for (final PsiReference psiReference : element.getReferences()) { + + assertHasReferenceToFile(reference, Arrays.asList(element.getReferences())); + } + + protected void assertHasReferenceToFile( + final String reference, + final Class providerClass + ) { + final PsiElement element = getLeafElementFromCaret(); + final List references = new ArrayList<>(); + + try { + final PsiReferenceProvider provider = providerClass.getConstructor().newInstance(); + references.addAll( + Arrays.asList( + provider.getReferencesByElement(element, new ProcessingContext()) + ) + ); + } catch (NoSuchMethodException + | IllegalAccessException + | InvocationTargetException + | InstantiationException exception + ) { + references.addAll(Arrays.asList(element.getReferences())); + } + + assertHasReferenceToFile(reference, references); + } + + protected void assertHasReferenceToFile( + final String reference, + final List references + ) { + for (final PsiReference psiReference : references) { final PsiElement resolved = psiReference.resolve(); if (!(resolved instanceof PsiFile)) { continue; @@ -250,4 +291,8 @@ protected void assertEmptyReference() { private PsiElement getElementFromCaret() { return myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent(); } + + private PsiElement getLeafElementFromCaret() { + return myFixture.getFile().findElementAt(myFixture.getCaretOffset()); + } } diff --git a/tests/com/magento/idea/magento2plugin/reference/js/RequireJsReferenceRegistrarTest.java b/tests/com/magento/idea/magento2plugin/reference/js/RequireJsReferenceRegistrarTest.java index 195c927cf..0ecb6f720 100644 --- a/tests/com/magento/idea/magento2plugin/reference/js/RequireJsReferenceRegistrarTest.java +++ b/tests/com/magento/idea/magento2plugin/reference/js/RequireJsReferenceRegistrarTest.java @@ -5,9 +5,12 @@ package com.magento.idea.magento2plugin.reference.js; +import com.magento.idea.magento2plugin.reference.provider.FilePathReferenceProvider; + public class RequireJsReferenceRegistrarTest extends ReferenceJsFixtureTestCase { private static final String FIXTURE_PATH = "test.js"; + private static final String MIXIN_FIXTURE_PATH = "requirejs-config.js"; /** * Mapped parameters should have reference to file. @@ -44,4 +47,16 @@ public void testLibInjectionParameterMustHaveReference() { assertHasReferenceToFile("/lib/web/testjs.js"); } + + /** + * Mixin declaration parameters should have reference to file. + */ + public void testFilePathInMixinDeclarationMustHaveReference() { + myFixture.configureByFile(getFixturePath(MIXIN_FIXTURE_PATH)); + + assertHasReferenceToFile( + "app/code/Foo/Bar/view/frontend/web/js/file.js", + FilePathReferenceProvider.class + ); + } } From 334b769263ef87892956fccfc6ed214401802735 Mon Sep 17 00:00:00 2001 From: Serhii Akulov Date: Fri, 25 Mar 2022 16:22:15 +0200 Subject: [PATCH 109/111] UCT-1030: added xml files --- .../inspections/xml/ModuleConfigFileInspection.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java b/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java index f4d77bfad..f241e1df3 100644 --- a/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java +++ b/src/com/magento/idea/magento2uct/inspections/xml/ModuleConfigFileInspection.java @@ -45,6 +45,15 @@ abstract class ModuleConfigFileInspection extends XmlSuppressableInspectionTool "mview.xml", "product_types.xml", "widget.xml", + "queue.xml", + "product_options.xml", + "export.xml", + "import.xml", + "analytics.xml", + "reports.xml", + "pdf.xml", + "cache.xml", + "validation.xml" }; private ProblemsHolder problemsHolder; From 71cfee9bbddaab3311a1200c1519f1371739f87b Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sun, 3 Apr 2022 14:35:07 +0300 Subject: [PATCH 110/111] Revert "Mainline EAV attribute generators" --- .github/workflows/gradle.yml | 3 +- resources/META-INF/plugin.xml | 9 - ... Category Admin Form XML Decoration.xml.ft | 7 - .../Magento Category Admin Form XML.xml.ft | 4 - ...omer Eav Attribute Data Patch Class.php.ft | 122 ---- ...er Eav Attribute Data Patch Class.php.html | 15 - ...ento Eav Attribute Data Patch Class.php.ft | 87 --- .../Magento Source Model Class.php.ft | 22 - resources/magento2/validation.properties | 1 - .../NewCustomerEavAttributeAction.java | 31 -- .../generation/data/CategoryEntityData.java | 202 ------- .../generation/data/CategoryFormXmlData.java | 58 -- .../generation/data/CustomerEntityData.java | 269 --------- .../data/EavEntityDataInterface.java | 74 --- .../generation/data/ProductEntityData.java | 275 --------- .../generation/data/SourceModelData.java | 52 -- .../dialog/NewCategoryEavAttributeDialog.form | 425 -------------- .../dialog/NewCategoryEavAttributeDialog.java | 274 --------- .../dialog/NewCustomerEavAttributeDialog.form | 465 ---------------- .../dialog/NewCustomerEavAttributeDialog.java | 338 ----------- .../dialog/NewProductEavAttributeDialog.form | 517 ----------------- .../dialog/NewProductEavAttributeDialog.java | 287 ---------- .../eavattribute/EavAttributeDialog.java | 526 ------------------ .../eavdialog/ApplyToVisibleListener.java | 28 - .../event/eavdialog/AttributeCodeAdapter.java | 46 -- ...AttributeSourcePanelComponentListener.java | 49 -- .../AttributeSourceRelationsItemListener.java | 28 - .../event/eavdialog/DataPatchNameAdapter.java | 88 --- .../EavAttributeInputItemListener.java | 47 -- .../OptionsPanelVisibilityChangeListener.java | 45 -- .../eavdialog/SourceModelNameAdapter.java | 54 -- .../util/SplitEavAttributeCodeUtil.java | 27 - .../dialog/util/eavdialog/AttributeUtil.java | 90 --- .../validator/annotation/RuleRegistry.java | 4 +- .../rule/CommaSeparatedStringRule.java | 22 - .../NewCategoryEavAttributeAction.java | 30 - .../eavattribute/NewEavAttributeAction.java | 60 -- .../NewProductEavAttributeAction.java | 30 - .../generator/CategoryFormXmlGenerator.java | 232 -------- .../CustomerEavAttributePatchGenerator.java | 114 ---- .../EavAttributeSetupPatchGenerator.java | 103 ---- .../GetFormElementByAttributeInputUtil.java | 43 -- .../generator/SourceModelGenerator.java | 74 --- .../GetAttributeOptionPropertiesUtil.java | 55 -- .../util/eav/AttributeMapperFactory.java | 28 - .../util/eav/AttributeMapperInterface.java | 14 - .../util/eav/CategoryAttributeMapper.java | 35 -- .../util/eav/CustomerAttributeMapper.java | 47 -- .../util/eav/DefaultAttributeMapper.java | 167 ------ .../util/eav/ProductAttributeMapper.java | 64 --- .../actions/groups/NewEavAttributeGroup.java | 30 - .../magento2plugin/indexes/IndexManager.java | 5 +- .../xml/ObserverDeclarationInspection.java | 8 +- .../magento/files/CategoryFormXmlFile.java | 44 -- .../CustomerEavAttributeDataPatchFile.java | 42 -- .../files/EavAttributeDataPatchFile.java | 36 -- .../magento/files/ProductTypeXml.java | 33 -- .../magento/files/SourceModelFile.java | 60 -- .../packages/eav/AttributeBackendModel.java | 21 - .../magento/packages/eav/AttributeInput.java | 48 -- .../packages/eav/AttributeProperty.java | 39 -- .../magento/packages/eav/AttributeScope.java | 22 - .../packages/eav/AttributeSourceModel.java | 25 - .../magento/packages/eav/AttributeType.java | 25 - .../magento/packages/eav/CustomerForm.java | 27 - .../packages/eav/DataPatchDependency.java | 26 - .../magento/packages/eav/EavEntity.java | 22 - .../uicomponent/AvailableSourcesByInput.java | 62 --- .../stubs/indexes/xml/ProductTypeIndex.java | 106 ---- .../idea/magento2plugin/util/RegExUtil.java | 3 - .../util/magento/GetProductTypesListUtil.java | 31 -- .../AddTestAttributeCategoryAttribute.php | 92 --- .../generateFormFile/category_form.xml | 7 - .../AddMultiselectTestCustomerAttribute.php | 139 ----- .../generateFile/AddTestAttribute.php | 97 ---- .../AddAppliedToAttribute.php | 98 ---- .../AddBooleanInputAttributeAttribute.php | 97 ---- .../AddAttributeWithCustomSourceAttribute.php | 97 ---- .../AddAttributeWithOptionsAttribute.php | 105 ---- .../generateFile/CustomSourceModel.php | 18 - .../CustomSourceModel.php | 18 - ...ributePropertySetupPatchGeneratorTest.java | 94 ---- ...tomerAttributeSetupPatchGeneratorTest.java | 63 --- ...ributePropertySetupPatchGeneratorTest.java | 215 ------- .../generator/SourceModelGeneratorTest.java | 61 -- 85 files changed, 5 insertions(+), 7598 deletions(-) delete mode 100644 resources/fileTemplates/code/Magento Category Admin Form XML Decoration.xml.ft delete mode 100644 resources/fileTemplates/internal/Magento Category Admin Form XML.xml.ft delete mode 100644 resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.ft delete mode 100644 resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.html delete mode 100644 resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft delete mode 100644 resources/fileTemplates/internal/Magento Source Model Class.php.ft delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/NewCustomerEavAttributeAction.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/CategoryEntityData.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/CustomerEntityData.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/ApplyToVisibleListener.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeCodeAdapter.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeSourcePanelComponentListener.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeSourceRelationsItemListener.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/EavAttributeInputItemListener.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/OptionsPanelVisibilityChangeListener.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/util/SplitEavAttributeCodeUtil.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/util/eavdialog/AttributeUtil.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/CommaSeparatedStringRule.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewEavAttributeAction.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/CategoryFormXmlGenerator.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/GetFormElementByAttributeInputUtil.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/GetAttributeOptionPropertiesUtil.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CategoryAttributeMapper.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CustomerAttributeMapper.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/groups/NewEavAttributeGroup.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/files/CategoryFormXmlFile.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/files/CustomerEavAttributeDataPatchFile.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchFile.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/files/ProductTypeXml.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/files/SourceModelFile.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeBackendModel.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInput.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeProperty.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScope.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeType.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/CustomerForm.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java delete mode 100644 src/com/magento/idea/magento2plugin/stubs/indexes/xml/ProductTypeIndex.java delete mode 100644 src/com/magento/idea/magento2plugin/util/magento/GetProductTypesListUtil.java delete mode 100644 testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php delete mode 100644 testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFormFile/category_form.xml delete mode 100644 testData/actions/generation/generator/CustomerAttributeSetupPatchGenerator/generateMultiselectAttributeDataPatch/AddMultiselectTestCustomerAttribute.php delete mode 100644 testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php delete mode 100644 testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php delete mode 100644 testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php delete mode 100644 testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php delete mode 100644 testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php delete mode 100644 testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php delete mode 100644 testData/actions/generation/generator/SourceModelGenerator/generateFileInCustomDirectory/CustomSourceModel.php delete mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/CategoryAttributePropertySetupPatchGeneratorTest.java delete mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/CustomerAttributeSetupPatchGeneratorTest.java delete mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java delete mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 6f92519b8..94244ea64 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -5,7 +5,7 @@ name: Run automated tests on: pull_request: - branches: [ master, '*-develop', 'mainline*' ] + branches: [ master, 4.3.0-develop ] jobs: build-linux: @@ -107,7 +107,6 @@ jobs: run: ./gradlew checkstyleCI -i --no-daemon env: MODIFIED_FILES: ${{ steps.file_changes.outputs.files}} - ACTIONS_STEP_DEBUG: true - name: Run PMD Quality Check run: ./gradlew pmdCI -i --no-daemon env: diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 81a8e1e67..74c52dbff 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -101,14 +101,6 @@ - - - - - - - - @@ -208,7 +200,6 @@ - diff --git a/resources/fileTemplates/code/Magento Category Admin Form XML Decoration.xml.ft b/resources/fileTemplates/code/Magento Category Admin Form XML Decoration.xml.ft deleted file mode 100644 index 09ce53202..000000000 --- a/resources/fileTemplates/code/Magento Category Admin Form XML Decoration.xml.ft +++ /dev/null @@ -1,7 +0,0 @@ -#if(${INCLUDE_FIELDSET}) -
-#end - -#if(${INCLUDE_FIELDSET}) -
-#end \ No newline at end of file diff --git a/resources/fileTemplates/internal/Magento Category Admin Form XML.xml.ft b/resources/fileTemplates/internal/Magento Category Admin Form XML.xml.ft deleted file mode 100644 index ffe195975..000000000 --- a/resources/fileTemplates/internal/Magento Category Admin Form XML.xml.ft +++ /dev/null @@ -1,4 +0,0 @@ - -
-
diff --git a/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.ft b/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.ft deleted file mode 100644 index 52d51a592..000000000 --- a/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.ft +++ /dev/null @@ -1,122 +0,0 @@ -moduleDataSetup = $moduleDataSetup; - $this->eavSetupFactory = $eavSetupFactory; - $this->eavConfig = $eavConfig; - $this->attributeResource = $attributeResource; - } - - /** - * Run code inside patch - * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert - * means run PatchInterface::revert() - * - * If we speak about data, under revert means: $transaction->rollback() - * - * @return $this - */ - public function apply() - { -/** @var ${EAV_SETUP} $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); - - $eavSetup->addAttribute( - ${ENTITY_CLASS}::ENTITY, - '${ATTRIBUTE_CODE}', - [ - #set ($attributeSet = ${ATTRIBUTE_SET}) - #foreach ($attribute in $attributeSet.split("->")) - $attribute - #end -] - ); - - $eavSetup->addAttributeToSet( - ${CUSTOMER_METADATA_INTERFACE}::ENTITY_TYPE_CUSTOMER, - ${CUSTOMER_METADATA_INTERFACE}::ATTRIBUTE_SET_ID_CUSTOMER, - null, - '${ATTRIBUTE_CODE}' - ); - - #if (${CUSTOMER_FORMS}) - $attribute = $this->eavConfig->getAttribute(${ENTITY_CLASS}::ENTITY, '${ATTRIBUTE_CODE}'); - $attribute->setData( - 'used_in_forms', - [${CUSTOMER_FORMS}] - ); - $this->attributeResource->save($attribute); - #end - - return $this; - } - - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } -} diff --git a/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.html b/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.html deleted file mode 100644 index 0a2028f8b..000000000 --- a/resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - -

- Data patch for the customer EAV attribute -

-
- - \ No newline at end of file diff --git a/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft b/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft deleted file mode 100644 index 7c6813869..000000000 --- a/resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft +++ /dev/null @@ -1,87 +0,0 @@ -moduleDataSetup = $moduleDataSetup; - $this->eavSetupFactory = $eavSetupFactory; - } - - /** - * Run code inside patch - * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert - * means run PatchInterface::revert() - * - * If we speak about data, under revert means: $transaction->rollback() - */ - public function apply() - { - /** @var ${EAV_SETUP} $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); - - $eavSetup->addAttribute( - ${ENTITY_CLASS}::ENTITY, - '${ATTRIBUTE_CODE}', - [ - #set ($attributeSet = ${ATTRIBUTE_SET}) - #foreach ($attribute in $attributeSet.split("->")) - $attribute - #end -] - ); - } - - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } -} diff --git a/resources/fileTemplates/internal/Magento Source Model Class.php.ft b/resources/fileTemplates/internal/Magento Source Model Class.php.ft deleted file mode 100644 index 108281c0e..000000000 --- a/resources/fileTemplates/internal/Magento Source Model Class.php.ft +++ /dev/null @@ -1,22 +0,0 @@ - options; - private Map optionsSortOrder; - - @Override - public void setCode(final String code) { - this.code = code; - } - - @Override - public void setType(final String type) { - this.type = type; - } - - @Override - public void setLabel(final String label) { - this.label = label; - } - - @Override - public void setInput(final String input) { - this.input = input; - } - - @Override - public void setNamespace(final String namespace) { - this.namespace = namespace; - } - - @Override - public void setModuleName(final String moduleName) { - this.moduleName = moduleName; - } - - @Override - public void setDirectory(final String directory) { - this.directory = directory; - } - - @Override - public void setDataPatchName(final String dataPatchName) { - this.dataPatchName = dataPatchName; - } - - @Override - public void setSource(final String source) { - this.source = source; - } - - @Override - public void setSortOrder(final int sortOrder) { - this.sortOrder = sortOrder; - } - - @Override - public void setOptions(final Map options) { - this.options = options; - } - - @Override - public void setOptionsSortOrder(final Map optionsSortOrder) { - this.optionsSortOrder = optionsSortOrder; - } - - @Override - public void setRequired(final boolean required) { - this.required = required; - } - - @Override - public void setVisible(final boolean visible) { - this.visible = visible; - } - - @Override - public void setBackendModel(final String model) { - this.backendModel = model; - } - - public void setGroup(final String group) { - this.group = group; - } - - public void setScope(final String scope) { - this.scope = scope; - } - - @Override - public String getCode() { - return code; - } - - @Override - public String getType() { - return type; - } - - @Override - public String getLabel() { - return label; - } - - @Override - public String getInput() { - return input; - } - - @Override - public String getNamespace() { - return namespace; - } - - @Override - public String getModuleName() { - return moduleName; - } - - @Override - public String getDirectory() { - return directory; - } - - @Override - public String getDataPatchName() { - return dataPatchName; - } - - @Override - public String getEntityClass() { - return EavEntity.CATEGORY.getEntityClass(); - } - - @Override - public String getSource() { - return source; - } - - @Override - public String getBackendModel() { - return backendModel; - } - - @Override - public int getSortOrder() { - return sortOrder; - } - - @Override - public Map getOptions() { - return options; - } - - @Override - public Map getOptionsSortOrder() { - return optionsSortOrder; - } - - @Override - public boolean isRequired() { - return this.required; - } - - @Override - public boolean isVisible() { - return this.visible; - } - - public String getGroup() { - return group; - } - - public String getScope() { - return scope; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java deleted file mode 100644 index 7598502e3..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/CategoryFormXmlData.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - * - */ - -package com.magento.idea.magento2plugin.actions.generation.data; - -import org.jetbrains.annotations.NotNull; - -public class CategoryFormXmlData { - private final String fieldSetName; - private final String fieldName; - private final String attributeInput; - private final int sortOrder; - - /** - * Category Form data class. - * - * @param fieldSetName name of the fieldset - * @param fieldName field name - * @param attributeInput attribute input - * @param sortOrder sort order - */ - public CategoryFormXmlData( - @NotNull final String fieldSetName, - @NotNull final String fieldName, - @NotNull final String attributeInput, - @NotNull final int sortOrder - ) { - this.fieldSetName = convertGroupNameToFieldSet(fieldSetName); - this.fieldName = fieldName; - this.attributeInput = attributeInput; - this.sortOrder = sortOrder; - } - - private String convertGroupNameToFieldSet(final String groupName) { - final String[] nameParts = groupName.toLowerCase().split(" ");//NOPMD - - return String.join("_", nameParts); - } - - public String getFieldSetName() { - return fieldSetName; - } - - public String getFieldName() { - return fieldName; - } - - public int getSortOrder() { - return sortOrder; - } - - public String getAttributeInput() { - return attributeInput; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/CustomerEntityData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/CustomerEntityData.java deleted file mode 100644 index db45bf7c7..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/CustomerEntityData.java +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.data; - -import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity; -import java.util.Map; - -@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessivePublicCount"}) -public class CustomerEntityData implements EavEntityDataInterface { - - private String code; - private String type; - private String label; - private String input; - private String namespace; - private String moduleName; - private String directory; - private String dataPatchName; - private String source; - private int sortOrder; - private Map options; - private String model; - private Map optionsSortOrder; - private boolean required; - private boolean visible; - private boolean userDefined; - private boolean useInAdminhtmlCustomerForm; - private boolean useInAdminhtmlCheckoutForm; - private boolean useInCustomerAccountCreateForm; - private boolean useInCustomerAccountEditForm; - private boolean usedInGrid; - private boolean visibleInGrid; - private boolean filterableInGrid; - private boolean system; - - @Override - public void setCode(final String code) { - this.code = code; - } - - @Override - public void setType(final String type) { - this.type = type; - } - - @Override - public void setLabel(final String label) { - this.label = label; - } - - @Override - public void setInput(final String input) { - this.input = input; - } - - @Override - public void setNamespace(final String namespace) { - this.namespace = namespace; - } - - @Override - public void setModuleName(final String moduleName) { - this.moduleName = moduleName; - } - - @Override - public void setDirectory(final String directory) { - this.directory = directory; - } - - @Override - public void setDataPatchName(final String dataPatchName) { - this.dataPatchName = dataPatchName; - } - - @Override - public void setSource(final String source) { - this.source = source; - } - - @Override - public void setSortOrder(final int sortOrder) { - this.sortOrder = sortOrder; - } - - @Override - public void setOptions(final Map options) { - this.options = options; - } - - @Override - public void setOptionsSortOrder(final Map optionsSortOrder) { - this.optionsSortOrder = optionsSortOrder; - } - - @Override - public void setRequired(final boolean required) { - this.required = required; - } - - @Override - public void setVisible(final boolean visible) { - this.visible = visible; - } - - @Override - public void setBackendModel(final String model) { - this.model = model; - } - - public void setUserDefined(final boolean userDefined) { - this.userDefined = userDefined; - } - - public void setUseInAdminhtmlCustomerForm(final boolean useInAdminhtmlCustomerForm) { - this.useInAdminhtmlCustomerForm = useInAdminhtmlCustomerForm; - } - - public void setUseInAdminhtmlCheckoutForm(final boolean useInAdminhtmlCheckoutForm) { - this.useInAdminhtmlCheckoutForm = useInAdminhtmlCheckoutForm; - } - - public void setUseInCustomerAccountCreateForm(final boolean useInCustomerAccountCreateForm) { - this.useInCustomerAccountCreateForm = useInCustomerAccountCreateForm; - } - - public void setUseInCustomerAccountEditForm(final boolean useInCustomerAccountEditForm) { - this.useInCustomerAccountEditForm = useInCustomerAccountEditForm; - } - - public void setUsedInGrid(final boolean usedInGrid) { - this.usedInGrid = usedInGrid; - } - - public void setVisibleInGrid(final boolean visibleInGrid) { - this.visibleInGrid = visibleInGrid; - } - - public void setFilterableInGrid(final boolean filterableInGrid) { - this.filterableInGrid = filterableInGrid; - } - - public void setSystem(final boolean system) { - this.system = system; - } - - @Override - public String getCode() { - return code; - } - - @Override - public String getType() { - return type; - } - - @Override - public String getLabel() { - return label; - } - - @Override - public String getInput() { - return input; - } - - @Override - public String getNamespace() { - return namespace; - } - - @Override - public String getModuleName() { - return moduleName; - } - - @Override - public String getDirectory() { - return directory; - } - - @Override - public String getDataPatchName() { - return dataPatchName; - } - - @Override - public String getEntityClass() { - return EavEntity.CUSTOMER.getEntityClass(); - } - - @Override - public String getSource() { - return source; - } - - @Override - public String getBackendModel() { - return null; - } - - @Override - public int getSortOrder() { - return sortOrder; - } - - @Override - public Map getOptions() { - return options; - } - - public String getModel() { - return model; - } - - @Override - public Map getOptionsSortOrder() { - return optionsSortOrder; - } - - @Override - public boolean isRequired() { - return required; - } - - @Override - public boolean isVisible() { - return visible; - } - - public boolean isUserDefined() { - return userDefined; - } - - public boolean isUseInAdminhtmlCustomerForm() { - return useInAdminhtmlCustomerForm; - } - - public boolean isUseInAdminhtmlCheckoutForm() { - return useInAdminhtmlCheckoutForm; - } - - public boolean isUseInCustomerAccountCreateForm() { - return useInCustomerAccountCreateForm; - } - - public boolean isUseInCustomerAccountEditForm() { - return useInCustomerAccountEditForm; - } - - public boolean isUsedInGrid() { - return usedInGrid; - } - - public boolean isVisibleInGrid() { - return visibleInGrid; - } - - public boolean isFilterableInGrid() { - return filterableInGrid; - } - - public boolean isSystem() { - return system; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java b/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java deleted file mode 100644 index f25f64f68..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/EavEntityDataInterface.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.data; - -import java.util.Map; - -@SuppressWarnings({"PMD.UnnecessaryModifier"}) -public interface EavEntityDataInterface { - - void setCode(final String code); - - void setType(final String type); - - void setLabel(final String label); - - void setInput(final String input); - - void setNamespace(final String namespace); - - void setModuleName(final String moduleName); - - void setDirectory(final String directory); - - void setDataPatchName(final String dataPatchName); - - void setSource(final String source); - - void setSortOrder(final int sortOrder); - - void setOptions(final Map options); - - void setOptionsSortOrder(final Map optionsSortOrder); - - void setRequired(final boolean required); - - void setVisible(final boolean visible); - - void setBackendModel(final String model); - - String getCode(); - - String getType(); - - String getLabel(); - - String getInput(); - - String getNamespace(); - - String getModuleName(); - - String getDirectory(); - - String getDataPatchName(); - - String getEntityClass(); - - String getSource(); - - String getBackendModel(); - - int getSortOrder(); - - Map getOptions(); - - Map getOptionsSortOrder(); - - boolean isRequired(); - - boolean isVisible(); -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java deleted file mode 100644 index 99ac0b70d..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.data; - -import com.magento.idea.magento2plugin.magento.files.EavAttributeDataPatchFile; -import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity; -import java.util.Map; - -@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessivePublicCount"}) -public class ProductEntityData implements EavEntityDataInterface { - private String group; - private String code; - private String type; - private String label; - private String input; - private String source; - private String scope; - private String applyTo; - private String backendModel; - private boolean required; - private boolean usedInGrid; - private boolean visibleInGrid; - private boolean filterableInGrid; - private boolean visible; - private boolean htmlAllowedOnFront; - private boolean visibleOnFront; - private int sortOrder; - private Map options; - private Map optionsSortOrder; - - private String dataPatchName; - private String namespace; - private String directory; - private String moduleName; - - /** - * Constructor. - */ - public ProductEntityData() { - this.required = false; - this.usedInGrid = false; - this.visibleInGrid = false; - this.filterableInGrid = false; - this.visible = true; - this.htmlAllowedOnFront = false; - this.visibleOnFront = false; - this.sortOrder = 0; - } - - public void setGroup(final String group) { - this.group = group; - } - - @Override - public void setCode(final String code) { - this.code = code; - } - - @Override - public void setType(final String type) { - this.type = type; - } - - @Override - public void setLabel(final String label) { - this.label = label; - } - - @Override - public void setInput(final String input) { - this.input = input; - } - - @Override - public void setSource(final String source) { - this.source = source; - } - - public void setScope(final String scope) { - this.scope = scope; - } - - public void setApplyTo(final String applyTo) { - this.applyTo = applyTo; - } - - @Override - public void setRequired(final boolean required) { - this.required = required; - } - - public void setUsedInGrid(final boolean usedInGrid) { - this.usedInGrid = usedInGrid; - } - - public void setVisibleInGrid(final boolean visibleInGrid) { - this.visibleInGrid = visibleInGrid; - } - - public void setFilterableInGrid(final boolean filterableInGrid) { - this.filterableInGrid = filterableInGrid; - } - - @Override - public void setVisible(final boolean visible) { - this.visible = visible; - } - - @Override - public void setBackendModel(final String model) { - this.backendModel = model; - } - - public void setHtmlAllowedOnFront(final boolean htmlAllowedOnFront) { - this.htmlAllowedOnFront = htmlAllowedOnFront; - } - - public void setVisibleOnFront(final boolean visibleOnFront) { - this.visibleOnFront = visibleOnFront; - } - - @Override - public void setSortOrder(final int sortOrder) { - this.sortOrder = sortOrder; - } - - @Override - public void setDataPatchName(final String dataPatchName) { - this.dataPatchName = dataPatchName; - } - - @Override - public void setNamespace(final String namespace) { - this.namespace = namespace; - } - - @Override - public void setDirectory(final String directory) { - this.directory = directory; - } - - @Override - public void setModuleName(final String moduleName) { - this.moduleName = moduleName; - } - - @Override - public void setOptions(final Map options) { - this.options = options; - } - - @Override - public void setOptionsSortOrder(final Map optionsSortOrder) { - this.optionsSortOrder = optionsSortOrder; - } - - @Override - public Map getOptions() { - return options; - } - - @Override - public Map getOptionsSortOrder() { - return optionsSortOrder; - } - - @Override - public String getCode() { - return code; - } - - @Override - public String getType() { - return type; - } - - @Override - public String getLabel() { - return label; - } - - @Override - public String getInput() { - return input; - } - - @Override - public String getNamespace() { - return namespace; - } - - @Override - public String getModuleName() { - return moduleName; - } - - @Override - public String getDirectory() { - if (directory == null) { - directory = EavAttributeDataPatchFile.DEFAULT_DIR; - } - - return directory; - } - - @Override - public String getDataPatchName() { - return dataPatchName; - } - - @Override - public String getEntityClass() { - return EavEntity.PRODUCT.getEntityClass(); - } - - public String getGroup() { - return group; - } - - @Override - public String getSource() { - return source; - } - - @Override - public String getBackendModel() { - return backendModel; - } - - public String getScope() { - return scope; - } - - public String getApplyTo() { - return applyTo; - } - - @Override - public boolean isRequired() { - return required; - } - - public boolean isUsedInGrid() { - return usedInGrid; - } - - public boolean isVisibleInGrid() { - return visibleInGrid; - } - - public boolean isFilterableInGrid() { - return filterableInGrid; - } - - @Override - public boolean isVisible() { - return visible; - } - - public boolean isHtmlAllowedOnFront() { - return htmlAllowedOnFront; - } - - public boolean isVisibleOnFront() { - return visibleOnFront; - } - - @Override - public int getSortOrder() { - return sortOrder; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java deleted file mode 100644 index c5c1b862e..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.data; - -import com.magento.idea.magento2plugin.magento.files.SourceModelFile; - -public class SourceModelData { - private String className; - private String moduleName; - private String directory; - - public String getClassName() { - return className; - } - - /** - * Get default namespace. - * - * @return String - */ - public String getModuleName() { - return moduleName; - } - - /** - * Get directory path. - * - * @return String - */ - public String getDirectory() { - if (this.directory == null) { - return SourceModelFile.DEFAULT_DIR; - } - - return this.directory; - } - - public void setClassName(final String className) { - this.className = className; - } - - public void setModuleName(final String moduleName) { - this.moduleName = moduleName; - } - - public void setDirectory(final String directory) { - this.directory = directory; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form deleted file mode 100644 index 09e1bdc5a..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form +++ /dev/null @@ -1,425 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java deleted file mode 100644 index 494e5c28e..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.magento.idea.magento2plugin.actions.generation.data.CategoryEntityData; -import com.magento.idea.magento2plugin.actions.generation.data.CategoryFormXmlData; -import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; -import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; -import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; -import com.magento.idea.magento2plugin.actions.generation.dialog.util.eavdialog.AttributeUtil; -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.Lowercase; -import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; -import com.magento.idea.magento2plugin.actions.generation.generator.CategoryFormXmlGenerator; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTable; -import javax.swing.JTextField; - -@SuppressWarnings({ - "PMD.TooManyFields", - "PMD.ExcessiveImports", - "PMD.TooManyMethods", - "PMD.UnusedPrivateField" -}) -public class NewCategoryEavAttributeDialog extends EavAttributeDialog { - - private static final String ENTITY_NAME = "Category"; - private JPanel contentPanel; - private JButton buttonOK; - private JButton buttonCancel; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Code"}) - @FieldValidation(rule = RuleRegistry.LOWERCASE, - message = {Lowercase.MESSAGE, "Attribute Code"}) - private JTextField codeTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Label"}) - private JTextField labelTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Group"}) - private JTextField groupTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Data Patch Name"}) - private JTextField dataPatchNameTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) - @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, - message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) - private JTextField sortOrderTextField; - private JComboBox inputComboBox; - private JComboBox typeComboBox; - private JComboBox scopeComboBox; - private JComboBox sourceComboBox; - private JCheckBox requiredCheckBox; - private JCheckBox visibleCheckBox; - private JPanel sourcePanel; - private JPanel customSourceModelPanel; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Source Model Directory"}) - private JTextField sourceModelDirectoryTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Source Model Name"}) - private JTextField sourceModelNameTextField; - private JTable optionsTable; - private JButton addNewOptionButton; - private JPanel optionsPanel; - private JLabel codeTextFieldErrorMessage; - private JLabel labelTextFieldErrorMessage; - private JLabel dataPatchNameTextFieldErrorMessage; - private JLabel groupTextFieldErrorMessage; - private JLabel sourceModelDirectoryTextFieldErrorMessage; - private JLabel sourceModelNameTextFieldErrorMessage; - private JLabel sortOrderTextFieldErrorMessage; - - /** - * Constructor. - * - * @param project Project - * @param directory PsiDirectory - * @param actionName String - */ - public NewCategoryEavAttributeDialog( - final Project project, - final PsiDirectory directory, - final String actionName - ) { - super(project, directory, actionName); - } - - @Override - protected void initBaseDialogState() { - super.initBaseDialogState(); - fillAttributeScopeComboBoxes(); - } - - @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") - protected void fillAttributeScopeComboBoxes() { - for (final AttributeScope globalValue : AttributeScope.values()) { - scopeComboBox.addItem( - new ComboBoxItemData(globalValue.getScope(), globalValue.name()) - ); - } - } - - @Override - protected JPanel getContentPanel() { - return contentPanel; - } - - @Override - protected JButton getButtonOk() { - return buttonOK; - } - - @Override - protected JButton getButtonCancel() { - return buttonCancel; - } - - @Override - protected JComboBox getAttributeTypeCompoBox() { - return typeComboBox; - } - - @Override - protected JComboBox getAttributeInputComboBox() { - return inputComboBox; - } - - @Override - protected JTable getOptionsTable() { - return optionsTable; - } - - @Override - protected JButton getNewOptionButton() { - return addNewOptionButton; - } - - @Override - protected JComboBox getAttributeSourceComboBox() { - return sourceComboBox; - } - - @Override - protected JTextField getAttributeSourceModelNameTexField() { - return sourceModelNameTextField; - } - - @Override - protected JTextField getSourceModelDirectoryTextField() { - return sourceModelDirectoryTextField; - } - - @Override - protected JPanel getAttributeCustomSourceModelPanel() { - return customSourceModelPanel; - } - - @Override - protected JPanel getAttributeOptionsPanel() { - return optionsPanel; - } - - @Override - protected JTextField getAttributeCodeTextField() { - return codeTextField; - } - - @Override - protected JTextField getDataPatchNameTextField() { - return dataPatchNameTextField; - } - - @Override - protected JTextField getSourceModelNameTextField() { - return sourceModelNameTextField; - } - - @Override - protected JTextField getAttributeLabelTexField() { - return labelTextField; - } - - @Override - protected JTextField getAttributeSortOrderTextField() { - return sortOrderTextField; - } - - @Override - protected JCheckBox getAttributeRequiredCheckBox() { - return requiredCheckBox; - } - - @Override - protected JCheckBox getAttributeVisibleBox() { - return visibleCheckBox; - } - - @Override - protected String getEntityName() { - return ENTITY_NAME; - } - - @Override - protected EavEntityDataInterface getEavEntityData() { - return populateCategoryEntityData(new CategoryEntityData()); - } - - private CategoryEntityData populateCategoryEntityData( - final CategoryEntityData categoryEntityData - ) { - categoryEntityData.setModuleName(moduleName); - - categoryEntityData.setDataPatchName(getDataPatchName()); - categoryEntityData.setCode(getAttributeCode()); - categoryEntityData.setLabel(getAttributeLabel()); - categoryEntityData.setSortOrder(getAttributeSortOrder()); - categoryEntityData.setRequired(isRequiredAttribute()); - categoryEntityData.setVisible(isVisibleAttribute()); - categoryEntityData.setType(getAttributeBackendType()); - categoryEntityData.setInput(getAttributeInput()); - categoryEntityData.setScope( - AttributeUtil.getScopeClassBySelectedItem( - (ComboBoxItemData) scopeComboBox.getSelectedItem() - ) - ); - categoryEntityData.setSource(getAttributeSource(sourceModelData)); - categoryEntityData.setOptions( - getAttributeOptions(entityPropertiesTableGroupWrapper) - ); - categoryEntityData.setOptionsSortOrder( - getAttributeOptionsSortOrders(entityPropertiesTableGroupWrapper) - ); - - categoryEntityData.setGroup(groupTextField.getText().trim()); - - return categoryEntityData; - } - - @Override - protected void generateExtraFilesAfterDataPatchGeneration( - final EavEntityDataInterface eavEntityDataInterface - ) { - super.generateExtraFilesAfterDataPatchGeneration(eavEntityDataInterface); - generateCategoryAdminForm((CategoryEntityData) eavEntityDataInterface); - } - - private void generateCategoryAdminForm(final CategoryEntityData categoryEntityData) { - final CategoryFormXmlData categoryFormXmlData = new CategoryFormXmlData( - categoryEntityData.getGroup(), - categoryEntityData.getCode(), - categoryEntityData.getInput(), - categoryEntityData.getSortOrder() - ); - - new CategoryFormXmlGenerator( - categoryFormXmlData, - project, - moduleName - ).generate(actionName, false); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form deleted file mode 100644 index 1f26f958e..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form +++ /dev/null @@ -1,465 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java deleted file mode 100644 index 47da9a97b..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.magento.idea.magento2plugin.actions.generation.data.CustomerEntityData; -import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; -import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; -import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; -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.Lowercase; -import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; -import com.magento.idea.magento2plugin.actions.generation.generator.CustomerEavAttributePatchGenerator; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; -import com.magento.idea.magento2plugin.magento.packages.uicomponent.AvailableSourcesByInput; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.util.List; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTable; -import javax.swing.JTextField; - -@SuppressWarnings({ - "PMD.TooManyFields", - "PMD.ExcessiveImports", - "PMD.TooManyMethods", - "PMD.UnusedPrivateField" -}) -public class NewCustomerEavAttributeDialog extends EavAttributeDialog { - - private static final String ENTITY_NAME = "Customer"; - private JPanel contentPanel; - private JButton buttonOK; - private JButton buttonCancel; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Code"}) - @FieldValidation(rule = RuleRegistry.LOWERCASE, - message = {Lowercase.MESSAGE, "Attribute Code"}) - private JTextField codeTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Label"}) - private JTextField labelTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Data Patch Name"}) - private JTextField dataPatchNameTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) - @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, - message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) - private JTextField sortOrderTextField; - private JComboBox inputComboBox; - private JComboBox typeComboBox; - private JComboBox sourceComboBox; - private JCheckBox requiredCheckBox; - private JCheckBox visibleCheckBox; - private JPanel sourcePanel; - private JPanel customSourceModelPanel; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Source Model Directory"}) - private JTextField sourceModelDirectoryTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Source Model Name"}) - private JTextField sourceModelNameTextField; - private JTable optionsTable; - private JButton addNewOptionButton; - private JPanel optionsPanel; - private JLabel codeTextFieldErrorMessage; - private JLabel labelTextFieldErrorMessage; - private JLabel dataPatchNameTextFieldErrorMessage; - private JLabel sourceModelDirectoryTextFieldErrorMessage; - private JLabel sourceModelNameTextFieldErrorMessage; - private JLabel sortOrderTextFieldErrorMessage; - private JCheckBox userDefineCheckBox; - private JCheckBox useInAdminhtmlCustomerCheckBox; - private JCheckBox useInCustomerAccountCreateCheckBox; - private JCheckBox useInCustomerAccountEditCheckBox; - private JCheckBox useInGridCheckBox; - private JCheckBox filterableInGridCheckBox; - private JCheckBox visibleInGridCheckBox; - private JCheckBox systemAttributeCheckBox; - private JCheckBox useInAdminhtmlCheckoutCheckBox; - - /** - * Constructor. - * - * @param project Project - * @param directory PsiDirectory - * @param actionName String - */ - public NewCustomerEavAttributeDialog( - final Project project, - final PsiDirectory directory, - final String actionName - ) { - super(project, directory, actionName); - } - - @Override - protected JPanel getContentPanel() { - return contentPanel; - } - - @Override - protected JButton getButtonOk() { - return buttonOK; - } - - @Override - protected JButton getButtonCancel() { - return buttonCancel; - } - - @Override - protected JComboBox getAttributeTypeCompoBox() { - return typeComboBox; - } - - @Override - protected JComboBox getAttributeInputComboBox() { - return inputComboBox; - } - - @Override - protected JTable getOptionsTable() { - return optionsTable; - } - - @Override - protected JButton getNewOptionButton() { - return addNewOptionButton; - } - - @Override - protected JComboBox getAttributeSourceComboBox() { - return sourceComboBox; - } - - @Override - protected JTextField getAttributeSourceModelNameTexField() { - return sourceModelNameTextField; - } - - @Override - protected JTextField getSourceModelDirectoryTextField() { - return sourceModelDirectoryTextField; - } - - @Override - protected JPanel getAttributeCustomSourceModelPanel() { - return customSourceModelPanel; - } - - @Override - protected JPanel getAttributeOptionsPanel() { - return optionsPanel; - } - - @Override - protected JTextField getAttributeCodeTextField() { - return codeTextField; - } - - @Override - protected JTextField getDataPatchNameTextField() { - return dataPatchNameTextField; - } - - @Override - protected JTextField getSourceModelNameTextField() { - return sourceModelNameTextField; - } - - @Override - protected JTextField getAttributeLabelTexField() { - return labelTextField; - } - - @Override - protected JTextField getAttributeSortOrderTextField() { - return sortOrderTextField; - } - - @Override - protected JCheckBox getAttributeRequiredCheckBox() { - return requiredCheckBox; - } - - @Override - protected JCheckBox getAttributeVisibleBox() { - return visibleCheckBox; - } - - @Override - protected String getEntityName() { - return ENTITY_NAME; - } - - @Override - protected void generateDataPatchFile(final EavEntityDataInterface eavEntityDataInterface) { - new CustomerEavAttributePatchGenerator( - eavEntityDataInterface, - project, - true - ).generate(actionName, true); - } - - @Override - protected EavEntityDataInterface getEavEntityData() { - return populateCategoryEntityData(new CustomerEntityData()); - } - - private CustomerEntityData populateCategoryEntityData( - final CustomerEntityData customerEntityData - ) { - customerEntityData.setModuleName(moduleName); - customerEntityData.setType(getAttributeBackendType()); - customerEntityData.setDataPatchName(getDataPatchName()); - customerEntityData.setCode(getAttributeCode()); - customerEntityData.setLabel(getAttributeLabel()); - customerEntityData.setSortOrder(getAttributeSortOrder()); - customerEntityData.setRequired(isRequiredAttribute()); - customerEntityData.setVisible(isVisibleAttribute()); - customerEntityData.setInput(getAttributeInput()); - customerEntityData.setSource(getAttributeSource(sourceModelData)); - customerEntityData.setOptions( - getAttributeOptions(entityPropertiesTableGroupWrapper) - ); - customerEntityData.setOptionsSortOrder( - getAttributeOptionsSortOrders(entityPropertiesTableGroupWrapper) - ); - customerEntityData.setUserDefined(userDefineCheckBox.isSelected()); - customerEntityData.setUseInAdminhtmlCustomerForm( - useInAdminhtmlCustomerCheckBox.isSelected() - ); - customerEntityData.setUseInAdminhtmlCheckoutForm( - useInAdminhtmlCheckoutCheckBox.isSelected() - ); - customerEntityData.setUseInCustomerAccountCreateForm( - useInCustomerAccountCreateCheckBox.isSelected() - ); - customerEntityData.setUseInCustomerAccountEditForm( - useInCustomerAccountEditCheckBox.isSelected() - ); - customerEntityData.setVisibleInGrid(visibleInGridCheckBox.isSelected()); - customerEntityData.setUsedInGrid(useInGridCheckBox.isSelected()); - customerEntityData.setFilterableInGrid(filterableInGridCheckBox.isSelected()); - customerEntityData.setSystem(systemAttributeCheckBox.isSelected()); - - return customerEntityData; - } - - @Override - protected void addOptionPanelListener( - final JComboBox attributeSourceComboBox, - final JComboBox attributeInputComboBox, - final JPanel attributeOptionsPanel - ) { - if (attributeSourceComboBox == null - || attributeInputComboBox == null - || attributeOptionsPanel == null - ) { - return; - } - - attributeSourceComboBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(final ItemEvent itemEvent) { - final ComboBoxItemData selectedInputItem = - (ComboBoxItemData) attributeInputComboBox.getSelectedItem(); - final String selectedInput = selectedInputItem == null - ? "" : selectedInputItem.toString(); - final boolean isAllowedInput = - AttributeInput.SELECT.getInput().equals(selectedInput) - || AttributeInput.MULTISELECT.getInput().equals(selectedInput); - - attributeOptionsPanel.setVisible(isAllowedInput); - } - }); - } - - @Override - protected void setAttributeInputComboBoxAction( - final JComboBox sourceComboBox, - final JComboBox inputComboBox - ) { - if (sourceComboBox == null || inputComboBox == null) { - return; - } - - inputComboBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(final ItemEvent itemEvent) { - final String selectedInput = itemEvent.getItem().toString(); - - final List availableSources = - new AvailableSourcesByInput(selectedInput).getItems(); - sourceComboBox.removeAllItems(); - - if (!selectedInput.equals(AttributeInput.SELECT.getInput()) - || !selectedInput.equals(AttributeInput.MULTISELECT.getInput())) { - final ComboBoxItemData defaultSourceItem = new ComboBoxItemData( - AttributeSourceModel.NULLABLE_SOURCE.name(), - AttributeSourceModel.NULLABLE_SOURCE.getSource() - ); - - sourceComboBox.addItem(defaultSourceItem); - sourceComboBox.setSelectedItem(defaultSourceItem); - } - - if (availableSources.isEmpty()) { - return; - } - - for (final ComboBoxItemData comboBoxItemData : availableSources) { - sourceComboBox.addItem(comboBoxItemData); - - if (comboBoxItemData.getText().equals(AttributeSourceModel.TABLE.getSource())) { - sourceComboBox.setSelectedItem(comboBoxItemData); - } - } - } - }); - } - - private void createUIComponents() { //NOPMD - suppressed UnusedPrivateMethod - // TODO: place custom component creation code here - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form deleted file mode 100644 index fb8710dee..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form +++ /dev/null @@ -1,517 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java deleted file mode 100644 index faba8d9a1..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; -import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData; -import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; -import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.ApplyToVisibleListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.util.eavdialog.AttributeUtil; -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.magento.packages.eav.AttributeScope; -import com.magento.idea.magento2plugin.util.magento.GetProductTypesListUtil; -import java.util.List; -import javax.swing.DefaultListModel; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JTable; -import javax.swing.JTextField; - -@SuppressWarnings({ - "PMD.TooManyFields", - "PMD.ExcessiveImports", - "PMD.TooManyMethods", - "PMD.UnusedPrivateField" -}) -public class NewProductEavAttributeDialog extends EavAttributeDialog { - - private static final String ENTITY_NAME = "Product"; - private JPanel contentPanel; - private JButton buttonOK; - private JButton buttonCancel; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Code"}) - @FieldValidation(rule = RuleRegistry.LOWERCASE, - message = {Lowercase.MESSAGE, "Attribute Code"}) - private JTextField codeTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Label"}) - private JTextField labelTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Group"}) - private JTextField groupTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Data Patch Name"}) - private JTextField dataPatchNameTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) - @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, - message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) - private JTextField sortOrderTextField; - private JComboBox inputComboBox; - private JComboBox typeComboBox; - private JComboBox scopeComboBox; - private JComboBox sourceComboBox; - private JCheckBox requiredCheckBox; - private JCheckBox usedInGridGridCheckBox; - private JCheckBox visibleInGridCheckBox; - private JCheckBox filterableInGridCheckBox; - private JCheckBox visibleCheckBox; - private JCheckBox htmlAllowedOnCheckBox; - private JCheckBox visibleOnFrontCheckBox; - private JPanel sourcePanel; - private JPanel customSourceModelPanel; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Source Model Directory"}) - private JTextField sourceModelDirectoryTextField; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, "Source Model Name"}) - private JTextField sourceModelNameTextField; - private JTable optionsTable; - private JButton addNewOptionButton; - private JPanel optionsPanel; - @FieldValidation(rule = RuleRegistry.COMMA_SEPARATED_STRING, - message = {CommaSeparatedStringRule.MESSAGE, "Apply To"}) - private JCheckBox applyToAllProductsCheckBox; - private JPanel applyToPanel; - private JList productsTypesList; - private JLabel labelTextFieldErrorMessage; - private JLabel codeTextFieldErrorMessage; - private JLabel dataPatchNameTextFieldErrorMessage; - private JLabel groupTextFieldErrorMessage; - private JLabel sourceModelDirectoryTextFieldErrorMessage; - private JLabel sourceModelNameTextFieldErrorMessage; - private JLabel sortOrderTextFieldErrorMessage; - - /** - * Constructor. - * - * @param project Project - * @param directory PsiDirectory - */ - public NewProductEavAttributeDialog( - final Project project, - final PsiDirectory directory, - final String actionName - ) { - super(project, directory, actionName); - } - - @Override - protected void initBaseDialogState() { - super.initBaseDialogState(); - fillAttributeScopeComboBoxes(); - addApplyToVisibilityAction(); - fillProductsTypesList(); - } - - @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") - protected void fillAttributeScopeComboBoxes() { - for (final AttributeScope globalValue : AttributeScope.values()) { - scopeComboBox.addItem( - new ComboBoxItemData(globalValue.getScope(), globalValue.name()) - ); - } - } - - @Override - protected JPanel getContentPanel() { - return contentPanel; - } - - @Override - protected JButton getButtonOk() { - return buttonOK; - } - - @Override - protected JButton getButtonCancel() { - return buttonCancel; - } - - @Override - protected JComboBox getAttributeTypeCompoBox() { - return typeComboBox; - } - - @Override - protected JComboBox getAttributeInputComboBox() { - return inputComboBox; - } - - @Override - protected JTable getOptionsTable() { - return optionsTable; - } - - @Override - protected JButton getNewOptionButton() { - return addNewOptionButton; - } - - @Override - protected JComboBox getAttributeSourceComboBox() { - return sourceComboBox; - } - - @Override - protected JTextField getAttributeSourceModelNameTexField() { - return sourceModelNameTextField; - } - - @Override - protected JTextField getSourceModelDirectoryTextField() { - return sourceModelDirectoryTextField; - } - - @Override - protected JPanel getAttributeCustomSourceModelPanel() { - return customSourceModelPanel; - } - - @Override - protected JPanel getAttributeOptionsPanel() { - return optionsPanel; - } - - @Override - protected JTextField getAttributeCodeTextField() { - return codeTextField; - } - - @Override - protected JTextField getDataPatchNameTextField() { - return dataPatchNameTextField; - } - - @Override - protected JTextField getSourceModelNameTextField() { - return sourceModelNameTextField; - } - - @Override - protected JTextField getAttributeLabelTexField() { - return labelTextField; - } - - @Override - protected JTextField getAttributeSortOrderTextField() { - return sortOrderTextField; - } - - @Override - protected JCheckBox getAttributeRequiredCheckBox() { - return requiredCheckBox; - } - - @Override - protected JCheckBox getAttributeVisibleBox() { - return visibleCheckBox; - } - - @Override - protected String getEntityName() { - return ENTITY_NAME; - } - - @Override - protected EavEntityDataInterface getEavEntityData() { - return populateProductEntityData(new ProductEntityData()); - } - - private ProductEntityData populateProductEntityData(final ProductEntityData productEntityData) { - productEntityData.setModuleName(moduleName); - - productEntityData.setDataPatchName(getDataPatchName()); - productEntityData.setCode(getAttributeCode()); - productEntityData.setLabel(getAttributeLabel()); - productEntityData.setSortOrder(getAttributeSortOrder()); - productEntityData.setRequired(isRequiredAttribute()); - productEntityData.setVisible(isVisibleAttribute()); - productEntityData.setGroup(groupTextField.getText().trim()); - productEntityData.setUsedInGrid(usedInGridGridCheckBox.isSelected()); - productEntityData.setVisibleInGrid(visibleInGridCheckBox.isSelected()); - productEntityData.setFilterableInGrid(filterableInGridCheckBox.isSelected()); - productEntityData.setHtmlAllowedOnFront(htmlAllowedOnCheckBox.isSelected()); - productEntityData.setVisibleOnFront(visibleOnFrontCheckBox.isSelected()); - productEntityData.setType(getAttributeBackendType()); - productEntityData.setInput(getAttributeInput()); - productEntityData.setScope( - AttributeUtil.getScopeClassBySelectedItem( - (ComboBoxItemData) scopeComboBox.getSelectedItem() - ) - ); - productEntityData.setSource(getAttributeSource(sourceModelData)); - productEntityData.setOptions( - getAttributeOptions(entityPropertiesTableGroupWrapper) - ); - productEntityData.setOptionsSortOrder( - getAttributeOptionsSortOrders(entityPropertiesTableGroupWrapper) - ); - - if (!applyToAllProductsCheckBox.isSelected()) { - productEntityData.setApplyTo( - String.join(",", productsTypesList.getSelectedValuesList()) - ); - } - - return productEntityData; - } - - protected void addApplyToVisibilityAction() { - applyToAllProductsCheckBox.addChangeListener(new ApplyToVisibleListener(applyToPanel)); - } - - private void fillProductsTypesList() { - final List productTypes = GetProductTypesListUtil.execute(project); - - final DefaultListModel listModel = new DefaultListModel<>(); - listModel.addAll(productTypes); - productsTypesList.setModel(listModel); - productsTypesList.setSelectedIndex(0); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java deleted file mode 100644 index 885baff52..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java +++ /dev/null @@ -1,526 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; -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.AbstractDialog; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeCodeAdapter; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourcePanelComponentListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourceRelationsItemListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.DataPatchNameAdapter; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.EavAttributeInputItemListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.OptionsPanelVisibilityChangeListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.SourceModelNameAdapter; -import com.magento.idea.magento2plugin.actions.generation.dialog.util.eavdialog.AttributeUtil; -import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.GetAttributeOptionPropertiesUtil; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType; -import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; -import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.KeyStroke; -import org.jetbrains.annotations.NotNull; - -@SuppressWarnings({ - "PMD.GodClass", - "PMD.TooManyMethods", - "PMD.ExcessiveImports", - "PMD.AccessorMethodGeneration" -}) -public abstract class EavAttributeDialog extends AbstractDialog { - - protected String moduleName; - protected Project project; - protected String actionName; - protected TableGroupWrapper entityPropertiesTableGroupWrapper; - protected SourceModelData sourceModelData; - - protected abstract EavEntityDataInterface getEavEntityData(); - - protected abstract JPanel getContentPanel(); - - protected abstract JButton getButtonOk(); - - protected abstract JButton getButtonCancel(); - - protected abstract JComboBox getAttributeTypeCompoBox(); - - protected abstract JComboBox getAttributeInputComboBox(); - - protected abstract JTable getOptionsTable(); - - protected abstract JButton getNewOptionButton(); - - protected abstract JComboBox getAttributeSourceComboBox(); - - protected abstract JTextField getAttributeSourceModelNameTexField(); - - protected abstract JTextField getSourceModelDirectoryTextField(); - - protected abstract JPanel getAttributeCustomSourceModelPanel(); - - protected abstract JPanel getAttributeOptionsPanel(); - - protected abstract JTextField getAttributeCodeTextField(); - - protected abstract JTextField getDataPatchNameTextField(); - - protected abstract JTextField getSourceModelNameTextField(); - - protected abstract JTextField getAttributeLabelTexField(); - - protected abstract JTextField getAttributeSortOrderTextField(); - - protected abstract JCheckBox getAttributeRequiredCheckBox(); - - protected abstract JCheckBox getAttributeVisibleBox(); - - protected abstract String getEntityName(); - - /** - * Constructor. - * - * @param project Project - * @param directory PsiDirectory - * @param actionName String - */ - public EavAttributeDialog( - final Project project, - final PsiDirectory directory, - final String actionName - ) { - super(); - - this.project = project; - this.actionName = actionName; - this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); - this.sourceModelData = new SourceModelData(); - } - - /** - * Open dialog window. - */ - public void open() { - this.initBaseDialogState(); - pack(); - centerDialog(this); - setTitle(actionName); - setVisible(true); - } - - protected void initBaseDialogState() { - this.setPanelConfiguration(); - this.fillAttributeTypeComboBox(getAttributeTypeCompoBox()); - this.fillAttributeInputComboBox(getAttributeInputComboBox()); - - this.initPropertiesTable( - new LinkedList<>(Arrays.asList( - "Value", - "Sort Order" - )), - getOptionsTable(), - getNewOptionButton(), - getDefaultColumnsValues(), - getColumnsSources() - ); - - this.addActionListenersForOkButton(getButtonOk()); - this.addActionListenersForOkCancel(getButtonCancel()); - - this.addCancelActionForWindow(); - this.addCancelActionForEsc(); - - this.setAttributeInputComboBoxAction( - getAttributeSourceComboBox(), - getAttributeInputComboBox() - ); - this.setSourceComboBoxAction(getAttributeSourceComboBox()); - - this.setSourceModelPanelAction( - getAttributeCustomSourceModelPanel(), - getSourceModelDirectoryTextField() - ); - this.addOptionPanelListener( - getAttributeSourceComboBox(), - getAttributeInputComboBox(), - getAttributeOptionsPanel() - ); - this.setDefaultSources(getAttributeSourceComboBox()); - this.setAutocompleteListenerForAttributeCodeField( - getAttributeLabelTexField(), - getAttributeCodeTextField() - ); - this.setAutocompleteListenerForDataPathNameField( - getAttributeCodeTextField(), - getDataPatchNameTextField() - ); - this.setAutocompleteListenerForSourceModelNameField( - getAttributeCodeTextField(), - getSourceModelNameTextField() - ); - } - - protected void setPanelConfiguration() { - setContentPane(this.getContentPanel()); - setModal(this.isModalWindow()); - getRootPane().setDefaultButton(this.getButtonOk()); - } - - protected boolean isModalWindow() { - return true; - } - - @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") - protected void fillAttributeTypeComboBox(final JComboBox typeComboBox) { - if (typeComboBox == null) { - return; - } - - for (final AttributeType typeValue : AttributeType.values()) { - typeComboBox.addItem( - new ComboBoxItemData(typeValue.getType(), typeValue.getType()) - ); - } - } - - @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") - protected void fillAttributeInputComboBox(final JComboBox inputComboBox) { - if (inputComboBox == null) { - return; - } - - for (final AttributeInput inputValue : AttributeInput.values()) { - inputComboBox.addItem( - new ComboBoxItemData(inputValue.getInput(), inputValue.getInput()) - ); - } - } - - protected void initPropertiesTable( - final List columns, - final JTable optionsTable, - final JButton newOptionButton, - final Map defaultColumnsValues, - final Map> columnsSources - - ) { - // Initialize entity properties Table Group - entityPropertiesTableGroupWrapper = new TableGroupWrapper( - optionsTable, - newOptionButton, - columns, - defaultColumnsValues, - columnsSources - ); - entityPropertiesTableGroupWrapper.initTableGroup(); - } - - protected Map getDefaultColumnsValues() { - return new HashMap<>(); - } - - protected Map> getColumnsSources() { - return new HashMap<>(); - } - - protected void addActionListenersForOkButton(final JButton okButton) { - okButton.addActionListener(e -> onOk()); - } - - protected void addActionListenersForOkCancel(final JButton cancelButton) { - cancelButton.addActionListener(e -> onCancel()); - } - - protected void onOk() { - stopOptionsTableEditing(getOptionsTable()); - - if (!validateFormFields()) { - return; - } - - generateExtraFilesBeforeDataPatchGeneration(); - - final EavEntityDataInterface eavEntityDataInterface = getEavEntityData(); - generateDataPatchFile(eavEntityDataInterface); - generateExtraFilesAfterDataPatchGeneration(eavEntityDataInterface); - - setVisible(false); - } - - protected void generateSourceModelFile() { - final ComboBoxItemData selectedSource = - (ComboBoxItemData) getAttributeSourceComboBox().getSelectedItem(); - - if (selectedSource == null - || !selectedSource.getText().equals( - AttributeSourceModel.GENERATE_SOURCE.getSource() - )) { - return; - } - - sourceModelData.setModuleName(moduleName); - sourceModelData.setClassName(getAttributeSourceModelNameTexField().getText().trim()); - sourceModelData.setDirectory(getSourceModelDirectoryTextField().getText().trim()); - - new SourceModelGenerator(sourceModelData, project, true) - .generate(actionName, false); - } - - protected void generateDataPatchFile(final EavEntityDataInterface eavEntityDataInterface) { - new EavAttributeSetupPatchGenerator( - eavEntityDataInterface, - project, - true - ).generate(actionName, true); - } - - protected void generateExtraFilesBeforeDataPatchGeneration() { - generateSourceModelFile(); - } - - @SuppressWarnings({ - "PMD.EmptyMethodInAbstractClassShouldBeAbstract", - "PMD.UncommentedEmptyMethodBody" - }) - protected void generateExtraFilesAfterDataPatchGeneration( - final EavEntityDataInterface eavEntityDataInterface - ) {} - - protected void addCancelActionForWindow() { - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - } - - protected void addCancelActionForEsc() { - getContentPanel().registerKeyboardAction( - event -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); - } - - protected void setAttributeInputComboBoxAction( - final JComboBox sourceComboBox, - final JComboBox inputComboBox - ) { - if (sourceComboBox == null || inputComboBox == null) { - return; - } - - inputComboBox.addItemListener( - new EavAttributeInputItemListener(sourceComboBox) - ); - } - - protected void setSourceComboBoxAction(final JComboBox sourceComboBox) { - if (sourceComboBox == null) { - return; - } - - sourceComboBox.addItemListener( - new AttributeSourceRelationsItemListener(getAttributeCustomSourceModelPanel()) - ); - } - - protected void setSourceModelPanelAction( - final JPanel attributeCustomSourceModelPanel, - final JTextField sourceModelDirectoryTexField - ) { - if (attributeCustomSourceModelPanel == null || sourceModelDirectoryTexField == null) { - return; - } - - attributeCustomSourceModelPanel.addComponentListener( - new AttributeSourcePanelComponentListener(sourceModelDirectoryTexField) - ); - } - - protected void addOptionPanelListener( - final JComboBox attributeSourceComboBox, - final JComboBox attributeInputComboBox, - final JPanel attributeOptionsPanel - ) { - if (attributeSourceComboBox == null - || attributeInputComboBox == null - || attributeOptionsPanel == null - ) { - return; - } - - attributeSourceComboBox.addItemListener( - new OptionsPanelVisibilityChangeListener( - attributeOptionsPanel, - attributeInputComboBox - ) - ); - } - - protected void setDefaultSources(final JComboBox sourceComboBox) { - if (sourceComboBox == null) { - return; - } - - final ComboBoxItemData generateSourceItem = new ComboBoxItemData( - AttributeSourceModel.GENERATE_SOURCE.getSource(), - AttributeSourceModel.GENERATE_SOURCE.getSource() - ); - final ComboBoxItemData defaultSourceItem = new ComboBoxItemData( - AttributeSourceModel.NULLABLE_SOURCE.name(), - AttributeSourceModel.NULLABLE_SOURCE.getSource() - ); - - sourceComboBox.addItem(defaultSourceItem); - sourceComboBox.addItem(generateSourceItem); - - sourceComboBox.setSelectedItem(defaultSourceItem); - } - - protected void setAutocompleteListenerForAttributeCodeField( - @NotNull final JTextField attributeLabelTextField, - @NotNull final JTextField attributeCodeTextField - ) { - attributeLabelTextField.getDocument() - .addDocumentListener(new AttributeCodeAdapter(attributeCodeTextField)); - } - - protected void setAutocompleteListenerForDataPathNameField( - final JTextField mainTextField, - final JTextField dependentTextField - - ) { - if (mainTextField == null || dependentTextField == null) { - return; - } - - mainTextField.getDocument() - .addDocumentListener(new DataPatchNameAdapter(dependentTextField, getEntityName())); - } - - protected void setAutocompleteListenerForSourceModelNameField( - final JTextField mainTextField, - final JTextField dependentTextField - ) { - if (mainTextField == null || dependentTextField == null) { - return; - } - - mainTextField.getDocument() - .addDocumentListener(new SourceModelNameAdapter(dependentTextField)); - } - - protected String getDataPatchName() { - final JTextField dataPatchNameTextField = getDataPatchNameTextField(); - - return dataPatchNameTextField == null - ? "" : dataPatchNameTextField.getText().trim(); - } - - protected String getAttributeCode() { - final JTextField codeTextField = getAttributeCodeTextField(); - - return codeTextField == null - ? "" : codeTextField.getText().trim(); - } - - protected String getAttributeLabel() { - final JTextField labelTextField = getAttributeLabelTexField(); - - return labelTextField == null - ? "" : labelTextField.getText().trim(); - } - - protected int getAttributeSortOrder() { - final JTextField sortOrderTextField = getAttributeSortOrderTextField(); - - return sortOrderTextField == null - ? 0 : Integer.parseInt(sortOrderTextField.getText().trim()); - } - - protected boolean isRequiredAttribute() { - final JCheckBox requiredCheckBox = getAttributeRequiredCheckBox(); - - return requiredCheckBox != null && requiredCheckBox.isSelected(); - } - - protected boolean isVisibleAttribute() { - final JCheckBox visibleCheckBox = getAttributeVisibleBox(); - - return visibleCheckBox != null && visibleCheckBox.isSelected(); - } - - protected String getAttributeBackendType() { - final JComboBox typeComboBox = getAttributeTypeCompoBox(); - - return AttributeUtil.getBackendTypeBySelectedItem( - (ComboBoxItemData) typeComboBox.getSelectedItem() - ); - } - - protected String getAttributeInput() { - final JComboBox inputComboBox = getAttributeInputComboBox(); - - return AttributeUtil.getInputTypeBySelectedItem( - (ComboBoxItemData) inputComboBox.getSelectedItem() - ); - } - - protected String getAttributeSource(final SourceModelData sourceModelData) { - final JComboBox sourceComboBox = getAttributeSourceComboBox(); - - return AttributeUtil.getSourceClassBySelectedItem( - (ComboBoxItemData) sourceComboBox.getSelectedItem(), - sourceModelData - ); - } - - protected Map getAttributeOptions( - final TableGroupWrapper entityPropertiesTableGroupWrapper - ) { - return GetAttributeOptionPropertiesUtil.getValues( - entityPropertiesTableGroupWrapper.getColumnsData() - ); - } - - protected Map getAttributeOptionsSortOrders( - final TableGroupWrapper entityPropertiesTableGroupWrapper - ) { - return GetAttributeOptionPropertiesUtil.getSortOrders( - entityPropertiesTableGroupWrapper.getColumnsData() - ); - } - - private void stopOptionsTableEditing(final JTable optionsTable) { - if (optionsTable != null && optionsTable.isEditing()) { - optionsTable.getCellEditor().stopCellEditing(); - } - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/ApplyToVisibleListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/ApplyToVisibleListener.java deleted file mode 100644 index 1b9133e07..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/ApplyToVisibleListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; - -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(); - - applyToPanel.setVisible(!checkBox.isSelected()); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeCodeAdapter.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeCodeAdapter.java deleted file mode 100644 index a1143cdd7..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeCodeAdapter.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; - -import com.intellij.ui.DocumentAdapter; -import java.util.Locale; -import javax.swing.JTextField; -import javax.swing.event.DocumentEvent; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import org.jetbrains.annotations.NotNull; - -public class AttributeCodeAdapter extends DocumentAdapter { - - private final JTextField attributeCodeTextField; - - public AttributeCodeAdapter(@NotNull final JTextField attributeCodeTextField) { - super(); - this.attributeCodeTextField = attributeCodeTextField; - } - - @Override - protected void textChanged(final @NotNull DocumentEvent event) { - final Document document = event.getDocument(); - - try { - final String attributeLabel = document.getText( - 0, document.getEndPosition().getOffset() - ).trim(); - attributeCodeTextField.setText( - convertLabelToAttributeCode(attributeLabel) - ); - } catch (BadLocationException badLocationException) { - return; - } - } - - private String convertLabelToAttributeCode(final String attributeLabel) { - final String formattedAttributeLabel = attributeLabel.trim().toLowerCase(Locale.ROOT); - - return formattedAttributeLabel.replaceAll("^ +| +$|( )+", "_"); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeSourcePanelComponentListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeSourcePanelComponentListener.java deleted file mode 100644 index b7d1eaecd..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeSourcePanelComponentListener.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; - -import com.magento.idea.magento2plugin.magento.files.SourceModelFile; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; -import javax.swing.JTextField; - -public class AttributeSourcePanelComponentListener implements ComponentListener { - private final JTextField sourceModelDirectoryTexField; - - public AttributeSourcePanelComponentListener( - final JTextField sourceModelDirectoryTexField - ) { - this.sourceModelDirectoryTexField = sourceModelDirectoryTexField; - } - - @Override - public void componentResized(final ComponentEvent componentEvent) { - // - } - - @Override - public void componentMoved(final ComponentEvent componentEvent) { - // - } - - @Override - public void componentShown(final ComponentEvent componentEvent) { - initSetDirectoryFieldValue(); - } - - @Override - public void componentHidden(final ComponentEvent componentEvent) { - initSetDirectoryFieldValue(); - } - - private void initSetDirectoryFieldValue() { - final String sourceDirectoryValue = sourceModelDirectoryTexField.getText().trim(); - - if (sourceDirectoryValue.isEmpty()) { - sourceModelDirectoryTexField.setText(SourceModelFile.DEFAULT_DIR); - } - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeSourceRelationsItemListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeSourceRelationsItemListener.java deleted file mode 100644 index ccf84ceb3..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/AttributeSourceRelationsItemListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; - -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import javax.swing.JPanel; - -public class AttributeSourceRelationsItemListener implements ItemListener { - private final JPanel customSourcePanel; - - public AttributeSourceRelationsItemListener(final JPanel customSourcePanel) { - this.customSourcePanel = customSourcePanel; - } - - @Override - public void itemStateChanged(final ItemEvent itemEvent) { - final String selectedSource = itemEvent.getItem().toString(); - - customSourcePanel.setVisible( - selectedSource.equals(AttributeSourceModel.GENERATE_SOURCE.getSource()) - ); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java deleted file mode 100644 index 536b1a487..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/DataPatchNameAdapter.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; - -import com.intellij.ui.DocumentAdapter; -import com.magento.idea.magento2plugin.actions.generation.dialog.util.SplitEavAttributeCodeUtil; -import javax.swing.JTextField; -import javax.swing.event.DocumentEvent; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import org.codehaus.plexus.util.StringUtils; -import org.jetbrains.annotations.NotNull; - -public class DataPatchNameAdapter extends DocumentAdapter { - - private static final String NAME_PREFIX = "Add"; - private static final String NAME_SUFFIX = "Attribute"; - private final String entityType; - private final JTextField dataPatchNameTextField; - - /** - * Constructor. - * - * @param dataPatchNameTextField JTextField - */ - public DataPatchNameAdapter(final JTextField dataPatchNameTextField) { - super(); - - this.dataPatchNameTextField = dataPatchNameTextField; - entityType = ""; - } - - /** - * Constructor. - * - * @param dataPatchNameTextField JTextField - * @param entityType String - */ - public DataPatchNameAdapter( - final JTextField dataPatchNameTextField, - final String entityType - ) { - super(); - - this.dataPatchNameTextField = dataPatchNameTextField; - this.entityType = entityType; - } - - @Override - protected void textChanged(@NotNull final DocumentEvent event) { - final Document document = event.getDocument(); - - try { - final String attributeCode = document.getText( - 0, document.getEndPosition().getOffset() - ).trim(); - updateDataPatchFileName(attributeCode); - } catch (BadLocationException badLocationException) { - return; - } - } - - private void updateDataPatchFileName(final String attributeCode) { - if (attributeCode.isEmpty()) { - dataPatchNameTextField.setText(""); - - return; - } - - String fileName = ""; - - for (final String fileNamePart : SplitEavAttributeCodeUtil.execute(attributeCode)) { - fileName = String.join("", fileName, StringUtils.capitalise(fileNamePart)); - } - - dataPatchNameTextField.setText( - String.join( - "", - NAME_PREFIX, - fileName, - StringUtils.capitalise(entityType), NAME_SUFFIX - ) - ); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/EavAttributeInputItemListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/EavAttributeInputItemListener.java deleted file mode 100644 index fbe835fec..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/EavAttributeInputItemListener.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; - -import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; -import com.magento.idea.magento2plugin.magento.packages.uicomponent.AvailableSourcesByInput; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.util.List; -import javax.swing.JComboBox; - -public class EavAttributeInputItemListener implements ItemListener { - private final JComboBox sourceComboBox; - - public EavAttributeInputItemListener(final JComboBox sourceComboBox) { - this.sourceComboBox = sourceComboBox; - } - - @Override - public void itemStateChanged(final ItemEvent itemEvent) { - final String selectedInput = itemEvent.getItem().toString(); - - final List availableSources = - new AvailableSourcesByInput(selectedInput).getItems(); - sourceComboBox.removeAllItems(); - - final ComboBoxItemData defaultSourceItem = new ComboBoxItemData( - AttributeSourceModel.NULLABLE_SOURCE.name(), - AttributeSourceModel.NULLABLE_SOURCE.getSource() - ); - - sourceComboBox.addItem(defaultSourceItem); - sourceComboBox.setSelectedItem(defaultSourceItem); - - if (availableSources.isEmpty()) { - return; - } - - for (final ComboBoxItemData comboBoxItemData : availableSources) { - sourceComboBox.addItem(comboBoxItemData); - } - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/OptionsPanelVisibilityChangeListener.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/OptionsPanelVisibilityChangeListener.java deleted file mode 100644 index 6bc0cab76..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/OptionsPanelVisibilityChangeListener.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; - -import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import javax.swing.JComboBox; -import javax.swing.JPanel; -import org.jetbrains.annotations.NotNull; - -public class OptionsPanelVisibilityChangeListener implements ItemListener { - private final JPanel optionsPanel; - private final JComboBox inputComboBox; - - public OptionsPanelVisibilityChangeListener( - @NotNull final JPanel optionsPanel, - @NotNull final JComboBox inputComboBox - ) { - this.optionsPanel = optionsPanel; - this.inputComboBox = inputComboBox; - } - - @Override - public void itemStateChanged(final ItemEvent itemEvent) { - final String selectedSource = itemEvent.getItem().toString(); - - final ComboBoxItemData selectedInputItem = - (ComboBoxItemData) inputComboBox.getSelectedItem(); - final String selectedInput = selectedInputItem == null ? "" : selectedInputItem.toString(); - - final boolean isAttributeWithoutSource = - AttributeSourceModel.NULLABLE_SOURCE.getSource().equals(selectedSource); - final boolean isAllowedInput = - AttributeInput.SELECT.getInput().equals(selectedInput) - || AttributeInput.MULTISELECT.getInput().equals(selectedInput); - - optionsPanel.setVisible(isAllowedInput && isAttributeWithoutSource); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java deleted file mode 100644 index 1128e2ef1..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/event/eavdialog/SourceModelNameAdapter.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog; - -import com.intellij.ui.DocumentAdapter; -import com.magento.idea.magento2plugin.actions.generation.dialog.util.SplitEavAttributeCodeUtil; -import javax.swing.JTextField; -import javax.swing.event.DocumentEvent; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import org.codehaus.plexus.util.StringUtils; -import org.jetbrains.annotations.NotNull; - -public class SourceModelNameAdapter extends DocumentAdapter { - - private final JTextField sourceModelNameTexField; - - public SourceModelNameAdapter(final JTextField sourceModelNameTexField) { - super(); - this.sourceModelNameTexField = sourceModelNameTexField; - } - - @Override - protected void textChanged(@NotNull final DocumentEvent event) { - final Document document = event.getDocument(); - try { - final String attributeCode = document.getText( - 0, document.getEndPosition().getOffset() - ).trim(); - updateSourceModelName(attributeCode); - } catch (BadLocationException badLocationException) { - return; - } - } - - private void updateSourceModelName(final String attributeCode) { - if (attributeCode.isEmpty()) { - sourceModelNameTexField.setText(""); - - return; - } - - final StringBuilder sourceModelClassName = new StringBuilder(); - - for (final String codePart : SplitEavAttributeCodeUtil.execute(attributeCode)) { - sourceModelClassName.append(StringUtils.capitalise(codePart)); - } - - sourceModelNameTexField.setText(sourceModelClassName.toString()); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/SplitEavAttributeCodeUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/SplitEavAttributeCodeUtil.java deleted file mode 100644 index 3f70f962c..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/SplitEavAttributeCodeUtil.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - * - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.util; - -import org.jetbrains.annotations.NotNull; - -public final class SplitEavAttributeCodeUtil { - - public static final String ATTRIBUTE_SEPARATOR = "_"; - - private SplitEavAttributeCodeUtil(){} - - /** - * Return separated attribute code. - * - * @param attributeCode String - * @return String[] - */ - @NotNull - public static String[] execute(final String attributeCode) { - return attributeCode.split(ATTRIBUTE_SEPARATOR); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/eavdialog/AttributeUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/eavdialog/AttributeUtil.java deleted file mode 100644 index 1199fff64..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/eavdialog/AttributeUtil.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.util.eavdialog; - -import com.magento.idea.magento2plugin.actions.generation.data.SourceModelData; -import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; -import com.magento.idea.magento2plugin.magento.files.SourceModelFile; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; - -public final class AttributeUtil { - - private AttributeUtil() {} - - /** - * Return actual source class by selected item. - * - * @param selectedSourceItem ComboBoxItemData - * @param sourceModelData SourceModelData - * @return String - */ - public static String getSourceClassBySelectedItem( - final ComboBoxItemData selectedSourceItem, - final SourceModelData sourceModelData - ) { - if (selectedSourceItem == null - || selectedSourceItem.getText().equals( - AttributeSourceModel.NULLABLE_SOURCE.getSource() - )) { - return null; - } - - if (selectedSourceItem.getText().equals(AttributeSourceModel.GENERATE_SOURCE.getSource()) - && sourceModelData != null) { - - return "\\" + new SourceModelFile( - sourceModelData.getModuleName(), - sourceModelData.getClassName(), - sourceModelData.getDirectory() - ).getClassFqn(); - } - - return selectedSourceItem.toString(); - } - - /** - * Return actual scope class by selected item. - * - * @param selectedScopeItem ComboBoxItemData - * @return String - */ - public static String getScopeClassBySelectedItem(final ComboBoxItemData selectedScopeItem) { - if (selectedScopeItem != null) { - return selectedScopeItem.getKey().trim(); - } - - return AttributeScope.GLOBAL.getScope(); - } - - /** - * Return actual input type by selected item. - * - * @param selectedInputItem ComboBoxItemData - * @return String - */ - public static String getInputTypeBySelectedItem(final ComboBoxItemData selectedInputItem) { - if (selectedInputItem != null) { - return selectedInputItem.getText().trim(); - } - - return ""; - } - - /** - * Return actual backend type by selected item. - * - * @param selectedTypeItem ComboBoxItemData - * @return String - */ - public static String getBackendTypeBySelectedItem(final ComboBoxItemData selectedTypeItem) { - if (selectedTypeItem != null) { - return selectedTypeItem.getText(); - } - - return ""; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java index cf479956b..14a5ee1de 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java @@ -12,7 +12,6 @@ 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; @@ -60,8 +59,7 @@ public enum RuleRegistry { EXTENDED_NUMERIC(ExtendedNumericRule.class), TABLE_NAME_LENGTH(TableNameLength.class), MENU_IDENTIFIER(MenuIdentifierRule.class), - LAYOUT_NAME(LayoutNameRule.class), - COMMA_SEPARATED_STRING(CommaSeparatedStringRule.class); + LAYOUT_NAME(LayoutNameRule.class); private Class rule; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/CommaSeparatedStringRule.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/CommaSeparatedStringRule.java deleted file mode 100644 index a61a6a2d7..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/CommaSeparatedStringRule.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java deleted file mode 100644 index 446247f02..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.eavattribute; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.magento.idea.magento2plugin.MagentoIcons; -import com.magento.idea.magento2plugin.actions.generation.dialog.NewCategoryEavAttributeDialog; -import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; - -public class NewCategoryEavAttributeAction extends NewEavAttributeAction { - - public static final String ACTION_NAME = "Category Attribute"; - public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Catalog Attribute"; - - public NewCategoryEavAttributeAction() { - super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); - } - - @Override - protected EavAttributeDialog getDialogWindow( - final Project project, - final PsiDirectory directory - ) { - return new NewCategoryEavAttributeDialog(project, directory, ACTION_NAME); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewEavAttributeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewEavAttributeAction.java deleted file mode 100644 index 698917073..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewEavAttributeAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.eavattribute; - -import com.intellij.ide.IdeView; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.LangDataKeys; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; -import javax.swing.Icon; -import org.jetbrains.annotations.NotNull; - -public abstract class NewEavAttributeAction extends AnAction { - public NewEavAttributeAction( - final String actionName, - final String actionDescription, - final Icon icon - ) { - super(actionName, actionDescription, icon); - } - - @Override - public void actionPerformed(final @NotNull AnActionEvent event) { - final DataContext dataContext = event.getDataContext(); - final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); - if (view == null) { - return; - } - - final Project project = CommonDataKeys.PROJECT.getData(dataContext); - if (project == null) { - return; - } - - final PsiDirectory directory = view.getOrChooseDirectory(); - if (directory == null) { - return; - } - - final EavAttributeDialog eavAttributeDialog = getDialogWindow(project, directory); - eavAttributeDialog.open(); - } - - @Override - public boolean isDumbAware() { - return false; - } - - protected abstract EavAttributeDialog getDialogWindow( - Project project, - PsiDirectory directory - ); -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java b/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java deleted file mode 100644 index 1fa44915c..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.eavattribute; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.magento.idea.magento2plugin.MagentoIcons; -import com.magento.idea.magento2plugin.actions.generation.dialog.NewProductEavAttributeDialog; -import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; - -public class NewProductEavAttributeAction extends NewEavAttributeAction { - - public static final String ACTION_NAME = "Product Attribute"; - public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Product Attribute"; - - public NewProductEavAttributeAction() { - super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); - } - - @Override - protected EavAttributeDialog getDialogWindow( - final Project project, - final PsiDirectory directory - ) { - return new NewProductEavAttributeDialog(project, directory, ACTION_NAME); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/CategoryFormXmlGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/CategoryFormXmlGenerator.java deleted file mode 100644 index bc71ab122..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/CategoryFormXmlGenerator.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - * - */ - -package com.magento.idea.magento2plugin.actions.generation.generator; - -import com.intellij.openapi.command.WriteCommandAction; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiDocumentManager; -import com.intellij.psi.PsiFile; -import com.intellij.psi.codeStyle.CodeStyleManager; -import com.intellij.psi.xml.XmlFile; -import com.intellij.psi.xml.XmlTag; -import com.magento.idea.magento2plugin.actions.generation.data.CategoryFormXmlData; -import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.GetCodeTemplateUtil; -import com.magento.idea.magento2plugin.actions.generation.generator.util.XmlFilePositionUtil; -import com.magento.idea.magento2plugin.bundles.CommonBundle; -import com.magento.idea.magento2plugin.bundles.ValidatorBundle; -import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.CategoryFormXmlFile; -import com.magento.idea.magento2plugin.magento.packages.Areas; -import com.magento.idea.magento2plugin.magento.packages.File; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; -import com.magento.idea.magento2plugin.util.magento.FileBasedIndexUtil; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import javax.swing.JOptionPane; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class CategoryFormXmlGenerator extends FileGenerator { - - private final CategoryFormXmlData categoryFormXmlData; - private final String moduleName; - private final DirectoryGenerator directoryGenerator; - private final FileFromTemplateGenerator fileFromTemplateGenerator; - private final GetCodeTemplateUtil getCodeTemplateUtil; - private final XmlFilePositionUtil xmlFilePositionUtil; - private final ValidatorBundle validatorBundle; - private final CommonBundle commonBundle; - private boolean allowedFieldsetNodeInclude = true; - - /** - * Category form XML Generator. - * - * @param categoryFormXmlData Category form data class - * @param project Project - * @param moduleName module name - */ - public CategoryFormXmlGenerator( - final @NotNull CategoryFormXmlData categoryFormXmlData, - final @NotNull Project project, - final @NotNull String moduleName - ) { - super(project); - - this.categoryFormXmlData = categoryFormXmlData; - this.moduleName = moduleName; - this.directoryGenerator = DirectoryGenerator.getInstance(); - this.xmlFilePositionUtil = new XmlFilePositionUtil(); - this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); - this.getCodeTemplateUtil = new GetCodeTemplateUtil(project); - this.validatorBundle = new ValidatorBundle(); - this.commonBundle = new CommonBundle(); - } - - @Override - public PsiFile generate(final String actionName) { - final PsiDirectory directory = getFileDirectory(); - - PsiFile categoryAdminFormXmlFile = FileBasedIndexUtil.findModuleViewFile( - CategoryFormXmlFile.FILE_NAME, - Areas.getAreaByString(Areas.adminhtml.name()), - moduleName, - project, - CategoryFormXmlFile.SUB_DIRECTORY - ); - - if (categoryAdminFormXmlFile == null) { - categoryAdminFormXmlFile = fileFromTemplateGenerator.generate( - new CategoryFormXmlFile(), - new Properties(), - directory, - actionName - ); - } - - if (categoryAdminFormXmlFile == null) { - showDeclarationCannotBeCreatedDialog(); - return null; - } - - final XmlTag rootTag = ((XmlFile) categoryAdminFormXmlFile).getRootTag(); - - if (rootTag == null) { - showDeclarationCannotBeCreatedDialog(); - return null; - } - - final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project); - final Document document = psiDocumentManager.getDocument(categoryAdminFormXmlFile); - - - if (document == null) { - showDeclarationCannotBeCreatedDialog(); - return null; - } - - try { - final XmlTag matchedFieldsetByName = findMatchedFieldsetByName( - findFieldsetTagsInRoot(rootTag), - categoryFormXmlData.getFieldSetName() - ); - - allowedFieldsetNodeInclude = matchedFieldsetByName == null; - - writeInFile( - matchedFieldsetByName == null ? rootTag : matchedFieldsetByName, - psiDocumentManager, - document - ); - } catch (IOException e) { - showDeclarationCannotBeCreatedDialog(); - } - - return reformatFile(categoryAdminFormXmlFile); - } - - private void showDeclarationCannotBeCreatedDialog() { - JOptionPane.showMessageDialog( - null, - validatorBundle.message( - "validator.file.cantBeCreated", - "Category Admin Form XML file" - ), - commonBundle.message("common.error"), - JOptionPane.ERROR_MESSAGE - ); - } - - private PsiDirectory getFileDirectory() { - PsiDirectory directory = - new ModuleIndex(project).getModuleDirectoryByModuleName(moduleName); - - for (final String handlerDirectory: CategoryFormXmlFile.DIRECTORY.split(File.separator)) { - directory = directoryGenerator.findOrCreateSubdirectory( - directory, - handlerDirectory - ); - } - return directory; - } - - private void writeInFile( - final XmlTag targetTag, - final PsiDocumentManager psiDocumentManager, - final Document document - ) throws IOException { - final int insertPosition = xmlFilePositionUtil.getEndPositionOfTag(targetTag); - - final String declarationXml = - getCodeTemplateUtil.execute( - CategoryFormXmlFile.DECLARATION_TEMPLATE, - getAttributes() - ); - - WriteCommandAction.runWriteCommandAction(project, () -> { - document.insertString(insertPosition, declarationXml); - psiDocumentManager.commitDocument(document); - }); - } - - private PsiFile reformatFile(final PsiFile categoryAdminFormXmlFile) { - WriteCommandAction.runWriteCommandAction(project, () -> { - CodeStyleManager.getInstance(project).reformat(categoryAdminFormXmlFile); - }); - - return categoryAdminFormXmlFile; - } - - @NotNull - private List findFieldsetTagsInRoot(final XmlTag rootTag) { - final XmlTag[] subTags = rootTag.getSubTags(); - final List fieldsetList = new ArrayList<>(); - - for (final XmlTag subTag: subTags) { - if (subTag.getName().equals(CategoryFormXmlFile.XML_TAG_FIELDSET)) { - fieldsetList.add(subTag); - } - } - return fieldsetList; - } - - @Nullable - private XmlTag findMatchedFieldsetByName( - final List fieldsetList, - final String fieldsetName - ) { - for (final XmlTag fieldset: fieldsetList) { - final String attributeValue = fieldset.getAttributeValue( - CategoryFormXmlFile.XML_ATTR_FIELDSET_NAME - ); - if (attributeValue != null && attributeValue.equals(fieldsetName)) { - return fieldset; - } - } - - return null; - } - - @Override - protected void fillAttributes(final Properties attributes) { - attributes.setProperty("FIELDSET_NAME", categoryFormXmlData.getFieldSetName()); - attributes.setProperty("FIELD_NAME", categoryFormXmlData.getFieldName()); - attributes.setProperty("SORT_ORDER", Integer.toString(categoryFormXmlData.getSortOrder())); - attributes.setProperty("FORM_ELEMENT", GetFormElementByAttributeInputUtil.execute( - AttributeInput.getAttributeInputByCode(categoryFormXmlData.getAttributeInput()) - )); - - if (allowedFieldsetNodeInclude) { - attributes.setProperty("INCLUDE_FIELDSET", "include"); - } - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java deleted file mode 100644 index 890be334d..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.generator; - -import com.intellij.openapi.project.Project; -import com.magento.idea.magento2plugin.actions.generation.data.CustomerEntityData; -import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; -import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; -import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; -import com.magento.idea.magento2plugin.magento.files.CustomerEavAttributeDataPatchFile; -import com.magento.idea.magento2plugin.magento.packages.eav.CustomerForm; -import com.magento.idea.magento2plugin.magento.packages.eav.DataPatchDependency; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import org.jetbrains.annotations.NotNull; - -public class CustomerEavAttributePatchGenerator extends EavAttributeSetupPatchGenerator { - - private final EavEntityDataInterface data; - - public CustomerEavAttributePatchGenerator( - final @NotNull EavEntityDataInterface data, - final Project project - ) { - this(data, project, true); - } - - /** - * Php file generator constructor. - * - * @param project Project - * @param checkFileAlreadyExists boolean - */ - public CustomerEavAttributePatchGenerator( - final @NotNull EavEntityDataInterface data, - final @NotNull Project project, - final boolean checkFileAlreadyExists - ) { - super(data, project, checkFileAlreadyExists); - this.data = data; - } - - @Override - protected AbstractPhpFile initFile() { - return new CustomerEavAttributeDataPatchFile(data.getModuleName(), data.getDataPatchName()); - } - - @Override - protected void fillAttributes(final Properties attributes) { - super.fillAttributes(attributes); - phpClassTypesBuilder - .append( - "EAV_CONFIG_CLASS", - DataPatchDependency.EAV_CONFIG.getClassPatch() - ).append( - "ATTRIBUTE_RESOURCE", - DataPatchDependency.ATTRIBUTE_RESOURCE.getClassPatch() - ).append( - "CUSTOMER_METADATA_INTERFACE", - DataPatchDependency.CUSTOMER_METADATA_INTERFACE.getClassPatch() - ); - - final String selectedCustomerForms = getFormsForAttribute((CustomerEntityData) data); - - if (!selectedCustomerForms.isEmpty()) { - phpClassTypesBuilder.appendProperty("CUSTOMER_FORMS", selectedCustomerForms); - } - - phpClassTypesBuilder.mergeProperties(attributes); - - attributes.setProperty( - "USES", - PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()) - ); - } - - private String getFormsForAttribute(final CustomerEntityData customerEntityData) { - final List usedInForms = new ArrayList<>(); - - if (customerEntityData.isUseInAdminhtmlCustomerForm()) { - usedInForms.add( - "'" + CustomerForm.ADMINHTML_CUSTOMER.getFormCode() + "'" - ); - } - - if (customerEntityData.isUseInAdminhtmlCheckoutForm()) { - usedInForms.add( - "'" + CustomerForm.ADMINHTML_CHECKOUT.getFormCode() + "'" - ); - } - - if (customerEntityData.isUseInCustomerAccountCreateForm()) { - usedInForms.add( - "'" + CustomerForm.CUSTOMER_ACCOUNT_CREATE.getFormCode() + "'" - ); - } - - if (customerEntityData.isUseInCustomerAccountEditForm()) { - usedInForms.add( - "'" + CustomerForm.CUSTOMER_ACCOUNT_EDIT.getFormCode() + "'" - ); - } - - if (usedInForms.isEmpty()) { - return ""; - } - - return String.join(",", usedInForms); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java deleted file mode 100644 index 3339abf99..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.generator; - -import com.intellij.openapi.project.Project; -import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; -import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; -import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; -import com.magento.idea.magento2plugin.actions.generation.generator.util.eav.AttributeMapperFactory; -import com.magento.idea.magento2plugin.actions.generation.generator.util.eav.AttributeMapperInterface; -import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; -import com.magento.idea.magento2plugin.magento.files.EavAttributeDataPatchFile; -import com.magento.idea.magento2plugin.magento.packages.eav.DataPatchDependency; -import java.util.List; -import java.util.Properties; -import org.jetbrains.annotations.NotNull; - -public class EavAttributeSetupPatchGenerator extends PhpFileGenerator { - - private final EavEntityDataInterface data; - protected final PhpClassTypesBuilder phpClassTypesBuilder; - - /** - * Constructor. - * - * @param data EavEntityDataInterface - * @param project Project - */ - public EavAttributeSetupPatchGenerator( - final @NotNull EavEntityDataInterface data, - final Project project - ) { - this(data, project, true); - } - - /** - * Php file generator constructor. - * - * @param project Project - * @param checkFileAlreadyExists boolean - */ - public EavAttributeSetupPatchGenerator( - final @NotNull EavEntityDataInterface data, - final @NotNull Project project, - final boolean checkFileAlreadyExists - ) { - super(project, checkFileAlreadyExists); - this.data = data; - this.phpClassTypesBuilder = new PhpClassTypesBuilder(); - } - - @Override - protected AbstractPhpFile initFile() { - return new EavAttributeDataPatchFile(data.getModuleName(), data.getDataPatchName()); - } - - @Override - protected void fillAttributes(final Properties attributes) { - phpClassTypesBuilder - .appendProperty("CLASS_NAME", data.getDataPatchName()) - .appendProperty("NAMESPACE", this.getFile().getNamespace()) - .appendProperty("ENTITY_CLASS", data.getEntityClass()) - .appendProperty("ATTRIBUTE_CODE", data.getCode()) - .appendProperty("ATTRIBUTE_SET", String.join("->", getAttributesList(data))) - .append( - "IMPLEMENTS", - DataPatchDependency.DATA_PATCH_INTERFACE.getClassPatch() - ) - .append( - "ENTITY_CLASS", - data.getEntityClass() - ) - .append( - "MODULE_DATA_SETUP_INTERFACE", - DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch() - ) - .append( - "EAV_SETUP_FACTORY", - DataPatchDependency.EAV_SETUP_FACTORY.getClassPatch() - ) - .append( - "EAV_SETUP", - DataPatchDependency.ENV_SETUP.getClassPatch() - ) - .mergeProperties(attributes); - attributes.setProperty( - "USES", - PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()) - ); - } - - private List getAttributesList(final EavEntityDataInterface eavEntityData) { - final AttributeMapperFactory attributeMapperFactory = new AttributeMapperFactory(); - final AttributeMapperInterface attributeMapper = attributeMapperFactory.createByEntityClass( - eavEntityData.getEntityClass() - ); - - return attributeMapper.mapAttributesByEntityData(eavEntityData); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/GetFormElementByAttributeInputUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/GetFormElementByAttributeInputUtil.java deleted file mode 100644 index 078ab883f..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/GetFormElementByAttributeInputUtil.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - * - */ - -package com.magento.idea.magento2plugin.actions.generation.generator; - -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; -import com.magento.idea.magento2plugin.magento.packages.uicomponent.FormElementType; - -public final class GetFormElementByAttributeInputUtil { - - private GetFormElementByAttributeInputUtil(){} - - /** - * Returns for available form element by attribute input type. - * - * @param inputType AttributeInput - * @return String - */ - public static String execute(final AttributeInput inputType) { - switch (inputType) { - case TEXT: - return FormElementType.INPUT.getType(); - case TEXTAREA: - return FormElementType.TEXTAREA.getType(); - case BOOLEAN: - case SELECT: - return FormElementType.SELECT.getType(); - case MULTISELECT: - return FormElementType.MULTISELECT.getType(); - case DATE: - return FormElementType.DATE.getType(); - case PRICE: - return FormElementType.PRICE.getType(); - case HIDDEN: - return FormElementType.HIDDEN.getType(); - default: - return ""; - } - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java deleted file mode 100644 index 23dc558e6..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGenerator.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.generator; - -import com.intellij.openapi.project.Project; -import com.magento.idea.magento2plugin.actions.generation.data.SourceModelData; -import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; -import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; -import com.magento.idea.magento2plugin.magento.files.SourceModelFile; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import org.jetbrains.annotations.NotNull; - -public class SourceModelGenerator extends PhpFileGenerator { - private final SourceModelData data; - - /** - * Constructor. - * - * @param project Project - * @param data SourceModelData - */ - public SourceModelGenerator( - @NotNull final SourceModelData data, - @NotNull final Project project - ) { - this(data, project, true); - } - - /** - * Constructor. - * - * @param project Project - * @param data SourceModelData - * @param checkFileAlreadyExists boolean - */ - public SourceModelGenerator( - @NotNull final SourceModelData data, - @NotNull final Project project, - final boolean checkFileAlreadyExists - ) { - super(project, checkFileAlreadyExists); - this.data = data; - } - - @Override - protected AbstractPhpFile initFile() { - return new SourceModelFile( - data.getModuleName(), - data.getClassName(), - data.getDirectory() - ); - } - - @Override - protected void fillAttributes(final Properties attributes) { - final String abstractSourceClass = - "Magento\\Eav\\Model\\Entity\\Attribute\\Source\\AbstractSource"; - final List uses = new ArrayList<>(); - uses.add(abstractSourceClass); - - attributes.setProperty("NAME", data.getClassName()); - attributes.setProperty("NAMESPACE", this.getFile().getNamespace()); - attributes.setProperty( - "EXTENDS", - PhpClassGeneratorUtil.getNameFromFqn(abstractSourceClass) - ); - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/GetAttributeOptionPropertiesUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/GetAttributeOptionPropertiesUtil.java deleted file mode 100644 index 97620041b..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/GetAttributeOptionPropertiesUtil.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.generator.util; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.jetbrains.annotations.NotNull; - -public final class GetAttributeOptionPropertiesUtil { - public static final String OPTION_VALUE = "Value"; - public static final String OPTION_SORT_ORDER = "Sort Order"; - - private GetAttributeOptionPropertiesUtil() {} - - /** - * Returns sort orders for options. - * - * @param columnsData List - */ - public static Map getSortOrders( - @NotNull final List> columnsData - ) { - final Map sortOrders = new HashMap<>(); - - for (int i = 0; i < columnsData.size(); i++) { - final String sortOrder = columnsData.get(i).get(OPTION_SORT_ORDER); - if (!sortOrder.isEmpty()) { - sortOrders.put(i, sortOrder); - } - } - - return sortOrders; - } - - /** - * Returns options values. - * - * @param columnsData List - */ - public static Map getValues( - @NotNull final List> columnsData - ) { - final Map options = new HashMap<>(); - - for (int i = 0; i < columnsData.size(); i++) { - options.put(i, columnsData.get(i).get(OPTION_VALUE)); - } - - return options; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java deleted file mode 100644 index 1d9bf01d5..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperFactory.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; - -import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity; -import com.sun.istack.NotNull; - -public class AttributeMapperFactory { - /** - * Create entity mapper by entity class. - * - * @param entityClass String - */ - public AttributeMapperInterface createByEntityClass(@NotNull final String entityClass) { - if (entityClass.equals(EavEntity.PRODUCT.getEntityClass())) { - return new ProductAttributeMapper(); - } else if (entityClass.equals(EavEntity.CATEGORY.getEntityClass())) { - return new CategoryAttributeMapper(); - } else if (entityClass.equals(EavEntity.CUSTOMER.getEntityClass())) { - return new CustomerAttributeMapper(); - } - - return null; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java deleted file mode 100644 index f6ccb2b4c..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/AttributeMapperInterface.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; - -import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; -import com.sun.istack.NotNull; -import java.util.List; - -public interface AttributeMapperInterface { - List mapAttributesByEntityData(@NotNull EavEntityDataInterface entityData); -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CategoryAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CategoryAttributeMapper.java deleted file mode 100644 index b291e3e06..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CategoryAttributeMapper.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - * - */ - -package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; - -import com.magento.idea.magento2plugin.actions.generation.data.CategoryEntityData; -import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeProperty; -import java.util.Map; - -public class CategoryAttributeMapper extends DefaultAttributeMapper { - @Override - protected Map getMappedAttributes(final EavEntityDataInterface eavEntityData) { - final Map mappedAttributes = super.getMappedAttributes(eavEntityData); - final CategoryEntityData categoryEavEntityData = (CategoryEntityData) eavEntityData; - - mappedAttributes.put( - AttributeProperty.SORT_ORDER.getProperty(), - Integer.toString(categoryEavEntityData.getSortOrder()) - ); - mappedAttributes.put( - AttributeProperty.GLOBAL.getProperty(), - categoryEavEntityData.getScope() - ); - mappedAttributes.put( - AttributeProperty.GROUP.getProperty(), - wrapStringValueForTemplate(categoryEavEntityData.getGroup()) - ); - - return mappedAttributes; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CustomerAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CustomerAttributeMapper.java deleted file mode 100644 index fa74a6052..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/CustomerAttributeMapper.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; - -import com.magento.idea.magento2plugin.actions.generation.data.CustomerEntityData; -import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeProperty; -import java.util.Map; - -public class CustomerAttributeMapper extends DefaultAttributeMapper { - - @Override - protected Map getMappedAttributes(final EavEntityDataInterface eavEntityData) { - final Map mappedAttributes = super.getMappedAttributes(eavEntityData); - final CustomerEntityData customerEntityData = (CustomerEntityData) eavEntityData; - - mappedAttributes.put( - AttributeProperty.POSITION.getProperty(), - Integer.toString(customerEntityData.getSortOrder()) - ); - mappedAttributes.put( - AttributeProperty.USER_DEFINED.getProperty(), - Boolean.toString(customerEntityData.isUserDefined()) - ); - mappedAttributes.put( - AttributeProperty.IS_USED_IN_GRID.getProperty(), - Boolean.toString(customerEntityData.isUsedInGrid()) - ); - mappedAttributes.put( - AttributeProperty.IS_VISIBLE_IN_GRID.getProperty(), - Boolean.toString(customerEntityData.isVisibleInGrid()) - ); - mappedAttributes.put( - AttributeProperty.IS_FILTERABLE_IN_GRID.getProperty(), - Boolean.toString(customerEntityData.isFilterableInGrid()) - ); - mappedAttributes.put( - AttributeProperty.SYSTEM.getProperty(), - Boolean.toString(customerEntityData.isSystem()) - ); - - return mappedAttributes; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java deleted file mode 100644 index f209305c0..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/DefaultAttributeMapper.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; - -import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeBackendModel; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeProperty; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class DefaultAttributeMapper implements AttributeMapperInterface { - private static final String PHP_DOUBLE_ARROW_OPERATOR = " => "; - - @Override - public List mapAttributesByEntityData(final EavEntityDataInterface entityData) { - final List attributesWithValues = new ArrayList<>(); - - final Map mappedAttributes = getMappedAttributes(entityData); - - for (final Map.Entry attributePair : mappedAttributes.entrySet()) { - final String attributeKey = "'" + attributePair.getKey() + "'"; - final String attributeValue = attributePair.getValue(); - - attributesWithValues.add( - String.join("=>", attributeKey, attributeValue + ",") - ); - } - - return attributesWithValues; - } - - @SuppressWarnings({"PMD.NullAssignment"}) - protected Map getMappedAttributes(final EavEntityDataInterface eavEntityData) { - final Map mappedAttributes = new HashMap<>(); - mappedAttributes.put( - AttributeProperty.TYPE.getProperty(), - wrapStringValueForTemplate(eavEntityData.getType()) - ); - mappedAttributes.put( - AttributeProperty.LABEL.getProperty(), - wrapStringValueForTemplate(eavEntityData.getLabel()) - ); - mappedAttributes.put( - AttributeProperty.INPUT.getProperty(), - wrapStringValueForTemplate(eavEntityData.getInput()) - ); - mappedAttributes.put( - AttributeProperty.SOURCE.getProperty(), - getEntitySource(eavEntityData) - ); - mappedAttributes.put( - AttributeProperty.REQUIRED.getProperty(), - Boolean.toString(eavEntityData.isRequired()) - ); - mappedAttributes.put( - AttributeProperty.VISIBLE.getProperty(), - Boolean.toString(eavEntityData.isVisible()) - ); - - final String attributeOptions = getMappedOptions( - eavEntityData.getOptions(), - eavEntityData.getOptionsSortOrder() - ); - - if (!attributeOptions.isEmpty()) { - mappedAttributes.put( - AttributeProperty.OPTION.getProperty(), - getMappedOptions( - eavEntityData.getOptions(), - eavEntityData.getOptionsSortOrder() - ) - ); - } - - if (eavEntityData.getInput().equals(AttributeInput.MULTISELECT.getInput())) { - mappedAttributes.put( - AttributeProperty.BACKEND_MODEL.getProperty(), - wrapClassValueForTemplate(AttributeBackendModel.ARRAY.getModel()) - ); - } - - return mappedAttributes; - } - - protected String wrapStringValueForTemplate(final String value) { - return "'" + value + "'"; - } - - protected String wrapClassValueForTemplate(final String value) { - return value + "::class"; - } - - protected String getEntitySource(final EavEntityDataInterface eavEntityData) { - final String eavSource = eavEntityData.getSource(); - - return eavSource == null - || eavSource.equals(AttributeSourceModel.NULLABLE_SOURCE.getSource()) - ? null : wrapClassValueForTemplate(eavSource); - } - - protected String getMappedOptions( - final Map optionValues, - final Map optionSortOrders - ) { - if (optionValues == null || optionValues.isEmpty()) { - return ""; - } - - return "[" + getParsedOptions(optionValues) - + (optionSortOrders == null || optionSortOrders.isEmpty() - ? "->" : "," + getParsedOptionSortOrders(optionSortOrders)) + "]"; - } - - protected String getParsedOptions(final Map optionValues) { - final String valueNode = "->" + wrapStringValueForTemplate("value") - + PHP_DOUBLE_ARROW_OPERATOR; - final StringBuilder optionsContent = new StringBuilder(); - - for (final Integer optionKey : optionValues.keySet()) { - final String optionValue = optionValues.get(optionKey); - - if (optionValue.isEmpty()) { - continue; - } - - optionsContent - .append("->") - .append(wrapStringValueForTemplate("option_" + optionKey)) - .append(PHP_DOUBLE_ARROW_OPERATOR) - .append('[') - .append(wrapStringValueForTemplate(optionValue)) - .append("], "); - } - - return valueNode + "[" + optionsContent + "->]"; - } - - protected String getParsedOptionSortOrders(final Map optionSortOrders) { - final String orderNode = "->" + wrapStringValueForTemplate("order") - + PHP_DOUBLE_ARROW_OPERATOR; - final StringBuilder ordersContent = new StringBuilder(); - - for (final Integer optionKey : optionSortOrders.keySet()) { - final String orderValue = optionSortOrders.get(optionKey); - - if (orderValue.isEmpty()) { - continue; - } - - ordersContent - .append("->") - .append(wrapStringValueForTemplate("option_" + optionKey)) - .append(PHP_DOUBLE_ARROW_OPERATOR) - .append(orderValue) - .append(','); - } - - return orderNode + "[" + ordersContent + "->]->"; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java deleted file mode 100644 index 4dd4c7265..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/eav/ProductAttributeMapper.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.generator.util.eav; - -import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; -import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeProperty; -import java.util.Map; - -public class ProductAttributeMapper extends DefaultAttributeMapper { - - @SuppressWarnings({"PMD.NullAssignment"}) - @Override - protected Map getMappedAttributes(final EavEntityDataInterface eavEntityData) { - final Map mappedAttributes = super.getMappedAttributes(eavEntityData); - - final ProductEntityData productEavEntityData = (ProductEntityData) eavEntityData; - mappedAttributes.put( - AttributeProperty.SORT_ORDER.getProperty(), - Integer.toString(productEavEntityData.getSortOrder()) - ); - mappedAttributes.put( - AttributeProperty.GROUP.getProperty(), - wrapStringValueForTemplate(productEavEntityData.getGroup()) - ); - mappedAttributes.put( - AttributeProperty.GLOBAL.getProperty(), - productEavEntityData.getScope() - ); - mappedAttributes.put( - AttributeProperty.IS_USED_IN_GRID.getProperty(), - Boolean.toString(productEavEntityData.isUsedInGrid()) - ); - mappedAttributes.put( - AttributeProperty.IS_VISIBLE_IN_GRID.getProperty(), - Boolean.toString(productEavEntityData.isVisibleInGrid()) - ); - mappedAttributes.put( - AttributeProperty.IS_FILTERABLE_IN_GRID.getProperty(), - Boolean.toString(productEavEntityData.isFilterableInGrid()) - ); - mappedAttributes.put( - AttributeProperty.IS_HTML_ALLOWED_ON_FRONT.getProperty(), - Boolean.toString(productEavEntityData.isHtmlAllowedOnFront()) - ); - mappedAttributes.put( - AttributeProperty.VISIBLE_ON_FRONT.getProperty(), - Boolean.toString(productEavEntityData.isVisibleOnFront()) - ); - - if (productEavEntityData.getApplyTo() != null - && !productEavEntityData.getApplyTo().isEmpty()) { - mappedAttributes.put( - AttributeProperty.APPLY_TO.getProperty(), - wrapStringValueForTemplate(productEavEntityData.getApplyTo()) - ); - } - - return mappedAttributes; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/groups/NewEavAttributeGroup.java b/src/com/magento/idea/magento2plugin/actions/groups/NewEavAttributeGroup.java deleted file mode 100644 index c057e6c22..000000000 --- a/src/com/magento/idea/magento2plugin/actions/groups/NewEavAttributeGroup.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.groups; - -import com.intellij.ide.actions.NonTrivialActionGroup; -import com.intellij.openapi.util.IconLoader; -import com.magento.idea.magento2plugin.MagentoIcons; -import javax.swing.Icon; -import org.jetbrains.annotations.NotNull; - -public class NewEavAttributeGroup extends NonTrivialActionGroup { - - /** - * Group for Eav attribute generation actions. - */ - public NewEavAttributeGroup() { - super(); - - this.getTemplatePresentation().setIcon(new IconLoader.LazyIcon() { - @NotNull - @Override - protected Icon compute() { - return MagentoIcons.MODULE; - } - }); - } -} diff --git a/src/com/magento/idea/magento2plugin/indexes/IndexManager.java b/src/com/magento/idea/magento2plugin/indexes/IndexManager.java index 61c05fca5..56aaad711 100644 --- a/src/com/magento/idea/magento2plugin/indexes/IndexManager.java +++ b/src/com/magento/idea/magento2plugin/indexes/IndexManager.java @@ -29,7 +29,6 @@ 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"}) @@ -72,9 +71,7 @@ public static void manualReindex() { TestNameIndex.KEY, TestExtendsIndex.KEY, //graphql - GraphQlResolverIndex.KEY, - //product types - ProductTypeIndex.KEY + GraphQlResolverIndex.KEY }; for (final ID id: indexIds) { diff --git a/src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java b/src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java index 762c5e14d..b38a80a9c 100644 --- a/src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java +++ b/src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java @@ -3,7 +3,7 @@ * See COPYING.txt for license details. */ -package com.magento.idea.magento2plugin.inspections.xml; +package com.magento.idea.magento2plugin.inspections.xml;//NOPMD import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.codeInspection.ProblemsHolder; @@ -39,11 +39,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -@SuppressWarnings({ - "PMD.ExcessiveMethodLength", - "PMD.NPathComplexity", - "PMD.ExcessiveImports", -}) +@SuppressWarnings({"PMD.ExcessiveMethodLength", "PMD.NPathComplexity"}) public class ObserverDeclarationInspection extends PhpInspection { @NotNull diff --git a/src/com/magento/idea/magento2plugin/magento/files/CategoryFormXmlFile.java b/src/com/magento/idea/magento2plugin/magento/files/CategoryFormXmlFile.java deleted file mode 100644 index ae71b6e58..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/CategoryFormXmlFile.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 CategoryFormXmlFile implements ModuleFileInterface { - - public static final String FILE_NAME = "category_form.xml"; - public static final String TEMPLATE = "Magento Category Admin Form XML"; - public static final String DECLARATION_TEMPLATE = "Magento Category Admin Form XML Decoration"; - public static final String DIRECTORY = "view/adminhtml/ui_component"; - public static final String SUB_DIRECTORY = "ui_component"; - - //attributes - public static final String XML_ATTR_FIELDSET_NAME = "name"; - public static final String XML_ATTR_FIELD_NAME = "name"; - public static final String XML_ATTR_FIELD_SORT_ORDER = "sortOrder"; - public static final String XML_ATTR_FIELD_FORM_ELEMENT = "formElement"; - - //tags - public static final String XML_TAG_FIELDSET = "fieldset"; - public static final String XML_TAG_FIELD = "field"; - - @Override - public String getFileName() { - return FILE_NAME; - } - - @Override - public String getTemplate() { - return TEMPLATE; - } - - @Override - public Language getLanguage() { - return XMLLanguage.INSTANCE; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/files/CustomerEavAttributeDataPatchFile.java b/src/com/magento/idea/magento2plugin/magento/files/CustomerEavAttributeDataPatchFile.java deleted file mode 100644 index 02a90c03b..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/CustomerEavAttributeDataPatchFile.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.files; - -import org.jetbrains.annotations.NotNull; - -public class CustomerEavAttributeDataPatchFile extends AbstractPhpFile { - public static final String HUMAN_READABLE_NAME = "Customer Eav Attribute Data Patch Class"; - public static final String TEMPLATE = "Magento Customer Eav Attribute Data Patch Class"; - public static final String DEFAULT_DIR = "Setup/Patch/Data"; - - /** - * Abstract php file constructor. - * - * @param moduleName String - * @param className String - */ - public CustomerEavAttributeDataPatchFile( - final @NotNull String moduleName, - final @NotNull String className - ) { - super(moduleName, className); - } - - @Override - public String getDirectory() { - return DEFAULT_DIR; - } - - @Override - public String getHumanReadableName() { - return HUMAN_READABLE_NAME; - } - - @Override - public String getTemplate() { - return TEMPLATE; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchFile.java b/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchFile.java deleted file mode 100644 index 7c6a5fb52..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/EavAttributeDataPatchFile.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.files; - -public class EavAttributeDataPatchFile extends AbstractPhpFile { - public static final String HUMAN_READABLE_NAME = "Eav Attribute Data Patch Class"; - public static final String TEMPLATE = "Magento Eav Attribute Data Patch Class"; - public static final String DEFAULT_DIR = "Setup/Patch/Data"; - - /** - * Constructor. - * - * @param className String - */ - public EavAttributeDataPatchFile(final String moduleName, final String className) { - super(moduleName, className); - } - - @Override - public String getDirectory() { - return DEFAULT_DIR; - } - - @Override - public String getHumanReadableName() { - return HUMAN_READABLE_NAME; - } - - @Override - public String getTemplate() { - return TEMPLATE; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/files/ProductTypeXml.java b/src/com/magento/idea/magento2plugin/magento/files/ProductTypeXml.java deleted file mode 100644 index ea5c6a3ca..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/ProductTypeXml.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/files/SourceModelFile.java b/src/com/magento/idea/magento2plugin/magento/files/SourceModelFile.java deleted file mode 100644 index 13a47c9d6..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/SourceModelFile.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.files; - -import org.jetbrains.annotations.NotNull; - -public class SourceModelFile extends AbstractPhpFile { - public static final String HUMAN_READABLE_NAME = "Source model class"; - public static final String TEMPLATE = "Magento Source Model Class"; - public static final String DEFAULT_DIR = "Model/Source"; - private String directory; - - /** - * Constructor. - * - * @param className String - */ - public SourceModelFile( - @NotNull final String moduleName, - @NotNull final String className - ) { - super(moduleName, className); - } - - /** - * Constructor. - * - * @param className String - */ - public SourceModelFile( - @NotNull final String moduleName, - @NotNull final String className, - final String directory - ) { - this(moduleName, className); - this.directory = directory; - } - - @Override - public String getDirectory() { - if (directory == null) { - return DEFAULT_DIR; - } - - return directory; - } - - @Override - public String getHumanReadableName() { - return HUMAN_READABLE_NAME; - } - - @Override - public String getTemplate() { - return TEMPLATE; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeBackendModel.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeBackendModel.java deleted file mode 100644 index 2e9524912..000000000 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeBackendModel.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - * - */ - -package com.magento.idea.magento2plugin.magento.packages.eav; - -public enum AttributeBackendModel { - ARRAY("\\Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\ArrayBackend"); - - private String model; - - AttributeBackendModel(final String model) { - this.model = model; - } - - public String getModel() { - return model; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInput.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInput.java deleted file mode 100644 index 773b18516..000000000 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeInput.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.packages.eav; - -public enum AttributeInput { - TEXT("text"), - TEXTAREA("textarea"), - BOOLEAN("boolean"), - SELECT("select"), - MULTISELECT("multiselect"), - DATE("date"), - PRICE("price"), - HIDDEN("hidden"); - - private String input; - - AttributeInput(final String input) { - this.input = input; - } - - /** - * Return attribute input. - * - * @return String - */ - public String getInput() { - return this.input; - } - - /** - * Return attribute input item by input code. - * - * @param code String - * @return AttributeInput - */ - public static AttributeInput getAttributeInputByCode(final String code) { - for (final AttributeInput attributeInput: values()) { - if (attributeInput.getInput().equals(code)) { - return attributeInput; - } - } - - return null; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeProperty.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeProperty.java deleted file mode 100644 index 3a2b47200..000000000 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeProperty.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.packages.eav; - -public enum AttributeProperty { - GROUP("group"), - TYPE("type"), - LABEL("label"), - INPUT("input"), - SOURCE("source"), - REQUIRED("required"), - SORT_ORDER("sort_order"), - GLOBAL("global"), - IS_USED_IN_GRID("is_used_in_grid"), - IS_VISIBLE_IN_GRID("is_visible_in_grid"), - IS_FILTERABLE_IN_GRID("is_filterable_in_grid"), - VISIBLE("visible"), - IS_HTML_ALLOWED_ON_FRONT("is_html_allowed_on_front"), - VISIBLE_ON_FRONT("visible_on_front"), - APPLY_TO("apply_to"), - OPTION("option"), - BACKEND_MODEL("backend"), - USER_DEFINED("user_defined"), - POSITION("position"), - SYSTEM("system"); - - private String attribute; - - AttributeProperty(final String attribute) { - this.attribute = attribute; - } - - public String getProperty() { - return attribute; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScope.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScope.java deleted file mode 100644 index e0738bc37..000000000 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeScope.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.packages.eav; - -public enum AttributeScope { - GLOBAL("\\Magento\\Eav\\Model\\Entity\\Attribute\\ScopedAttributeInterface::SCOPE_GLOBAL"), - STORE("\\Magento\\Eav\\Model\\Entity\\Attribute\\ScopedAttributeInterface::SCOPE_STORE"), - WEBSITE("\\Magento\\Eav\\Model\\Entity\\Attribute\\ScopedAttributeInterface::SCOPE_WEBSITE"); - - private String scope; - - AttributeScope(final String scope) { - this.scope = scope; - } - - public String getScope() { - return scope; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java deleted file mode 100644 index a19075813..000000000 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeSourceModel.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.packages.eav; - -public enum AttributeSourceModel { - BOOLEAN("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Boolean"), - TABLE("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table"), - CONFIG("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Config"), - STORE("\\Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Store"), - GENERATE_SOURCE("Custom Source"), - NULLABLE_SOURCE("Without Source Model"); - - private String source; - - AttributeSourceModel(final String source) { - this.source = source; - } - - public String getSource() { - return source; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeType.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeType.java deleted file mode 100644 index 988fa865a..000000000 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/AttributeType.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.packages.eav; - -public enum AttributeType { - STATIC("static"), - VARCHAR("varchar"), - INT("int"), - TEXT("text"), - DATETIME("datetime"), - DECIMAL("decimal"); - - private String type; - - AttributeType(final String type) { - this.type = type; - } - - public String getType() { - return this.type; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/CustomerForm.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/CustomerForm.java deleted file mode 100644 index 40c7733ff..000000000 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/CustomerForm.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.packages.eav; - -public enum CustomerForm { - - ADMINHTML_CHECKOUT("adminhtml_checkout"), - ADMINHTML_CUSTOMER("adminhtml_customer"), - ADMINHTML_CUSTOMER_ADDRESS("adminhtml_customer_address"), - CUSTOMER_ACCOUNT_CREATE("customer_account_create"), - CUSTOMER_ACCOUNT_EDIT("customer_account_edit"), - CUSTOMER_ADDRESS_EDIT("customer_address_edit"), - CUSTOMER_REGISTER_ADDRESS("customer_register_address"); - - private final String formCode; - - CustomerForm(final String formCode) { - this.formCode = formCode; - } - - public String getFormCode() { - return this.formCode; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java deleted file mode 100644 index aee63c3d9..000000000 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.packages.eav; - -public enum DataPatchDependency { - CUSTOMER_METADATA_INTERFACE("Magento\\Customer\\Api\\CustomerMetadataInterface"), - DATA_PATCH_INTERFACE("Magento\\Framework\\Setup\\Patch\\DataPatchInterface"), - EAV_CONFIG("Magento\\Eav\\Model\\Config"), - EAV_SETUP_FACTORY("Magento\\Eav\\Setup\\EavSetupFactory"), - ENV_SETUP("Magento\\Eav\\Setup\\EavSetup"), - MODULE_DATA_SETUP_INTERFACE("Magento\\Framework\\Setup\\ModuleDataSetupInterface"), - ATTRIBUTE_RESOURCE("Magento\\Customer\\Model\\ResourceModel\\Attribute"); - - private String classPatch; - - DataPatchDependency(final String classPatch) { - this.classPatch = classPatch; - } - - public String getClassPatch() { - return classPatch; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java b/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java deleted file mode 100644 index ee3e770ea..000000000 --- a/src/com/magento/idea/magento2plugin/magento/packages/eav/EavEntity.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.packages.eav; - -public enum EavEntity { - PRODUCT("Magento\\Catalog\\Model\\Product"), - CATEGORY("Magento\\Catalog\\Model\\Category"), - CUSTOMER("Magento\\Customer\\Model\\Customer"); - - private String entityClass; - - EavEntity(final String entityClass) { - this.entityClass = entityClass; - } - - public String getEntityClass() { - return entityClass; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java b/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java deleted file mode 100644 index f587e0d98..000000000 --- a/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/AvailableSourcesByInput.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.packages.uicomponent; - -import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; -import com.sun.istack.NotNull; -import java.util.ArrayList; -import java.util.List; - -public class AvailableSourcesByInput { - private final String input; - - public AvailableSourcesByInput(@NotNull final String input) { - this.input = input; - } - - /** - * Source items getter. - * - * @return List - */ - public List getItems() { - final List items = new ArrayList<>(); - final ComboBoxItemData generateSourceItem = new ComboBoxItemData( - AttributeSourceModel.GENERATE_SOURCE.getSource(), - AttributeSourceModel.GENERATE_SOURCE.getSource() - ); - items.add(generateSourceItem); - - if (input.equals(AttributeInput.BOOLEAN.getInput())) { - items.add(new ComboBoxItemData( - AttributeSourceModel.BOOLEAN.getSource(), - AttributeSourceModel.BOOLEAN.getSource()) - ); - } else if (input.equals(AttributeInput.SELECT.getInput()) - || input.equals(AttributeInput.MULTISELECT.getInput())) { - items.add(new ComboBoxItemData( - AttributeSourceModel.BOOLEAN.getSource(), - AttributeSourceModel.BOOLEAN.getSource()) - ); - items.add(new ComboBoxItemData( - AttributeSourceModel.TABLE.getSource(), - AttributeSourceModel.TABLE.getSource() - )); - items.add(new ComboBoxItemData( - AttributeSourceModel.STORE.getSource(), - AttributeSourceModel.STORE.getSource() - )); - items.add(new ComboBoxItemData( - AttributeSourceModel.CONFIG.getSource(), - AttributeSourceModel.CONFIG.getSource() - )); - } - - return items; - } -} diff --git a/src/com/magento/idea/magento2plugin/stubs/indexes/xml/ProductTypeIndex.java b/src/com/magento/idea/magento2plugin/stubs/indexes/xml/ProductTypeIndex.java deleted file mode 100644 index e95cfb414..000000000 --- a/src/com/magento/idea/magento2plugin/stubs/indexes/xml/ProductTypeIndex.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.stubs.indexes.xml; - -import com.intellij.ide.highlighter.XmlFileType; -import com.intellij.psi.PsiFile; -import com.intellij.psi.xml.XmlDocument; -import com.intellij.psi.xml.XmlFile; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.indexing.DataIndexer; -import com.intellij.util.indexing.FileBasedIndex; -import com.intellij.util.indexing.FileContent; -import com.intellij.util.indexing.ID; -import com.intellij.util.indexing.ScalarIndexExtension; -import com.intellij.util.io.EnumeratorStringDescriptor; -import com.intellij.util.io.KeyDescriptor; -import com.magento.idea.magento2plugin.magento.files.ProductTypeXml; -import com.magento.idea.magento2plugin.project.Settings; -import gnu.trove.THashMap; -import java.util.Map; -import org.jetbrains.annotations.NotNull; - -public class ProductTypeIndex extends ScalarIndexExtension { - private static final String TEST_DIRECTORY_PATTERN = ".*\\/[Tt]ests?\\/?.*"; - private final KeyDescriptor myKeyDescriptor = new EnumeratorStringDescriptor(); - public static final ID KEY = ID.create( - "com.magento.idea.magento2plugin.stubs.indexes.product_types"); - - @Override - public @NotNull - ID getName() { - return KEY; - } - - @Override - public @NotNull - DataIndexer getIndexer() { - return inputData -> { - final Map map = new THashMap<>(); - final String filePath = inputData.getFile().getPath(); - - if (filePath.matches(TEST_DIRECTORY_PATTERN)) { - return map; - } - - final PsiFile psiFile = inputData.getPsiFile(); - if (!Settings.isEnabled(psiFile.getProject())) { - return map; - } - - if (!(psiFile instanceof XmlFile)) { - return map; - } - - final XmlDocument xmlDocument = ((XmlFile) psiFile).getDocument(); - - if (xmlDocument == null) { - return map; - } - - final XmlTag xmlRootTag = xmlDocument.getRootTag(); - - if (xmlRootTag != null) { - parseRootTag(map, xmlRootTag); - } - - return map; - }; - } - - private void parseRootTag(final Map map, final XmlTag xmlRootTag) { - for (final XmlTag productTypeTag : xmlRootTag.findSubTags(ProductTypeXml.XML_TAG_TYPE)) { - final String productTypeName = productTypeTag.getAttributeValue( - ProductTypeXml.XML_ATTRIBUTE_NAME - ); - map.put(productTypeName, null); - } - } - - @Override - public @NotNull - KeyDescriptor getKeyDescriptor() { - return this.myKeyDescriptor; - } - - @Override - public int getVersion() { - return 0; - } - - @Override - @SuppressWarnings({"PMD.LiteralsFirstInComparisons"}) - public FileBasedIndex.InputFilter getInputFilter() { - return file -> - file.getFileType() == XmlFileType.INSTANCE - && file.getName().equalsIgnoreCase(ProductTypeXml.FILE_NAME); - } - - @Override - public boolean dependsOnFileContent() { - return true; - } -} diff --git a/src/com/magento/idea/magento2plugin/util/RegExUtil.java b/src/com/magento/idea/magento2plugin/util/RegExUtil.java index 632f5a8f4..17dd76d9d 100644 --- a/src/com/magento/idea/magento2plugin/util/RegExUtil.java +++ b/src/com/magento/idea/magento2plugin/util/RegExUtil.java @@ -83,9 +83,6 @@ public static class Magento { public static final String TEST_CLASS_FQN = "^(\\\\)?(\\w+\\\\){1}(\\w+\\\\){1}Test(\\\\\\w+)+$"; - - public static final String COMMA_SEPARATED_STRING = - "^[^\\s,]+(?:,\\s*[^\\s,]+)*$"; } public static class PhpRegex { diff --git a/src/com/magento/idea/magento2plugin/util/magento/GetProductTypesListUtil.java b/src/com/magento/idea/magento2plugin/util/magento/GetProductTypesListUtil.java deleted file mode 100644 index 527759024..000000000 --- a/src/com/magento/idea/magento2plugin/util/magento/GetProductTypesListUtil.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.util.magento; - -import com.intellij.openapi.project.Project; -import com.intellij.util.indexing.FileBasedIndex; -import com.magento.idea.magento2plugin.stubs.indexes.xml.ProductTypeIndex; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -public final class GetProductTypesListUtil { - - private GetProductTypesListUtil() {} - - /** - * Product types util. - * - * @param project Project - * @return List - */ - public static List execute(final Project project) { - final Collection productTypesList = - FileBasedIndex.getInstance().getAllKeys(ProductTypeIndex.KEY, project); - - return productTypesList.stream().sorted().collect(Collectors.toList()); - } -} diff --git a/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php b/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php deleted file mode 100644 index 0c43f12d0..000000000 --- a/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFile/AddTestAttributeCategoryAttribute.php +++ /dev/null @@ -1,92 +0,0 @@ -moduleDataSetup = $moduleDataSetup; - $this->eavSetupFactory = $eavSetupFactory; - } - - /** - * Run code inside patch - * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert - * means run PatchInterface::revert() - * - * If we speak about data, under revert means: $transaction->rollback() - */ - public function apply() - { - /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); - - $eavSetup->addAttribute( - Category::ENTITY, - 'test_attribute', - [ - 'input' => 'text', - 'visible' => true, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'label' => 'Test Attribute', - 'source' => null, - 'type' => 'static', - 'sort_order' => 10, - 'required' => false, - 'group' => 'Content', - ] - ); - } - - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } -} diff --git a/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFormFile/category_form.xml b/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFormFile/category_form.xml deleted file mode 100644 index 58c560cfa..000000000 --- a/testData/actions/generation/generator/CategoryAttributePropertySetupPatchGenerator/generateFormFile/category_form.xml +++ /dev/null @@ -1,7 +0,0 @@ - -
-
- -
-
diff --git a/testData/actions/generation/generator/CustomerAttributeSetupPatchGenerator/generateMultiselectAttributeDataPatch/AddMultiselectTestCustomerAttribute.php b/testData/actions/generation/generator/CustomerAttributeSetupPatchGenerator/generateMultiselectAttributeDataPatch/AddMultiselectTestCustomerAttribute.php deleted file mode 100644 index 4757629dd..000000000 --- a/testData/actions/generation/generator/CustomerAttributeSetupPatchGenerator/generateMultiselectAttributeDataPatch/AddMultiselectTestCustomerAttribute.php +++ /dev/null @@ -1,139 +0,0 @@ -moduleDataSetup = $moduleDataSetup; - $this->eavSetupFactory = $eavSetupFactory; - $this->eavConfig = $eavConfig; - $this->attributeResource = $attributeResource; - } - - /** - * Run code inside patch - * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert - * means run PatchInterface::revert() - * - * If we speak about data, under revert means: $transaction->rollback() - * - * @return $this - */ - public function apply() - { - /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); - - $eavSetup->addAttribute( - Customer::ENTITY, - 'multiselect_test', - [ - 'is_visible_in_grid' => false, - 'visible' => true, - 'label' => 'Multiselect Test', - 'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class, - 'type' => 'varchar', - 'is_used_in_grid' => false, - 'required' => false, - 'input' => 'multiselect', - 'user_defined' => true, - 'is_filterable_in_grid' => false, - 'system' => false, - 'backend' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class, - 'position' => 10, - 'option' => [ - 'value' => [ - 'option_0' => ['option1'], - 'option_1' => ['option2'], - 'option_2' => ['option3'], - ] - ], - ] - ); - - $eavSetup->addAttributeToSet( - CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, - CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER, - null, - 'multiselect_test' - ); - - $attribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'multiselect_test'); - $attribute->setData( - 'used_in_forms', - ['adminhtml_customer'] - ); - $this->attributeResource->save($attribute); - - return $this; - } - - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } -} diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php deleted file mode 100644 index 129a8f068..000000000 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFile/AddTestAttribute.php +++ /dev/null @@ -1,97 +0,0 @@ -moduleDataSetup = $moduleDataSetup; - $this->eavSetupFactory = $eavSetupFactory; - } - - /** - * Run code inside patch - * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert - * means run PatchInterface::revert() - * - * If we speak about data, under revert means: $transaction->rollback() - */ - public function apply() - { - /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); - - $eavSetup->addAttribute( - Product::ENTITY, - 'test', - [ - 'is_visible_in_grid' => false, - 'is_html_allowed_on_front' => false, - 'visible_on_front' => false, - 'visible' => true, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'label' => 'Test Label', - 'source' => null, - 'type' => 'static', - 'is_used_in_grid' => false, - 'required' => false, - 'input' => 'text', - 'is_filterable_in_grid' => false, - 'sort_order' => 10, - 'group' => 'General', - ] - ); - } - - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } -} diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php deleted file mode 100644 index 90be38a37..000000000 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithApplyToAttribute/AddAppliedToAttribute.php +++ /dev/null @@ -1,98 +0,0 @@ -moduleDataSetup = $moduleDataSetup; - $this->eavSetupFactory = $eavSetupFactory; - } - - /** - * Run code inside patch - * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert - * means run PatchInterface::revert() - * - * If we speak about data, under revert means: $transaction->rollback() - */ - public function apply() - { - /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); - - $eavSetup->addAttribute( - Product::ENTITY, - 'applied_to_attribute', - [ - 'is_visible_in_grid' => false, - 'is_html_allowed_on_front' => false, - 'visible_on_front' => false, - 'visible' => true, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'label' => 'Test Label', - 'source' => null, - 'type' => 'static', - 'is_used_in_grid' => false, - 'required' => false, - 'input' => 'text', - 'is_filterable_in_grid' => false, - 'apply_to' => 'configurable,simple', - 'sort_order' => 10, - 'group' => 'General', - ] - ); - } - - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } -} diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php deleted file mode 100644 index 574350b72..000000000 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithBooleanSourceModel/AddBooleanInputAttributeAttribute.php +++ /dev/null @@ -1,97 +0,0 @@ -moduleDataSetup = $moduleDataSetup; - $this->eavSetupFactory = $eavSetupFactory; - } - - /** - * Run code inside patch - * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert - * means run PatchInterface::revert() - * - * If we speak about data, under revert means: $transaction->rollback() - */ - public function apply() - { - /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); - - $eavSetup->addAttribute( - Product::ENTITY, - 'boolean_input_attribute', - [ - 'is_visible_in_grid' => false, - 'is_html_allowed_on_front' => false, - 'visible_on_front' => false, - 'visible' => true, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'label' => 'Test Label', - 'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class, - 'type' => 'static', - 'is_used_in_grid' => false, - 'required' => false, - 'input' => 'boolean', - 'is_filterable_in_grid' => false, - 'sort_order' => 10, - 'group' => 'General', - ] - ); - } - - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } -} diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php deleted file mode 100644 index 2dc15f408..000000000 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithGeneratedSourceModel/AddAttributeWithCustomSourceAttribute.php +++ /dev/null @@ -1,97 +0,0 @@ -moduleDataSetup = $moduleDataSetup; - $this->eavSetupFactory = $eavSetupFactory; - } - - /** - * Run code inside patch - * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert - * means run PatchInterface::revert() - * - * If we speak about data, under revert means: $transaction->rollback() - */ - public function apply() - { - /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); - - $eavSetup->addAttribute( - Product::ENTITY, - 'attribute_with_custom_source', - [ - 'is_visible_in_grid' => false, - 'is_html_allowed_on_front' => false, - 'visible_on_front' => false, - 'visible' => true, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'label' => 'Test Label', - 'source' => \Foo\Bar\Model\Source\AttributeWithCustomSource::class, - 'type' => 'static', - 'is_used_in_grid' => false, - 'required' => false, - 'input' => 'text', - 'is_filterable_in_grid' => false, - 'sort_order' => 10, - 'group' => 'General', - ] - ); - } - - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } -} diff --git a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php b/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php deleted file mode 100644 index 2a1a353ca..000000000 --- a/testData/actions/generation/generator/ProductAttributePropertySetupPatchGenerator/generateFileWithOptions/AddAttributeWithOptionsAttribute.php +++ /dev/null @@ -1,105 +0,0 @@ -moduleDataSetup = $moduleDataSetup; - $this->eavSetupFactory = $eavSetupFactory; - } - - /** - * Run code inside patch - * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert - * means run PatchInterface::revert() - * - * If we speak about data, under revert means: $transaction->rollback() - */ - public function apply() - { - /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); - - $eavSetup->addAttribute( - Product::ENTITY, - 'attribute_with_options', - [ - 'is_visible_in_grid' => false, - 'is_html_allowed_on_front' => false, - 'visible_on_front' => false, - 'visible' => true, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'label' => 'Attribute With Options', - 'source' => null, - 'type' => 'varchar', - 'is_used_in_grid' => false, - 'required' => false, - 'input' => 'multiselect', - 'is_filterable_in_grid' => false, - 'backend' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class, - 'sort_order' => 10, - 'option' => [ - 'value' => [ - 'option_0' => ['option1'], - 'option_1' => ['option2'], - 'option_2' => ['option3'], - ] - ], - 'group' => 'General', - ] - ); - } - - /** - * Get array of patches that have to be executed prior to this. - * - * Example of implementation: - * - * [ - * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, - * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class - * ] - * - * @return string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Get aliases (previous names) for the patch. - * - * @return string[] - */ - public function getAliases() - { - return []; - } -} diff --git a/testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php b/testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php deleted file mode 100644 index 891b5d153..000000000 --- a/testData/actions/generation/generator/SourceModelGenerator/generateFile/CustomSourceModel.php +++ /dev/null @@ -1,18 +0,0 @@ - options = new HashMap<>(); - options.put(0, "option1"); - options.put(1, "option2"); - options.put(2, "option3"); - customerEntityData.setOptions(options); - - customerEntityData.setDataPatchName("AddMultiselectTestCustomerAttribute"); - customerEntityData.setModuleName(MODULE_NAME); - - - final CustomerEavAttributePatchGenerator setupPatchGenerator = - new CustomerEavAttributePatchGenerator(customerEntityData, project); - final PsiFile dataPatchFile = setupPatchGenerator.generate( - "testGenerateMultiselectAttributeDataPatch" - ); - - final String filePatch = this.getFixturePath("AddMultiselectTestCustomerAttribute.php"); - final PsiFile expectedFile = myFixture.configureByFile(filePatch); - - assertGeneratedFileIsCorrect( - expectedFile, - "src/app/code/Foo/Bar/Setup/Patch/Data", - dataPatchFile - ); - } -} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java deleted file mode 100644 index 8e05991c2..000000000 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ProductAttributePropertySetupPatchGeneratorTest.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.generator; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiFile; -import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; -import java.util.HashMap; -import java.util.Map; - -public class ProductAttributePropertySetupPatchGeneratorTest extends BaseGeneratorTestCase { - private static final String MODULE_NAME = "Foo_Bar"; - private static final String LABEL = "Test Label"; - private static final String TYPE = "static"; - private static final int SORT_ORDER = 10; - private static final String GROUP = "General"; - private static final String FILE_PATH = "src/app/code/Foo/Bar/Setup/Patch/Data"; - - /** - * Test Data patch for product's eav attribute generator. - */ - public void testGenerateFile() { - final Project project = myFixture.getProject(); - - final ProductEntityData productEntityData = new ProductEntityData(); - productEntityData.setCode("test"); - productEntityData.setVisibleInGrid(false); - productEntityData.setHtmlAllowedOnFront(false); - productEntityData.setVisibleOnFront(false); - productEntityData.setVisible(true); - productEntityData.setScope(AttributeScope.GLOBAL.getScope()); - productEntityData.setLabel(LABEL); - productEntityData.setType(TYPE); - productEntityData.setUsedInGrid(false); - productEntityData.setRequired(false); - productEntityData.setInput("text"); - productEntityData.setFilterableInGrid(false); - productEntityData.setSortOrder(SORT_ORDER); - productEntityData.setGroup(GROUP); - - productEntityData.setDataPatchName("AddTestAttribute"); - productEntityData.setModuleName(MODULE_NAME); - - final EavAttributeSetupPatchGenerator setupPatchGenerator = - new EavAttributeSetupPatchGenerator(productEntityData, project); - final PsiFile dataPatchFile = setupPatchGenerator.generate("testGenerateFile"); - - final String filePatch = this.getFixturePath("AddTestAttribute.php"); - final PsiFile expectedFile = myFixture.configureByFile(filePatch); - - assertGeneratedFileIsCorrect(expectedFile, FILE_PATH, dataPatchFile); - } - - /** - * Tests the generated file with the boolean source model. - */ - public void testGenerateFileWithBooleanSourceModel() { - final Project project = myFixture.getProject(); - - final ProductEntityData productEntityData = new ProductEntityData(); - productEntityData.setCode("boolean_input_attribute"); - productEntityData.setVisibleInGrid(false); - productEntityData.setHtmlAllowedOnFront(false); - productEntityData.setVisibleOnFront(false); - productEntityData.setVisible(true); - productEntityData.setScope(AttributeScope.GLOBAL.getScope()); - productEntityData.setLabel(LABEL); - productEntityData.setType(TYPE); - productEntityData.setUsedInGrid(false); - productEntityData.setRequired(false); - productEntityData.setInput("boolean"); - productEntityData.setSource(AttributeSourceModel.BOOLEAN.getSource()); - productEntityData.setFilterableInGrid(false); - productEntityData.setSortOrder(SORT_ORDER); - productEntityData.setGroup(GROUP); - - productEntityData.setDataPatchName("AddBooleanInputAttributeAttribute"); - productEntityData.setModuleName(MODULE_NAME); - - final EavAttributeSetupPatchGenerator setupPatchGenerator = - new EavAttributeSetupPatchGenerator(productEntityData, project); - final PsiFile dataPatchFile = setupPatchGenerator.generate( - "testGenerateFileWithBooleanSourceModel" - ); - - final String filePatch = this.getFixturePath("AddBooleanInputAttributeAttribute.php"); - final PsiFile expectedFile = myFixture.configureByFile(filePatch); - - assertGeneratedFileIsCorrect(expectedFile, FILE_PATH, dataPatchFile); - } - - /** - * Tests the generated file with the source model. - */ - public void testGenerateFileWithGeneratedSourceModel() { - final Project project = myFixture.getProject(); - - final ProductEntityData productEntityData = new ProductEntityData(); - productEntityData.setCode("attribute_with_custom_source"); - productEntityData.setVisibleInGrid(false); - productEntityData.setHtmlAllowedOnFront(false); - productEntityData.setVisibleOnFront(false); - productEntityData.setVisible(true); - productEntityData.setScope(AttributeScope.GLOBAL.getScope()); - productEntityData.setLabel("Test Label"); - productEntityData.setType("static"); - productEntityData.setUsedInGrid(false); - productEntityData.setRequired(false); - productEntityData.setInput("text"); - productEntityData.setSource("\\Foo\\Bar\\Model\\Source\\AttributeWithCustomSource"); - productEntityData.setFilterableInGrid(false); - productEntityData.setSortOrder(10); - productEntityData.setGroup(GROUP); - - productEntityData.setDataPatchName("AddAttributeWithCustomSourceAttribute"); - productEntityData.setModuleName(MODULE_NAME); - - final EavAttributeSetupPatchGenerator setupPatchGenerator = - new EavAttributeSetupPatchGenerator(productEntityData, project); - final PsiFile dataPatchFile = setupPatchGenerator.generate( - "testGenerateFileWithBooleanSourceModel" - ); - - final String filePatch = this.getFixturePath("AddAttributeWithCustomSourceAttribute.php"); - final PsiFile expectedFile = myFixture.configureByFile(filePatch); - - assertGeneratedFileIsCorrect(expectedFile, FILE_PATH, dataPatchFile); - } - - /** - * Tests file with the `apply to` attribute. - */ - public void testGenerateFileWithApplyToAttribute() { - final Project project = myFixture.getProject(); - - final ProductEntityData productEntityData = new ProductEntityData(); - productEntityData.setCode("applied_to_attribute"); - productEntityData.setVisibleInGrid(false); - productEntityData.setHtmlAllowedOnFront(false); - productEntityData.setVisibleOnFront(false); - productEntityData.setVisible(true); - productEntityData.setScope(AttributeScope.GLOBAL.getScope()); - productEntityData.setLabel("Test Label"); - productEntityData.setType("static"); - productEntityData.setUsedInGrid(false); - productEntityData.setRequired(false); - productEntityData.setInput("text"); - productEntityData.setFilterableInGrid(false); - productEntityData.setSortOrder(10); - productEntityData.setGroup(GROUP); - productEntityData.setApplyTo("configurable,simple"); - - productEntityData.setDataPatchName("AddAppliedToAttribute"); - productEntityData.setModuleName(MODULE_NAME); - - final EavAttributeSetupPatchGenerator setupPatchGenerator = - new EavAttributeSetupPatchGenerator(productEntityData, project); - final PsiFile dataPatchFile = setupPatchGenerator.generate( - "testGenerateFileWithApplyToAttribute" - ); - - final String filePatch = this.getFixturePath("AddAppliedToAttribute.php"); - final PsiFile expectedFile = myFixture.configureByFile(filePatch); - - assertGeneratedFileIsCorrect(expectedFile, FILE_PATH, dataPatchFile); - } - - /** - * Tests file with options. - */ - public void testGenerateFileWithOptions() { - final Project project = myFixture.getProject(); - - final ProductEntityData productEntityData = new ProductEntityData(); - productEntityData.setVisibleInGrid(false); - productEntityData.setHtmlAllowedOnFront(false); - productEntityData.setVisibleOnFront(false); - productEntityData.setVisible(true); - productEntityData.setScope(AttributeScope.GLOBAL.getScope()); - productEntityData.setCode("attribute_with_options"); - productEntityData.setLabel("Attribute With Options"); - productEntityData.setType("varchar"); - productEntityData.setUsedInGrid(false); - productEntityData.setRequired(false); - productEntityData.setInput("multiselect"); - productEntityData.setSource(AttributeSourceModel.NULLABLE_SOURCE.getSource()); - productEntityData.setFilterableInGrid(false); - productEntityData.setSortOrder(10); - productEntityData.setGroup(GROUP); - - final Map options = new HashMap<>(); - options.put(0, "option1"); - options.put(1, "option2"); - options.put(2, "option3"); - - productEntityData.setOptions(options); - - productEntityData.setDataPatchName("AddAttributeWithOptionsAttribute"); - productEntityData.setModuleName(MODULE_NAME); - - final EavAttributeSetupPatchGenerator setupPatchGenerator = - new EavAttributeSetupPatchGenerator(productEntityData, project); - final PsiFile dataPatchFile = setupPatchGenerator.generate("testGenerateFileWithOptions"); - - final String filePatch = this.getFixturePath("AddAttributeWithOptionsAttribute.php"); - final PsiFile expectedFile = myFixture.configureByFile(filePatch); - - assertGeneratedFileIsCorrect(expectedFile, FILE_PATH, dataPatchFile); - } -} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java deleted file mode 100644 index 76c059190..000000000 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/SourceModelGeneratorTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.generator; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiFile; -import com.magento.idea.magento2plugin.actions.generation.data.SourceModelData; - -public class SourceModelGeneratorTest extends BaseGeneratorTestCase { - private static final String MODULE_NAME = "Foo_Bar"; - - /** - * Test source model generation. - */ - public void testGenerateFile() { - final Project project = myFixture.getProject(); - - final SourceModelData sourceModelData = new SourceModelData(); - sourceModelData.setClassName("CustomSourceModel"); - sourceModelData.setModuleName(MODULE_NAME); - - final SourceModelGenerator sourceModelGeneratorGenerator = - new SourceModelGenerator(sourceModelData, project); - final PsiFile dataPatchFile = sourceModelGeneratorGenerator.generate("test"); - final String filePatch = this.getFixturePath("CustomSourceModel.php"); - final PsiFile expectedFile = myFixture.configureByFile(filePatch); - - assertGeneratedFileIsCorrect( - expectedFile, - "src/app/code/Foo/Bar/Model/Source", - dataPatchFile - ); - } - - /** - * Test source model in custom directory generation. - */ - public void testGenerateFileInCustomDirectory() { - final Project project = myFixture.getProject(); - - final SourceModelData sourceModelData = new SourceModelData(); - sourceModelData.setClassName("CustomSourceModel"); - sourceModelData.setModuleName(MODULE_NAME); - sourceModelData.setDirectory("Custom/Source/Directory"); - - final SourceModelGenerator sourceModelGeneratorGenerator = - new SourceModelGenerator(sourceModelData, project); - final PsiFile dataPatchFile = sourceModelGeneratorGenerator.generate("test custom dir"); - final String filePatch = this.getFixturePath("CustomSourceModel.php"); - final PsiFile expectedFile = myFixture.configureByFile(filePatch); - - assertGeneratedFileIsCorrect( - expectedFile, - "src/app/code/Foo/Bar/Custom/Source/Directory", - dataPatchFile - ); - } -} From 63c4337d5a05913b25777f725f5a0f98167c19cf Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Mon, 4 Apr 2022 18:51:35 +0300 Subject: [PATCH 111/111] 4.3.0 pre release --- CHANGELOG.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f33105460..10cb6fede 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,58 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). ## 4.3.0 +### Added + +- Code generation of `layout.xml` file [#1021](https://github.com/magento/magento2-phpstorm-plugin/pull/1021) +- Code generation of `page_types.xml` file [#1003](https://github.com/magento/magento2-phpstorm-plugin/pull/1003) +- Code generation of `crontab.xml file` [#1001](https://github.com/magento/magento2-phpstorm-plugin/pull/1001) +- Code generation of `email_templates.xml` file [#998](https://github.com/magento/magento2-phpstorm-plugin/pull/998) +- Code generation of `sections.xml` file [#997](https://github.com/magento/magento2-phpstorm-plugin/pull/997) +- Code generation of `fieldset.xml` file [#996](https://github.com/magento/magento2-phpstorm-plugin/pull/996) +- Code generation of `view.xml` file [#990](https://github.com/magento/magento2-phpstorm-plugin/pull/990) +- Code generation of `indexer.xml` file [#988](https://github.com/magento/magento2-phpstorm-plugin/pull/988) +- Code generation of `mview.xml` file [#987](https://github.com/magento/magento2-phpstorm-plugin/pull/987) +- Code generation of `widget.xml` file [#983](https://github.com/magento/magento2-phpstorm-plugin/pull/983) +- Code generation of `extension_attributes.xml` file [#982](https://github.com/magento/magento2-phpstorm-plugin/pull/982) +- Code generation of `system.xml` file [#978](https://github.com/magento/magento2-phpstorm-plugin/pull/978) +- Code generation of `config.xml` file [#976](https://github.com/magento/magento2-phpstorm-plugin/pull/976) +- Code generation of `webapi.xml` file [#971](https://github.com/magento/magento2-phpstorm-plugin/pull/971) +- Code generation of `di.xml` file [#970](https://github.com/magento/magento2-phpstorm-plugin/pull/970) +- Code generation of `acl.xml` file [#969](https://github.com/magento/magento2-phpstorm-plugin/pull/969) +- Code generation of `routes.xml` file [#958](https://github.com/magento/magento2-phpstorm-plugin/pull/958) +- Images support for Copy Magento Path [#1020](https://github.com/magento/magento2-phpstorm-plugin/pull/1020) +- Add/Replace an argument of a constructor via di.xml [#1027](https://github.com/magento/magento2-phpstorm-plugin/pull/1027) +- Possibility to compare overridden template with the original one [#1032](https://github.com/magento/magento2-phpstorm-plugin/pull/1032) +- Themes support of the UCT action execution [#1029](https://github.com/magento/magento2-phpstorm-plugin/pull/1029) +- Configuration files support of the UCT action execution [#1038](https://github.com/magento/magento2-phpstorm-plugin/pull/1038) +- Possibility to override a LESS file [#1036](https://github.com/magento/magento2-phpstorm-plugin/pull/1036) +- Added references for the extended MFTF tests [#974](https://github.com/magento/magento2-phpstorm-plugin/pull/974) + +### Changed + +- Improved RequireJS Mapping [#1045](https://github.com/magento/magento2-phpstorm-plugin/pull/1045) +- Improved the override a theme file feature [#1046](https://github.com/magento/magento2-phpstorm-plugin/pull/1046) +- Improved DocBlock code generator [#1022](https://github.com/magento/magento2-phpstorm-plugin/pull/1022) +- Added the possibility to create a plugin for a method in the parent class [#981](https://github.com/magento/magento2-phpstorm-plugin/pull/981) +- Extended custom search scope (to exclude test files from search) with the `is integration enabled` flag [#944](https://github.com/magento/magento2-phpstorm-plugin/pull/944) +- Extended uiComponent highlighting with the `is integration enabled` flag [#942](https://github.com/magento/magento2-phpstorm-plugin/pull/942) +- Added "module" prefix to module name in `composer.json` [#848](https://github.com/magento/magento2-phpstorm-plugin/pull/848) + +### Fixed + +- Sort order of the context actions [#1004](https://github.com/magento/magento2-phpstorm-plugin/pull/1004) +- Fixed the email template form title [#956](https://github.com/magento/magento2-phpstorm-plugin/pull/956) +- Placeholders on forms [#1009](https://github.com/magento/magento2-phpstorm-plugin/pull/1009) [#1008](https://github.com/magento/magento2-phpstorm-plugin/pull/1008) [#1005](https://github.com/magento/magento2-phpstorm-plugin/pull/1005) [#962](https://github.com/magento/magento2-phpstorm-plugin/pull/962) [#938](https://github.com/magento/magento2-phpstorm-plugin/pull/938) +- Creating new module with the package name in the valid package directory on Windows OS [#1013](https://github.com/magento/magento2-phpstorm-plugin/pull/1013) +- Inspection titles [#1015](https://github.com/magento/magento2-phpstorm-plugin/pull/1015) +- Fixed ArrayIndexOutOfBoundsException [#1018](https://github.com/magento/magento2-phpstorm-plugin/pull/1018) +- Generating UI form Delete button [#1019](https://github.com/magento/magento2-phpstorm-plugin/pull/1019) +- Removed deprecated method FilenameIndex#getVirtualFilesByName [#1037](https://github.com/magento/magento2-phpstorm-plugin/pull/1037) +- Removed deprecated method Function#getReturnType [#1043](https://github.com/magento/magento2-phpstorm-plugin/pull/1043) +- Issue with wrong references resolved for a class if a proxy class is generated for it [#1044](https://github.com/magento/magento2-phpstorm-plugin/pull/1044) +- Fixed Magento installation path suggestion [#1047](https://github.com/magento/magento2-phpstorm-plugin/pull/1047) +- Issue during composer json generation if in dependent module version tag is not specified [#972](https://github.com/magento/magento2-phpstorm-plugin/pull/972) + ## 4.2.3 ### Fixed