Skip to content

Commit 64dc689

Browse files
committed
Added dynamic table to NewDataModelDialog
1 parent 7cf309a commit 64dc689

File tree

2 files changed

+121
-32
lines changed

2 files changed

+121
-32
lines changed
Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,82 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<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">
3+
<grid id="cbd77" binding="contentPanel" layout-manager="GridLayoutManager" row-count="7" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="10" left="10" bottom="10" right="10"/>
55
<constraints>
66
<xy x="48" y="54" width="454" height="423"/>
77
</constraints>
88
<properties>
9-
<preferredSize width="450" height="300"/>
9+
<preferredSize width="500" height="700"/>
1010
</properties>
1111
<border type="none"/>
1212
<children>
13+
<grid id="e3588" layout-manager="GridLayoutManager" row-count="3" 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="4" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
17+
</constraints>
18+
<properties/>
19+
<border type="none"/>
20+
<children>
21+
<component id="5a121" class="javax.swing.JLabel">
22+
<constraints>
23+
<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"/>
24+
</constraints>
25+
<properties>
26+
<text resource-bundle="magento2/common" key="common.name"/>
27+
</properties>
28+
</component>
29+
<component id="4e6cb" class="javax.swing.JTextField" binding="modelName">
30+
<constraints>
31+
<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">
32+
<preferred-size width="150" height="-1"/>
33+
</grid>
34+
</constraints>
35+
<properties>
36+
<text value=""/>
37+
</properties>
38+
</component>
39+
</children>
40+
</grid>
41+
<grid id="ebe15" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
42+
<margin top="5" left="5" bottom="5" right="5"/>
43+
<constraints>
44+
<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"/>
45+
</constraints>
46+
<properties/>
47+
<border type="empty" title="Properties" title-justification="2" title-position="2"/>
48+
<children>
49+
<scrollpane id="85d26">
50+
<constraints>
51+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
52+
</constraints>
53+
<properties/>
54+
<border type="none"/>
55+
<children>
56+
<component id="df4c9" class="javax.swing.JTable" binding="properties">
57+
<constraints/>
58+
<properties>
59+
<intercellSpacing width="1" height="3"/>
60+
<requestFocusEnabled value="true"/>
61+
<rowHeight value="30"/>
62+
</properties>
63+
</component>
64+
</children>
65+
</scrollpane>
66+
<component id="7e1b3" class="javax.swing.JButton" binding="addProperty">
67+
<constraints>
68+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
69+
</constraints>
70+
<properties>
71+
<text value="Add Property"/>
72+
</properties>
73+
</component>
74+
</children>
75+
</grid>
1376
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1477
<margin top="0" left="0" bottom="0" right="0"/>
1578
<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"/>
79+
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
1780
</constraints>
1881
<properties/>
1982
<border type="none"/>
@@ -51,34 +114,6 @@
51114
</grid>
52115
</children>
53116
</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>
82117
</children>
83118
</grid>
84119
</form>

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

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package com.magento.idea.magento2plugin.actions.generation.dialog;
77

88
import com.intellij.openapi.project.Project;
9+
import com.intellij.openapi.ui.ComboBoxTableRenderer;
910
import com.intellij.psi.PsiDirectory;
1011
import com.magento.idea.magento2plugin.actions.generation.NewDataModelAction;
1112
import com.magento.idea.magento2plugin.actions.generation.data.DataModelData;
@@ -19,13 +20,20 @@
1920
import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder;
2021
import com.magento.idea.magento2plugin.magento.files.DataModel;
2122
import com.magento.idea.magento2plugin.magento.files.DataModelInterface;
23+
import com.magento.idea.magento2plugin.ui.table.ComboBoxEditor;
24+
import com.magento.idea.magento2plugin.ui.table.DeleteRowButton;
25+
import com.magento.idea.magento2plugin.ui.table.TableButton;
2226
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
2327

2428
import javax.swing.JButton;
29+
import javax.swing.JCheckBox;
2530
import javax.swing.JComponent;
2631
import javax.swing.JPanel;
32+
import javax.swing.JTable;
2733
import javax.swing.JTextField;
2834
import javax.swing.KeyStroke;
35+
import javax.swing.table.DefaultTableModel;
36+
import javax.swing.table.TableColumn;
2937
import java.awt.event.ActionEvent;
3038
import java.awt.event.KeyEvent;
3139
import java.awt.event.WindowAdapter;
@@ -38,10 +46,18 @@ public class NewDataModelDialog extends AbstractDialog {
3846
private NamespaceBuilder modelNamespace;
3947

4048
private static final String MODEL_NAME = "Model Name";
49+
private static final String PROPERTY_NAME = "Name";
50+
private static final String PROPERTY_TYPE = "Type";
51+
private static final String PROPERTY_ACTION = "Action";
52+
private static final String PROPERTY_DELETE = "Delete";
53+
54+
private static final String[] PROPERTY_TYPES = {"int", "float", "string", "bool"};
4155

4256
private JPanel contentPanel;
4357
private JButton buttonOK;
4458
private JButton buttonCancel;
59+
private JTable properties;
60+
private JButton addProperty;
4561

4662
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
4763
message = {NotEmptyRule.MESSAGE, MODEL_NAME})
@@ -72,6 +88,8 @@ public void windowClosing(final WindowEvent event) {
7288
}
7389
});
7490

91+
initPropertiesTable();
92+
7593
// call onCancel() on ESCAPE KEY press
7694
contentPanel.registerKeyboardAction(
7795
(final ActionEvent event) -> onCancel(),
@@ -87,7 +105,7 @@ public static void open(final Project project, final PsiDirectory directory) {
87105
dialog.setVisible(true);
88106
}
89107

90-
protected void onOK() {
108+
private void onOK() {
91109
if (validateFormFields()) {
92110
buildNamespaces();
93111
generateModelInterfaceFile();
@@ -162,4 +180,40 @@ private String getModelFQN() {
162180
private String getProperties() {
163181
return "";
164182
}
183+
184+
private void initPropertiesTable() {
185+
final DefaultTableModel propertiesTable = getPropertiesTable();
186+
propertiesTable.setDataVector(
187+
new Object[][]{},
188+
new Object[]{
189+
PROPERTY_NAME,
190+
PROPERTY_TYPE,
191+
PROPERTY_ACTION
192+
}
193+
);
194+
195+
final TableColumn column = properties.getColumn(PROPERTY_ACTION);
196+
column.setCellRenderer(new TableButton(PROPERTY_DELETE));
197+
column.setCellEditor(new DeleteRowButton(new JCheckBox()));
198+
199+
addProperty.addActionListener(e -> {
200+
propertiesTable.addRow(new Object[]{
201+
"",
202+
PROPERTY_TYPES[0],
203+
PROPERTY_DELETE
204+
});
205+
});
206+
207+
initPropertyTypeColumn();
208+
}
209+
210+
private void initPropertyTypeColumn() {
211+
final TableColumn formElementTypeColumn = properties.getColumn(PROPERTY_TYPE);
212+
formElementTypeColumn.setCellEditor(new ComboBoxEditor(PROPERTY_TYPES));
213+
formElementTypeColumn.setCellRenderer(new ComboBoxTableRenderer<>(PROPERTY_TYPES));
214+
}
215+
216+
private DefaultTableModel getPropertiesTable() {
217+
return (DefaultTableModel) properties.getModel();
218+
}
165219
}

0 commit comments

Comments
 (0)