88import com .intellij .openapi .project .Project ;
99import com .intellij .openapi .ui .popup .JBPopupFactory ;
1010import com .intellij .psi .PsiFile ;
11- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .OverrideInThemeDialogValidator ;
11+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
12+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
13+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
1214import com .magento .idea .magento2plugin .actions .generation .generator .OverrideInThemeGenerator ;
1315import com .magento .idea .magento2plugin .indexes .ModuleIndex ;
1416import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
@@ -29,12 +31,14 @@ public class OverrideInThemeDialog extends AbstractDialog {
2931 @ NotNull
3032 private final Project project ;
3133 private final PsiFile psiFile ;
32- @ NotNull
33- private final OverrideInThemeDialogValidator validator ;
3434 private JPanel contentPane ;
3535 private JButton buttonOK ;
3636 private JButton buttonCancel ;
3737 private JLabel selectTheme ; //NOPMD
38+ private static final String THEME_NAME = "target theme" ;
39+
40+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
41+ message = {NotEmptyRule .MESSAGE , THEME_NAME })
3842 private FilteredComboBox theme ;
3943
4044 /**
@@ -48,23 +52,13 @@ public OverrideInThemeDialog(final @NotNull Project project, final PsiFile psiFi
4852
4953 this .project = project ;
5054 this .psiFile = psiFile ;
51- this .validator = new OverrideInThemeDialogValidator (this );
5255
5356 setContentPane (contentPane );
5457 setModal (true );
5558 getRootPane ().setDefaultButton (buttonOK );
5659
57- buttonOK .addActionListener (new ActionListener () {
58- public void actionPerformed (final ActionEvent event ) {
59- onOK (); //NOPMD
60- }
61- });
62-
63- buttonCancel .addActionListener (new ActionListener () {
64- public void actionPerformed (final ActionEvent event ) {
65- onCancel ();
66- }
67- });
60+ buttonOK .addActionListener ((final ActionEvent event ) -> onOK ());
61+ buttonCancel .addActionListener ((final ActionEvent event ) -> onCancel ());
6862
6963 setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
7064 addWindowListener (new WindowAdapter () {
@@ -73,18 +67,15 @@ public void windowClosing(final WindowEvent event) {
7367 }
7468 });
7569
76- contentPane .registerKeyboardAction (new ActionListener () {
77- public void actionPerformed (final ActionEvent event ) {
78- onCancel ();
79- }
80- }, KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
81- JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
70+ contentPane .registerKeyboardAction (
71+ (final ActionEvent event ) -> onCancel (),
72+ KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
73+ JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
74+ );
8275 }
8376
8477 private void onOK () {
85- if (!validator .validate (project )) {
86- JBPopupFactory .getInstance ().createMessage ("Invalid theme selection." )
87- .showCenteredInCurrentWindow (project );
78+ if (!validateFormFields ()) {
8879 return ;
8980 }
9081
0 commit comments