1111import com .magento .idea .magento2plugin .actions .generation .CreateAPluginAction ;
1212import com .magento .idea .magento2plugin .actions .generation .data .PluginDiXmlData ;
1313import com .magento .idea .magento2plugin .actions .generation .data .PluginFileData ;
14- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .CreateAPluginDialogValidator ;
14+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
15+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
16+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .DirectoryRule ;
17+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .IdentifierRule ;
18+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
19+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NumericRule ;
20+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .PhpClassRule ;
1521import com .magento .idea .magento2plugin .actions .generation .generator .PluginClassGenerator ;
1622import com .magento .idea .magento2plugin .actions .generation .generator .PluginDiXmlGenerator ;
1723import com .magento .idea .magento2plugin .indexes .ModuleIndex ;
2127import com .magento .idea .magento2plugin .magento .packages .Package ;
2228import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
2329import java .awt .event .ActionEvent ;
24- import java .awt .event .ActionListener ;
2530import java .awt .event .KeyEvent ;
2631import java .awt .event .WindowAdapter ;
2732import java .awt .event .WindowEvent ;
3540import javax .swing .KeyStroke ;
3641import org .jetbrains .annotations .NotNull ;
3742
38- @ SuppressWarnings ({"PMD.TooManyFields" , "PMD.DataClass" , "PMD.UnusedPrivateMethod" })
43+ @ SuppressWarnings ({
44+ "PMD.TooManyFields" ,
45+ "PMD.DataClass" ,
46+ "PMD.UnusedPrivateMethod" ,
47+ "PMD.ExcessiveImports"
48+ })
3949public class CreateAPluginDialog extends AbstractDialog {
4050 @ NotNull
4151 private final Project project ;
4252 private final Method targetMethod ;
4353 private final PhpClass targetClass ;
44- @ NotNull
45- private final CreateAPluginDialogValidator validator ;
4654 private JPanel contentPane ;
4755 private JButton buttonOK ;
4856 private JButton buttonCancel ;
49- private JTextField pluginClassName ;
50- private JTextField pluginDirectory ;
5157 private JComboBox pluginType ;
52- private FilteredComboBox pluginModule ;
5358 private JComboBox pluginArea ;
59+
60+ private static final String CLASS_NAME = "class name" ;
61+ private static final String DIRECTORY = "directory path" ;
62+ private static final String SORT_ORDER = "sort order" ;
63+ private static final String PLUGIN_NAME = "plugin name" ;
64+ private static final String TARGET_MODULE = "target module" ;
65+
66+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
67+ message = {NotEmptyRule .MESSAGE , TARGET_MODULE })
68+ private FilteredComboBox pluginModule ;
69+
70+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
71+ message = {NotEmptyRule .MESSAGE , CLASS_NAME })
72+ @ FieldValidation (rule = RuleRegistry .PHP_CLASS ,
73+ message = {PhpClassRule .MESSAGE , CLASS_NAME })
74+ private JTextField pluginClassName ;
75+
76+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
77+ message = {NotEmptyRule .MESSAGE , DIRECTORY })
78+ @ FieldValidation (rule = RuleRegistry .DIRECTORY ,
79+ message = {DirectoryRule .MESSAGE , DIRECTORY })
80+ private JTextField pluginDirectory ;
81+
82+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
83+ message = {NotEmptyRule .MESSAGE , SORT_ORDER })
84+ @ FieldValidation (rule = RuleRegistry .NUMERIC ,
85+ message = {NumericRule .MESSAGE , SORT_ORDER })
5486 private JTextField pluginSortOrder ;
87+
88+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
89+ message = {NotEmptyRule .MESSAGE , PLUGIN_NAME })
90+ @ FieldValidation (rule = RuleRegistry .IDENTIFIER ,
91+ message = {IdentifierRule .MESSAGE , PLUGIN_NAME })
5592 private JTextField pluginName ;
93+
5694 private JLabel pluginDirectoryName ;//NOPMD
5795 private JLabel selectPluginModule ;//NOPMD
5896 private JLabel pluginTypeLabel ;//NOPMD
@@ -77,25 +115,15 @@ public CreateAPluginDialog(
77115 this .project = project ;
78116 this .targetMethod = targetMethod ;
79117 this .targetClass = targetClass ;
80- this .validator = CreateAPluginDialogValidator .getInstance (this );
81118
82119 setContentPane (contentPane );
83120 setModal (true );
84121 getRootPane ().setDefaultButton (buttonOK );
85122 fillPluginTypeOptions ();
86123 fillTargetAreaOptions ();
87124
88- buttonOK .addActionListener (new ActionListener () {
89- public void actionPerformed (final ActionEvent event ) {
90- onOK ();
91- }
92- });
93-
94- buttonCancel .addActionListener (new ActionListener () {
95- public void actionPerformed (final ActionEvent event ) {
96- onCancel ();
97- }
98- });
125+ buttonOK .addActionListener ((final ActionEvent event ) -> onOK ());
126+ buttonCancel .addActionListener ((final ActionEvent event ) -> onCancel ());
99127
100128 setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
101129 addWindowListener (new WindowAdapter () {
@@ -104,11 +132,9 @@ public void windowClosing(final WindowEvent event) {
104132 }
105133 });
106134
107- contentPane .registerKeyboardAction (new ActionListener () {
108- public void actionPerformed (final ActionEvent event ) {
109- onCancel ();
110- }
111- }, KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
135+ contentPane .registerKeyboardAction (
136+ (final ActionEvent event ) -> onCancel (),
137+ KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
112138 JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
113139 );
114140 }
@@ -126,7 +152,7 @@ private void fillTargetAreaOptions() {
126152 }
127153
128154 protected void onOK () {
129- if (!validator . validate ( project )) {
155+ if (!validateFormFields ( )) {
130156 return ;
131157 }
132158 new PluginClassGenerator (new PluginFileData (
0 commit comments