diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml
index d694cf55b..605b39ded 100644
--- a/resources/META-INF/plugin.xml
+++ b/resources/META-INF/plugin.xml
@@ -67,6 +67,7 @@
+ The mview.xml file is used to track database changes for a certain entity. + Allows tracking database changes for a certain entity (product, category, etc.) and running change handler. + Emulates the materialized view technology for MySQL using triggers and separate materialization process + (provides executing PHP code instead of SQL queries, which allows materializing multiple queries). +
++ Read more about mview.xml in the + DevDocs. +
+ + + diff --git a/src/com/magento/idea/magento2plugin/actions/context/xml/NewMviewXmlAction.java b/src/com/magento/idea/magento2plugin/actions/context/xml/NewMviewXmlAction.java new file mode 100644 index 000000000..da4aecf19 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/context/xml/NewMviewXmlAction.java @@ -0,0 +1,57 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.context.xml; + +import com.intellij.ide.fileTemplates.actions.AttributesDefaults; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.context.AbstractContextAction; +import com.magento.idea.magento2plugin.magento.files.ModuleMviewXmlFile; +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 org.jetbrains.annotations.NotNull; + +public class NewMviewXmlAction extends AbstractContextAction { + + public static final String ACTION_NAME = "Magento 2 Mview File"; + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 mview.xml file"; + + /** + * New mview.xml file generation action constructor. + */ + public NewMviewXmlAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, new ModuleMviewXmlFile()); + } + + @Override + protected boolean isVisible( + final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData, + final @NotNull PsiDirectory targetDirectory, + final PsiFile targetFile + ) { + final PsiDirectory configDir = moduleData.getConfigDir(); + + if (configDir == null) { + return false; + } + + return targetDirectory.getName().equals(Package.moduleBaseAreaDir) + && targetDirectory.equals(configDir) + && moduleData.getType().equals(ComponentType.module); + } + + + @Override + protected AttributesDefaults getProperties( + final @NotNull AttributesDefaults defaults, + final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData, + final PsiDirectory targetDirectory, + final PsiFile targetFile + ) { + return defaults; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/ModuleMviewXmlFile.java b/src/com/magento/idea/magento2plugin/magento/files/ModuleMviewXmlFile.java new file mode 100644 index 000000000..36ea5dcee --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/ModuleMviewXmlFile.java @@ -0,0 +1,30 @@ +/* + * 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 final class ModuleMviewXmlFile implements ModuleFileInterface { + + public static final String FILE_NAME = "mview.xml"; + public static final String TEMPLATE = "Magento Mview XML"; + + @Override + public String getFileName() { + return FILE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return XMLLanguage.INSTANCE; + } +}