14
14
import com .magento .idea .magento2plugin .actions .generation .data .DataModelData ;
15
15
import com .magento .idea .magento2plugin .actions .generation .data .DataModelInterfaceData ;
16
16
import com .magento .idea .magento2plugin .actions .generation .data .PreferenceDiXmFileData ;
17
+ import com .magento .idea .magento2plugin .actions .generation .data .code .ClassPropertyData ;
17
18
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
18
19
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
19
20
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
37
38
import java .awt .event .WindowAdapter ;
38
39
import java .awt .event .WindowEvent ;
39
40
import java .util .ArrayList ;
41
+ import java .util .List ;
40
42
import javax .swing .JButton ;
41
43
import javax .swing .JCheckBox ;
42
44
import javax .swing .JComponent ;
@@ -58,9 +60,9 @@ public class NewDataModelDialog extends AbstractDialog {
58
60
private final String moduleName ;
59
61
private final ValidatorBundle validatorBundle ;
60
62
private final CommonBundle commonBundle ;
63
+ private final List <String > properties ;
61
64
private NamespaceBuilder interfaceNamespace ;
62
65
private NamespaceBuilder modelNamespace ;
63
- private String formattedProperties ;
64
66
65
67
private static final String MODEL_NAME = "Model Name" ;
66
68
private static final String PROPERTY_NAME = "Name" ;
@@ -73,7 +75,7 @@ public class NewDataModelDialog extends AbstractDialog {
73
75
private JPanel contentPanel ;
74
76
private JButton buttonOK ;
75
77
private JButton buttonCancel ;
76
- private JTable properties ;
78
+ private JTable propertyTable ;
77
79
private JButton addProperty ;
78
80
79
81
@ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
@@ -92,6 +94,7 @@ public NewDataModelDialog(final Project project, final PsiDirectory directory) {
92
94
this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
93
95
this .validatorBundle = new ValidatorBundle ();
94
96
this .commonBundle = new CommonBundle ();
97
+ this .properties = new ArrayList <>();
95
98
96
99
setContentPane (contentPanel );
97
100
setModal (true );
@@ -148,8 +151,8 @@ protected boolean validateFormFields() {
148
151
valid = true ;
149
152
final String errorTitle = commonBundle .message ("common.error" );
150
153
final int column = 0 ;
151
- for (int row = 0 ; row < properties .getRowCount (); row ++) {
152
- final String propertyName = ((String ) properties .getValueAt (row , column )).trim ();
154
+ for (int row = 0 ; row < propertyTable .getRowCount (); row ++) {
155
+ final String propertyName = ((String ) propertyTable .getValueAt (row , column )).trim ();
153
156
if (propertyName .isEmpty ()) {
154
157
valid = false ;
155
158
final String errorMessage = validatorBundle .message (
@@ -227,29 +230,25 @@ private void buildNamespaces() {
227
230
}
228
231
229
232
/**
230
- * Formats properties into a string format, ready for templating.
231
- * "UPPER_SNAKE;lower_snake;type;UpperCamel;lowerCamel".
233
+ * Formats properties into an array of ClassPropertyData objects.
232
234
*/
233
235
private void formatProperties () {
234
236
final DefaultTableModel propertiesTable = getPropertiesTable ();
235
- final ArrayList <String > properties = new ArrayList <>();
236
- final ArrayList <String > propertyData = new ArrayList <>();
237
237
final int rowCount = propertiesTable .getRowCount ();
238
238
String name ;
239
239
String type ;
240
240
241
- for (int index = 0 ; index < rowCount ; index ++, propertyData . clear () ) {
241
+ for (int index = 0 ; index < rowCount ; index ++) {
242
242
name = propertiesTable .getValueAt (index , 0 ).toString ();
243
243
type = propertiesTable .getValueAt (index , 1 ).toString ();
244
- propertyData .add (CaseFormat .LOWER_UNDERSCORE .to (CaseFormat .UPPER_UNDERSCORE , name ));
245
- propertyData .add (name );
246
- propertyData .add (type );
247
- propertyData .add (CaseFormat .LOWER_UNDERSCORE .to (CaseFormat .UPPER_CAMEL , name ));
248
- propertyData .add (CaseFormat .LOWER_UNDERSCORE .to (CaseFormat .LOWER_CAMEL , name ));
249
- properties .add (StringUtils .join (propertyData , ";" ));
244
+ properties .add ((new ClassPropertyData (
245
+ type ,
246
+ CaseFormat .LOWER_UNDERSCORE .to (CaseFormat .LOWER_CAMEL , name ),
247
+ CaseFormat .LOWER_UNDERSCORE .to (CaseFormat .UPPER_CAMEL , name ),
248
+ name ,
249
+ CaseFormat .LOWER_UNDERSCORE .to (CaseFormat .UPPER_UNDERSCORE , name )
250
+ )).string ());
250
251
}
251
-
252
- formattedProperties = StringUtils .join (properties , "," );
253
252
}
254
253
255
254
private String getModuleName () {
@@ -280,8 +279,12 @@ private String getModelFQN() {
280
279
return modelNamespace .getClassFqn ();
281
280
}
282
281
282
+ /**
283
+ * Gets properties as a string, ready for templating.
284
+ * "UPPER_SNAKE;lower_snake;type;UpperCamel;lowerCamel".
285
+ */
283
286
private String getProperties () {
284
- return formattedProperties ;
287
+ return StringUtils . join ( properties , "," ) ;
285
288
}
286
289
287
290
private void initPropertiesTable () {
@@ -295,7 +298,7 @@ private void initPropertiesTable() {
295
298
}
296
299
);
297
300
298
- final TableColumn column = properties .getColumn (PROPERTY_ACTION );
301
+ final TableColumn column = propertyTable .getColumn (PROPERTY_ACTION );
299
302
column .setCellRenderer (new TableButton (PROPERTY_DELETE ));
300
303
column .setCellEditor (new DeleteRowButton (new JCheckBox ()));
301
304
@@ -311,12 +314,12 @@ private void initPropertiesTable() {
311
314
}
312
315
313
316
private void initPropertyTypeColumn () {
314
- final TableColumn formElementTypeColumn = properties .getColumn (PROPERTY_TYPE );
317
+ final TableColumn formElementTypeColumn = propertyTable .getColumn (PROPERTY_TYPE );
315
318
formElementTypeColumn .setCellEditor (new ComboBoxEditor (PROPERTY_TYPES ));
316
319
formElementTypeColumn .setCellRenderer (new ComboBoxTableRenderer <>(PROPERTY_TYPES ));
317
320
}
318
321
319
322
private DefaultTableModel getPropertiesTable () {
320
- return (DefaultTableModel ) properties .getModel ();
323
+ return (DefaultTableModel ) propertyTable .getModel ();
321
324
}
322
325
}
0 commit comments