1212import com .magento .idea .magento2plugin .actions .generation .data .ModuleComposerJsonData ;
1313import com .magento .idea .magento2plugin .actions .generation .data .ModuleRegistrationPhpData ;
1414import 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 ;
1620import com .magento .idea .magento2plugin .actions .generation .generator .ModuleComposerJsonGenerator ;
1721import com .magento .idea .magento2plugin .actions .generation .generator .ModuleRegistrationPhpGenerator ;
1822import com .magento .idea .magento2plugin .actions .generation .generator .ModuleXmlGenerator ;
2428import com .magento .idea .magento2plugin .util .CamelCaseToHyphen ;
2529import com .magento .idea .magento2plugin .util .magento .MagentoVersionUtil ;
2630import java .awt .event .ActionEvent ;
27- import java .awt .event .ActionListener ;
2831import java .awt .event .KeyEvent ;
2932import java .awt .event .WindowAdapter ;
3033import java .awt .event .WindowEvent ;
4649
4750@ SuppressWarnings ({"PMD.TooManyFields" , "PMD.DataClass" , "PMD.UnusedPrivateMethod" })
4851public 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 })
5863 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 })
6072 private JTextField moduleName ;
73+
74+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
75+ message = {NotEmptyRule .MESSAGE , MODULE_DESCRIPTION })
6176 private JTextArea moduleDescription ;
62- private final ModuleIndex moduleIndex ;
77+
78+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
79+ message = {NotEmptyRule .MESSAGE , MODULE_VERSION })
6380 private JTextField moduleVersion ;
64- private String detectedPackageName ;
81+
82+ private JTextField moduleLicenseCustom ;
83+
6584 private JList moduleDependencies ;
6685 private JList moduleLicense ;
67- private JTextField moduleLicenseCustom ;
68- private JLabel moduleLicenseLabel ;//NOPMD
86+
6987 private JScrollPane moduleLicenseScrollPanel ;//NOPMD
88+ private JScrollPane moduleDependenciesScrollPanel ;//NOPMD
89+
90+ private JLabel moduleLicenseLabel ;//NOPMD
7091 private JLabel moduleVersionLabel ;//NOPMD
7192 private JLabel moduleDependenciesLabel ;//NOPMD
72- private JScrollPane moduleDependenciesScrollPanel ;//NOPMD
7393 private JLabel moduleDescriptionLabel ;//NOPMD
7494 private JLabel moduleNameLabel ;//NOPMD
95+ private JLabel packageNameLabel ;
96+
97+ private JPanel contentPane ;
98+
99+ private JButton buttonOK ;
100+ private JButton buttonCancel ;
75101
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 ;
76109 private static final String MAGENTO_BEFORE_DECLARATIVE_SCHEMA_VERSION = "2.2.11" ;
77110
78111 /**
@@ -90,7 +123,6 @@ public NewModuleDialog(
90123 this .project = project ;
91124 this .initialBaseDir = initialBaseDir ;
92125 this .camelCaseToHyphen = CamelCaseToHyphen .getInstance ();
93- this .validator = NewModuleDialogValidator .getInstance (this );
94126 this .moduleIndex = ModuleIndex .getInstance (project );
95127 detectPackageName (initialBaseDir );
96128 setContentPane (contentPane );
@@ -102,19 +134,8 @@ public NewModuleDialog(
102134 moduleLicenseCustom .setToolTipText ("Custom License Name" );
103135 moduleLicenseCustom .setText (Settings .getDefaultLicenseName (project ));
104136
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 ());
118139
119140 setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
120141 addWindowListener (new WindowAdapter () {
@@ -124,13 +145,11 @@ public void windowClosing(final WindowEvent event) {
124145 }
125146 });
126147
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+ );
134153 }
135154
136155 private void detectPackageName (final @ NotNull PsiDirectory initialBaseDir ) {
@@ -139,11 +158,12 @@ private void detectPackageName(final @NotNull PsiDirectory initialBaseDir) {
139158 packageName .setVisible (false );
140159 packageNameLabel .setVisible (false );
141160 this .detectedPackageName = initialBaseDir .getName ();
161+ packageName .setText (this .detectedPackageName );
142162 }
143163 }
144164
145165 protected void onOK () {
146- if (!validator . validate ()) {
166+ if (!validateFormFields ()) {
147167 return ;
148168 }
149169 generateFiles ();
0 commit comments