8
8
import com .intellij .openapi .project .Project ;
9
9
import com .intellij .openapi .ui .popup .JBPopupFactory ;
10
10
import 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 ;
12
14
import com .magento .idea .magento2plugin .actions .generation .generator .OverrideInThemeGenerator ;
13
15
import com .magento .idea .magento2plugin .indexes .ModuleIndex ;
14
16
import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
@@ -29,12 +31,14 @@ public class OverrideInThemeDialog extends AbstractDialog {
29
31
@ NotNull
30
32
private final Project project ;
31
33
private final PsiFile psiFile ;
32
- @ NotNull
33
- private final OverrideInThemeDialogValidator validator ;
34
34
private JPanel contentPane ;
35
35
private JButton buttonOK ;
36
36
private JButton buttonCancel ;
37
37
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 })
38
42
private FilteredComboBox theme ;
39
43
40
44
/**
@@ -48,23 +52,13 @@ public OverrideInThemeDialog(final @NotNull Project project, final PsiFile psiFi
48
52
49
53
this .project = project ;
50
54
this .psiFile = psiFile ;
51
- this .validator = new OverrideInThemeDialogValidator (this );
52
55
53
56
setContentPane (contentPane );
54
57
setModal (true );
55
58
getRootPane ().setDefaultButton (buttonOK );
56
59
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 ());
68
62
69
63
setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
70
64
addWindowListener (new WindowAdapter () {
@@ -73,18 +67,15 @@ public void windowClosing(final WindowEvent event) {
73
67
}
74
68
});
75
69
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
+ );
82
75
}
83
76
84
77
private void onOK () {
85
- if (!validator .validate (project )) {
86
- JBPopupFactory .getInstance ().createMessage ("Invalid theme selection." )
87
- .showCenteredInCurrentWindow (project );
78
+ if (!validateFormFields ()) {
88
79
return ;
89
80
}
90
81
0 commit comments