6
6
package com .magento .idea .magento2plugin .actions .generation .dialog ;
7
7
8
8
import com .intellij .openapi .project .Project ;
9
- import com .intellij .openapi .ui .popup .JBPopupFactory ;
10
9
import com .intellij .psi .PsiFile ;
11
- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .OverrideInThemeDialogValidator ;
10
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
11
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
12
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
12
13
import com .magento .idea .magento2plugin .actions .generation .generator .OverrideInThemeGenerator ;
13
14
import com .magento .idea .magento2plugin .indexes .ModuleIndex ;
14
- import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
15
15
import java .awt .event .ActionEvent ;
16
- import java .awt .event .ActionListener ;
17
16
import java .awt .event .KeyEvent ;
18
17
import java .awt .event .WindowAdapter ;
19
18
import java .awt .event .WindowEvent ;
20
19
import java .util .List ;
21
20
import javax .swing .JButton ;
21
+ import javax .swing .JComboBox ;
22
22
import javax .swing .JComponent ;
23
23
import javax .swing .JLabel ;
24
24
import javax .swing .JPanel ;
@@ -29,13 +29,15 @@ public class OverrideInThemeDialog extends AbstractDialog {
29
29
@ NotNull
30
30
private final Project project ;
31
31
private final PsiFile psiFile ;
32
- @ NotNull
33
- private final OverrideInThemeDialogValidator validator ;
34
32
private JPanel contentPane ;
35
33
private JButton buttonOK ;
36
34
private JButton buttonCancel ;
37
35
private JLabel selectTheme ; //NOPMD
38
- private FilteredComboBox theme ;
36
+ private static final String THEME_NAME = "target theme" ;
37
+
38
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
39
+ message = {NotEmptyRule .MESSAGE , THEME_NAME })
40
+ private JComboBox theme ;
39
41
40
42
/**
41
43
* Constructor.
@@ -48,23 +50,14 @@ public OverrideInThemeDialog(final @NotNull Project project, final PsiFile psiFi
48
50
49
51
this .project = project ;
50
52
this .psiFile = psiFile ;
51
- this .validator = new OverrideInThemeDialogValidator (this );
52
53
53
54
setContentPane (contentPane );
54
55
setModal (true );
55
56
getRootPane ().setDefaultButton (buttonOK );
57
+ fillThemeOptions ();
56
58
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
- });
59
+ buttonOK .addActionListener ((final ActionEvent event ) -> onOK ());
60
+ buttonCancel .addActionListener ((final ActionEvent event ) -> onCancel ());
68
61
69
62
setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
70
63
addWindowListener (new WindowAdapter () {
@@ -73,18 +66,15 @@ public void windowClosing(final WindowEvent event) {
73
66
}
74
67
});
75
68
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 );
69
+ contentPane .registerKeyboardAction (
70
+ (final ActionEvent event ) -> onCancel (),
71
+ KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 ),
72
+ JComponent .WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
73
+ );
82
74
}
83
75
84
76
private void onOK () {
85
- if (!validator .validate (project )) {
86
- JBPopupFactory .getInstance ().createMessage ("Invalid theme selection." )
87
- .showCenteredInCurrentWindow (project );
77
+ if (!validateFormFields ()) {
88
78
return ;
89
79
}
90
80
@@ -112,9 +102,10 @@ public static void open(final @NotNull Project project, final PsiFile psiFile) {
112
102
dialog .setVisible (true );
113
103
}
114
104
115
- private void createUIComponents () { //NOPMD
116
- final List <String > allThemesList = ModuleIndex .getInstance (project ).getEditableThemeNames ();
117
-
118
- this .theme = new FilteredComboBox (allThemesList );
105
+ private void fillThemeOptions () {
106
+ final List <String > themeNames = ModuleIndex .getInstance (project ).getEditableThemeNames ();
107
+ for (final String themeName : themeNames ) {
108
+ theme .addItem (themeName );
109
+ }
119
110
}
120
111
}
0 commit comments