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 .AlphanumericRule ;
17+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .DirectoryRule ;
18+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .IdentifierRule ;
19+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
20+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NumericRule ;
21+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .PhpClassRule ;
22+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .StartWithNumberOrCapitalLetterRule ;
1523import com .magento .idea .magento2plugin .actions .generation .generator .PluginClassGenerator ;
1624import com .magento .idea .magento2plugin .actions .generation .generator .PluginDiXmlGenerator ;
1725import com .magento .idea .magento2plugin .indexes .ModuleIndex ;
2129import com .magento .idea .magento2plugin .magento .packages .Package ;
2230import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
2331import java .awt .event .ActionEvent ;
24- import java .awt .event .ActionListener ;
2532import java .awt .event .KeyEvent ;
2633import java .awt .event .WindowAdapter ;
2734import java .awt .event .WindowEvent ;
@@ -41,18 +48,50 @@ public class CreateAPluginDialog extends AbstractDialog {
4148 private final Project project ;
4249 private final Method targetMethod ;
4350 private final PhpClass targetClass ;
44- @ NotNull
45- private final CreateAPluginDialogValidator validator ;
4651 private JPanel contentPane ;
4752 private JButton buttonOK ;
4853 private JButton buttonCancel ;
49- private JTextField pluginClassName ;
50- private JTextField pluginDirectory ;
5154 private JComboBox pluginType ;
52- private FilteredComboBox pluginModule ;
5355 private JComboBox pluginArea ;
56+
57+ private static final String CLASS_NAME = "class name" ;
58+ private static final String DIRECTORY = "directory path" ;
59+ private static final String SORT_ORDER = "sort order" ;
60+ private static final String PLUGIN_NAME = "plugin name" ;
61+ private static final String TARGET_MODULE = "target module" ;
62+
63+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
64+ message = {NotEmptyRule .MESSAGE , TARGET_MODULE })
65+ private FilteredComboBox pluginModule ;
66+
67+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
68+ message = {NotEmptyRule .MESSAGE , CLASS_NAME })
69+ @ FieldValidation (rule = RuleRegistry .PHP_CLASS ,
70+ message = {PhpClassRule .MESSAGE , CLASS_NAME })
71+ @ FieldValidation (rule = RuleRegistry .ALPHANUMERIC ,
72+ message = {AlphanumericRule .MESSAGE , CLASS_NAME })
73+ @ FieldValidation (rule = RuleRegistry .START_WITH_NUMBER_OR_CAPITAL_LETTER ,
74+ message = {StartWithNumberOrCapitalLetterRule .MESSAGE , CLASS_NAME })
75+ private JTextField pluginClassName ;
76+
77+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
78+ message = {NotEmptyRule .MESSAGE , DIRECTORY })
79+ @ FieldValidation (rule = RuleRegistry .DIRECTORY ,
80+ message = {DirectoryRule .MESSAGE , DIRECTORY })
81+ private JTextField pluginDirectory ;
82+
83+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
84+ message = {NotEmptyRule .MESSAGE , SORT_ORDER })
85+ @ FieldValidation (rule = RuleRegistry .NUMERIC ,
86+ message = {NumericRule .MESSAGE , SORT_ORDER })
5487 private JTextField pluginSortOrder ;
88+
89+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
90+ message = {NotEmptyRule .MESSAGE , PLUGIN_NAME })
91+ @ FieldValidation (rule = RuleRegistry .IDENTIFIER ,
92+ message = {IdentifierRule .MESSAGE , PLUGIN_NAME })
5593 private JTextField pluginName ;
94+
5695 private JLabel pluginDirectoryName ;//NOPMD
5796 private JLabel selectPluginModule ;//NOPMD
5897 private JLabel pluginTypeLabel ;//NOPMD
@@ -77,25 +116,15 @@ public CreateAPluginDialog(
77116 this .project = project ;
78117 this .targetMethod = targetMethod ;
79118 this .targetClass = targetClass ;
80- this .validator = CreateAPluginDialogValidator .getInstance (this );
81119
82120 setContentPane (contentPane );
83121 setModal (true );
84122 getRootPane ().setDefaultButton (buttonOK );
85123 fillPluginTypeOptions ();
86124 fillTargetAreaOptions ();
87125
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- });
126+ buttonOK .addActionListener ((final ActionEvent event ) -> onOK ());
127+ buttonCancel .addActionListener ((final ActionEvent event ) -> onCancel ());
99128
100129 setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
101130 addWindowListener (new WindowAdapter () {
@@ -104,11 +133,9 @@ public void windowClosing(final WindowEvent event) {
104133 }
105134 });
106135
107- contentPane .registerKeyboardAction (new ActionListener () {
108- public void actionPerformed (final ActionEvent event ) {
109- onCancel ();
110- }
111- }, KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
136+ contentPane .registerKeyboardAction (
137+ (final ActionEvent event ) -> onCancel (),
138+ KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
112139 JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
113140 );
114141 }
@@ -126,7 +153,7 @@ private void fillTargetAreaOptions() {
126153 }
127154
128155 protected void onOK () {
129- if (!validator . validate ( project )) {
156+ if (!validateFormFields ( )) {
130157 return ;
131158 }
132159 new PluginClassGenerator (new PluginFileData (
0 commit comments