Skip to content

Data model generation #399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added basic generation for Data Model with Interface
  • Loading branch information
drpayyne committed Nov 18, 2020
commit 9126424b882fdc8dc87517d3325efb5b3983ace4
3 changes: 3 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<action id="MagentoCreateCLICommand" class="com.magento.idea.magento2plugin.actions.generation.NewCLICommandAction" />
<action id="MagentoCreateUiComponentGrid" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentGridAction" />
<action id="MagentoCreateUiComponentForm" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentFormAction" />
<action id="MagentoCreateADataModel" class="com.magento.idea.magento2plugin.actions.generation.NewDataModelAction" />
<add-to-group group-id="NewGroup" anchor="last"/>
</group>

Expand Down Expand Up @@ -210,6 +211,8 @@
<internalFileTemplate name="Magento Routes XML"/>
<internalFileTemplate name="Magento Layout XML"/>
<internalFileTemplate name="Magento ACL XML"/>
<internalFileTemplate name="Magento Data Model"/>
<internalFileTemplate name="Magento Data Model Interface"/>

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
#parse("PHP File Header.php")

#if (${NAMESPACE})
namespace ${NAMESPACE};
#end

interface ${NAME} {

}
Empty file.
15 changes: 15 additions & 0 deletions resources/fileTemplates/internal/Magento Data Model.php.ft
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
#parse("PHP File Header.php")

#if (${NAMESPACE})
namespace ${NAMESPACE};
#end

#set ($uses = ${USES})
#foreach ($use in $uses.split(","))
use $use;
#end

class ${NAME} #if (${EXTENDS})extends ${EXTENDS} #end #if (${IMPLEMENTS})implements ${IMPLEMENTS}#end {

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

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

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.MagentoIcons;
import com.magento.idea.magento2plugin.actions.generation.dialog.NewDataModelDialog;
import org.jetbrains.annotations.NotNull;

public class NewDataModelAction extends AnAction {
public static final String ACTION_NAME = "Magento 2 Data Model";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Data Model";

/**
* Constructor.
*/
public NewDataModelAction() {
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
}

@Override
public void actionPerformed(@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;
}

NewDataModelDialog.open(project, directory);
}

@Override
public boolean isDumbAware() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation.data;

public class DataModelData {
private final String namespace;
private final String name;
private final String moduleName;
private final String fqn;
private final String interfaceFQN;

public DataModelData(
final String namespace,
final String name,
final String moduleName,
final String fqn,
final String interfaceFQN
) {
this.namespace = namespace;
this.name = name;
this.moduleName = moduleName;
this.fqn = fqn;
this.interfaceFQN = interfaceFQN;
}

public String getNamespace() {
return namespace;
}

public String getName() {
return name;
}

public String getModuleName() {
return moduleName;
}

public String getFQN() {
return fqn;
}

public String getInterfaceFQN() {
return interfaceFQN;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation.data;

public class DataModelInterfaceData {
private final String namespace;
private final String name;
private final String moduleName;
private final String fqn;

public DataModelInterfaceData(
final String namespace,
final String name,
final String moduleName,
final String fqn
) {
this.namespace = namespace;
this.name = name;
this.moduleName = moduleName;
this.fqn = fqn;
}

public String getNamespace() {
return namespace;
}

public String getName() {
return name;
}

public String getModuleName() {
return moduleName;
}

public String getFQN() {
return fqn;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.magento.idea.magento2plugin.actions.generation.dialog.NewDataModelDialog">
<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">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="48" y="54" width="454" height="423"/>
</constraints>
<properties>
<preferredSize width="450" height="300"/>
</properties>
<border type="none"/>
<children>
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="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"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<hspacer id="98af6">
<constraints>
<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"/>
</constraints>
</hspacer>
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<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"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
<constraints>
<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"/>
</constraints>
<properties>
<text resource-bundle="magento2/common" key="common.ok"/>
</properties>
</component>
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
<constraints>
<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"/>
</constraints>
<properties>
<text resource-bundle="magento2/common" key="common.cancel"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="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"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="5a121" class="javax.swing.JLabel">
<constraints>
<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"/>
</constraints>
<properties>
<text resource-bundle="magento2/common" key="common.name"/>
</properties>
</component>
<component id="4e6cb" class="javax.swing.JTextField" binding="modelName">
<constraints>
<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">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>
Loading