|
5 | 5 |
|
6 | 6 | package com.magento.idea.magento2plugin.actions.generation.dialog;
|
7 | 7 |
|
| 8 | +import com.google.common.base.CaseFormat; |
8 | 9 | import com.intellij.openapi.project.Project;
|
9 | 10 | import com.intellij.openapi.ui.ComboBoxTableRenderer;
|
10 | 11 | import com.intellij.psi.PsiDirectory;
|
|
24 | 25 | import com.magento.idea.magento2plugin.ui.table.DeleteRowButton;
|
25 | 26 | import com.magento.idea.magento2plugin.ui.table.TableButton;
|
26 | 27 | import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
|
27 |
| - |
| 28 | +import java.awt.event.ActionEvent; |
| 29 | +import java.awt.event.KeyEvent; |
| 30 | +import java.awt.event.WindowAdapter; |
| 31 | +import java.awt.event.WindowEvent; |
| 32 | +import java.util.ArrayList; |
28 | 33 | import javax.swing.JButton;
|
29 | 34 | import javax.swing.JCheckBox;
|
30 | 35 | import javax.swing.JComponent;
|
|
34 | 39 | import javax.swing.KeyStroke;
|
35 | 40 | import javax.swing.table.DefaultTableModel;
|
36 | 41 | import javax.swing.table.TableColumn;
|
37 |
| -import java.awt.event.ActionEvent; |
38 |
| -import java.awt.event.KeyEvent; |
39 |
| -import java.awt.event.WindowAdapter; |
40 |
| -import java.awt.event.WindowEvent; |
| 42 | +import org.apache.commons.lang.StringUtils; |
| 43 | + |
41 | 44 |
|
| 45 | +@SuppressWarnings({ |
| 46 | + "PMD.ExcessiveImports" |
| 47 | +}) |
42 | 48 | public class NewDataModelDialog extends AbstractDialog {
|
43 | 49 | private final Project project;
|
44 | 50 | private final String moduleName;
|
45 | 51 | private NamespaceBuilder interfaceNamespace;
|
46 | 52 | private NamespaceBuilder modelNamespace;
|
| 53 | + private String formattedProperties; |
47 | 54 |
|
48 | 55 | private static final String MODEL_NAME = "Model Name";
|
49 | 56 | private static final String PROPERTY_NAME = "Name";
|
@@ -108,6 +115,7 @@ public static void open(final Project project, final PsiDirectory directory) {
|
108 | 115 | private void onOK() {
|
109 | 116 | if (validateFormFields()) {
|
110 | 117 | buildNamespaces();
|
| 118 | + formatProperties(); |
111 | 119 | generateModelInterfaceFile();
|
112 | 120 | generateModelFile();
|
113 | 121 | this.setVisible(false);
|
@@ -149,6 +157,32 @@ private void buildNamespaces() {
|
149 | 157 | );
|
150 | 158 | }
|
151 | 159 |
|
| 160 | + /** |
| 161 | + * Formats properties into a string format, ready for templating. |
| 162 | + * "UPPER_SNAKE;lower_snake;type;UpperCamel;lowerCamel". |
| 163 | + */ |
| 164 | + private void formatProperties() { |
| 165 | + final DefaultTableModel propertiesTable = getPropertiesTable(); |
| 166 | + final ArrayList<String> properties = new ArrayList<>(); |
| 167 | + final ArrayList<String> propertyData = new ArrayList<>(); |
| 168 | + final int rowCount = propertiesTable.getRowCount(); |
| 169 | + String name; |
| 170 | + String type; |
| 171 | + |
| 172 | + for (int index = 0; index < rowCount; index++, propertyData.clear()) { |
| 173 | + name = propertiesTable.getValueAt(index, 0).toString(); |
| 174 | + type = propertiesTable.getValueAt(index, 1).toString(); |
| 175 | + propertyData.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_UNDERSCORE, name)); |
| 176 | + propertyData.add(name); |
| 177 | + propertyData.add(type); |
| 178 | + propertyData.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name)); |
| 179 | + propertyData.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name)); |
| 180 | + properties.add(StringUtils.join(propertyData, ";")); |
| 181 | + } |
| 182 | + |
| 183 | + formattedProperties = StringUtils.join(properties, ","); |
| 184 | + } |
| 185 | + |
152 | 186 | private String getModuleName() {
|
153 | 187 | return moduleName;
|
154 | 188 | }
|
@@ -178,7 +212,7 @@ private String getModelFQN() {
|
178 | 212 | }
|
179 | 213 |
|
180 | 214 | private String getProperties() {
|
181 |
| - return ""; |
| 215 | + return formattedProperties; |
182 | 216 | }
|
183 | 217 |
|
184 | 218 | private void initPropertiesTable() {
|
|
0 commit comments