Skip to content

Commit 81c4b3c

Browse files
UI Component form development
1 parent 5d9275a commit 81c4b3c

File tree

4 files changed

+112
-31
lines changed

4 files changed

+112
-31
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<border type="none"/>
2323
<children>
2424
<grid id="6be8b" binding="generalTable" layout-manager="GridLayoutManager" row-count="7" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
25-
<margin top="0" left="10" bottom="0" right="10"/>
25+
<margin top="10" left="10" bottom="0" right="10"/>
2626
<constraints>
2727
<tabbedpane title="General"/>
2828
</constraints>
@@ -138,7 +138,7 @@
138138
</children>
139139
</grid>
140140
<grid id="e3309" layout-manager="GridLayoutManager" row-count="8" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
141-
<margin top="0" left="10" bottom="0" right="10"/>
141+
<margin top="10" left="10" bottom="0" right="10"/>
142142
<constraints>
143143
<tabbedpane title="Admin UI Components"/>
144144
</constraints>
@@ -323,7 +323,7 @@
323323
</children>
324324
</grid>
325325
<grid id="2a206" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
326-
<margin top="0" left="10" bottom="0" right="10"/>
326+
<margin top="10" left="10" bottom="0" right="10"/>
327327
<constraints>
328328
<tabbedpane title="ACL"/>
329329
</constraints>
@@ -413,7 +413,7 @@
413413
</children>
414414
</grid>
415415
<grid id="81b65" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
416-
<margin top="0" left="10" bottom="0" right="10"/>
416+
<margin top="10" left="10" bottom="0" right="10"/>
417417
<constraints>
418418
<tabbedpane title="Menu"/>
419419
</constraints>
@@ -516,7 +516,7 @@
516516
</children>
517517
</grid>
518518
<grid id="9e945" binding="propertiesPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
519-
<margin top="0" left="0" bottom="0" right="0"/>
519+
<margin top="10" left="0" bottom="0" right="0"/>
520520
<constraints>
521521
<tabbedpane title="Properties"/>
522522
</constraints>

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import com.magento.idea.magento2plugin.magento.packages.PropertiesTypes;
8383
import com.magento.idea.magento2plugin.magento.packages.database.TableEngines;
8484
import com.magento.idea.magento2plugin.magento.packages.database.TableResources;
85+
import com.magento.idea.magento2plugin.magento.packages.uiComponent.FormElementType;
8586
import com.magento.idea.magento2plugin.stubs.indexes.xml.MenuIndex;
8687
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
8788
import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper;
@@ -690,8 +691,8 @@ public List<UiComponentFormFieldsetData> getFieldsets() {
690691
*
691692
* @return List[UiComponentFormButtonData]
692693
*/
693-
protected List getButtons() {
694-
final List buttons = new ArrayList();
694+
protected List<UiComponentFormButtonData> getButtons() {
695+
final List<UiComponentFormButtonData> buttons = new ArrayList<>();
695696
final String directory = "Block/Form";
696697

697698
final NamespaceBuilder namespaceBuilderSave = new NamespaceBuilder(
@@ -701,7 +702,7 @@ protected List getButtons() {
701702
);
702703
buttons.add(new UiComponentFormButtonData(
703704
directory,
704-
"SaveEntity",
705+
"Save",
705706
getModuleName(),
706707
"Save",
707708
namespaceBuilderSave.getNamespace(),
@@ -758,13 +759,13 @@ public List<UiComponentFormFieldData> getFields() {
758759

759760
fieldsets.add(
760761
new UiComponentFormFieldData(
761-
"entity_id",
762-
"int",
762+
getEntityIdColumn(),
763763
"Entity ID",
764764
"0",
765765
"general",
766-
"hidden",
767-
"entity_id"
766+
FormElementType.HIDDEN.getType(),
767+
"text",
768+
getEntityIdColumn()
768769
)
769770
);
770771

@@ -776,7 +777,12 @@ public List<UiComponentFormFieldData> getFields() {
776777
final String label = model.getValueAt(count, 0).toString(); //todo: convert
777778
final String sortOrder = String.valueOf(count).concat("0");
778779
final String fieldset = "general";
779-
final String formElementType = model.getValueAt(count, 1).toString();
780+
781+
final PropertiesTypes property =
782+
PropertiesTypes.getByValue(model.getValueAt(count, 1).toString());
783+
final String formElementType =
784+
FormElementType.getDefaultForProperty(property).getType();
785+
780786
final String source = model.getValueAt(count, 0).toString(); //todo: convert
781787

782788
final UiComponentFormFieldData fieldsetData = new UiComponentFormFieldData(//NOPMD

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.magento.idea.magento2plugin.magento.packages.Areas;
4848
import com.magento.idea.magento2plugin.magento.packages.File;
4949
import com.magento.idea.magento2plugin.magento.packages.HttpMethod;
50+
import com.magento.idea.magento2plugin.magento.packages.uiComponent.FormElementType;
5051
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
5152
import com.magento.idea.magento2plugin.ui.table.ComboBoxEditor;
5253
import com.magento.idea.magento2plugin.ui.table.DeleteRowButton;
@@ -346,25 +347,9 @@ protected void initFieldTable() {
346347
}
347348

348349
private void initFormElementTypeColumn() {
349-
final String[] formElementTypes = {
350-
"hidden",
351-
"file",
352-
"input",
353-
"date",
354-
"boolean",
355-
"checkbox",
356-
"checkboxset",
357-
"email",
358-
"select",
359-
"multiselect",
360-
"text",
361-
"textarea",
362-
"price",
363-
"radioset",
364-
"wysiwyg"
365-
};
366-
350+
final String[] formElementTypes = FormElementType.getTypeList().toArray(new String[0]);
367351
final TableColumn formElementTypeColumn = fields.getColumn(FORM_ELEMENT_TYPE_COLUMN);
352+
368353
formElementTypeColumn.setCellEditor(new ComboBoxEditor(formElementTypes));
369354
formElementTypeColumn.setCellRenderer(new ComboBoxTableRenderer<>(formElementTypes));
370355
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.magento.packages.uiComponent;
7+
import com.intellij.openapi.externalSystem.service.execution.NotSupportedException;
8+
import com.magento.idea.magento2plugin.magento.packages.PropertiesTypes;
9+
import java.util.LinkedList;
10+
import java.util.List;
11+
import org.jetbrains.annotations.NotNull;
12+
13+
public enum FormElementType {
14+
HIDDEN("hidden"),
15+
FILE("file"),
16+
INPUT("input"),
17+
DATE("date"),
18+
BOOLEAN("boolean"),
19+
CHECKBOX("checkbox"),
20+
CHECKBOX_SET("checkboxset"),
21+
EMAIL("email"),
22+
SELECT("select"),
23+
MULTISELECT("multiselect"),
24+
TEXT("text"),
25+
TEXTAREA("textarea"),
26+
PRICE("price"),
27+
RADIO_SET("radioset"),
28+
WYSIWYG("wysiwyg");
29+
30+
/**
31+
* UI Component form element type.
32+
*/
33+
private final String type;
34+
35+
/**
36+
* Form element type constructor.
37+
*
38+
* @param type String
39+
*/
40+
FormElementType(final @NotNull String type) {
41+
this.type = type;
42+
}
43+
44+
/**
45+
* Get form element type.
46+
*
47+
* @return String
48+
*/
49+
public @NotNull String getType() {
50+
return type;
51+
}
52+
53+
/**
54+
* Get list of available types.
55+
*
56+
* @return List[String] of available types.
57+
*/
58+
public static List<String> getTypeList() {
59+
final List<String> availableTypes = new LinkedList<>();
60+
61+
for (final FormElementType type : FormElementType.values()) {
62+
availableTypes.add(type.getType());
63+
}
64+
65+
return availableTypes;
66+
}
67+
68+
/**
69+
* Get default form element for specified property type.
70+
*
71+
* @param property PropertiesTypes
72+
*
73+
* @return FormElementType
74+
*/
75+
public static FormElementType getDefaultForProperty(final @NotNull PropertiesTypes property) {
76+
switch (property) {
77+
case INT:
78+
case STRING:
79+
return FormElementType.INPUT;
80+
case BOOL:
81+
return FormElementType.BOOLEAN;
82+
case FLOAT:
83+
return FormElementType.PRICE;
84+
default:
85+
throw new NotSupportedException(
86+
"ENUMs " + FormElementType.class + " property is not supported."
87+
);
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)