6
6
package com .magento .idea .magento2plugin .actions .generation .dialog ;
7
7
8
8
import com .intellij .openapi .project .Project ;
9
+ import com .intellij .openapi .ui .ComboBoxTableRenderer ;
9
10
import com .intellij .psi .PsiDirectory ;
10
11
import com .magento .idea .magento2plugin .actions .generation .NewDataModelAction ;
11
12
import com .magento .idea .magento2plugin .actions .generation .data .DataModelData ;
19
20
import com .magento .idea .magento2plugin .actions .generation .generator .util .NamespaceBuilder ;
20
21
import com .magento .idea .magento2plugin .magento .files .DataModel ;
21
22
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 ;
22
26
import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
23
27
24
28
import javax .swing .JButton ;
29
+ import javax .swing .JCheckBox ;
25
30
import javax .swing .JComponent ;
26
31
import javax .swing .JPanel ;
32
+ import javax .swing .JTable ;
27
33
import javax .swing .JTextField ;
28
34
import javax .swing .KeyStroke ;
35
+ import javax .swing .table .DefaultTableModel ;
36
+ import javax .swing .table .TableColumn ;
29
37
import java .awt .event .ActionEvent ;
30
38
import java .awt .event .KeyEvent ;
31
39
import java .awt .event .WindowAdapter ;
@@ -38,10 +46,18 @@ public class NewDataModelDialog extends AbstractDialog {
38
46
private NamespaceBuilder modelNamespace ;
39
47
40
48
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" };
41
55
42
56
private JPanel contentPanel ;
43
57
private JButton buttonOK ;
44
58
private JButton buttonCancel ;
59
+ private JTable properties ;
60
+ private JButton addProperty ;
45
61
46
62
@ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
47
63
message = {NotEmptyRule .MESSAGE , MODEL_NAME })
@@ -72,6 +88,8 @@ public void windowClosing(final WindowEvent event) {
72
88
}
73
89
});
74
90
91
+ initPropertiesTable ();
92
+
75
93
// call onCancel() on ESCAPE KEY press
76
94
contentPanel .registerKeyboardAction (
77
95
(final ActionEvent event ) -> onCancel (),
@@ -87,7 +105,7 @@ public static void open(final Project project, final PsiDirectory directory) {
87
105
dialog .setVisible (true );
88
106
}
89
107
90
- protected void onOK () {
108
+ private void onOK () {
91
109
if (validateFormFields ()) {
92
110
buildNamespaces ();
93
111
generateModelInterfaceFile ();
@@ -162,4 +180,40 @@ private String getModelFQN() {
162
180
private String getProperties () {
163
181
return "" ;
164
182
}
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
+ }
165
219
}
0 commit comments