diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideInTheme.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideInTheme.form index a0ea214a0..2364a0712 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideInTheme.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideInTheme.form @@ -72,7 +72,7 @@ - + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideInThemeDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideInThemeDialog.java index af1167ed5..310c4559b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideInThemeDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideInThemeDialog.java @@ -6,19 +6,19 @@ package com.magento.idea.magento2plugin.actions.generation.dialog; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.psi.PsiFile; -import com.magento.idea.magento2plugin.actions.generation.dialog.validator.OverrideInThemeDialogValidator; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; import com.magento.idea.magento2plugin.actions.generation.generator.OverrideInThemeGenerator; import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.ui.FilteredComboBox; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.List; import javax.swing.JButton; +import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; @@ -29,13 +29,15 @@ public class OverrideInThemeDialog extends AbstractDialog { @NotNull private final Project project; private final PsiFile psiFile; - @NotNull - private final OverrideInThemeDialogValidator validator; private JPanel contentPane; private JButton buttonOK; private JButton buttonCancel; private JLabel selectTheme; //NOPMD - private FilteredComboBox theme; + private static final String THEME_NAME = "target theme"; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, + message = {NotEmptyRule.MESSAGE, THEME_NAME}) + private JComboBox theme; /** * Constructor. @@ -48,23 +50,14 @@ public OverrideInThemeDialog(final @NotNull Project project, final PsiFile psiFi this.project = project; this.psiFile = psiFile; - this.validator = new OverrideInThemeDialogValidator(this); setContentPane(contentPane); setModal(true); getRootPane().setDefaultButton(buttonOK); + fillThemeOptions(); - buttonOK.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent event) { - onOK(); //NOPMD - } - }); - - buttonCancel.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent event) { - onCancel(); - } - }); + buttonOK.addActionListener((final ActionEvent event) -> onOK()); + buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @@ -73,18 +66,15 @@ public void windowClosing(final WindowEvent event) { } }); - contentPane.registerKeyboardAction(new ActionListener() { - public void actionPerformed(final ActionEvent event) { - onCancel(); - } - }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + contentPane.registerKeyboardAction( + (final ActionEvent event) -> onCancel(), + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT + ); } private void onOK() { - if (!validator.validate(project)) { - JBPopupFactory.getInstance().createMessage("Invalid theme selection.") - .showCenteredInCurrentWindow(project); + if (!validateFormFields()) { return; } @@ -112,9 +102,10 @@ public static void open(final @NotNull Project project, final PsiFile psiFile) { dialog.setVisible(true); } - private void createUIComponents() { //NOPMD - final List allThemesList = ModuleIndex.getInstance(project).getEditableThemeNames(); - - this.theme = new FilteredComboBox(allThemesList); + private void fillThemeOptions() { + final List themeNames = ModuleIndex.getInstance(project).getEditableThemeNames(); + for (final String themeName: themeNames) { + theme.addItem(themeName); + } } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/OverrideInThemeDialogValidator.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/OverrideInThemeDialogValidator.java deleted file mode 100644 index 9435b1a07..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/OverrideInThemeDialogValidator.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.validator; - -import com.intellij.openapi.project.Project; -import com.magento.idea.magento2plugin.actions.generation.dialog.OverrideInThemeDialog; -import com.magento.idea.magento2plugin.bundles.CommonBundle; -import com.magento.idea.magento2plugin.bundles.ValidatorBundle; -import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import java.util.List; -import javax.swing.JOptionPane; - -public class OverrideInThemeDialogValidator { - private final ValidatorBundle validatorBundle; - private final CommonBundle commonBundle; - private final OverrideInThemeDialog dialog; - - /** - * Constructor. - * - * @param dialog OverrideInThemeDialog - */ - public OverrideInThemeDialogValidator(final OverrideInThemeDialog dialog) { - this.dialog = dialog; - this.validatorBundle = new ValidatorBundle(); - this.commonBundle = new CommonBundle(); - } - - /** - * Validate dialog. - * - * @param project Project - * @return boolean - */ - public boolean validate(final Project project) { - final String errorTitle = commonBundle.message("common.error"); - - final String theme = dialog.getTheme(); - if (theme.length() == 0) { - final String errorMessage = validatorBundle.message( - "validator.notEmpty", - "Target Theme" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - errorTitle, - JOptionPane.ERROR_MESSAGE - ); - - return false; - } - - final List allThemesList = ModuleIndex.getInstance(project).getEditableThemeNames(); - if (!allThemesList.contains(theme)) { - final String errorMessage = validatorBundle - .message("validator.module.noSuchModule", theme); - JOptionPane.showMessageDialog( - null, - errorMessage, - errorTitle, - JOptionPane.ERROR_MESSAGE - ); - - return false; - } - - return true; - } -}