18
18
import com .magento .idea .magento2plugin .actions .generation .data .UiComponentDataProviderData ;
19
19
import com .magento .idea .magento2plugin .actions .generation .data .UiComponentGridData ;
20
20
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 ;
22
32
import com .magento .idea .magento2plugin .actions .generation .generator .LayoutXmlGenerator ;
23
33
import com .magento .idea .magento2plugin .actions .generation .generator .MenuXmlGenerator ;
24
34
import com .magento .idea .magento2plugin .actions .generation .generator .ModuleControllerClassGenerator ;
25
35
import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentDataProviderGenerator ;
26
36
import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentGridXmlGenerator ;
27
37
import com .magento .idea .magento2plugin .actions .generation .generator .util .NamespaceBuilder ;
28
- import com .magento .idea .magento2plugin .indexes .ModuleIndex ;
29
38
import com .magento .idea .magento2plugin .magento .files .ControllerBackendPhp ;
30
39
import com .magento .idea .magento2plugin .magento .files .UiComponentDataProviderPhp ;
31
40
import com .magento .idea .magento2plugin .magento .packages .Areas ;
36
45
import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
37
46
import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
38
47
import com .magento .idea .magento2plugin .util .magento .GetResourceCollections ;
39
- import org .jetbrains .annotations .NotNull ;
40
-
41
48
import java .awt .event .KeyEvent ;
42
49
import java .awt .event .WindowAdapter ;
43
50
import java .awt .event .WindowEvent ;
46
53
import java .util .Collection ;
47
54
import java .util .Collections ;
48
55
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 ;
50
64
51
65
@ SuppressWarnings ({"PMD.TooManyFields" , "PMD.ExcessiveImports" , "PMD.UnusedPrivateMethod" })
52
66
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
+
53
71
private final Project project ;
54
72
private final String moduleName ;
55
- private final NewUiComponentGridDialogValidator validator ;
56
73
private List <String > collectionOptions ;
57
74
private JPanel contentPanel ;
58
75
private JButton buttonOK ;
59
76
private JButton buttonCancel ;
77
+
78
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY , message = {NotEmptyRule .MESSAGE , "Name" })
79
+ @ FieldValidation (rule = RuleRegistry .IDENTIFIER , message = {IdentifierRule .MESSAGE , "Name" })
60
80
private JTextField uiComponentName ;
81
+
82
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY , message = {NotEmptyRule .MESSAGE , "Name" })
83
+ @ FieldValidation (rule = RuleRegistry .IDENTIFIER , message = {IdentifierRule .MESSAGE , "Name" })
61
84
private JTextField idField ;
85
+
62
86
private JCheckBox addToolBar ;
63
87
private JCheckBox addBookmarksCheckBox ;
64
88
private JCheckBox addColumnsControlCheckBox ;
65
89
private JCheckBox addFullTextSearchCheckBox ;
66
90
private JCheckBox addListingFiltersCheckBox ;
67
91
private JCheckBox addListingPagingCheckBox ;
92
+
68
93
private FilteredComboBox collection ;
69
94
private FilteredComboBox dataProviderType ;
70
95
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 })
71
103
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 })
72
111
private JTextField dataProviderParentDirectory ;
112
+
73
113
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 })
78
116
private JTextField route ;
117
+
118
+ @ FieldValidation (rule = RuleRegistry .PHP_NAMESPACE_NAME ,
119
+ message = {PhpNamespaceNameRule .MESSAGE , "Controller Name" })
79
120
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 })
80
130
private JTextField actionName ;
81
- private JLabel parentMenuItemLabel ;
131
+
132
+ @ FieldValidation (rule = RuleRegistry .NUMERIC ,
133
+ message = {NumericRule .MESSAGE , "Sort Order" })
82
134
private JTextField sortOrder ;
135
+
136
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
137
+ message = {NotEmptyRule .MESSAGE , "Menu Identifier" })
83
138
private JTextField menuIdentifier ;
84
- private JLabel sortOrderLabel ;
85
- private JLabel menuIdentifierLabel ;
139
+
140
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
141
+ message = {NotEmptyRule .MESSAGE , "Menu Title" })
86
142
private JTextField menuTitle ;
87
- private JLabel menuTitleLabel ;
143
+
144
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
145
+ message = {NotEmptyRule .MESSAGE , "Parent Menu" })
88
146
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
90
158
91
159
/**
92
160
* New UI component grid dialog constructor.
@@ -97,7 +165,6 @@ public class NewUiComponentGridDialog extends AbstractDialog {
97
165
public NewUiComponentGridDialog (final Project project , final PsiDirectory directory ) {
98
166
super ();
99
167
this .project = project ;
100
- this .validator = NewUiComponentGridDialogValidator .getInstance ();
101
168
this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
102
169
103
170
setContentPane (contentPanel );
@@ -194,7 +261,7 @@ protected void onCancel() {
194
261
}
195
262
196
263
private void onOK () {
197
- if (!validator . validate ( this )) {
264
+ if (!validateFormFields ( )) {
198
265
return ;
199
266
}
200
267
@@ -309,10 +376,10 @@ private void createUIComponents() {
309
376
}
310
377
311
378
@ NotNull
312
- private ArrayList <String > getMenuReferences () {
379
+ private List <String > getMenuReferences () {
313
380
final Collection <String > menuReferences
314
381
= FileBasedIndex .getInstance ().getAllKeys (MenuIndex .KEY , project );
315
- ArrayList <String > menuReferencesList = new ArrayList <>(menuReferences );
382
+ final ArrayList <String > menuReferencesList = new ArrayList <>(menuReferences );
316
383
Collections .sort (menuReferencesList );
317
384
return menuReferencesList ;
318
385
}
@@ -477,9 +544,9 @@ public String getMenuIdentifier() {
477
544
private String getMenuAction () {
478
545
return getRoute ()
479
546
+ File .separator
480
- + getControllerName ().toLowerCase ()
547
+ + getControllerName ().toLowerCase (new java . util . Locale ( "en" , "EN" ) )
481
548
+ File .separator
482
- + getActionName ().toLowerCase ();
549
+ + getActionName ().toLowerCase (new java . util . Locale ( "en" , "EN" ) );
483
550
}
484
551
485
552
public String getMenuTitle () {
0 commit comments