Skip to content

Commit 186f680

Browse files
committed
Completed property generation
1 parent 64dc689 commit 186f680

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
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="7" 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="3" 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="500" height="700"/>
9+
<preferredSize width="500" height="600"/>
1010
</properties>
1111
<border type="none"/>
1212
<children>
1313
<grid id="e3588" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1414
<margin top="0" left="0" bottom="0" right="0"/>
1515
<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"/>
16+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
1717
</constraints>
1818
<properties/>
1919
<border type="none"/>
@@ -41,7 +41,7 @@
4141
<grid id="ebe15" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4242
<margin top="5" left="5" bottom="5" right="5"/>
4343
<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"/>
44+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
4545
</constraints>
4646
<properties/>
4747
<border type="empty" title="Properties" title-justification="2" title-position="2"/>
@@ -76,7 +76,7 @@
7676
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
7777
<margin top="0" left="0" bottom="0" right="0"/>
7878
<constraints>
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"/>
79+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
8080
</constraints>
8181
<properties/>
8282
<border type="none"/>

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

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package com.magento.idea.magento2plugin.actions.generation.dialog;
77

8+
import com.google.common.base.CaseFormat;
89
import com.intellij.openapi.project.Project;
910
import com.intellij.openapi.ui.ComboBoxTableRenderer;
1011
import com.intellij.psi.PsiDirectory;
@@ -24,7 +25,11 @@
2425
import com.magento.idea.magento2plugin.ui.table.DeleteRowButton;
2526
import com.magento.idea.magento2plugin.ui.table.TableButton;
2627
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;
2833
import javax.swing.JButton;
2934
import javax.swing.JCheckBox;
3035
import javax.swing.JComponent;
@@ -34,16 +39,18 @@
3439
import javax.swing.KeyStroke;
3540
import javax.swing.table.DefaultTableModel;
3641
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+
4144

45+
@SuppressWarnings({
46+
"PMD.ExcessiveImports"
47+
})
4248
public class NewDataModelDialog extends AbstractDialog {
4349
private final Project project;
4450
private final String moduleName;
4551
private NamespaceBuilder interfaceNamespace;
4652
private NamespaceBuilder modelNamespace;
53+
private String formattedProperties;
4754

4855
private static final String MODEL_NAME = "Model Name";
4956
private static final String PROPERTY_NAME = "Name";
@@ -108,6 +115,7 @@ public static void open(final Project project, final PsiDirectory directory) {
108115
private void onOK() {
109116
if (validateFormFields()) {
110117
buildNamespaces();
118+
formatProperties();
111119
generateModelInterfaceFile();
112120
generateModelFile();
113121
this.setVisible(false);
@@ -149,6 +157,32 @@ private void buildNamespaces() {
149157
);
150158
}
151159

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+
152186
private String getModuleName() {
153187
return moduleName;
154188
}
@@ -178,7 +212,7 @@ private String getModelFQN() {
178212
}
179213

180214
private String getProperties() {
181-
return "";
215+
return formattedProperties;
182216
}
183217

184218
private void initPropertiesTable() {

src/com/magento/idea/magento2plugin/actions/generation/generator/util/PhpClassGeneratorUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ public static String getNameFromFqn(final String fqn) {
3535

3636
return fqnArray[fqnArray.length - 1];
3737
}
38-
}
38+
}

src/com/magento/idea/magento2plugin/magento/files/DataModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ public String getTemplate() {
3131
public Language getLanguage() {
3232
return PhpLanguage.INSTANCE;
3333
}
34-
}
34+
}

0 commit comments

Comments
 (0)