1414import com .magento .idea .magento2plugin .actions .generation .data .DataModelData ;
1515import com .magento .idea .magento2plugin .actions .generation .data .DataModelInterfaceData ;
1616import com .magento .idea .magento2plugin .actions .generation .data .PreferenceDiXmFileData ;
17+ import com .magento .idea .magento2plugin .actions .generation .data .code .ClassPropertyData ;
1718import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
1819import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
1920import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
3738import java .awt .event .WindowAdapter ;
3839import java .awt .event .WindowEvent ;
3940import java .util .ArrayList ;
41+ import java .util .List ;
4042import javax .swing .JButton ;
4143import javax .swing .JCheckBox ;
4244import javax .swing .JComponent ;
@@ -58,9 +60,9 @@ public class NewDataModelDialog extends AbstractDialog {
5860 private final String moduleName ;
5961 private final ValidatorBundle validatorBundle ;
6062 private final CommonBundle commonBundle ;
63+ private final List <String > properties ;
6164 private NamespaceBuilder interfaceNamespace ;
6265 private NamespaceBuilder modelNamespace ;
63- private String formattedProperties ;
6466
6567 private static final String MODEL_NAME = "Model Name" ;
6668 private static final String PROPERTY_NAME = "Name" ;
@@ -73,7 +75,7 @@ public class NewDataModelDialog extends AbstractDialog {
7375 private JPanel contentPanel ;
7476 private JButton buttonOK ;
7577 private JButton buttonCancel ;
76- private JTable properties ;
78+ private JTable propertyTable ;
7779 private JButton addProperty ;
7880
7981 @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
@@ -92,6 +94,7 @@ public NewDataModelDialog(final Project project, final PsiDirectory directory) {
9294 this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
9395 this .validatorBundle = new ValidatorBundle ();
9496 this .commonBundle = new CommonBundle ();
97+ this .properties = new ArrayList <>();
9598
9699 setContentPane (contentPanel );
97100 setModal (true );
@@ -148,8 +151,8 @@ protected boolean validateFormFields() {
148151 valid = true ;
149152 final String errorTitle = commonBundle .message ("common.error" );
150153 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 ();
153156 if (propertyName .isEmpty ()) {
154157 valid = false ;
155158 final String errorMessage = validatorBundle .message (
@@ -227,29 +230,25 @@ private void buildNamespaces() {
227230 }
228231
229232 /**
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.
232234 */
233235 private void formatProperties () {
234236 final DefaultTableModel propertiesTable = getPropertiesTable ();
235- final ArrayList <String > properties = new ArrayList <>();
236- final ArrayList <String > propertyData = new ArrayList <>();
237237 final int rowCount = propertiesTable .getRowCount ();
238238 String name ;
239239 String type ;
240240
241- for (int index = 0 ; index < rowCount ; index ++, propertyData . clear () ) {
241+ for (int index = 0 ; index < rowCount ; index ++) {
242242 name = propertiesTable .getValueAt (index , 0 ).toString ();
243243 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 ());
250251 }
251-
252- formattedProperties = StringUtils .join (properties , "," );
253252 }
254253
255254 private String getModuleName () {
@@ -280,8 +279,12 @@ private String getModelFQN() {
280279 return modelNamespace .getClassFqn ();
281280 }
282281
282+ /**
283+ * Gets properties as a string, ready for templating.
284+ * "UPPER_SNAKE;lower_snake;type;UpperCamel;lowerCamel".
285+ */
283286 private String getProperties () {
284- return formattedProperties ;
287+ return StringUtils . join ( properties , "," ) ;
285288 }
286289
287290 private void initPropertiesTable () {
@@ -295,7 +298,7 @@ private void initPropertiesTable() {
295298 }
296299 );
297300
298- final TableColumn column = properties .getColumn (PROPERTY_ACTION );
301+ final TableColumn column = propertyTable .getColumn (PROPERTY_ACTION );
299302 column .setCellRenderer (new TableButton (PROPERTY_DELETE ));
300303 column .setCellEditor (new DeleteRowButton (new JCheckBox ()));
301304
@@ -311,12 +314,12 @@ private void initPropertiesTable() {
311314 }
312315
313316 private void initPropertyTypeColumn () {
314- final TableColumn formElementTypeColumn = properties .getColumn (PROPERTY_TYPE );
317+ final TableColumn formElementTypeColumn = propertyTable .getColumn (PROPERTY_TYPE );
315318 formElementTypeColumn .setCellEditor (new ComboBoxEditor (PROPERTY_TYPES ));
316319 formElementTypeColumn .setCellRenderer (new ComboBoxTableRenderer <>(PROPERTY_TYPES ));
317320 }
318321
319322 private DefaultTableModel getPropertiesTable () {
320- return (DefaultTableModel ) properties .getModel ();
323+ return (DefaultTableModel ) propertyTable .getModel ();
321324 }
322325}
0 commit comments