66package  com .magento .idea .magento2plugin .actions .generation .dialog ;
77
88import  com .intellij .openapi .project .Project ;
9- import  com .intellij .openapi .ui .popup .JBPopupFactory ;
109import  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 ;
1213import  com .magento .idea .magento2plugin .actions .generation .generator .OverrideInThemeGenerator ;
1314import  com .magento .idea .magento2plugin .indexes .ModuleIndex ;
14- import  com .magento .idea .magento2plugin .ui .FilteredComboBox ;
1515import  java .awt .event .ActionEvent ;
16- import  java .awt .event .ActionListener ;
1716import  java .awt .event .KeyEvent ;
1817import  java .awt .event .WindowAdapter ;
1918import  java .awt .event .WindowEvent ;
2019import  java .util .List ;
2120import  javax .swing .JButton ;
21+ import  javax .swing .JComboBox ;
2222import  javax .swing .JComponent ;
2323import  javax .swing .JLabel ;
2424import  javax .swing .JPanel ;
@@ -29,13 +29,15 @@ public class OverrideInThemeDialog extends AbstractDialog {
2929    @ NotNull 
3030    private  final  Project  project ;
3131    private  final  PsiFile  psiFile ;
32-     @ NotNull 
33-     private  final  OverrideInThemeDialogValidator  validator ;
3432    private  JPanel  contentPane ;
3533    private  JButton  buttonOK ;
3634    private  JButton  buttonCancel ;
3735    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 ;
3941
4042    /** 
4143     * Constructor. 
@@ -48,23 +50,14 @@ public OverrideInThemeDialog(final @NotNull Project project, final PsiFile psiFi
4850
4951        this .project  = project ;
5052        this .psiFile  = psiFile ;
51-         this .validator  = new  OverrideInThemeDialogValidator (this );
5253
5354        setContentPane (contentPane );
5455        setModal (true );
5556        getRootPane ().setDefaultButton (buttonOK );
57+         fillThemeOptions ();
5658
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 ());
6861
6962        setDefaultCloseOperation (DO_NOTHING_ON_CLOSE );
7063        addWindowListener (new  WindowAdapter () {
@@ -73,18 +66,15 @@ public void windowClosing(final WindowEvent event) {
7366            }
7467        });
7568
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+         );
8274    }
8375
8476    private  void  onOK () {
85-         if  (!validator .validate (project )) {
86-             JBPopupFactory .getInstance ().createMessage ("Invalid theme selection." )
87-                     .showCenteredInCurrentWindow (project );
77+         if  (!validateFormFields ()) {
8878            return ;
8979        }
9080
@@ -112,9 +102,10 @@ public static void open(final @NotNull Project project, final PsiFile psiFile) {
112102        dialog .setVisible (true );
113103    }
114104
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+         }
119110    }
120111}
0 commit comments