Skip to content

Commit 71ade4c

Browse files
committed
Improved data model generation integrated with the entity manager
1 parent e1a3a80 commit 71ade4c

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<properties/>
2222
<border type="none"/>
2323
<children>
24-
<grid id="6be8b" binding="generalTable" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
24+
<grid id="6be8b" binding="generalTable" layout-manager="GridLayoutManager" row-count="6" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
2525
<margin top="0" left="0" bottom="0" right="0"/>
2626
<constraints>
2727
<tabbedpane title="General"/>
@@ -55,15 +55,15 @@
5555
</component>
5656
<component id="5dc1e" class="javax.swing.JTextField" binding="entityName">
5757
<constraints>
58-
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
58+
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
5959
<preferred-size width="150" height="-1"/>
6060
</grid>
6161
</constraints>
6262
<properties/>
6363
</component>
6464
<component id="5f234" class="javax.swing.JTextField" binding="dbTableName">
6565
<constraints>
66-
<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">
66+
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
6767
<preferred-size width="150" height="-1"/>
6868
</grid>
6969
</constraints>
@@ -79,7 +79,7 @@
7979
</component>
8080
<component id="de936" class="javax.swing.JTextField" binding="entityId">
8181
<constraints>
82-
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
82+
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
8383
<preferred-size width="150" height="-1"/>
8484
</grid>
8585
</constraints>
@@ -97,7 +97,7 @@
9797
</component>
9898
<component id="2fa4e" class="javax.swing.JComboBox" binding="tableEngine">
9999
<constraints>
100-
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
100+
<grid row="3" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
101101
</constraints>
102102
<properties/>
103103
</component>
@@ -112,7 +112,7 @@
112112
</component>
113113
<component id="3edf8" class="javax.swing.JComboBox" binding="tableResource">
114114
<constraints>
115-
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
115+
<grid row="4" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
116116
</constraints>
117117
<properties/>
118118
</component>
@@ -125,6 +125,15 @@
125125
<text value="Resource"/>
126126
</properties>
127127
</component>
128+
<component id="44a12" class="javax.swing.JCheckBox" binding="createInterface">
129+
<constraints>
130+
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
131+
</constraints>
132+
<properties>
133+
<selected value="true"/>
134+
<text value="Create Interface"/>
135+
</properties>
136+
</component>
128137
</children>
129138
</grid>
130139
<grid id="e3309" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.intellij.psi.PsiFile;
1212
import com.intellij.util.indexing.FileBasedIndex;
1313
import com.magento.idea.magento2plugin.actions.generation.NewViewModelAction;
14+
import com.magento.idea.magento2plugin.actions.generation.OverrideClassByAPreferenceAction;
1415
import com.magento.idea.magento2plugin.actions.generation.data.AclXmlData;
1516
import com.magento.idea.magento2plugin.actions.generation.data.CollectionData;
1617
import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData;
@@ -20,6 +21,7 @@
2021
import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData;
2122
import com.magento.idea.magento2plugin.actions.generation.data.MenuXmlData;
2223
import com.magento.idea.magento2plugin.actions.generation.data.ModelData;
24+
import com.magento.idea.magento2plugin.actions.generation.data.PreferenceDiXmFileData;
2325
import com.magento.idea.magento2plugin.actions.generation.data.ResourceModelData;
2426
import com.magento.idea.magento2plugin.actions.generation.data.RoutesXmlData;
2527
import com.magento.idea.magento2plugin.actions.generation.data.UiComponentDataProviderData;
@@ -42,6 +44,7 @@
4244
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator;
4345
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleModelGenerator;
4446
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleResourceModelGenerator;
47+
import com.magento.idea.magento2plugin.actions.generation.generator.PreferenceDiXmlGenerator;
4548
import com.magento.idea.magento2plugin.actions.generation.generator.RoutesXmlGenerator;
4649
import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentDataProviderGenerator;
4750
import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentFormGenerator;
@@ -64,6 +67,7 @@
6467
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
6568
import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper;
6669
import com.magento.idea.magento2plugin.util.FirstLetterToLowercaseUtil;
70+
import com.magento.idea.magento2plugin.util.GetPhpClassByFQN;
6771
import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil;
6872
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
6973
import java.awt.event.ActionEvent;
@@ -153,6 +157,7 @@ public class NewEntityDialog extends AbstractDialog {
153157
private JLabel tableEngineLabel;
154158
private JComboBox tableResource;
155159
private JLabel tableResourceLabel;
160+
private JCheckBox createInterface;
156161
private final List<String> properties;
157162
private TableGroupWrapper entityPropertiesTableGroupWrapper;
158163

@@ -262,10 +267,13 @@ private void onOK() {
262267
generateModelFile();
263268
generateResourceModelFile();
264269
generateCollectionFile();
265-
266270
formatProperties();
267271
generateDataModelFile();
268-
generateDataModelInterfaceFile();
272+
273+
if (createInterface.isSelected()) {
274+
generateDataModelInterfaceFile();
275+
generateDataModelPreference();
276+
}
269277

270278
generateRoutesXmlFile();
271279
generateViewControllerFile();
@@ -274,7 +282,6 @@ private void onOK() {
274282
generateLayoutFile();
275283
generateFormFile();
276284
generateAclXmlFile();
277-
278285
generateGridViewControllerFile();
279286
generateGridLayoutFile();
280287
generateMenuFile();
@@ -290,6 +297,7 @@ private void onOK() {
290297

291298
generateDbSchemaXmlFile(dbSchemaXmlData);
292299
generateWhitelistJsonFile(dbSchemaXmlData);
300+
this.setVisible(false);
293301
}
294302

295303
private PsiFile generateModelFile() {
@@ -333,6 +341,23 @@ private NamespaceBuilder getResourceModelNamespace() {
333341
);
334342
}
335343

344+
/**
345+
* Generate preference for data model.
346+
*/
347+
private void generateDataModelPreference() {
348+
final NamespaceBuilder modelNamespace = getModelNamespace();
349+
final NamespaceBuilder modelInterfaceNamespace = getDataModelInterfaceNamespace();
350+
new PreferenceDiXmlGenerator(new PreferenceDiXmFileData(
351+
getModuleName(),
352+
GetPhpClassByFQN.getInstance(project).execute(
353+
modelInterfaceNamespace.getClassFqn()
354+
),
355+
modelNamespace.getClassFqn(),
356+
getModelName(),
357+
Areas.base.toString()
358+
), project).generate(OverrideClassByAPreferenceAction.ACTION_NAME);
359+
}
360+
336361
private String getModuleName() {
337362
return moduleName;
338363
}
@@ -410,6 +435,9 @@ private PsiFile generateCollectionFile() {
410435
), project).generate(ACTION_NAME, true);
411436
}
412437

438+
/**
439+
* Generate Data Model File.
440+
*/
413441
private void generateDataModelFile() {
414442
final NamespaceBuilder nameSpaceBuilder = getDataModelNamespace();
415443
new DataModelGenerator(project, new DataModelData(
@@ -418,7 +446,8 @@ private void generateDataModelFile() {
418446
getModuleName(),
419447
nameSpaceBuilder.getClassFqn(),
420448
getDataModelInterfaceNamespace().getClassFqn(),
421-
getProperties()
449+
getProperties(),
450+
createInterface.isSelected()
422451
)).generate(ACTION_NAME, true);
423452
}
424453

0 commit comments

Comments
 (0)