Skip to content

Commit 9126424

Browse files
committed
Added basic generation for Data Model with Interface
1 parent 4bf8869 commit 9126424

15 files changed

+783
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<action id="MagentoCreateCLICommand" class="com.magento.idea.magento2plugin.actions.generation.NewCLICommandAction" />
6868
<action id="MagentoCreateUiComponentGrid" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentGridAction" />
6969
<action id="MagentoCreateUiComponentForm" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentFormAction" />
70+
<action id="MagentoCreateADataModel" class="com.magento.idea.magento2plugin.actions.generation.NewDataModelAction" />
7071
<add-to-group group-id="NewGroup" anchor="last"/>
7172
</group>
7273

@@ -210,6 +211,8 @@
210211
<internalFileTemplate name="Magento Routes XML"/>
211212
<internalFileTemplate name="Magento Layout XML"/>
212213
<internalFileTemplate name="Magento ACL XML"/>
214+
<internalFileTemplate name="Magento Data Model"/>
215+
<internalFileTemplate name="Magento Data Model Interface"/>
213216

214217
<defaultLiveTemplates file="/liveTemplates/MagentoPWA.xml"/>
215218

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
4+
#if (${NAMESPACE})
5+
namespace ${NAMESPACE};
6+
#end
7+
8+
interface ${NAME} {
9+
10+
}

resources/fileTemplates/internal/Magento Data Model Interface.php.html

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
4+
#if (${NAMESPACE})
5+
namespace ${NAMESPACE};
6+
#end
7+
8+
#set ($uses = ${USES})
9+
#foreach ($use in $uses.split(","))
10+
use $use;
11+
#end
12+
13+
class ${NAME} #if (${EXTENDS})extends ${EXTENDS} #end #if (${IMPLEMENTS})implements ${IMPLEMENTS}#end {
14+
15+
}

resources/fileTemplates/internal/Magento Data Model.php.html

Whitespace-only changes.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation;
7+
8+
import com.intellij.ide.IdeView;
9+
import com.intellij.openapi.actionSystem.AnAction;
10+
import com.intellij.openapi.actionSystem.AnActionEvent;
11+
import com.intellij.openapi.actionSystem.CommonDataKeys;
12+
import com.intellij.openapi.actionSystem.DataContext;
13+
import com.intellij.openapi.actionSystem.LangDataKeys;
14+
import com.intellij.openapi.project.Project;
15+
import com.intellij.psi.PsiDirectory;
16+
import com.magento.idea.magento2plugin.MagentoIcons;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewDataModelDialog;
18+
import org.jetbrains.annotations.NotNull;
19+
20+
public class NewDataModelAction extends AnAction {
21+
public static final String ACTION_NAME = "Magento 2 Data Model";
22+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Data Model";
23+
24+
/**
25+
* Constructor.
26+
*/
27+
public NewDataModelAction() {
28+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
29+
}
30+
31+
@Override
32+
public void actionPerformed(@NotNull AnActionEvent event) {
33+
final DataContext dataContext = event.getDataContext();
34+
35+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
36+
if (view == null) {
37+
return;
38+
}
39+
40+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
41+
if (project == null) {
42+
return;
43+
}
44+
45+
final PsiDirectory directory = view.getOrChooseDirectory();
46+
if (directory == null) {
47+
return;
48+
}
49+
50+
NewDataModelDialog.open(project, directory);
51+
}
52+
53+
@Override
54+
public boolean isDumbAware() {
55+
return false;
56+
}
57+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.data;
7+
8+
public class DataModelData {
9+
private final String namespace;
10+
private final String name;
11+
private final String moduleName;
12+
private final String fqn;
13+
private final String interfaceFQN;
14+
15+
public DataModelData(
16+
final String namespace,
17+
final String name,
18+
final String moduleName,
19+
final String fqn,
20+
final String interfaceFQN
21+
) {
22+
this.namespace = namespace;
23+
this.name = name;
24+
this.moduleName = moduleName;
25+
this.fqn = fqn;
26+
this.interfaceFQN = interfaceFQN;
27+
}
28+
29+
public String getNamespace() {
30+
return namespace;
31+
}
32+
33+
public String getName() {
34+
return name;
35+
}
36+
37+
public String getModuleName() {
38+
return moduleName;
39+
}
40+
41+
public String getFQN() {
42+
return fqn;
43+
}
44+
45+
public String getInterfaceFQN() {
46+
return interfaceFQN;
47+
}
48+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.data;
7+
8+
public class DataModelInterfaceData {
9+
private final String namespace;
10+
private final String name;
11+
private final String moduleName;
12+
private final String fqn;
13+
14+
public DataModelInterfaceData(
15+
final String namespace,
16+
final String name,
17+
final String moduleName,
18+
final String fqn
19+
) {
20+
this.namespace = namespace;
21+
this.name = name;
22+
this.moduleName = moduleName;
23+
this.fqn = fqn;
24+
}
25+
26+
public String getNamespace() {
27+
return namespace;
28+
}
29+
30+
public String getName() {
31+
return name;
32+
}
33+
34+
public String getModuleName() {
35+
return moduleName;
36+
}
37+
38+
public String getFQN() {
39+
return fqn;
40+
}
41+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.magento.idea.magento2plugin.actions.generation.dialog.NewDataModelDialog">
3+
<grid id="cbd77" binding="contentPanel" layout-manager="GridLayoutManager" row-count="8" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="10" left="10" bottom="10" right="10"/>
5+
<constraints>
6+
<xy x="48" y="54" width="454" height="423"/>
7+
</constraints>
8+
<properties>
9+
<preferredSize width="450" height="300"/>
10+
</properties>
11+
<border type="none"/>
12+
<children>
13+
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
14+
<margin top="0" left="0" bottom="0" right="0"/>
15+
<constraints>
16+
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
17+
</constraints>
18+
<properties/>
19+
<border type="none"/>
20+
<children>
21+
<hspacer id="98af6">
22+
<constraints>
23+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
24+
</constraints>
25+
</hspacer>
26+
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
27+
<margin top="0" left="0" bottom="0" right="0"/>
28+
<constraints>
29+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
30+
</constraints>
31+
<properties/>
32+
<border type="none"/>
33+
<children>
34+
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
35+
<constraints>
36+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
37+
</constraints>
38+
<properties>
39+
<text resource-bundle="magento2/common" key="common.ok"/>
40+
</properties>
41+
</component>
42+
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
43+
<constraints>
44+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
45+
</constraints>
46+
<properties>
47+
<text resource-bundle="magento2/common" key="common.cancel"/>
48+
</properties>
49+
</component>
50+
</children>
51+
</grid>
52+
</children>
53+
</grid>
54+
<grid id="e3588" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
55+
<margin top="0" left="0" bottom="0" right="0"/>
56+
<constraints>
57+
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
58+
</constraints>
59+
<properties/>
60+
<border type="none"/>
61+
<children>
62+
<component id="5a121" class="javax.swing.JLabel">
63+
<constraints>
64+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
65+
</constraints>
66+
<properties>
67+
<text resource-bundle="magento2/common" key="common.name"/>
68+
</properties>
69+
</component>
70+
<component id="4e6cb" class="javax.swing.JTextField" binding="modelName">
71+
<constraints>
72+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
73+
<preferred-size width="150" height="-1"/>
74+
</grid>
75+
</constraints>
76+
<properties>
77+
<text value=""/>
78+
</properties>
79+
</component>
80+
</children>
81+
</grid>
82+
</children>
83+
</grid>
84+
</form>

0 commit comments

Comments
 (0)