12
12
import com .magento .idea .magento2plugin .actions .generation .data .ModuleComposerJsonData ;
13
13
import com .magento .idea .magento2plugin .actions .generation .data .ModuleRegistrationPhpData ;
14
14
import com .magento .idea .magento2plugin .actions .generation .data .ModuleXmlData ;
15
- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .NewModuleDialogValidator ;
15
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
16
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
17
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .AlphanumericRule ;
18
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
19
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .StartWithNumberOrCapitalLetterRule ;
16
20
import com .magento .idea .magento2plugin .actions .generation .generator .ModuleComposerJsonGenerator ;
17
21
import com .magento .idea .magento2plugin .actions .generation .generator .ModuleRegistrationPhpGenerator ;
18
22
import com .magento .idea .magento2plugin .actions .generation .generator .ModuleXmlGenerator ;
24
28
import com .magento .idea .magento2plugin .util .CamelCaseToHyphen ;
25
29
import com .magento .idea .magento2plugin .util .magento .MagentoVersionUtil ;
26
30
import java .awt .event .ActionEvent ;
27
- import java .awt .event .ActionListener ;
28
31
import java .awt .event .KeyEvent ;
29
32
import java .awt .event .WindowAdapter ;
30
33
import java .awt .event .WindowEvent ;
46
49
47
50
@ SuppressWarnings ({"PMD.TooManyFields" , "PMD.DataClass" , "PMD.UnusedPrivateMethod" })
48
51
public class NewModuleDialog extends AbstractDialog implements ListSelectionListener { //NOPMD
49
- @ NotNull
50
- private final Project project ;
51
- @ NotNull
52
- private final PsiDirectory initialBaseDir ;
53
- private final NewModuleDialogValidator validator ;
54
- private final CamelCaseToHyphen camelCaseToHyphen ;
55
- private JPanel contentPane ;
56
- private JButton buttonOK ;
57
- private JButton buttonCancel ;
52
+ private static final String MODULE_DESCRIPTION = "module description" ;
53
+ private static final String MODULE_VERSION = "module version" ;
54
+ private static final String MODULE_NAME = "module name" ;
55
+ private static final String PACKAGE_NAME = "package name" ;
56
+
57
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
58
+ message = {NotEmptyRule .MESSAGE , PACKAGE_NAME })
59
+ @ FieldValidation (rule = RuleRegistry .START_WITH_NUMBER_OR_CAPITAL_LETTER ,
60
+ message = {StartWithNumberOrCapitalLetterRule .MESSAGE , PACKAGE_NAME })
61
+ @ FieldValidation (rule = RuleRegistry .ALPHANUMERIC ,
62
+ message = {AlphanumericRule .MESSAGE , PACKAGE_NAME })
58
63
private JTextField packageName ;
59
- private JLabel packageNameLabel ;
64
+
65
+ /* TODO: module name !== package name */
66
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
67
+ message = {NotEmptyRule .MESSAGE , MODULE_NAME })
68
+ @ FieldValidation (rule = RuleRegistry .START_WITH_NUMBER_OR_CAPITAL_LETTER ,
69
+ message = {StartWithNumberOrCapitalLetterRule .MESSAGE , MODULE_NAME })
70
+ @ FieldValidation (rule = RuleRegistry .ALPHANUMERIC ,
71
+ message = {AlphanumericRule .MESSAGE , MODULE_NAME })
60
72
private JTextField moduleName ;
73
+
74
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
75
+ message = {NotEmptyRule .MESSAGE , MODULE_DESCRIPTION })
61
76
private JTextArea moduleDescription ;
62
- private final ModuleIndex moduleIndex ;
77
+
78
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
79
+ message = {NotEmptyRule .MESSAGE , MODULE_VERSION })
63
80
private JTextField moduleVersion ;
64
- private String detectedPackageName ;
81
+
82
+ private JTextField moduleLicenseCustom ;
83
+
65
84
private JList moduleDependencies ;
66
85
private JList moduleLicense ;
67
- private JTextField moduleLicenseCustom ;
68
- private JLabel moduleLicenseLabel ;//NOPMD
86
+
69
87
private JScrollPane moduleLicenseScrollPanel ;//NOPMD
88
+ private JScrollPane moduleDependenciesScrollPanel ;//NOPMD
89
+
90
+ private JLabel moduleLicenseLabel ;//NOPMD
70
91
private JLabel moduleVersionLabel ;//NOPMD
71
92
private JLabel moduleDependenciesLabel ;//NOPMD
72
- private JScrollPane moduleDependenciesScrollPanel ;//NOPMD
73
93
private JLabel moduleDescriptionLabel ;//NOPMD
74
94
private JLabel moduleNameLabel ;//NOPMD
95
+ private JLabel packageNameLabel ;
96
+
97
+ private JPanel contentPane ;
98
+
99
+ private JButton buttonOK ;
100
+ private JButton buttonCancel ;
75
101
102
+ @ NotNull
103
+ private final Project project ;
104
+ @ NotNull
105
+ private final PsiDirectory initialBaseDir ;
106
+ private String detectedPackageName ;
107
+ private final ModuleIndex moduleIndex ;
108
+ private final CamelCaseToHyphen camelCaseToHyphen ;
76
109
private static final String MAGENTO_BEFORE_DECLARATIVE_SCHEMA_VERSION = "2.2.11" ;
77
110
78
111
/**
@@ -90,7 +123,6 @@ public NewModuleDialog(
90
123
this .project = project ;
91
124
this .initialBaseDir = initialBaseDir ;
92
125
this .camelCaseToHyphen = CamelCaseToHyphen .getInstance ();
93
- this .validator = NewModuleDialogValidator .getInstance (this );
94
126
this .moduleIndex = ModuleIndex .getInstance (project );
95
127
detectPackageName (initialBaseDir );
96
128
setContentPane (contentPane );
@@ -102,19 +134,8 @@ public NewModuleDialog(
102
134
moduleLicenseCustom .setToolTipText ("Custom License Name" );
103
135
moduleLicenseCustom .setText (Settings .getDefaultLicenseName (project ));
104
136
105
- buttonOK .addActionListener (new ActionListener () {
106
- @ Override
107
- public void actionPerformed (final ActionEvent event ) {
108
- onOK ();
109
- }
110
- });
111
-
112
- buttonCancel .addActionListener (new ActionListener () {
113
- @ Override
114
- public void actionPerformed (final ActionEvent event ) {
115
- onCancel ();
116
- }
117
- });
137
+ buttonOK .addActionListener ((final ActionEvent event ) -> onOK ());
138
+ buttonCancel .addActionListener ((final ActionEvent event ) -> onCancel ());
118
139
119
140
setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
120
141
addWindowListener (new WindowAdapter () {
@@ -124,13 +145,11 @@ public void windowClosing(final WindowEvent event) {
124
145
}
125
146
});
126
147
127
- contentPane .registerKeyboardAction (new ActionListener () {
128
- @ Override
129
- public void actionPerformed (final ActionEvent event ) {
130
- onCancel ();
131
- }
132
- }, KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
133
- JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
148
+ contentPane .registerKeyboardAction (
149
+ (final ActionEvent event ) -> onCancel (),
150
+ KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
151
+ JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
152
+ );
134
153
}
135
154
136
155
private void detectPackageName (final @ NotNull PsiDirectory initialBaseDir ) {
@@ -139,11 +158,12 @@ private void detectPackageName(final @NotNull PsiDirectory initialBaseDir) {
139
158
packageName .setVisible (false );
140
159
packageNameLabel .setVisible (false );
141
160
this .detectedPackageName = initialBaseDir .getName ();
161
+ packageName .setText (this .detectedPackageName );
142
162
}
143
163
}
144
164
145
165
protected void onOK () {
146
- if (!validator . validate ()) {
166
+ if (!validateFormFields ()) {
147
167
return ;
148
168
}
149
169
generateFiles ();
0 commit comments