Skip to content

Commit 5ab8038

Browse files
author
Vitaliy Boyko
committed
Adjusted validation
1 parent 17ba661 commit 5ab8038

File tree

5 files changed

+110
-341
lines changed

5 files changed

+110
-341
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private String getMessageFromAnnotation(final FieldValidation validation) {
132132
} else {
133133
params = new String[]{};
134134
}
135-
return validatorBundle.message(validation.message()[0], params);
135+
return validatorBundle.message(validation.message()[0], (Object[]) params);
136136
}
137137

138138
private ValidationRule getRuleFromAnnotation(final FieldValidation validation)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public class NewUiComponentFormDialog extends AbstractDialog {
9191

9292
private static final String VIEW_ACTION_NAME = "View Action Name";
9393
private static final String SUBMIT_ACTION_NAME = "Submit Action Name";
94-
private static final String DATA_PROVIDER_CLASS_NAME = "Data Provider class name";
95-
private static final String DATA_PROVIDER_DIRECTORY = "Data Provider directory";
94+
private static final String DATA_PROVIDER_CLASS_NAME = "Data Provider Class Name";
95+
private static final String DATA_PROVIDER_DIRECTORY = "Data Provider Directory";
9696

9797
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Name"})
9898
@FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE, "Name"})

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@
340340
</component>
341341
</children>
342342
</grid>
343-
<grid id="3036c" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
343+
<grid id="3036c" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
344344
<margin top="0" left="0" bottom="0" right="0"/>
345345
<constraints>
346346
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -350,66 +350,74 @@
350350
<children>
351351
<component id="a6a38" class="javax.swing.JLabel" binding="parentMenuItemLabel">
352352
<constraints>
353-
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
353+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
354354
</constraints>
355355
<properties>
356356
<text value="Parent Menu Item"/>
357357
</properties>
358358
</component>
359359
<component id="4d93" class="javax.swing.JLabel" binding="sortOrderLabel">
360360
<constraints>
361-
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
361+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
362362
</constraints>
363363
<properties>
364364
<text value="Sort Order"/>
365365
</properties>
366366
</component>
367367
<component id="40a2b" class="javax.swing.JLabel" binding="menuIdentifierLabel">
368368
<constraints>
369-
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
369+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
370370
</constraints>
371371
<properties>
372-
<text value="Menu Identifier"/>
372+
<text value="Identifier"/>
373373
</properties>
374374
</component>
375375
<component id="ec0f7" class="javax.swing.JTextField" binding="sortOrder">
376376
<constraints>
377-
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
377+
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
378378
<preferred-size width="150" height="-1"/>
379379
</grid>
380380
</constraints>
381381
<properties/>
382382
</component>
383383
<component id="1264b" class="javax.swing.JTextField" binding="menuIdentifier">
384384
<constraints>
385-
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
385+
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
386386
<preferred-size width="150" height="-1"/>
387387
</grid>
388388
</constraints>
389389
<properties/>
390390
</component>
391391
<component id="4e6de" class="javax.swing.JLabel" binding="menuTitleLabel">
392392
<constraints>
393-
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
393+
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
394394
</constraints>
395395
<properties>
396-
<text value="Menu Title"/>
396+
<text value="Title"/>
397397
</properties>
398398
</component>
399399
<component id="9a0c1" class="javax.swing.JTextField" binding="menuTitle" default-binding="true">
400400
<constraints>
401-
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
401+
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
402402
<preferred-size width="150" height="-1"/>
403403
</grid>
404404
</constraints>
405405
<properties/>
406406
</component>
407407
<component id="bc5f8" class="com.magento.idea.magento2plugin.ui.FilteredComboBox" binding="parentMenu" custom-create="true">
408408
<constraints>
409-
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
409+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
410410
</constraints>
411411
<properties/>
412412
</component>
413+
<component id="827bd" class="javax.swing.JLabel" binding="formMenuLabel">
414+
<constraints>
415+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
416+
</constraints>
417+
<properties>
418+
<text value="Menu"/>
419+
</properties>
420+
</component>
413421
</children>
414422
</grid>
415423
</children>

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

Lines changed: 88 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,23 @@
1818
import com.magento.idea.magento2plugin.actions.generation.data.UiComponentDataProviderData;
1919
import com.magento.idea.magento2plugin.actions.generation.data.UiComponentGridData;
2020
import com.magento.idea.magento2plugin.actions.generation.data.UiComponentGridToolbarData;
21-
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.NewUiComponentGridDialogValidator;
21+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
22+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
23+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphanumericRule;
24+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule;
25+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierRule;
26+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
27+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NumericRule;
28+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule;
29+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpNamespaceNameRule;
30+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.RouteIdRule;
31+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.StartWithNumberOrCapitalLetterRule;
2232
import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator;
2333
import com.magento.idea.magento2plugin.actions.generation.generator.MenuXmlGenerator;
2434
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator;
2535
import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentDataProviderGenerator;
2636
import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentGridXmlGenerator;
2737
import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder;
28-
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
2938
import com.magento.idea.magento2plugin.magento.files.ControllerBackendPhp;
3039
import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderPhp;
3140
import com.magento.idea.magento2plugin.magento.packages.Areas;
@@ -36,8 +45,6 @@
3645
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
3746
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
3847
import com.magento.idea.magento2plugin.util.magento.GetResourceCollections;
39-
import org.jetbrains.annotations.NotNull;
40-
4148
import java.awt.event.KeyEvent;
4249
import java.awt.event.WindowAdapter;
4350
import java.awt.event.WindowEvent;
@@ -46,47 +53,108 @@
4653
import java.util.Collection;
4754
import java.util.Collections;
4855
import java.util.List;
49-
import javax.swing.*;
56+
import javax.swing.JButton;
57+
import javax.swing.JCheckBox;
58+
import javax.swing.JComponent;
59+
import javax.swing.JLabel;
60+
import javax.swing.JPanel;
61+
import javax.swing.JTextField;
62+
import javax.swing.KeyStroke;
63+
import org.jetbrains.annotations.NotNull;
5064

5165
@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports", "PMD.UnusedPrivateMethod"})
5266
public class NewUiComponentGridDialog extends AbstractDialog {
67+
private static final String ACTION_NAME = "Action Name";
68+
private static final String DATA_PROVIDER_CLASS_NAME = "Data Provider Class Name";
69+
private static final String DATA_PROVIDER_DIRECTORY = "Data Provider Directory";
70+
5371
private final Project project;
5472
private final String moduleName;
55-
private final NewUiComponentGridDialogValidator validator;
5673
private List<String> collectionOptions;
5774
private JPanel contentPanel;
5875
private JButton buttonOK;
5976
private JButton buttonCancel;
77+
78+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Name"})
79+
@FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE, "Name"})
6080
private JTextField uiComponentName;
81+
82+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Name"})
83+
@FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE, "Name"})
6184
private JTextField idField;
85+
6286
private JCheckBox addToolBar;
6387
private JCheckBox addBookmarksCheckBox;
6488
private JCheckBox addColumnsControlCheckBox;
6589
private JCheckBox addFullTextSearchCheckBox;
6690
private JCheckBox addListingFiltersCheckBox;
6791
private JCheckBox addListingPagingCheckBox;
92+
6893
private FilteredComboBox collection;
6994
private FilteredComboBox dataProviderType;
7095
private FilteredComboBox areaSelect;
96+
97+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
98+
message = {NotEmptyRule.MESSAGE, DATA_PROVIDER_CLASS_NAME})
99+
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
100+
message = {PhpClassRule.MESSAGE, DATA_PROVIDER_CLASS_NAME})
101+
@FieldValidation(rule = RuleRegistry.ALPHANUMERIC,
102+
message = {AlphanumericRule.MESSAGE, DATA_PROVIDER_CLASS_NAME})
71103
private JTextField providerClassName;
104+
105+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
106+
message = {NotEmptyRule.MESSAGE, DATA_PROVIDER_DIRECTORY})
107+
@FieldValidation(rule = RuleRegistry.DIRECTORY,
108+
message = {DirectoryRule.MESSAGE, DATA_PROVIDER_DIRECTORY})
109+
@FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER,
110+
message = {AlphanumericRule.MESSAGE, DATA_PROVIDER_DIRECTORY})
72111
private JTextField dataProviderParentDirectory;
112+
73113
private JTextField acl;
74-
private JLabel aclLabel;
75-
private JLabel routeLabel;
76-
private JLabel controllerLabel;
77-
private JLabel actionLabel;
114+
115+
@FieldValidation(rule = RuleRegistry.ROUTE_ID, message = {RouteIdRule.MESSAGE})
78116
private JTextField route;
117+
118+
@FieldValidation(rule = RuleRegistry.PHP_NAMESPACE_NAME,
119+
message = {PhpNamespaceNameRule.MESSAGE, "Controller Name"})
79120
private JTextField controllerName;
121+
122+
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
123+
message = {PhpClassRule.MESSAGE, ACTION_NAME})
124+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
125+
message = {NotEmptyRule.MESSAGE, ACTION_NAME})
126+
@FieldValidation(rule = RuleRegistry.ALPHANUMERIC,
127+
message = {AlphanumericRule.MESSAGE, ACTION_NAME})
128+
@FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER,
129+
message = {StartWithNumberOrCapitalLetterRule.MESSAGE, ACTION_NAME})
80130
private JTextField actionName;
81-
private JLabel parentMenuItemLabel;
131+
132+
@FieldValidation(rule = RuleRegistry.NUMERIC,
133+
message = {NumericRule.MESSAGE, "Sort Order"})
82134
private JTextField sortOrder;
135+
136+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
137+
message = {NotEmptyRule.MESSAGE, "Menu Identifier"})
83138
private JTextField menuIdentifier;
84-
private JLabel sortOrderLabel;
85-
private JLabel menuIdentifierLabel;
139+
140+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
141+
message = {NotEmptyRule.MESSAGE, "Menu Title"})
86142
private JTextField menuTitle;
87-
private JLabel menuTitleLabel;
143+
144+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
145+
message = {NotEmptyRule.MESSAGE, "Parent Menu"})
88146
private FilteredComboBox parentMenu;
89-
private JLabel collectionLabel;
147+
148+
private JLabel aclLabel;
149+
private JLabel routeLabel;//NOPMD
150+
private JLabel controllerLabel;//NOPMD
151+
private JLabel actionLabel;//NOPMD
152+
private JLabel parentMenuItemLabel;//NOPMD
153+
private JLabel sortOrderLabel;//NOPMD
154+
private JLabel menuIdentifierLabel;//NOPMD
155+
private JLabel menuTitleLabel;//NOPMD
156+
private JLabel formMenuLabel;//NOPMD
157+
private JLabel collectionLabel;//NOPMD
90158

91159
/**
92160
* New UI component grid dialog constructor.
@@ -97,7 +165,6 @@ public class NewUiComponentGridDialog extends AbstractDialog {
97165
public NewUiComponentGridDialog(final Project project, final PsiDirectory directory) {
98166
super();
99167
this.project = project;
100-
this.validator = NewUiComponentGridDialogValidator.getInstance();
101168
this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project);
102169

103170
setContentPane(contentPanel);
@@ -194,7 +261,7 @@ protected void onCancel() {
194261
}
195262

196263
private void onOK() {
197-
if (!validator.validate(this)) {
264+
if (!validateFormFields()) {
198265
return;
199266
}
200267

@@ -309,10 +376,10 @@ private void createUIComponents() {
309376
}
310377

311378
@NotNull
312-
private ArrayList<String> getMenuReferences() {
379+
private List<String> getMenuReferences() {
313380
final Collection<String> menuReferences
314381
= FileBasedIndex.getInstance().getAllKeys(MenuIndex.KEY, project);
315-
ArrayList<String> menuReferencesList = new ArrayList<>(menuReferences);
382+
final ArrayList<String> menuReferencesList = new ArrayList<>(menuReferences);
316383
Collections.sort(menuReferencesList);
317384
return menuReferencesList;
318385
}
@@ -477,9 +544,9 @@ public String getMenuIdentifier() {
477544
private String getMenuAction() {
478545
return getRoute()
479546
+ File.separator
480-
+ getControllerName().toLowerCase()
547+
+ getControllerName().toLowerCase(new java.util.Locale("en","EN"))
481548
+ File.separator
482-
+ getActionName().toLowerCase();
549+
+ getActionName().toLowerCase(new java.util.Locale("en","EN"));
483550
}
484551

485552
public String getMenuTitle() {

0 commit comments

Comments
 (0)