Skip to content

Commit 5d9275a

Browse files
author
Vitaliy
authored
Merge pull request #474 from anzin/fix-mainline-entity-maneger-dialog-form
Fix mainline entity manager dialog form
2 parents aeba3bf + dded030 commit 5d9275a

File tree

10 files changed

+323
-171
lines changed

10 files changed

+323
-171
lines changed

resources/magento2/validation.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ validator.magentoAclResourceIdInvalid=The ACL resource id is invalid
3535
validator.lowercaseCharacters={0} must contain lowercase characters only
3636
validator.db.invalidTableNameLength=Table name must contain up to 64 characters only (inclusive)
3737
validator.lowerSnakeCase=The {0} field must be of the lower snake case format
38+
validator.menuIdentifierInvalid=The menu identifier is invalid

src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public SaveEntityControllerFileData(
3636
final @NotNull String dtoType,
3737
final @NotNull String acl,
3838
final @NotNull String entityId
39-
) {
40-
this.entityName = entityName;
41-
this.moduleName = moduleName;
42-
this.namespace = namespace;
43-
this.saveCommandFqn = saveCommandFqn;
44-
this.dtoType = dtoType;
45-
this.acl = acl;
46-
this.entityId = entityId;
39+
) {
40+
this.entityName = entityName;
41+
this.moduleName = moduleName;
42+
this.namespace = namespace;
43+
this.saveCommandFqn = saveCommandFqn;
44+
this.dtoType = dtoType;
45+
this.acl = acl;
46+
this.entityId = entityId;
4747
}
4848

4949
/**

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ private void initPropertiesTable() {
312312

313313
addProperty.addActionListener(e -> {
314314
propertiesTable.addRow(new Object[]{
315-
"",
316-
PropertiesTypes.valueOf(PropertiesTypes.INT.toString())
317-
.getPropertyType(),
318-
PROPERTY_DELETE
315+
"",
316+
PropertiesTypes.valueOf(PropertiesTypes.INT.toString())
317+
.getPropertyType(),
318+
PROPERTY_DELETE
319319
});
320320
});
321321

@@ -324,8 +324,12 @@ private void initPropertiesTable() {
324324

325325
private void initPropertyTypeColumn() {
326326
final TableColumn formElementTypeColumn = propertyTable.getColumn(PROPERTY_TYPE);
327-
formElementTypeColumn.setCellEditor(new ComboBoxEditor(PropertiesTypes.getPropertyTypes()));
328-
formElementTypeColumn.setCellRenderer(new ComboBoxTableRenderer<>(PropertiesTypes.getPropertyTypes()));
327+
formElementTypeColumn.setCellEditor(
328+
new ComboBoxEditor(PropertiesTypes.getPropertyTypes())
329+
);
330+
formElementTypeColumn.setCellRenderer(
331+
new ComboBoxTableRenderer<>(PropertiesTypes.getPropertyTypes())
332+
);
329333
}
330334

331335
private DefaultTableModel getPropertiesTable() {

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

Lines changed: 239 additions & 144 deletions
Large diffs are not rendered by default.

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

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
import com.magento.idea.magento2plugin.actions.generation.data.UiComponentGridToolbarData;
3838
import com.magento.idea.magento2plugin.actions.generation.data.code.ClassPropertyData;
3939
import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData;
40+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
41+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
42+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AclResourceIdRule;
43+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierRule;
44+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.MenuIdentifierRule;
45+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
46+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NumericRule;
4047
import com.magento.idea.magento2plugin.actions.generation.generator.AclXmlGenerator;
4148
import com.magento.idea.magento2plugin.actions.generation.generator.DataModelGenerator;
4249
import com.magento.idea.magento2plugin.actions.generation.generator.DataModelInterfaceGenerator;
@@ -103,6 +110,7 @@
103110
import javax.swing.JTabbedPane;
104111
import javax.swing.JTable;
105112
import javax.swing.JTextField;
113+
import javax.swing.JTextPane;
106114
import javax.swing.KeyStroke;
107115
import javax.swing.table.DefaultTableModel;
108116
import org.apache.commons.lang.StringUtils;
@@ -140,25 +148,18 @@ public class NewEntityDialog extends AbstractDialog {
140148
private JLabel entityIdColumnNameLabel;
141149
private JTextField route;
142150
private JLabel routeLabel;
143-
private JTextField acl;
144151
private JLabel aclLabel;
145152
private JTextField aclTitle;
146153
private FilteredComboBox parentAcl;
147-
private JLabel formNameLabel;
148-
private JTextField formName;
149154
private JTextField formLabel;
150155
private JLabel formLabelLabel;
151-
private JTextField gridName;
152156
private JLabel gridNameLabel;
153157
private JLabel parentMenuItemLabel;
154158
private JLabel sortOrderLabel;
155159
private JLabel menuIdentifierLabel;
156-
private JTextField sortOrder;
157-
private JTextField menuIdentifier;
158160
private JLabel menuTitleLabel;
159161
private JTextField menuTitle;
160162
private FilteredComboBox parentMenu;
161-
private JLabel formMenuLabel;
162163
private JCheckBox addToolBar;
163164
private JCheckBox addBookmarksCheckBox;
164165
private JCheckBox addColumnsControlCheckBox;
@@ -176,7 +177,36 @@ public class NewEntityDialog extends AbstractDialog {
176177
private static final String ACTION_NAME = "Create Entity";
177178
private static final String PROPERTY_NAME = "Name";
178179
private static final String PROPERTY_TYPE = "Type";
180+
private static final String ACL_ID = "ACL ID";
181+
private static final String FORM_NAME = "Form Name";
182+
private static final String GRID_NAME = "Grit Name";
183+
private static final String IDENTIFIER = "Identifier";
184+
private static final String SORT_ORDER = "Sort Order";
185+
186+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, FORM_NAME})
187+
@FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE})
188+
private JTextField formName;
189+
190+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, GRID_NAME})
191+
@FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE})
192+
private JTextField gridName;
179193

194+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, ACL_ID})
195+
@FieldValidation(rule = RuleRegistry.ACL_RESOURCE_ID, message = {AclResourceIdRule.MESSAGE})
196+
private JTextField acl;
197+
198+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, SORT_ORDER})
199+
@FieldValidation(rule = RuleRegistry.NUMERIC, message = {NumericRule.MESSAGE})
200+
private JTextField sortOrder;
201+
202+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, IDENTIFIER})
203+
@FieldValidation(rule = RuleRegistry.MENU_IDENTIFIER, message = {MenuIdentifierRule.MESSAGE})
204+
private JTextField menuIdentifier;
205+
private JLabel formNameLabel;
206+
private JTextPane exampleIdentifier;
207+
private JTextPane exampleAclId;
208+
private JTextPane exampleFormName;
209+
private JTextPane exampleGridName;
180210
private JTextField observerName;
181211

182212
/**
@@ -276,6 +306,10 @@ private DefaultTableModel getPropertiesTable() {
276306
* Perform code generation using input data.
277307
*/
278308
private void onOK() {
309+
if (!validateFormFields()) {
310+
return;
311+
}
312+
279313
generateModelFile();
280314
generateResourceModelFile();
281315
generateCollectionFile();

src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierRule;
1919
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierWithColonRule;
2020
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.Lowercase;
21+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.MenuIdentifierRule;
2122
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
2223
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NumericRule;
2324
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassFqnRule;
@@ -50,7 +51,8 @@ public enum RuleRegistry {
5051
CONFIG_PATH(ConfigPathRule.class),
5152
CLI_COMMAND(CliCommandRule.class),
5253
NUMERIC(NumericRule.class),
53-
TABLE_NAME_LENGTH(TableNameLength.class);
54+
TABLE_NAME_LENGTH(TableNameLength.class),
55+
MENU_IDENTIFIER(MenuIdentifierRule.class);
5456

5557
private Class<?> rule;
5658

src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/AclResourceIdRule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class AclResourceIdRule implements ValidationRule {
1313

1414
@Override
1515
public boolean check(final String value) {
16-
return value.matches(RegExUtil.Magento.ACL_RESOURCE_ID);
16+
return value.matches(RegExUtil.Magento.XML_IDENTIFIER);
1717
}
1818

1919
public static ValidationRule getInstance() {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule;
2+
3+
import com.magento.idea.magento2plugin.util.RegExUtil;
4+
5+
public class MenuIdentifierRule implements ValidationRule {
6+
public static final String MESSAGE = "validator.menuIdentifierInvalid";
7+
private static final ValidationRule INSTANCE = new MenuIdentifierRule();
8+
9+
@Override
10+
public boolean check(final String value) {
11+
return value.matches(RegExUtil.Magento.XML_IDENTIFIER);
12+
}
13+
14+
public static ValidationRule getInstance() {
15+
return INSTANCE;
16+
}
17+
}

src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
import com.magento.idea.magento2plugin.magento.packages.Package;
2323
import com.magento.idea.magento2plugin.util.GetFirstClassOfFile;
2424
import com.magento.idea.magento2plugin.util.GetPhpClassByFQN;
25-
26-
import javax.swing.*;
2725
import java.util.Properties;
26+
import javax.swing.JOptionPane;
2827

2928
public class QueryGenerator extends FileGenerator {
3029
private final UiComponentDataProviderData uiComponentGridDataProviderData;

src/com/magento/idea/magento2plugin/util/RegExUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public static class Magento {
6666

6767
public static final String ROUTE_ID = "^[A-Za-z0-9_]{3,}$";
6868

69-
public static final String ACL_RESOURCE_ID
70-
= "^([A-Z]+[a-zA-Z0-9]{1,}){1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}$";
69+
public static final String XML_IDENTIFIER =
70+
"^([A-Z]+[a-zA-Z0-9]{1,}){1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}$";
7171
}
7272

7373
public class PhpRegex {

0 commit comments

Comments
 (0)