Skip to content

Commit 2f29726

Browse files
Merge branch 'mainline-entity-manager' of github.com:magento/magento2-phpstorm-plugin into add-entity-columns-to-grid
2 parents e57d130 + 5d9275a commit 2f29726

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
@@ -39,6 +39,13 @@
3939
import com.magento.idea.magento2plugin.actions.generation.data.UiComponentGridToolbarData;
4040
import com.magento.idea.magento2plugin.actions.generation.data.code.ClassPropertyData;
4141
import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData;
42+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
43+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
44+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AclResourceIdRule;
45+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierRule;
46+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.MenuIdentifierRule;
47+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
48+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NumericRule;
4249
import com.magento.idea.magento2plugin.actions.generation.generator.AclXmlGenerator;
4350
import com.magento.idea.magento2plugin.actions.generation.generator.DataModelGenerator;
4451
import com.magento.idea.magento2plugin.actions.generation.generator.DataModelInterfaceGenerator;
@@ -108,6 +115,7 @@
108115
import javax.swing.JTabbedPane;
109116
import javax.swing.JTable;
110117
import javax.swing.JTextField;
118+
import javax.swing.JTextPane;
111119
import javax.swing.KeyStroke;
112120
import javax.swing.table.DefaultTableModel;
113121
import org.apache.commons.lang.StringUtils;
@@ -145,25 +153,18 @@ public class NewEntityDialog extends AbstractDialog {
145153
private JLabel entityIdColumnNameLabel;
146154
private JTextField route;
147155
private JLabel routeLabel;
148-
private JTextField acl;
149156
private JLabel aclLabel;
150157
private JTextField aclTitle;
151158
private FilteredComboBox parentAcl;
152-
private JLabel formNameLabel;
153-
private JTextField formName;
154159
private JTextField formLabel;
155160
private JLabel formLabelLabel;
156-
private JTextField gridName;
157161
private JLabel gridNameLabel;
158162
private JLabel parentMenuItemLabel;
159163
private JLabel sortOrderLabel;
160164
private JLabel menuIdentifierLabel;
161-
private JTextField sortOrder;
162-
private JTextField menuIdentifier;
163165
private JLabel menuTitleLabel;
164166
private JTextField menuTitle;
165167
private FilteredComboBox parentMenu;
166-
private JLabel formMenuLabel;
167168
private JCheckBox addToolBar;
168169
private JCheckBox addBookmarksCheckBox;
169170
private JCheckBox addColumnsControlCheckBox;
@@ -181,7 +182,36 @@ public class NewEntityDialog extends AbstractDialog {
181182
private static final String ACTION_NAME = "Create Entity";
182183
private static final String PROPERTY_NAME = "Name";
183184
private static final String PROPERTY_TYPE = "Type";
185+
private static final String ACL_ID = "ACL ID";
186+
private static final String FORM_NAME = "Form Name";
187+
private static final String GRID_NAME = "Grit Name";
188+
private static final String IDENTIFIER = "Identifier";
189+
private static final String SORT_ORDER = "Sort Order";
190+
191+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, FORM_NAME})
192+
@FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE})
193+
private JTextField formName;
194+
195+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, GRID_NAME})
196+
@FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE})
197+
private JTextField gridName;
184198

199+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, ACL_ID})
200+
@FieldValidation(rule = RuleRegistry.ACL_RESOURCE_ID, message = {AclResourceIdRule.MESSAGE})
201+
private JTextField acl;
202+
203+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, SORT_ORDER})
204+
@FieldValidation(rule = RuleRegistry.NUMERIC, message = {NumericRule.MESSAGE})
205+
private JTextField sortOrder;
206+
207+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, IDENTIFIER})
208+
@FieldValidation(rule = RuleRegistry.MENU_IDENTIFIER, message = {MenuIdentifierRule.MESSAGE})
209+
private JTextField menuIdentifier;
210+
private JLabel formNameLabel;
211+
private JTextPane exampleIdentifier;
212+
private JTextPane exampleAclId;
213+
private JTextPane exampleFormName;
214+
private JTextPane exampleGridName;
185215
private JTextField observerName;
186216

187217
/**
@@ -281,6 +311,10 @@ private DefaultTableModel getPropertiesTable() {
281311
* Perform code generation using input data.
282312
*/
283313
private void onOK() {
314+
if (!validateFormFields()) {
315+
return;
316+
}
317+
284318
generateModelFile();
285319
generateResourceModelFile();
286320
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)