From 9dbe896fc987bb49ba72370f059a1305a6107b27 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyrko Date: Sat, 24 May 2025 11:59:36 +0300 Subject: [PATCH 01/30] 2080: Thread context was already set --- .../generation/dialog/AbstractDialog.java | 84 ++++++++++++++----- .../dialog/CreateAPluginDialog.java | 37 ++++---- .../dialog/CreateAnObserverDialog.java | 31 ++++--- .../dialog/GatherArrayValuesDialog.java | 31 +++---- .../dialog/InjectAViewModelDialog.java | 32 ++++--- .../dialog/NewArgumentInjectionDialog.java | 41 ++++----- .../generation/dialog/NewBlockDialog.java | 31 ++++--- .../dialog/NewCLICommandDialog.java | 33 ++++---- .../dialog/NewCategoryEavAttributeDialog.java | 2 +- .../dialog/NewControllerDialog.java | 33 ++++---- .../generation/dialog/NewCronGroupDialog.java | 36 ++++---- .../generation/dialog/NewCronjobDialog.java | 33 ++++---- .../dialog/NewCustomerEavAttributeDialog.java | 2 +- .../generation/dialog/NewDataModelDialog.java | 41 ++++----- .../generation/dialog/NewDbSchemaDialog.java | 40 ++++----- .../dialog/NewEmailTemplateDialog.java | 35 ++++---- .../generation/dialog/NewEntityDialog.java | 40 ++++----- .../dialog/NewGraphQlResolverDialog.java | 33 ++++---- .../dialog/NewInterfaceForServiceDialog.java | 31 ++++--- .../dialog/NewLayoutTemplateDialog.java | 41 ++++----- .../dialog/NewMessageQueueDialog.java | 31 ++++--- .../generation/dialog/NewModelsDialog.java | 31 ++++--- .../generation/dialog/NewModuleDialog.java | 36 ++++---- .../generation/dialog/NewObserverDialog.java | 33 ++++---- .../dialog/NewProductEavAttributeDialog.java | 2 +- .../dialog/NewSetupDataPatchDialog.java | 33 ++++---- .../dialog/NewUiComponentFormDialog.java | 38 ++++----- .../dialog/NewUiComponentGridDialog.java | 33 ++++---- .../generation/dialog/NewViewModelDialog.java | 33 ++++---- .../dialog/NewWebApiDeclarationDialog.java | 31 ++++--- .../OverrideClassByAPreferenceDialog.java | 32 ++++--- .../dialog/OverrideLayoutInThemeDialog.java | 30 +++---- .../dialog/OverrideTemplateInThemeDialog.java | 30 +++---- .../eavattribute/EavAttributeDialog.java | 41 ++++----- .../magento2uct/ui/ConfigurationDialog.java | 27 +++--- .../idea/magento2uct/ui/ReindexDialog.java | 27 +++--- 36 files changed, 557 insertions(+), 618 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java index b2a9af39b..aaf899bec 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java @@ -6,6 +6,9 @@ package com.magento.idea.magento2plugin.actions.generation.dialog; import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Pair; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; import com.magento.idea.magento2plugin.actions.generation.dialog.prompt.PlaceholderInitializerUtil; @@ -26,12 +29,12 @@ import java.util.List; import javax.swing.JComboBox; import javax.swing.JComponent; -import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.JTabbedPane; import javax.swing.JTextArea; import javax.swing.JTextField; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * All code generate dialog should extend this class. @@ -39,7 +42,7 @@ @SuppressWarnings({ "PMD.TooManyMethods" }) -public abstract class AbstractDialog extends JDialog { +public abstract class AbstractDialog extends DialogWrapper { protected transient CommonBundle bundle; protected final transient ValidatorBundle validatorBundle = new ValidatorBundle(); @@ -50,19 +53,44 @@ public abstract class AbstractDialog extends JDialog { /** * Abstract Dialog Constructor. + * + * @param project Project */ - public AbstractDialog() { - super(); + public AbstractDialog(final @Nullable Project project) { + super(project, true); bundle = new CommonBundle(); errorTitle = bundle.message("common.error"); fieldsValidationsList = new TypeFieldsRulesParser(this).parseValidationRules(); + init(); + } + + /** + * Abstract Dialog Constructor without project. + */ + public AbstractDialog() { + this(null); } + /** + * Center the dialog on the screen. + * Note: This is handled automatically by DialogWrapper, so this method is kept for compatibility. + * + * @param dialog AbstractDialog + */ protected void centerDialog(final AbstractDialog dialog) { - final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - final int coordinateX = screenSize.width / 2 - dialog.getSize().width / 2; - final int coordinateY = screenSize.height / 2 - dialog.getSize().height / 2; - dialog.setLocation(coordinateX, coordinateY); + // DialogWrapper handles centering automatically + } + + /** + * Create the center panel for the dialog. + * This method must be implemented by subclasses to provide the content panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return null; // Subclasses must override this method } /** @@ -76,7 +104,7 @@ protected void onCancel() { * Right way to hide dialog window. */ protected void exit() { - dispose(); + close(CANCEL_EXIT_CODE); } /** @@ -102,6 +130,24 @@ protected final void onOK() { } } + /** + * Called when the OK button is pressed. + * This method is called by DialogWrapper. + */ + @Override + public void doOKAction() { + onOK(); + } + + /** + * Called when the Cancel button is pressed. + * This method is called by DialogWrapper. + */ + @Override + public void doCancelAction() { + onCancel(); + } + /** * Validate all form fields. * @@ -217,11 +263,10 @@ protected void showErrorMessage(final String errorMessage) { if (isValidationErrorShown) { return; } - JOptionPane.showMessageDialog( - this, + Messages.showErrorDialog( + getContentPanel(), errorMessage, - errorTitle, - JOptionPane.ERROR_MESSAGE + errorTitle ); isValidationErrorShown = true; } @@ -302,10 +347,13 @@ private int getParentTabPaneForComponent(final @NotNull Container component) { return getParentTabPaneForComponent(parent); } - @Override - public void setVisible(final boolean status) { + /** + * Show the dialog. + * This method should be used instead of setVisible(true). + */ + public void showDialog() { new PlaceholderInitializerUtil(this).initialize(); - super.setVisible(status); + show(); } /** @@ -317,7 +365,7 @@ public void setVisible(final boolean status) { *

1) specify method in which desired field is focused:


*
      *     public void focusOnTheSampleField() {
-     *             sampleField.requestFocusInWindow();
+     *             sampleField.requestFocus();
      *     }
      * 
* @@ -327,8 +375,6 @@ public void setVisible(final boolean status) { * new FocusOnAFieldListener(this::focusOnTheSampleField) * ) * - * - * @see #requestFocusInWindow() */ public static final class FocusOnAFieldListener implements ComponentListener { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java index c727712c8..87f095245 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java @@ -42,6 +42,7 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -122,15 +123,12 @@ public CreateAPluginDialog( final Method targetMethod, final PhpClass targetClass ) { - super(); + super(project); this.project = project; this.targetMethod = targetMethod; this.targetClass = targetClass; - setContentPane(contentPane); - setModal(true); setTitle(CreateAPluginAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); fillPluginTypeOptions(); fillTargetAreaOptions(); @@ -138,24 +136,18 @@ public CreateAPluginDialog( this.targetMethodLabel.setVisible(false); } - buttonOK.addActionListener((final ActionEvent event) -> onOK()); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - - contentPane.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + init(); + } - addComponentListener(new FocusOnAFieldListener(() -> pluginModule.requestFocusInWindow())); + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } private void fillPluginTypeOptions() { @@ -261,9 +253,8 @@ public static void open( targetMethod, targetClass ); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); } private void createUIComponents() { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java index 63c06470d..12421b53a 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java @@ -36,6 +36,7 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -93,35 +94,24 @@ public class CreateAnObserverDialog extends AbstractDialog { * @param targetEvent Action Event */ public CreateAnObserverDialog(@NotNull final Project project, final String targetEvent) { - super(); + super(project); this.project = project; this.targetEvent = targetEvent; - setContentPane(contentPane); - setModal(true); setTitle(CreateAnObserverAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); fillTargetAreaOptions(); buttonOK.addActionListener(e -> onOK()); buttonCancel.addActionListener(e -> onCancel()); - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - contentPane.registerKeyboardAction( e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener(new FocusOnAFieldListener(() -> observerName.requestFocusInWindow())); + init(); } /** @@ -132,9 +122,19 @@ public void windowClosing(final WindowEvent event) { */ public static void open(@NotNull final Project project, final String targetEvent) { final CreateAnObserverDialog dialog = new CreateAnObserverDialog(project, targetEvent); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } /** @@ -215,4 +215,3 @@ private String getObserverClassFqn() { return getNamespace().concat(Package.fqnSeparator).concat(getObserverClassName()); } } - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java index df2746624..1c71e7a4e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java @@ -13,6 +13,7 @@ import com.magento.idea.magento2plugin.bundles.ValidatorBundle; import com.magento.idea.magento2plugin.magento.packages.DiArgumentType; import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; +import org.jetbrains.annotations.Nullable; import java.awt.Color; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; @@ -61,28 +62,16 @@ public GatherArrayValuesDialog( final @NotNull Project project, final DiArrayValueData arrayValueData ) { - super(); + super(project); this.project = project; this.arrayValueData = arrayValueData; - setContentPane(contentPane); - setModal(true); setTitle(InjectConstructorArgumentAction.GATHER_ARRAY_VALUES_ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener(event -> onOK()); buttonCancel.addActionListener(event -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPane.registerKeyboardAction( event -> onCancel(), @@ -93,6 +82,8 @@ public void windowClosing(final WindowEvent event) { initTable(); itemsTableErrorMessage.setVisible(false); itemsTableErrorMessage.setText(""); + + init(); } /** @@ -106,9 +97,19 @@ public static void open( final DiArrayValueData arrayValueData ) { final GatherArrayValuesDialog dialog = new GatherArrayValuesDialog(project, arrayValueData); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } /** diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java index 316b6c8c7..4e2cf38f6 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java @@ -38,6 +38,7 @@ import javax.swing.KeyStroke; import javax.swing.event.DocumentEvent; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.ExcessiveImports" @@ -87,7 +88,7 @@ public InjectAViewModelDialog( final @NotNull Project project, final XmlTag targetBlockTag ) { - super(); + super(project); this.project = project; this.targetBlockTag = targetBlockTag; @@ -102,31 +103,18 @@ protected void textChanged(final @NotNull DocumentEvent event) { }); this.viewModelDirectory.setText("ViewModel"); - setContentPane(contentPane); - setModal(true); setTitle(InjectAViewModelAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener((final ActionEvent event) -> onOK()); buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - contentPane.registerKeyboardAction( (final ActionEvent event) -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener( - new FocusOnAFieldListener(() -> viewModelClassName.requestFocusInWindow()) - ); + init(); } protected void updateArgumentText() { @@ -205,8 +193,18 @@ public String getViewModelArgumentName() { public static void open(final @NotNull Project project, final XmlTag targetXmlTag) { final InjectAViewModelDialog dialog = new InjectAViewModelDialog(project, targetXmlTag); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.java index 7599dce4f..4e72de3f5 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.java @@ -54,6 +54,7 @@ import javax.swing.KeyStroke; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -172,38 +173,16 @@ public NewArgumentInjectionDialog( final @NotNull PhpClass targetClass, final @NotNull Parameter parameter ) { - super(); + super(project); this.project = project; this.targetClass = targetClass; targetParameter = parameter; arrayValues = new DiArrayValueData(); - setContentPane(contentPane); - setModal(true); setTitle(InjectConstructorArgumentAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); - buttonOK.addActionListener(event -> onOK()); - buttonCancel.addActionListener(event -> onCancel()); - - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - - // call onCancel() on ESCAPE - contentPane.registerKeyboardAction( - event -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); - - addComponentListener(new FocusOnAFieldListener(() -> targetModule.requestFocusInWindow())); + init(); targetClassField.setText(targetClass.getPresentableFQN()); targetArgument.setText(parameter.getName()); @@ -355,9 +334,19 @@ public static void open( ) { final NewArgumentInjectionDialog dialog = new NewArgumentInjectionDialog(project, targetClass, parameter); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } /** diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java index bde6a9a4a..a4aa76ad1 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java @@ -31,6 +31,7 @@ import javax.swing.JTextField; import javax.swing.JTextPane; import javax.swing.KeyStroke; +import org.jetbrains.annotations.Nullable; public class NewBlockDialog extends AbstractDialog { @@ -64,30 +65,18 @@ public class NewBlockDialog extends AbstractDialog { * @param directory PsiDirectory */ public NewBlockDialog(final Project project, final PsiDirectory directory) { - super(); + super(project); this.project = project; this.baseDir = directory; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); - setContentPane(contentPanel); - setModal(true); setTitle(NewBlockAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); suggestBlockDirectory(); buttonOK.addActionListener((final ActionEvent event) -> onOK()); buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPanel.registerKeyboardAction( (final ActionEvent event) -> onCancel(), @@ -95,7 +84,7 @@ public void windowClosing(final WindowEvent event) { JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener(new FocusOnAFieldListener(() -> blockName.requestFocusInWindow())); + init(); } /** @@ -106,9 +95,19 @@ public void windowClosing(final WindowEvent event) { */ public static void open(final Project project, final PsiDirectory directory) { final NewBlockDialog dialog = new NewBlockDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPanel; } protected void onWriteActionOK() { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java index b90199442..39be23fdb 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java @@ -37,6 +37,7 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({"PMD.MissingSerialVersionUID", "PMD.ExcessiveImports"}) public class NewCLICommandDialog extends AbstractDialog { @@ -92,37 +93,24 @@ public NewCLICommandDialog( final @NotNull Project project, final @NotNull PsiDirectory directory ) { - super(); + super(project); this.project = project; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); this.toSnakeCase = CamelCaseToSnakeCase.getInstance(); this.commonBundle = new CommonBundle(); - setContentPane(contentPane); - setModal(true); - getRootPane().setDefaultButton(buttonOK); setTitle(NewCLICommandAction.ACTION_DESCRIPTION); buttonOK.addActionListener(e -> onOK()); buttonCancel.addActionListener(e -> onCancel()); - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - contentPane.registerKeyboardAction( event -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener( - new FocusOnAFieldListener(() -> cliCommandClassNameField.requestFocusInWindow()) - ); + init(); } /** @@ -133,10 +121,19 @@ public void windowClosing(final WindowEvent event) { */ public static void open(final Project project, final PsiDirectory directory) { final NewCLICommandDialog dialog = new NewCLICommandDialog(project, directory); - - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } public String getCLICommandClassName() { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java index 494e5c28e..9fbbdb713 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java @@ -114,7 +114,7 @@ protected void fillAttributeScopeComboBoxes() { } @Override - protected JPanel getContentPanel() { + protected JPanel getDialogPanel() { return contentPanel; } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java index 19a562284..675d4121a 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java @@ -37,6 +37,7 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.KeyStroke; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -82,14 +83,11 @@ public class NewControllerDialog extends AbstractDialog { * @param directory PsiDirectory */ public NewControllerDialog(final Project project, final PsiDirectory directory) { - super(); + super(project); this.project = project; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); - setContentPane(contentPane); - setModal(true); setTitle(NewControllerAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); suggestControllerDirectory(); controllerAreaSelect.addActionListener(e -> suggestControllerDirectory()); controllerAreaSelect.addActionListener(e -> toggleAdminPanel()); @@ -97,15 +95,6 @@ public NewControllerDialog(final Project project, final PsiDirectory directory) buttonOK.addActionListener(e -> onOK()); buttonCancel.addActionListener(e -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPane.registerKeyboardAction( (final ActionEvent event) -> onCancel(), @@ -113,9 +102,7 @@ public void windowClosing(final WindowEvent event) { JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener( - new FocusOnAFieldListener(() -> controllerAreaSelect.requestFocusInWindow()) - ); + init(); } private String getModuleName() { @@ -193,9 +180,19 @@ public String getActionDirectory() { */ public static void open(final Project project, final PsiDirectory directory) { final NewControllerDialog dialog = new NewControllerDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } protected void onWriteActionOK() { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java index 1a90b96f0..0591b91e7 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java @@ -31,6 +31,7 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; import javax.swing.SpinnerNumberModel; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -74,28 +75,17 @@ public class NewCronGroupDialog extends AbstractDialog { * @param directory Directory */ public NewCronGroupDialog(final Project project, final PsiDirectory directory) { - super(); + super(project); this.project = project; - setContentPane(contentPanel); - setModal(true); - setTitle(NewCronGroupAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); + setTitle(NewCronGroupAction.ACTION_DESCRIPTION); + buttonOK.addActionListener(event -> onOK()); buttonCancel.addActionListener(event -> onCancel()); addToggleListenersForCronGroupOptions(); addDefaultValuesToCronGroupOptions(); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPanel.registerKeyboardAction( event -> onCancel(), @@ -103,9 +93,7 @@ public void windowClosing(final WindowEvent event) { JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener( - new FocusOnAFieldListener(() -> cronGroupName.requestFocusInWindow()) - ); + init(); } /** @@ -136,9 +124,19 @@ public CronGroupXmlData getCronGroupXmlData() { */ public static void open(final Project project, final PsiDirectory directory) { final NewCronGroupDialog dialog = new NewCronGroupDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPanel; } protected void onWriteActionOK() { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java index f2db9e980..fc82a9f0b 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java @@ -42,6 +42,7 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.UncommentedEmptyMethodBody", @@ -129,14 +130,11 @@ public class NewCronjobDialog extends AbstractDialog { * @param directory Directory */ public NewCronjobDialog(final @NotNull Project project, final @NotNull PsiDirectory directory) { - super(); + super(project); this.project = project; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); this.camelCaseToSnakeCase = CamelCaseToSnakeCase.getInstance(); - setContentPane(contentPane); - setModal(true); - getRootPane().setDefaultButton(buttonOK); setTitle(NewCronjobAction.ACTION_DESCRIPTION); configPathField.setEditable(false); @@ -187,15 +185,6 @@ public void focusLost(final FocusEvent event) { } }); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPane.registerKeyboardAction( (final ActionEvent event) -> onCancel(), @@ -203,9 +192,7 @@ public void windowClosing(final WindowEvent event) { JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener( - new FocusOnAFieldListener(() -> cronjobClassNameField.requestFocusInWindow()) - ); + init(); } /** @@ -216,9 +203,19 @@ public void windowClosing(final WindowEvent event) { */ public static void open(final Project project, final PsiDirectory directory) { final NewCronjobDialog dialog = new NewCronjobDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } public String getCronjobClassName() { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java index 47da9a97b..c47d974df 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java @@ -106,7 +106,7 @@ public NewCustomerEavAttributeDialog( } @Override - protected JPanel getContentPanel() { + protected JPanel getDialogPanel() { return contentPanel; } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java index 932aaa277..692d91ca2 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java @@ -49,6 +49,7 @@ import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.ExcessiveImports", @@ -88,7 +89,7 @@ public NewDataModelDialog( final @NotNull Project project, final @NotNull PsiDirectory directory ) { - super(); + super(project); this.project = project; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); @@ -96,35 +97,22 @@ public NewDataModelDialog( this.commonBundle = new CommonBundle(); this.properties = new ArrayList<>(); - setContentPane(contentPanel); - setModal(false); setTitle(NewDataModelAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); - - buttonOK.addActionListener((final ActionEvent event) -> onOK()); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - - // call onCancel() on dialog close - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); initPropertiesTable(); - // call onCancel() on ESCAPE KEY press - contentPanel.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + init(); + } - addComponentListener(new FocusOnAFieldListener(() -> { - modelName.requestFocusInWindow(); - })); + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPanel; } /** @@ -135,9 +123,8 @@ public static void open( final @NotNull PsiDirectory directory ) { final NewDataModelDialog dialog = new NewDataModelDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); } /** diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java index bb048e498..d1a6e0f66 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java @@ -43,6 +43,7 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) public class NewDbSchemaDialog extends AbstractDialog { @@ -98,36 +99,26 @@ public NewDbSchemaDialog( final @NotNull Project project, final @NotNull PsiDirectory directory ) { - super(); + super(project); this.project = project; moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); setTitle(NewDbSchemaAction.ACTION_DESCRIPTION); - setContentPane(contentPanel); - setModal(true); - getRootPane().setDefaultButton(buttonOK); - buttonOK.addActionListener(e -> onOK()); - buttonCancel.addActionListener(e -> onCancel()); - - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - - // call onCancel() on ESCAPE - contentPanel.registerKeyboardAction( - event -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); fillComboBoxes(); initializeColumnsUiComponentGroup(); - addComponentListener(new FocusOnAFieldListener(() -> tableName.requestFocusInWindow())); + init(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPanel; } /** @@ -165,9 +156,8 @@ public static void open( final @NotNull PsiDirectory directory ) { final NewDbSchemaDialog dialog = new NewDbSchemaDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); } /** diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java index 8ff41ca92..d260f38d3 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java @@ -33,6 +33,7 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.KeyStroke; +import org.jetbrains.annotations.Nullable; public class NewEmailTemplateDialog extends AbstractDialog { @@ -78,28 +79,16 @@ public class NewEmailTemplateDialog extends AbstractDialog { * @param directory Directory */ public NewEmailTemplateDialog(final Project project, final PsiDirectory directory) { - super(); - setContentPane(contentPane); - setModal(true); - setTitle(NewEmailTemplateAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); + super(project); this.project = project; this.validator = new NewEmailTemplateDialogValidator(project); this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); + setTitle(NewEmailTemplateAction.ACTION_DESCRIPTION); + buttonOK.addActionListener(e -> onOK()); buttonCancel.addActionListener(e -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - - @Override - public void windowClosing(final WindowEvent windowEvent) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPane.registerKeyboardAction( actionEvent -> onCancel(), @@ -107,7 +96,7 @@ public void windowClosing(final WindowEvent windowEvent) { JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener(new FocusOnAFieldListener(() -> identifier.requestFocusInWindow())); + init(); } /** @@ -203,9 +192,19 @@ public String getTemplateType() { */ public static void open(final Project project, final PsiDirectory directory) { final NewEmailTemplateDialog dialog = new NewEmailTemplateDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } private String getModuleName() { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 6a068732b..ed129828e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -85,6 +85,7 @@ import javax.swing.table.DefaultTableModel; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -227,36 +228,18 @@ public class NewEntityDialog extends AbstractDialog { * @param directory PsiDirectory */ public NewEntityDialog(final @NotNull Project project, final PsiDirectory directory) { - super(); + super(project); this.project = project; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); this.properties = new ArrayList<>(); - setContentPane(contentPane); - setModal(false); setTitle(NewEntityAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); onOkActionFired = new ProcessWorker.InProgressFlag(false); buttonOK.addActionListener(this::generateNewEntityFiles); buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - - @SuppressWarnings("PMD.AccessorMethodGeneration") - @Override - public void windowOpened(final WindowEvent event) { - entityName.requestFocus(); - } - }); - initializeComboboxSources(); initPropertiesTable(); @@ -289,6 +272,8 @@ protected void textChanged(final @NotNull DocumentEvent event) { registerTabbedPane(tabbedPane1); sortOrder.setText(DEFAULT_MENU_SORT_ORDER); + + init(); } /** @@ -299,9 +284,19 @@ protected void textChanged(final @NotNull DocumentEvent event) { */ public static void open(final Project project, final PsiDirectory directory) { final NewEntityDialog dialog = new NewEntityDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } /** @@ -394,8 +389,6 @@ private void generateNewEntityFiles(final @NotNull ActionEvent event) { * Perform code generation using input data. */ protected void onWriteActionOK() { - setCursor(new Cursor(Cursor.WAIT_CURSOR)); - formatProperties(); final NewEntityDialogData dialogData = getNewEntityDialogData(); @@ -435,7 +428,6 @@ protected boolean validateFormFields() { * Release dialog buttons and hide. */ private void releaseDialogAfterGeneration() { - setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); buttonCancel.setEnabled(true); buttonOK.setEnabled(true); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java index 13f467c98..9db83308a 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java @@ -30,6 +30,7 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class NewGraphQlResolverDialog extends AbstractDialog { @@ -67,30 +68,18 @@ public NewGraphQlResolverDialog( final @NotNull Project project, final @NotNull PsiDirectory directory ) { - super(); + super(project); this.project = project; this.baseDir = directory; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); - setContentPane(contentPanel); - setModal(true); setTitle(NewGraphQlResolverAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); suggestGraphQlResolverDirectory(); buttonOK.addActionListener((final ActionEvent event) -> onOK()); buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPanel.registerKeyboardAction( (final ActionEvent event) -> onCancel(), @@ -98,9 +87,7 @@ public void windowClosing(final WindowEvent event) { JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener( - new FocusOnAFieldListener(() -> graphQlResolverClassName.requestFocusInWindow()) - ); + init(); } /** @@ -111,16 +98,26 @@ public void windowClosing(final WindowEvent event) { */ public static void open(final Project project, final PsiDirectory directory) { final NewGraphQlResolverDialog dialog = new NewGraphQlResolverDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); // TODO: It's a workaround. Proper fix should be done as: // https://github.com/magento/magento2-phpstorm-plugin/issues/2080 try (var token = com.intellij.concurrency.ThreadContext.resetThreadContext()) { - dialog.setVisible(true); + dialog.showDialog(); } } + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPanel; + } + protected void onWriteActionOK() { generateFile(); exit(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java index a3275cc69..be7143acb 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java @@ -34,6 +34,7 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) public class NewInterfaceForServiceDialog extends AbstractDialog { @@ -86,31 +87,19 @@ public NewInterfaceForServiceDialog( final @NotNull PsiDirectory directory, final @NotNull PhpClass phpClass ) { - super(); + super(project); this.project = project; this.phpClass = phpClass; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); serviceClassMethods = PhpTypeMetadataParserUtil.getPublicMethods(phpClass); - setContentPane(contentPane); - setModal(true); setTitle(NewWebApiInterfaceAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener(event -> onOK()); buttonCancel.addActionListener(event -> onCancel()); chooseMethodsButton.addActionListener(event -> openMethodChooser()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPane.registerKeyboardAction( event -> onCancel(), @@ -120,7 +109,7 @@ public void windowClosing(final WindowEvent event) { fillPredefinedValuesAndDisableInputs(); - addComponentListener(new FocusOnAFieldListener(() -> nameField.requestFocusInWindow())); + init(); } /** @@ -137,9 +126,19 @@ public static void open( ) { final NewInterfaceForServiceDialog dialog = new NewInterfaceForServiceDialog(project, directory, phpClass); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } /** diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java index 8f76987b5..ab5885e5e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java @@ -30,6 +30,7 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.KeyStroke; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -72,37 +73,15 @@ public class NewLayoutTemplateDialog extends AbstractDialog { * @param directory The PsiDirectory where the new layout will be created. */ public NewLayoutTemplateDialog(final Project project, final PsiDirectory directory) { - super(); + super(project); this.project = project; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); this.directory = directory; - setContentPane(contentPane); - setModal(false); setTitle(NewLayoutXmlAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); - - buttonOK.addActionListener(event -> onOK()); - buttonCancel.addActionListener(event -> onCancel()); - - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - - contentPane.registerKeyboardAction( - event -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); - - addComponentListener(new FocusOnAFieldListener(this::run)); autoSelectCurrentArea(); + init(); } /** @@ -113,9 +92,19 @@ public void windowClosing(final WindowEvent event) { */ public static void open(final Project project, final PsiDirectory directory) { final NewLayoutTemplateDialog dialog = new NewLayoutTemplateDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } /** diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java index 99569c28c..f9f049b5e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java @@ -46,6 +46,7 @@ import javax.swing.KeyStroke; import javax.swing.event.DocumentEvent; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -170,15 +171,12 @@ public NewMessageQueueDialog( final @NotNull Project project, final @NotNull PsiDirectory directory ) { - super(); + super(project); this.project = project; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); - setContentPane(contentPanel); - setModal(false); setTitle(NewMessageQueueAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); for (final String connection : MessageQueueConnections.getList()) { connectionName.addItem(connection); @@ -187,15 +185,6 @@ public NewMessageQueueDialog( buttonOK.addActionListener((final ActionEvent event) -> onOK()); buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - // call onCancel() on dialog close - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE KEY press contentPanel.registerKeyboardAction( (final ActionEvent event) -> onCancel(), @@ -218,7 +207,7 @@ protected void textChanged(final @NotNull DocumentEvent event) { connectionName.addActionListener(e -> toggleConsumer()); - addComponentListener(new FocusOnAFieldListener(() -> topicName.requestFocusInWindow())); + init(); } private void toggleConsumer() { @@ -250,9 +239,19 @@ public static void open( final @NotNull PsiDirectory directory ) { final NewMessageQueueDialog dialog = new NewMessageQueueDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPanel; } protected void onWriteActionOK() { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java index b30c084a2..fb46273d4 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java @@ -33,6 +33,7 @@ import javax.swing.KeyStroke; import javax.swing.event.DocumentEvent; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings("PMD.TooManyFields") public class NewModelsDialog extends AbstractDialog { @@ -107,26 +108,14 @@ public class NewModelsDialog extends AbstractDialog { * @param directory PsiDirectory */ public NewModelsDialog(final Project project, final PsiDirectory directory) { - super(); + super(project); this.project = project; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); - setContentPane(contentPane); - setModal(true); setTitle(NewModelsAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener(e -> onOK()); buttonCancel.addActionListener(e -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPane.registerKeyboardAction( (final ActionEvent event) -> onCancel(), @@ -141,7 +130,7 @@ protected void textChanged(final @NotNull DocumentEvent event) { } }); - addComponentListener(new FocusOnAFieldListener(() -> modelName.requestFocusInWindow())); + init(); } /** @@ -164,9 +153,19 @@ public static void open( final @NotNull PsiDirectory directory ) { final NewModelsDialog dialog = new NewModelsDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } /** diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java index 48cb03485..647e13e74 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java @@ -50,6 +50,7 @@ import javax.swing.event.ListSelectionListener; import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -130,17 +131,14 @@ public NewModuleDialog( final @NotNull Project project, final @NotNull PsiDirectory initialBaseDir ) { - super(); + super(project); this.project = project; this.initialBaseDir = initialBaseDir; this.camelCaseToHyphen = CamelCaseToHyphen.getInstance(); this.moduleIndex = new ModuleIndex(project); detectPackageName(initialBaseDir); - setContentPane(contentPane); - setModal(true); setTitle(NewModuleAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); setLicenses(); setModuleDependencies(); @@ -150,27 +148,13 @@ public NewModuleDialog( buttonOK.addActionListener((final ActionEvent event) -> onOK()); buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - contentPane.registerKeyboardAction( (final ActionEvent event) -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener(new FocusOnAFieldListener(() -> { - if (packageName.isVisible()) { - packageName.requestFocusInWindow(); - } else { - moduleName.requestFocusInWindow(); - } - })); + init(); } private void detectPackageName(final @NotNull PsiDirectory initialBaseDir) { @@ -361,9 +345,19 @@ public static void open( final @NotNull PsiDirectory initialBaseDir ) { final NewModuleDialog dialog = new NewModuleDialog(project, initialBaseDir); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } @NotNull diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java index 0c0fce903..cf9e7c233 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java @@ -52,6 +52,7 @@ import javax.swing.KeyStroke; import javax.swing.event.DocumentEvent; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -107,30 +108,18 @@ public NewObserverDialog( final String modulePackage, final String moduleName ) { - super(); + super(project); this.project = project; this.baseDir = directory; this.modulePackage = modulePackage; this.moduleName = moduleName; - setContentPane(contentPanel); - setModal(false); setTitle(NewObserverAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener((final ActionEvent event) -> onOK()); buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPanel.registerKeyboardAction( (final ActionEvent event) -> onCancel(), @@ -146,9 +135,7 @@ public void textChanged(final @NotNull DocumentEvent event) { } }); - addComponentListener( - new FocusOnAFieldListener(() -> className.requestFocusInWindow()) - ); + init(); } /** @@ -169,9 +156,19 @@ public static void open( modulePackage, moduleName ); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPanel; } private String getModuleName() { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java index faba8d9a1..42d3ead74 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java @@ -129,7 +129,7 @@ protected void fillAttributeScopeComboBoxes() { } @Override - protected JPanel getContentPanel() { + protected JPanel getDialogPanel() { return contentPanel; } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java index 9af505a39..2691650c2 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java @@ -26,6 +26,7 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.KeyStroke; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.ConstructorCallsOverridableMethod" @@ -64,30 +65,18 @@ public NewSetupDataPatchDialog( final String modulePackage, final String moduleName ) { - super(); + super(project); this.project = project; this.baseDir = directory; this.modulePackage = modulePackage; this.moduleName = moduleName; - setContentPane(contentPanel); - setModal(true); setTitle(NewSetupDataPatchAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener(event -> onOK()); buttonCancel.addActionListener(event -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPanel.registerKeyboardAction( event -> onCancel(), @@ -95,9 +84,7 @@ public void windowClosing(final WindowEvent event) { JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener(new FocusOnAFieldListener(() -> { - className.requestFocusInWindow(); - })); + init(); } /** @@ -115,9 +102,19 @@ public static void open( modulePackage, moduleName ); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPanel; } /** diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java index 7327446ca..d28d0ddb2 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java @@ -72,6 +72,7 @@ import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -218,42 +219,25 @@ public NewUiComponentFormDialog( final @NotNull Project project, final @NotNull PsiDirectory directory ) { - super(); + super(project); this.project = project; formButtonsValidator = new FormButtonsValidator(this); formFieldsetsValidator = new FormFieldsetsValidator(this); formFieldsValidator = new FormFieldsValidator(this); this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); - setContentPane(contentPane); - setModal(false); setTitle(NewUiComponentFormAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener(e -> onOK()); buttonCancel.addActionListener(e -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - initButtonsTable(); initFieldSetsTable(); initFieldTable(); // call onCancel() on ESCAPE contentPane.registerKeyboardAction( - new ActionListener() { - @Override - public void actionPerformed(final ActionEvent event) { - onCancel(); - } - }, + e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); @@ -262,7 +246,7 @@ public void actionPerformed(final ActionEvent event) { formAreaSelect.setEnabled(false); acl.setText(getModuleName() + "::manage"); - addComponentListener(new FocusOnAFieldListener(() -> formName.requestFocusInWindow())); + init(); } protected void initButtonsTable() { @@ -418,9 +402,19 @@ public static void open( final @NotNull PsiDirectory directory ) { final NewUiComponentFormDialog dialog = new NewUiComponentFormDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } protected void onWriteActionOK() { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java index c4059f1ee..8fd4ab441 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java @@ -70,6 +70,7 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -212,14 +213,11 @@ public NewUiComponentGridDialog( final @NotNull Project project, final @NotNull PsiDirectory directory ) { - super(); + super(project); this.project = project; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); - setContentPane(contentPanel); - setModal(false); setTitle(NewUiComponentGridAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); addActionListeners(); setDefaultValues(); @@ -227,15 +225,6 @@ public NewUiComponentGridDialog( buttonOK.addActionListener(event -> onOK()); buttonCancel.addActionListener(event -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPanel.registerKeyboardAction( event -> onCancel(), @@ -250,9 +239,7 @@ public void windowClosing(final WindowEvent event) { dataProviderParentDirectory.setVisible(false); dataProviderParentDirectoryLabel.setVisible(false); - addComponentListener( - new FocusOnAFieldListener(() -> uiComponentName.requestFocusInWindow()) - ); + init(); } /** @@ -266,9 +253,19 @@ public static void open( final @NotNull PsiDirectory directory ) { final NewUiComponentGridDialog dialog = new NewUiComponentGridDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPanel; } /** diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java index 7072a4df3..e7d6582d8 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java @@ -31,6 +31,7 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.KeyStroke; +import org.jetbrains.annotations.Nullable; public class NewViewModelDialog extends AbstractDialog { @@ -71,30 +72,18 @@ public class NewViewModelDialog extends AbstractDialog { * @param directory PsiDirectory */ public NewViewModelDialog(final Project project, final PsiDirectory directory) { - super(); + super(project); this.project = project; this.baseDir = directory; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); - setContentPane(contentPanel); - setModal(true); setTitle(NewViewModelAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); suggestViewModelDirectory(); buttonOK.addActionListener((final ActionEvent event) -> onOK()); buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPanel.registerKeyboardAction( (final ActionEvent event) -> onCancel(), @@ -102,9 +91,7 @@ public void windowClosing(final WindowEvent event) { JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener( - new FocusOnAFieldListener(() -> viewModelName.requestFocusInWindow()) - ); + init(); } /** @@ -115,9 +102,19 @@ public void windowClosing(final WindowEvent event) { */ public static void open(final Project project, final PsiDirectory directory) { final NewViewModelDialog dialog = new NewViewModelDialog(project, directory); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPanel; } protected void onWriteActionOK() { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java index cf3bd8a36..8ed7d3a9e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java @@ -20,6 +20,7 @@ import com.magento.idea.magento2plugin.magento.packages.WebApiResource; import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; +import org.jetbrains.annotations.Nullable; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -80,30 +81,18 @@ public NewWebApiDeclarationDialog( final @NotNull String classFqn, final @NotNull String methodName ) { - super(); + super(project); this.project = project; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); this.classFqn = classFqn; this.methodName = methodName; - setContentPane(contentPane); - setModal(true); setTitle(NewWebApiDeclarationAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener(event -> onOK()); buttonCancel.addActionListener(event -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPane.registerKeyboardAction( event -> onCancel(), @@ -113,7 +102,7 @@ public void windowClosing(final WindowEvent event) { fillPredefinedValuesAndDisableInputs(); - addComponentListener(new FocusOnAFieldListener(() -> routeUrl.requestFocusInWindow())); + init(); } /** @@ -132,9 +121,19 @@ public static void open( ) { final NewWebApiDeclarationDialog dialog = new NewWebApiDeclarationDialog(project, directory, classFqn, methodName); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } /** diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java index 55af630a2..d5156cd08 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java @@ -42,6 +42,7 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.UnusedPrivateMethod", @@ -96,7 +97,7 @@ public OverrideClassByAPreferenceDialog( final @NotNull Project project, final PhpClass targetClass ) { - super(); + super(project); this.project = project; this.targetClass = targetClass; @@ -104,10 +105,7 @@ public OverrideClassByAPreferenceDialog( this.commonBundle = new CommonBundle(); this.isInterface = false; - setContentPane(contentPane); - setModal(true); setTitle(OverrideClassByAPreferenceAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); fillTargetAreaOptions(); if (targetClass.isFinal()) { inheritClass.setVisible(false); @@ -122,23 +120,13 @@ public OverrideClassByAPreferenceDialog( buttonOK.addActionListener((final ActionEvent event) -> onOK()); buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - contentPane.registerKeyboardAction( (final ActionEvent event) -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener( - new FocusOnAFieldListener(() -> preferenceModule.requestFocusInWindow()) - ); + init(); } private void suggestPreferenceDirectory(final PhpClass targetClass) { @@ -232,9 +220,19 @@ public boolean isInheritClass() { public static void open(final @NotNull Project project, final PhpClass targetClass) { final OverrideClassByAPreferenceDialog dialog = new OverrideClassByAPreferenceDialog(project, targetClass); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } private void createUIComponents() { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java index a69b60586..726040a45 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java @@ -31,6 +31,7 @@ import javax.swing.JRadioButton; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class OverrideLayoutInThemeDialog extends AbstractDialog { @@ -59,15 +60,12 @@ public OverrideLayoutInThemeDialog( final @NotNull Project project, final @NotNull PsiFile psiFile ) { - super(); + super(project); this.project = project; this.psiFile = psiFile; - setContentPane(contentPane); - setModal(true); setTitle(OverrideLayoutInThemeAction.ACTION_DESCRIPTION); - getRootPane().setDefaultButton(buttonOK); fillThemeOptions(); buttonOK.addActionListener((final ActionEvent event) -> onOK()); @@ -76,21 +74,13 @@ public OverrideLayoutInThemeDialog( radioButtonOverride.addActionListener((final ActionEvent event) -> onOverride()); radioButtonExtend.addActionListener((final ActionEvent event) -> onExtend()); - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - contentPane.registerKeyboardAction( (final ActionEvent event) -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener(new FocusOnAFieldListener(() -> theme.requestFocusInWindow())); + init(); } /** @@ -102,9 +92,19 @@ public void windowClosing(final WindowEvent event) { public static void open(final @NotNull Project project, final @NotNull PsiFile psiFile) { final OverrideLayoutInThemeDialog dialog = new OverrideLayoutInThemeDialog(project, psiFile); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } protected void onWriteActionOK() { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java index ef067ba34..49d129db4 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java @@ -31,6 +31,7 @@ import javax.swing.JPanel; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class OverrideTemplateInThemeDialog extends AbstractDialog { @@ -57,14 +58,11 @@ public OverrideTemplateInThemeDialog( final @NotNull Project project, final @NotNull PsiFile psiFile ) { - super(); + super(project); this.project = project; this.psiFile = psiFile; - setContentPane(contentPane); - setModal(true); - final String fileType = psiFile.getVirtualFile().getExtension(); if (OverridableFileType.isFilePhtml(fileType)) { setTitle(OverrideTemplateInThemeAction.ACTION_TEMPLATE_DESCRIPTION); @@ -79,21 +77,11 @@ public OverrideTemplateInThemeDialog( buttonOK.addActionListener((final ActionEvent event) -> onOK()); buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - contentPane.registerKeyboardAction( (final ActionEvent event) -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - - addComponentListener(new FocusOnAFieldListener(() -> theme.requestFocusInWindow())); } /** @@ -107,9 +95,21 @@ public static void open(final @NotNull Project project, final @NotNull PsiFile p new OverrideTemplateInThemeDialog(project, psiFile); dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; } + protected void onWriteActionOK() { final OverrideTemplateInThemeGenerator overrideInThemeGenerator = new OverrideTemplateInThemeGenerator(project); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java index ff6d4b899..f185d0d60 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java @@ -44,6 +44,7 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.GodClass", @@ -61,7 +62,7 @@ public abstract class EavAttributeDialog extends AbstractDialog { protected abstract EavEntityDataInterface getEavEntityData(); - protected abstract JPanel getContentPanel(); + protected abstract JPanel getDialogPanel(); protected abstract JButton getButtonOk(); @@ -113,12 +114,14 @@ public EavAttributeDialog( final PsiDirectory directory, final String actionName ) { - super(); + super(project); this.project = project; this.actionName = actionName; this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); this.sourceModelData = new SourceModelData(); + + init(); } /** @@ -126,10 +129,9 @@ public EavAttributeDialog( */ public void open() { this.initBaseDialogState(); - pack(); - centerDialog(this); setTitle(actionName); - setVisible(true); + centerDialog(this); + showDialog(); } protected void initBaseDialogState() { @@ -185,9 +187,7 @@ protected void initBaseDialogState() { } protected void setPanelConfiguration() { - setContentPane(this.getContentPanel()); - setModal(this.isModalWindow()); - getRootPane().setDefaultButton(this.getButtonOk()); + // DialogWrapper handles panel configuration } protected boolean isModalWindow() { @@ -305,21 +305,22 @@ protected void generateExtraFilesAfterDataPatchGeneration( ) {} protected void addCancelActionForWindow() { - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); + // DialogWrapper handles window close actions } protected void addCancelActionForEsc() { - getContentPanel().registerKeyboardAction( - event -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles ESC key actions + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return getDialogPanel(); } protected void setAttributeInputComboBoxAction( diff --git a/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java b/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java index 94f3fc123..794815c4f 100644 --- a/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java +++ b/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java @@ -35,6 +35,7 @@ import javax.swing.JPanel; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) public class ConfigurationDialog extends AbstractDialog { @@ -70,13 +71,11 @@ public class ConfigurationDialog extends AbstractDialog { * @param project Project */ public ConfigurationDialog(final @NotNull Project project) { - super(); + super(project); this.project = project; settingsService = UctSettingsService.getInstance(project); - setContentPane(contentPanel); - setModal(true); setTitle(ConfigureUctAction.ACTION_NAME); getRootPane().setDefaultButton(buttonOk); @@ -85,15 +84,6 @@ public ConfigurationDialog(final @NotNull Project project) { buttonOk.addActionListener(event -> onOK()); buttonCancel.addActionListener(event -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPanel.registerKeyboardAction( event -> onCancel(), @@ -122,7 +112,18 @@ public static void open(final @NotNull Project project) { final ConfigurationDialog dialog = new ConfigurationDialog(project); dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPanel; } /** diff --git a/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java b/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java index bff6e8507..670ad21d7 100644 --- a/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java +++ b/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java @@ -25,6 +25,7 @@ import javax.swing.JPanel; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class ReindexDialog extends AbstractDialog { @@ -49,28 +50,17 @@ public ReindexDialog( final @NotNull Project project, final @NotNull PsiDirectory directory ) { - super(); + super(project); this.project = project; this.directory = directory; - setContentPane(contentPanel); - setModal(true); setTitle(ReindexVersionedIndexesAction.ACTION_NAME); getRootPane().setDefaultButton(buttonOk); buttonOk.addActionListener(event -> onOK()); buttonCancel.addActionListener(event -> onCancel()); - // call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - // call onCancel() on ESCAPE contentPanel.registerKeyboardAction( event -> onCancel(), @@ -95,7 +85,18 @@ public static void open( ); dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPanel; } /** From f0ba6c33b77d93d010d79b9a0d6e741ac5597ffe Mon Sep 17 00:00:00 2001 From: Vitaliy Boyrko Date: Sat, 24 May 2025 13:00:22 +0300 Subject: [PATCH 02/30] 2080: removed ok and cancels --- .../dialog/CreateAPluginDialog.form | 41 ------------------ .../dialog/CreateAnObserverDialog.form | 41 ------------------ .../dialog/GatherArrayValuesDialog.form | 31 ------------- .../dialog/InjectAViewModelDialog.form | 41 ------------------ .../dialog/NewArgumentInjectionDialog.form | 31 ------------- .../generation/dialog/NewBlockDialog.form | 41 ------------------ .../dialog/NewCLICommandDialog.form | 36 ---------------- .../dialog/NewCategoryEavAttributeDialog.form | 42 ------------------ .../dialog/NewControllerDialog.form | 41 ------------------ .../generation/dialog/NewCronGroupDialog.form | 41 ------------------ .../generation/dialog/NewCronjobDialog.form | 41 ------------------ .../dialog/NewCustomerEavAttributeDialog.form | 42 ------------------ .../generation/dialog/NewDataModelDialog.form | 41 ------------------ .../generation/dialog/NewDbSchemaDialog.form | 32 -------------- .../dialog/NewEmailTemplateDialog.form | 41 ------------------ .../dialog/NewEmailTemplateDialog.java | 5 --- .../generation/dialog/NewEntityDialog.form | 28 +----------- .../generation/dialog/NewEntityDialog.java | 10 ----- .../dialog/NewGraphQlResolverDialog.form | 41 ------------------ .../dialog/NewGraphQlResolverDialog.java | 7 +-- .../dialog/NewInterfaceForServiceDialog.form | 41 ------------------ .../dialog/NewInterfaceForServiceDialog.java | 4 -- .../dialog/NewLayoutTemplateDialog.form | 41 ------------------ .../dialog/NewLayoutTemplateDialog.java | 2 - .../dialog/NewMessageQueueDialog.form | 41 ------------------ .../generation/dialog/NewModelsDialog.form | 41 ------------------ .../generation/dialog/NewModelsDialog.java | 4 -- .../generation/dialog/NewModuleDialog.form | 41 ------------------ .../generation/dialog/NewModuleDialog.java | 5 --- .../generation/dialog/NewObserverDialog.form | 41 ------------------ .../dialog/NewProductEavAttributeDialog.form | 42 ------------------ .../dialog/NewSetupDataPatchDialog.form | 41 ------------------ .../dialog/NewUiComponentFormDialog.form | 41 ------------------ .../dialog/NewUiComponentFormDialog.java | 5 --- .../dialog/NewUiComponentGridDialog.form | 43 +------------------ .../dialog/NewUiComponentGridDialog.java | 5 --- .../generation/dialog/NewViewModelDialog.form | 41 ------------------ .../dialog/NewWebApiDeclarationDialog.form | 41 ------------------ .../OverrideClassByAPreferenceDialog.form | 26 ----------- .../OverrideClassByAPreferenceDialog.java | 5 --- .../dialog/OverrideLayoutInTheme.form | 26 ----------- .../dialog/OverrideLayoutInThemeDialog.java | 5 --- .../dialog/OverrideTemplateInThemeDialog.form | 26 ----------- .../dialog/OverrideTemplateInThemeDialog.java | 28 ++++++------ .../magento2uct/ui/ConfigurationDialog.form | 31 ------------- .../magento2uct/ui/ConfigurationDialog.java | 4 -- .../idea/magento2uct/ui/ReindexDialog.form | 16 ------- .../idea/magento2uct/ui/ReindexDialog.java | 6 +-- 48 files changed, 18 insertions(+), 1349 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.form index d4a02c695..d3568d4fd 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.form @@ -10,47 +10,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.form index 29ceca808..f5f5917da 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.form @@ -12,47 +12,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.form index 12fb4d29c..d1d40312d 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.form @@ -19,37 +19,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.form index 3bdde5930..41e24203e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.form @@ -11,47 +11,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.form index 01efe99ed..9956d47d9 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.form @@ -11,37 +11,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.form index c460ac6fa..10cd36936 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.form @@ -12,47 +12,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.form index 43b98f5b5..7a5f71dce 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.form @@ -90,42 +90,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form index 8719df26c..be8fbb71c 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.form @@ -338,48 +338,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.form index 25283ea73..c05b3ade9 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.form @@ -10,47 +10,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.form index 030b9841e..761441c97 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.form @@ -8,47 +8,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.form index 1da079a05..21de29acc 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.form @@ -10,47 +10,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form index 90e2c2fba..31e19cb2e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form @@ -375,48 +375,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.form index b9b2cb84b..9cb89152d 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.form @@ -94,47 +94,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.form index 78ac30fdd..7d2bf68ba 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.form @@ -11,38 +11,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.form index 411ec0e9d..99e784813 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.form @@ -10,47 +10,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java index d260f38d3..6e0d9594a 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java @@ -45,8 +45,6 @@ public class NewEmailTemplateDialog extends AbstractDialog { private final Project project; private final NewEmailTemplateDialogValidator validator; private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, EMAIL_TEMPLATE_ID}) @@ -86,9 +84,6 @@ public NewEmailTemplateDialog(final Project project, final PsiDirectory director setTitle(NewEmailTemplateAction.ACTION_DESCRIPTION); - buttonOK.addActionListener(e -> onOK()); - buttonCancel.addActionListener(e -> onCancel()); - // call onCancel() on ESCAPE contentPane.registerKeyboardAction( actionEvent -> onCancel(), diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form index 99dac0aa5..81bd08ae0 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form @@ -610,32 +610,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -645,4 +619,4 @@ - \ No newline at end of file + diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index ed129828e..a087ee405 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -101,8 +101,6 @@ public class NewEntityDialog extends AbstractDialog { private JPanel propertiesPanel; private JTable propertyTable; private JButton addProperty; - private JButton buttonOK; - private JButton buttonCancel; private JPanel generalTable; private JCheckBox createUiComponent; private JLabel entityNameLabel; @@ -237,8 +235,6 @@ public NewEntityDialog(final @NotNull Project project, final PsiDirectory direct setTitle(NewEntityAction.ACTION_DESCRIPTION); onOkActionFired = new ProcessWorker.InProgressFlag(false); - buttonOK.addActionListener(this::generateNewEntityFiles); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); initializeComboboxSources(); initPropertiesTable(); @@ -370,9 +366,6 @@ private void initPropertiesTable() { @SuppressWarnings("PMD.UnusedFormalParameter") private void generateNewEntityFiles(final @NotNull ActionEvent event) { if (!onOkActionFired.isInProgress()) { - buttonOK.setEnabled(false); - buttonCancel.setEnabled(false); - if (propertyTable.isEditing()) { propertyTable.getCellEditor().stopCellEditing(); } @@ -428,9 +421,6 @@ protected boolean validateFormFields() { * Release dialog buttons and hide. */ private void releaseDialogAfterGeneration() { - buttonCancel.setEnabled(true); - buttonOK.setEnabled(true); - if (onOkActionFired.isFinished()) { exit(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.form index 7ad64638b..c19f7c22f 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.form @@ -98,47 +98,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java index 9db83308a..1ab94929e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java @@ -99,12 +99,7 @@ public NewGraphQlResolverDialog( public static void open(final Project project, final PsiDirectory directory) { final NewGraphQlResolverDialog dialog = new NewGraphQlResolverDialog(project, directory); dialog.centerDialog(dialog); - - // TODO: It's a workaround. Proper fix should be done as: - // https://github.com/magento/magento2-phpstorm-plugin/issues/2080 - try (var token = com.intellij.concurrency.ThreadContext.resetThreadContext()) { - dialog.showDialog(); - } + dialog.showDialog(); } /** diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.form index 25690df76..0348945b7 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.form @@ -10,47 +10,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java index be7143acb..71474d427 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java @@ -49,8 +49,6 @@ public class NewInterfaceForServiceDialog extends AbstractDialog { private final List serviceClassMethods; private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; private JButton chooseMethodsButton; private JTextField serviceClassField; @@ -96,8 +94,6 @@ public NewInterfaceForServiceDialog( setTitle(NewWebApiInterfaceAction.ACTION_DESCRIPTION); - buttonOK.addActionListener(event -> onOK()); - buttonCancel.addActionListener(event -> onCancel()); chooseMethodsButton.addActionListener(event -> openMethodChooser()); // call onCancel() on ESCAPE diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.form index f5c0221d5..df31540d2 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.form @@ -10,47 +10,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java index ab5885e5e..831cec63f 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java @@ -49,8 +49,6 @@ public class NewLayoutTemplateDialog extends AbstractDialog { private final PsiDirectory directory; private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, LAYOUT_NAME}) @FieldValidation( diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form index 13e9efda6..bc1f6e4eb 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form @@ -236,47 +236,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.form index da7a3a909..ba8e9d54a 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.form @@ -10,47 +10,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java index fb46273d4..be6c23318 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java @@ -41,8 +41,6 @@ public class NewModelsDialog extends AbstractDialog { private final String moduleName; private final Project project; private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; private static final String ACTION_NAME = "Create Models"; private static final String MODEL_NAME = "Model Name"; @@ -113,8 +111,6 @@ public NewModelsDialog(final Project project, final PsiDirectory directory) { this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); setTitle(NewModelsAction.ACTION_DESCRIPTION); - buttonOK.addActionListener(e -> onOK()); - buttonCancel.addActionListener(e -> onCancel()); // call onCancel() on ESCAPE contentPane.registerKeyboardAction( diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.form index d9165ec5f..ac250734e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.form @@ -10,47 +10,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java index 647e13e74..26ff7187f 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java @@ -109,8 +109,6 @@ public class NewModuleDialog extends AbstractDialog implements ListSelectionList private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; private JCheckBox moduleReadmeMdCheckbox; @NotNull @@ -145,9 +143,6 @@ public NewModuleDialog( moduleLicenseCustom.setToolTipText("Custom License Name"); moduleLicenseCustom.setText(Settings.getDefaultLicenseName(project)); - buttonOK.addActionListener((final ActionEvent event) -> onOK()); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - contentPane.registerKeyboardAction( (final ActionEvent event) -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.form index 3908688d6..7d009b832 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.form @@ -12,47 +12,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form index 9f3e30b8f..3fdfb1228 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.form @@ -428,48 +428,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.form index f9879145a..1f1944ee0 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.form @@ -12,47 +12,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.form index 3251a2e2e..b595b41fc 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.form @@ -10,47 +10,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java index d28d0ddb2..d6be29c36 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java @@ -107,8 +107,6 @@ public class NewUiComponentFormDialog extends AbstractDialog { private final Project project; private final String moduleName; private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; private FilteredComboBox formAreaSelect; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Name"}) @@ -228,9 +226,6 @@ public NewUiComponentFormDialog( setTitle(NewUiComponentFormAction.ACTION_DESCRIPTION); - buttonOK.addActionListener(e -> onOK()); - buttonCancel.addActionListener(e -> onCancel()); - initButtonsTable(); initFieldSetsTable(); initFieldTable(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.form index 192290ff8..cf5ff1f99 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.form @@ -8,47 +8,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -682,4 +641,4 @@ - \ No newline at end of file + diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java index 8fd4ab441..9221e8ce1 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java @@ -90,8 +90,6 @@ public class NewUiComponentGridDialog extends AbstractDialog { private final String moduleName; private List collectionOptions; private JPanel contentPanel; - private JButton buttonOK; - private JButton buttonCancel; private JCheckBox addToolBar; private JCheckBox addBookmarksCheckBox; @@ -222,9 +220,6 @@ public NewUiComponentGridDialog( addActionListeners(); setDefaultValues(); - buttonOK.addActionListener(event -> onOK()); - buttonCancel.addActionListener(event -> onCancel()); - // call onCancel() on ESCAPE contentPanel.registerKeyboardAction( event -> onCancel(), diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.form index fa05e157a..3b1c22f01 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.form @@ -98,47 +98,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.form index 393840fbc..c30c8346e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.form @@ -10,47 +10,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.form index 1c052cad6..e00c98ae9 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.form @@ -24,32 +24,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java index d5156cd08..0017a9b2d 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java @@ -54,8 +54,6 @@ public class OverrideClassByAPreferenceDialog extends AbstractDialog { //NOPMD private final PhpClass targetClass; private boolean isInterface; private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; private final CommonBundle commonBundle; private final ValidatorBundle validatorBundle; private JLabel inheritClassLabel; @@ -117,9 +115,6 @@ public OverrideClassByAPreferenceDialog( suggestPreferenceClassName(targetClass); suggestPreferenceDirectory(targetClass); - buttonOK.addActionListener((final ActionEvent event) -> onOK()); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - contentPane.registerKeyboardAction( (final ActionEvent event) -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInTheme.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInTheme.form index 6f7e2862f..90bb643c0 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInTheme.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInTheme.form @@ -20,32 +20,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java index 726040a45..afd703bab 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java @@ -40,8 +40,6 @@ public class OverrideLayoutInThemeDialog extends AbstractDialog { private final @NotNull Project project; private final PsiFile psiFile; private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; private JLabel selectTheme; //NOPMD @FieldValidation(rule = RuleRegistry.NOT_EMPTY, @@ -68,9 +66,6 @@ public OverrideLayoutInThemeDialog( setTitle(OverrideLayoutInThemeAction.ACTION_DESCRIPTION); fillThemeOptions(); - buttonOK.addActionListener((final ActionEvent event) -> onOK()); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - radioButtonOverride.addActionListener((final ActionEvent event) -> onOverride()); radioButtonExtend.addActionListener((final ActionEvent event) -> onExtend()); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.form b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.form index 598e8eb48..1619c1acb 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.form +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.form @@ -19,32 +19,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java index 49d129db4..c509055d5 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java @@ -31,7 +31,6 @@ import javax.swing.JPanel; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class OverrideTemplateInThemeDialog extends AbstractDialog { @@ -71,7 +70,7 @@ public OverrideTemplateInThemeDialog( } else if (OverridableFileType.isFileStyle(fileType)) { setTitle(OverrideTemplateInThemeAction.ACTION_STYLES_DESCRIPTION); } - getRootPane().setDefaultButton(buttonOK); + fillThemeOptions(); buttonOK.addActionListener((final ActionEvent event) -> onOK()); @@ -82,6 +81,18 @@ public OverrideTemplateInThemeDialog( KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); + + init(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Override + protected JComponent createCenterPanel() { + return contentPane; } /** @@ -93,23 +104,10 @@ public OverrideTemplateInThemeDialog( public static void open(final @NotNull Project project, final @NotNull PsiFile psiFile) { final OverrideTemplateInThemeDialog dialog = new OverrideTemplateInThemeDialog(project, psiFile); - dialog.pack(); dialog.centerDialog(dialog); dialog.showDialog(); } - /** - * Create center panel. - * - * @return JComponent - */ - @Nullable - @Override - protected JComponent createCenterPanel() { - return contentPane; - } - - protected void onWriteActionOK() { final OverrideTemplateInThemeGenerator overrideInThemeGenerator = new OverrideTemplateInThemeGenerator(project); diff --git a/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.form b/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.form index 24967e7be..dde8aa441 100644 --- a/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.form +++ b/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.form @@ -169,37 +169,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java b/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java index 794815c4f..5717b8d54 100644 --- a/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java +++ b/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java @@ -35,7 +35,6 @@ import javax.swing.JPanel; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; @SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) public class ConfigurationDialog extends AbstractDialog { @@ -77,7 +76,6 @@ public ConfigurationDialog(final @NotNull Project project) { settingsService = UctSettingsService.getInstance(project); setTitle(ConfigureUctAction.ACTION_NAME); - getRootPane().setDefaultButton(buttonOk); hasAdditionalPath.addActionListener(event -> refreshAdditionalFields(hasAdditionalPath.isSelected())); @@ -110,7 +108,6 @@ public ConfigurationDialog(final @NotNull Project project) { */ public static void open(final @NotNull Project project) { final ConfigurationDialog dialog = new ConfigurationDialog(project); - dialog.pack(); dialog.centerDialog(dialog); dialog.showDialog(); } @@ -120,7 +117,6 @@ public static void open(final @NotNull Project project) { * * @return JComponent */ - @Nullable @Override protected JComponent createCenterPanel() { return contentPanel; diff --git a/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.form b/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.form index 2ffd58b7a..c44f00213 100644 --- a/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.form +++ b/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.form @@ -33,27 +33,11 @@ - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java b/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java index 670ad21d7..3271c3bd5 100644 --- a/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java +++ b/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java @@ -25,7 +25,6 @@ import javax.swing.JPanel; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class ReindexDialog extends AbstractDialog { @@ -56,7 +55,6 @@ public ReindexDialog( this.directory = directory; setTitle(ReindexVersionedIndexesAction.ACTION_NAME); - getRootPane().setDefaultButton(buttonOk); buttonOk.addActionListener(event -> onOK()); buttonCancel.addActionListener(event -> onCancel()); @@ -67,6 +65,8 @@ public ReindexDialog( KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); + + init(); } /** @@ -83,7 +83,6 @@ public static void open( project, directory ); - dialog.pack(); dialog.centerDialog(dialog); dialog.showDialog(); } @@ -93,7 +92,6 @@ public static void open( * * @return JComponent */ - @Nullable @Override protected JComponent createCenterPanel() { return contentPanel; From be386bded979ec474d3c7a9f0f73c3a1b78bdfa5 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyrko Date: Sat, 24 May 2025 19:37:33 +0300 Subject: [PATCH 03/30] 2080: Add custom dialogs to generate new Magento 2 classes This commit adds a new feature to the plugin that allows developers to easily create new Magento 2 classes using predefined templates. The added dialogs provide users with a more convenient and intuitive way to generate new code. The changes include: * New dialog for generating new Web API declarations, which replaces the existing action with a custom dialog. * New dialog for generating new controller classes, which also includes a custom UI for selecting the class directory and enabling/disabling the admin panel --- .../actions/generation/dialog/AbstractDialog.java | 3 --- .../generation/dialog/CreateAnObserverDialog.java | 9 +-------- .../generation/dialog/GatherArrayValuesDialog.java | 10 +--------- .../generation/dialog/InjectAViewModelDialog.java | 9 +-------- .../actions/generation/dialog/NewBlockDialog.java | 10 +--------- .../actions/generation/dialog/NewCLICommandDialog.java | 9 +-------- .../actions/generation/dialog/NewControllerDialog.java | 10 +--------- .../actions/generation/dialog/NewCronGroupDialog.java | 10 +--------- .../actions/generation/dialog/NewCronjobDialog.java | 10 ++-------- .../generation/dialog/NewGraphQlResolverDialog.java | 10 +--------- .../generation/dialog/NewMessageQueueDialog.java | 10 +--------- .../actions/generation/dialog/NewObserverDialog.java | 10 +--------- .../generation/dialog/NewSetupDataPatchDialog.java | 10 +--------- .../actions/generation/dialog/NewViewModelDialog.java | 10 +--------- .../generation/dialog/NewWebApiDeclarationDialog.java | 10 +--------- .../generation/dialog/OverrideLayoutInThemeDialog.java | 6 +----- .../dialog/OverrideTemplateInThemeDialog.java | 9 +-------- 17 files changed, 17 insertions(+), 138 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java index aaf899bec..6d9919ef2 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java @@ -20,8 +20,6 @@ import com.magento.idea.magento2plugin.bundles.CommonBundle; import com.magento.idea.magento2plugin.bundles.ValidatorBundle; import java.awt.Container; -import java.awt.Dimension; -import java.awt.Toolkit; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.lang.reflect.Field; @@ -29,7 +27,6 @@ import java.util.List; import javax.swing.JComboBox; import javax.swing.JComponent; -import javax.swing.JOptionPane; import javax.swing.JTabbedPane; import javax.swing.JTextArea; import javax.swing.JTextField; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java index 12421b53a..b0679f01f 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java @@ -102,14 +102,7 @@ public CreateAnObserverDialog(@NotNull final Project project, final String targe setTitle(CreateAnObserverAction.ACTION_DESCRIPTION); fillTargetAreaOptions(); - buttonOK.addActionListener(e -> onOK()); - buttonCancel.addActionListener(e -> onCancel()); - - contentPane.registerKeyboardAction( - e -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically init(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java index 1c71e7a4e..7197389cd 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java @@ -69,15 +69,7 @@ public GatherArrayValuesDialog( setTitle(InjectConstructorArgumentAction.GATHER_ARRAY_VALUES_ACTION_DESCRIPTION); - buttonOK.addActionListener(event -> onOK()); - buttonCancel.addActionListener(event -> onCancel()); - - // call onCancel() on ESCAPE - contentPane.registerKeyboardAction( - event -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically initTable(); itemsTableErrorMessage.setVisible(false); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java index 4e2cf38f6..b1f3db5ab 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java @@ -105,14 +105,7 @@ protected void textChanged(final @NotNull DocumentEvent event) { setTitle(InjectAViewModelAction.ACTION_DESCRIPTION); - buttonOK.addActionListener((final ActionEvent event) -> onOK()); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - - contentPane.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically init(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java index a4aa76ad1..f3b8c0cbc 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java @@ -74,15 +74,7 @@ public NewBlockDialog(final Project project, final PsiDirectory directory) { setTitle(NewBlockAction.ACTION_DESCRIPTION); suggestBlockDirectory(); - buttonOK.addActionListener((final ActionEvent event) -> onOK()); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - - // call onCancel() on ESCAPE - contentPanel.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically init(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java index 39be23fdb..68f43c02d 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java @@ -101,14 +101,7 @@ public NewCLICommandDialog( setTitle(NewCLICommandAction.ACTION_DESCRIPTION); - buttonOK.addActionListener(e -> onOK()); - buttonCancel.addActionListener(e -> onCancel()); - - contentPane.registerKeyboardAction( - event -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically init(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java index 675d4121a..f32949ea2 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java @@ -92,15 +92,7 @@ public NewControllerDialog(final Project project, final PsiDirectory directory) controllerAreaSelect.addActionListener(e -> suggestControllerDirectory()); controllerAreaSelect.addActionListener(e -> toggleAdminPanel()); inheritClass.addActionListener(e -> toggleAdminPanel()); - buttonOK.addActionListener(e -> onOK()); - buttonCancel.addActionListener(e -> onCancel()); - - // call onCancel() on ESCAPE - contentPane.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically init(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java index 0591b91e7..3e9eafe22 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java @@ -81,18 +81,10 @@ public NewCronGroupDialog(final Project project, final PsiDirectory directory) { setTitle(NewCronGroupAction.ACTION_DESCRIPTION); - buttonOK.addActionListener(event -> onOK()); - buttonCancel.addActionListener(event -> onCancel()); + // DialogWrapper handles button actions and ESC key automatically addToggleListenersForCronGroupOptions(); addDefaultValuesToCronGroupOptions(); - // call onCancel() on ESCAPE - contentPanel.registerKeyboardAction( - event -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); - init(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java index fc82a9f0b..d15bb89f7 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java @@ -138,8 +138,7 @@ public NewCronjobDialog(final @NotNull Project project, final @NotNull PsiDirect setTitle(NewCronjobAction.ACTION_DESCRIPTION); configPathField.setEditable(false); - buttonOK.addActionListener(e -> onOK()); - buttonCancel.addActionListener(e -> onCancel()); + // DialogWrapper handles button actions automatically fixedScheduleRadioButton.addActionListener(e -> { configurableSchedulePanel.setVisible(false); @@ -185,12 +184,7 @@ public void focusLost(final FocusEvent event) { } }); - // call onCancel() on ESCAPE - contentPane.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles ESC key automatically init(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java index 1ab94929e..4eeec965d 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java @@ -77,15 +77,7 @@ public NewGraphQlResolverDialog( setTitle(NewGraphQlResolverAction.ACTION_DESCRIPTION); suggestGraphQlResolverDirectory(); - buttonOK.addActionListener((final ActionEvent event) -> onOK()); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - - // call onCancel() on ESCAPE - contentPanel.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically init(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java index f9f049b5e..2b5b39390 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java @@ -182,15 +182,7 @@ public NewMessageQueueDialog( connectionName.addItem(connection); } - buttonOK.addActionListener((final ActionEvent event) -> onOK()); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - - // call onCancel() on ESCAPE KEY press - contentPanel.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically this.topicName.getDocument().addDocumentListener(new DocumentAdapter() { @Override diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java index cf9e7c233..a8b5b21cd 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java @@ -117,15 +117,7 @@ public NewObserverDialog( setTitle(NewObserverAction.ACTION_DESCRIPTION); - buttonOK.addActionListener((final ActionEvent event) -> onOK()); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - - // call onCancel() on ESCAPE - contentPanel.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically className.getDocument().addDocumentListener(new DocumentAdapter() { @SuppressWarnings("PMD.AccessorMethodGeneration") diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java index 2691650c2..bc7f94bda 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java @@ -74,15 +74,7 @@ public NewSetupDataPatchDialog( setTitle(NewSetupDataPatchAction.ACTION_DESCRIPTION); - buttonOK.addActionListener(event -> onOK()); - buttonCancel.addActionListener(event -> onCancel()); - - // call onCancel() on ESCAPE - contentPanel.registerKeyboardAction( - event -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically init(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java index e7d6582d8..a37462596 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java @@ -81,15 +81,7 @@ public NewViewModelDialog(final Project project, final PsiDirectory directory) { setTitle(NewViewModelAction.ACTION_DESCRIPTION); suggestViewModelDirectory(); - buttonOK.addActionListener((final ActionEvent event) -> onOK()); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - - // call onCancel() on ESCAPE - contentPanel.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically init(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java index 8ed7d3a9e..9e00e6a2e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java @@ -90,15 +90,7 @@ public NewWebApiDeclarationDialog( setTitle(NewWebApiDeclarationAction.ACTION_DESCRIPTION); - buttonOK.addActionListener(event -> onOK()); - buttonCancel.addActionListener(event -> onCancel()); - - // call onCancel() on ESCAPE - contentPane.registerKeyboardAction( - event -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically fillPredefinedValuesAndDisableInputs(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java index afd703bab..e6dc2ff05 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java @@ -69,11 +69,7 @@ public OverrideLayoutInThemeDialog( radioButtonOverride.addActionListener((final ActionEvent event) -> onOverride()); radioButtonExtend.addActionListener((final ActionEvent event) -> onExtend()); - contentPane.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles ESC key automatically init(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java index c509055d5..b5790e5e5 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java @@ -73,14 +73,7 @@ public OverrideTemplateInThemeDialog( fillThemeOptions(); - buttonOK.addActionListener((final ActionEvent event) -> onOK()); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - - contentPane.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically init(); } From 1cdaafc2b87470c720c5d1998eaf7e5f6fac3c8d Mon Sep 17 00:00:00 2001 From: Vitaliy Boyrko Date: Sat, 24 May 2025 19:55:02 +0300 Subject: [PATCH 04/30] 2080: adds a new action to generate a Magento 2 EAV customer attribute, with a corresponding dialog window to configure the attributes. --- .../NewCustomerEavAttributeAction.java | 31 -- .../eavattribute/EavAttributeDialog.java | 521 ------------------ ...ava => NewCustomerEavAttributeAction.java} | 43 +- src/main/resources/META-INF/plugin.xml | 4 +- 4 files changed, 17 insertions(+), 582 deletions(-) delete mode 100644 src/main/java/com/magento/idea/magento2plugin/actions/generation/NewCustomerEavAttributeAction.java delete mode 100644 src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java rename src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/{NewEavAttributeAction.java => NewCustomerEavAttributeAction.java} (59%) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/NewCustomerEavAttributeAction.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/NewCustomerEavAttributeAction.java deleted file mode 100644 index 576749b7a..000000000 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/NewCustomerEavAttributeAction.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.magento.idea.magento2plugin.MagentoIcons; -import com.magento.idea.magento2plugin.actions.generation.dialog.NewCustomerEavAttributeDialog; -import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; -import com.magento.idea.magento2plugin.actions.generation.eavattribute.NewEavAttributeAction; - -public class NewCustomerEavAttributeAction extends NewEavAttributeAction { - - public static final String ACTION_NAME = "Customer Attribute"; - public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Customer Attribute"; - - public NewCustomerEavAttributeAction() { - super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); - } - - @Override - protected EavAttributeDialog getDialogWindow( - final Project project, - final PsiDirectory directory - ) { - return new NewCustomerEavAttributeDialog(project, directory, ACTION_NAME); - } -} diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java deleted file mode 100644 index f185d0d60..000000000 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java +++ /dev/null @@ -1,521 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; -import com.magento.idea.magento2plugin.actions.generation.data.SourceModelData; -import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; -import com.magento.idea.magento2plugin.actions.generation.dialog.AbstractDialog; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeCodeAdapter; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourcePanelComponentListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourceRelationsItemListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.DataPatchNameAdapter; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.EavAttributeInputItemListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.OptionsPanelVisibilityChangeListener; -import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.SourceModelNameAdapter; -import com.magento.idea.magento2plugin.actions.generation.dialog.util.eavdialog.AttributeUtil; -import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.GetAttributeOptionPropertiesUtil; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType; -import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; -import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.KeyStroke; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -@SuppressWarnings({ - "PMD.GodClass", - "PMD.TooManyMethods", - "PMD.ExcessiveImports", - "PMD.AccessorMethodGeneration" -}) -public abstract class EavAttributeDialog extends AbstractDialog { - - protected String moduleName; - protected Project project; - protected String actionName; - protected TableGroupWrapper entityPropertiesTableGroupWrapper; - protected SourceModelData sourceModelData; - - protected abstract EavEntityDataInterface getEavEntityData(); - - protected abstract JPanel getDialogPanel(); - - protected abstract JButton getButtonOk(); - - protected abstract JButton getButtonCancel(); - - protected abstract JComboBox getAttributeTypeCompoBox(); - - protected abstract JComboBox getAttributeInputComboBox(); - - protected abstract JTable getOptionsTable(); - - protected abstract JButton getNewOptionButton(); - - protected abstract JComboBox getAttributeSourceComboBox(); - - protected abstract JTextField getAttributeSourceModelNameTexField(); - - protected abstract JTextField getSourceModelDirectoryTextField(); - - protected abstract JPanel getAttributeCustomSourceModelPanel(); - - protected abstract JPanel getAttributeOptionsPanel(); - - protected abstract JTextField getAttributeCodeTextField(); - - protected abstract JTextField getDataPatchNameTextField(); - - protected abstract JTextField getSourceModelNameTextField(); - - protected abstract JTextField getAttributeLabelTexField(); - - protected abstract JTextField getAttributeSortOrderTextField(); - - protected abstract JCheckBox getAttributeRequiredCheckBox(); - - protected abstract JCheckBox getAttributeVisibleBox(); - - protected abstract String getEntityName(); - - /** - * Constructor. - * - * @param project Project - * @param directory PsiDirectory - * @param actionName String - */ - public EavAttributeDialog( - final Project project, - final PsiDirectory directory, - final String actionName - ) { - super(project); - - this.project = project; - this.actionName = actionName; - this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); - this.sourceModelData = new SourceModelData(); - - init(); - } - - /** - * Open dialog window. - */ - public void open() { - this.initBaseDialogState(); - setTitle(actionName); - centerDialog(this); - showDialog(); - } - - protected void initBaseDialogState() { - this.setPanelConfiguration(); - this.fillAttributeTypeComboBox(getAttributeTypeCompoBox()); - this.fillAttributeInputComboBox(getAttributeInputComboBox()); - - this.initPropertiesTable( - new LinkedList<>(Arrays.asList( - "Value", - "Sort Order" - )), - getOptionsTable(), - getNewOptionButton(), - getDefaultColumnsValues(), - getColumnsSources() - ); - - this.addActionListenersForOkButton(getButtonOk()); - this.addActionListenersForOkCancel(getButtonCancel()); - - this.addCancelActionForWindow(); - this.addCancelActionForEsc(); - - this.setAttributeInputComboBoxAction( - getAttributeSourceComboBox(), - getAttributeInputComboBox() - ); - this.setSourceComboBoxAction(getAttributeSourceComboBox()); - - this.setSourceModelPanelAction( - getAttributeCustomSourceModelPanel(), - getSourceModelDirectoryTextField() - ); - this.addOptionPanelListener( - getAttributeSourceComboBox(), - getAttributeInputComboBox(), - getAttributeOptionsPanel() - ); - this.setDefaultSources(getAttributeSourceComboBox()); - this.setAutocompleteListenerForAttributeCodeField( - getAttributeLabelTexField(), - getAttributeCodeTextField() - ); - this.setAutocompleteListenerForDataPathNameField( - getAttributeCodeTextField(), - getDataPatchNameTextField() - ); - this.setAutocompleteListenerForSourceModelNameField( - getAttributeCodeTextField(), - getSourceModelNameTextField() - ); - } - - protected void setPanelConfiguration() { - // DialogWrapper handles panel configuration - } - - protected boolean isModalWindow() { - return true; - } - - @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") - protected void fillAttributeTypeComboBox(final JComboBox typeComboBox) { - if (typeComboBox == null) { - return; - } - - for (final AttributeType typeValue : AttributeType.values()) { - typeComboBox.addItem( - new ComboBoxItemData(typeValue.getType(), typeValue.getType()) - ); - } - } - - @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") - protected void fillAttributeInputComboBox(final JComboBox inputComboBox) { - if (inputComboBox == null) { - return; - } - - for (final AttributeInput inputValue : AttributeInput.values()) { - inputComboBox.addItem( - new ComboBoxItemData(inputValue.getInput(), inputValue.getInput()) - ); - } - } - - protected void initPropertiesTable( - final List columns, - final JTable optionsTable, - final JButton newOptionButton, - final Map defaultColumnsValues, - final Map> columnsSources - - ) { - // Initialize entity properties Table Group - entityPropertiesTableGroupWrapper = new TableGroupWrapper( - optionsTable, - newOptionButton, - columns, - defaultColumnsValues, - columnsSources - ); - entityPropertiesTableGroupWrapper.initTableGroup(); - } - - protected Map getDefaultColumnsValues() { - return new HashMap<>(); - } - - protected Map> getColumnsSources() { - return new HashMap<>(); - } - - protected void addActionListenersForOkButton(final JButton okButton) { - okButton.addActionListener(e -> onOK()); - } - - protected void addActionListenersForOkCancel(final JButton cancelButton) { - cancelButton.addActionListener(e -> onCancel()); - } - - protected void onWriteActionOK() { - stopOptionsTableEditing(getOptionsTable()); - generateExtraFilesBeforeDataPatchGeneration(); - final EavEntityDataInterface eavEntityDataInterface = getEavEntityData(); - generateDataPatchFile(eavEntityDataInterface); - generateExtraFilesAfterDataPatchGeneration(eavEntityDataInterface); - - exit(); - } - - protected void generateSourceModelFile() { - final ComboBoxItemData selectedSource = - (ComboBoxItemData) getAttributeSourceComboBox().getSelectedItem(); - - if (selectedSource == null - || !selectedSource.getText().equals( - AttributeSourceModel.GENERATE_SOURCE.getSource() - )) { - return; - } - - sourceModelData.setModuleName(moduleName); - sourceModelData.setClassName(getAttributeSourceModelNameTexField().getText().trim()); - sourceModelData.setDirectory(getSourceModelDirectoryTextField().getText().trim()); - - new SourceModelGenerator(sourceModelData, project, true) - .generate(actionName, false); - } - - protected void generateDataPatchFile(final EavEntityDataInterface eavEntityDataInterface) { - new EavAttributeSetupPatchGenerator( - eavEntityDataInterface, - project, - true - ).generate(actionName, true); - } - - protected void generateExtraFilesBeforeDataPatchGeneration() { - generateSourceModelFile(); - } - - @SuppressWarnings({ - "PMD.EmptyMethodInAbstractClassShouldBeAbstract", - "PMD.UncommentedEmptyMethodBody" - }) - protected void generateExtraFilesAfterDataPatchGeneration( - final EavEntityDataInterface eavEntityDataInterface - ) {} - - protected void addCancelActionForWindow() { - // DialogWrapper handles window close actions - } - - protected void addCancelActionForEsc() { - // DialogWrapper handles ESC key actions - } - - /** - * Create center panel. - * - * @return JComponent - */ - @Nullable - @Override - protected JComponent createCenterPanel() { - return getDialogPanel(); - } - - protected void setAttributeInputComboBoxAction( - final JComboBox sourceComboBox, - final JComboBox inputComboBox - ) { - if (sourceComboBox == null || inputComboBox == null) { - return; - } - - inputComboBox.addItemListener( - new EavAttributeInputItemListener(sourceComboBox) - ); - } - - protected void setSourceComboBoxAction(final JComboBox sourceComboBox) { - if (sourceComboBox == null) { - return; - } - - sourceComboBox.addItemListener( - new AttributeSourceRelationsItemListener(getAttributeCustomSourceModelPanel()) - ); - } - - protected void setSourceModelPanelAction( - final JPanel attributeCustomSourceModelPanel, - final JTextField sourceModelDirectoryTexField - ) { - if (attributeCustomSourceModelPanel == null || sourceModelDirectoryTexField == null) { - return; - } - - attributeCustomSourceModelPanel.addComponentListener( - new AttributeSourcePanelComponentListener(sourceModelDirectoryTexField) - ); - } - - protected void addOptionPanelListener( - final JComboBox attributeSourceComboBox, - final JComboBox attributeInputComboBox, - final JPanel attributeOptionsPanel - ) { - if (attributeSourceComboBox == null - || attributeInputComboBox == null - || attributeOptionsPanel == null - ) { - return; - } - - attributeSourceComboBox.addItemListener( - new OptionsPanelVisibilityChangeListener( - attributeOptionsPanel, - attributeInputComboBox - ) - ); - } - - protected void setDefaultSources(final JComboBox sourceComboBox) { - if (sourceComboBox == null) { - return; - } - - final ComboBoxItemData generateSourceItem = new ComboBoxItemData( - AttributeSourceModel.GENERATE_SOURCE.getSource(), - AttributeSourceModel.GENERATE_SOURCE.getSource() - ); - final ComboBoxItemData defaultSourceItem = new ComboBoxItemData( - AttributeSourceModel.NULLABLE_SOURCE.name(), - AttributeSourceModel.NULLABLE_SOURCE.getSource() - ); - - sourceComboBox.addItem(defaultSourceItem); - sourceComboBox.addItem(generateSourceItem); - - sourceComboBox.setSelectedItem(defaultSourceItem); - } - - protected void setAutocompleteListenerForAttributeCodeField( - @NotNull final JTextField attributeLabelTextField, - @NotNull final JTextField attributeCodeTextField - ) { - attributeLabelTextField.getDocument() - .addDocumentListener(new AttributeCodeAdapter(attributeCodeTextField)); - } - - protected void setAutocompleteListenerForDataPathNameField( - final JTextField mainTextField, - final JTextField dependentTextField - - ) { - if (mainTextField == null || dependentTextField == null) { - return; - } - - mainTextField.getDocument() - .addDocumentListener(new DataPatchNameAdapter(dependentTextField, getEntityName())); - } - - protected void setAutocompleteListenerForSourceModelNameField( - final JTextField mainTextField, - final JTextField dependentTextField - ) { - if (mainTextField == null || dependentTextField == null) { - return; - } - - mainTextField.getDocument() - .addDocumentListener(new SourceModelNameAdapter(dependentTextField)); - } - - protected String getDataPatchName() { - final JTextField dataPatchNameTextField = getDataPatchNameTextField(); - - return dataPatchNameTextField == null - ? "" : dataPatchNameTextField.getText().trim(); - } - - protected String getAttributeCode() { - final JTextField codeTextField = getAttributeCodeTextField(); - - return codeTextField == null - ? "" : codeTextField.getText().trim(); - } - - protected String getAttributeLabel() { - final JTextField labelTextField = getAttributeLabelTexField(); - - return labelTextField == null - ? "" : labelTextField.getText().trim(); - } - - protected int getAttributeSortOrder() { - final JTextField sortOrderTextField = getAttributeSortOrderTextField(); - - return sortOrderTextField == null - ? 0 : Integer.parseInt(sortOrderTextField.getText().trim()); - } - - protected boolean isRequiredAttribute() { - final JCheckBox requiredCheckBox = getAttributeRequiredCheckBox(); - - return requiredCheckBox != null && requiredCheckBox.isSelected(); - } - - protected boolean isVisibleAttribute() { - final JCheckBox visibleCheckBox = getAttributeVisibleBox(); - - return visibleCheckBox != null && visibleCheckBox.isSelected(); - } - - protected String getAttributeBackendType() { - final JComboBox typeComboBox = getAttributeTypeCompoBox(); - - return AttributeUtil.getBackendTypeBySelectedItem( - (ComboBoxItemData) typeComboBox.getSelectedItem() - ); - } - - protected String getAttributeInput() { - final JComboBox inputComboBox = getAttributeInputComboBox(); - - return AttributeUtil.getInputTypeBySelectedItem( - (ComboBoxItemData) inputComboBox.getSelectedItem() - ); - } - - protected String getAttributeSource(final SourceModelData sourceModelData) { - final JComboBox sourceComboBox = getAttributeSourceComboBox(); - - return AttributeUtil.getSourceClassBySelectedItem( - (ComboBoxItemData) sourceComboBox.getSelectedItem(), - sourceModelData - ); - } - - protected Map getAttributeOptions( - final TableGroupWrapper entityPropertiesTableGroupWrapper - ) { - return GetAttributeOptionPropertiesUtil.getValues( - entityPropertiesTableGroupWrapper.getColumnsData() - ); - } - - protected Map getAttributeOptionsSortOrders( - final TableGroupWrapper entityPropertiesTableGroupWrapper - ) { - return GetAttributeOptionPropertiesUtil.getSortOrders( - entityPropertiesTableGroupWrapper.getColumnsData() - ); - } - - private void stopOptionsTableEditing(final JTable optionsTable) { - if (optionsTable != null && optionsTable.isEditing()) { - optionsTable.getCellEditor().stopCellEditing(); - } - } -} diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewEavAttributeAction.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCustomerEavAttributeAction.java similarity index 59% rename from src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewEavAttributeAction.java rename to src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCustomerEavAttributeAction.java index 190e9a988..e324d2fa0 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewEavAttributeAction.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCustomerEavAttributeAction.java @@ -6,7 +6,6 @@ package com.magento.idea.magento2plugin.actions.generation.eavattribute; import com.intellij.ide.IdeView; -import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; @@ -14,17 +13,17 @@ import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; -import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; -import javax.swing.Icon; +import com.magento.idea.magento2plugin.MagentoIcons; +import com.magento.idea.magento2plugin.actions.generation.dialog.NewCustomerEavAttributeDialog; import org.jetbrains.annotations.NotNull; -public abstract class NewEavAttributeAction extends AnAction { - public NewEavAttributeAction( - final String actionName, - final String actionDescription, - final Icon icon - ) { - super(actionName, actionDescription, icon); +public class NewCustomerEavAttributeAction extends AnAction { + + public static final String ACTION_NAME = "Customer Attribute"; + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Customer Attribute"; + + public NewCustomerEavAttributeAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); } @Override @@ -45,22 +44,10 @@ public void actionPerformed(final @NotNull AnActionEvent event) { return; } - final EavAttributeDialog eavAttributeDialog = getDialogWindow(project, directory); - eavAttributeDialog.open(); - } - - @Override - public @NotNull ActionUpdateThread getActionUpdateThread() { - return ActionUpdateThread.BGT; + NewCustomerEavAttributeDialog.open( + project, + directory, + ACTION_NAME + ); } - - @Override - public boolean isDumbAware() { - return false; - } - - protected abstract EavAttributeDialog getDialogWindow( - Project project, - PsiDirectory directory - ); -} +} \ No newline at end of file diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 2011ea5f0..60be06cf8 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -110,7 +110,7 @@ - + @@ -711,4 +711,4 @@ - \ No newline at end of file + From 5cafb40700aa4d9db44c0f749cc93b97c24095d6 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyrko Date: Sat, 24 May 2025 19:56:09 +0300 Subject: [PATCH 05/30] 2080: Implemented new action for generating EAV Product attribute with UI dialog" --- .../dialog/NewCategoryEavAttributeDialog.java | 551 ++++++++++++--- .../dialog/NewCustomerEavAttributeDialog.java | 629 +++++++++++++----- .../dialog/NewProductEavAttributeDialog.java | 544 ++++++++++++--- .../NewCategoryEavAttributeAction.java | 37 +- .../NewProductEavAttributeAction.java | 37 +- 5 files changed, 1432 insertions(+), 366 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java index 9fbbdb713..9c886d92e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java @@ -8,24 +8,44 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; import com.magento.idea.magento2plugin.actions.generation.data.CategoryEntityData; -import com.magento.idea.magento2plugin.actions.generation.data.CategoryFormXmlData; import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; +import com.magento.idea.magento2plugin.actions.generation.data.SourceModelData; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; -import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeCodeAdapter; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourcePanelComponentListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourceRelationsItemListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.DataPatchNameAdapter; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.EavAttributeInputItemListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.OptionsPanelVisibilityChangeListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.SourceModelNameAdapter; import com.magento.idea.magento2plugin.actions.generation.dialog.util.eavdialog.AttributeUtil; 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.Lowercase; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; -import com.magento.idea.magento2plugin.actions.generation.generator.CategoryFormXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.GetAttributeOptionPropertiesUtil; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType; +import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; +import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; +import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.JTextField; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -33,9 +53,15 @@ "PMD.TooManyMethods", "PMD.UnusedPrivateField" }) -public class NewCategoryEavAttributeDialog extends EavAttributeDialog { +public class NewCategoryEavAttributeDialog extends AbstractDialog { private static final String ENTITY_NAME = "Category"; + private String moduleName; + private Project project; + private String actionName; + private TableGroupWrapper entityPropertiesTableGroupWrapper; + private SourceModelData sourceModelData; + private JPanel contentPanel; private JButton buttonOK; private JButton buttonCancel; @@ -55,8 +81,6 @@ public class NewCategoryEavAttributeDialog extends EavAttributeDialog { private JTextField dataPatchNameTextField; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) - @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, - message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) private JTextField sortOrderTextField; private JComboBox inputComboBox; private JComboBox typeComboBox; @@ -75,8 +99,8 @@ public class NewCategoryEavAttributeDialog extends EavAttributeDialog { private JTable optionsTable; private JButton addNewOptionButton; private JPanel optionsPanel; - private JLabel codeTextFieldErrorMessage; private JLabel labelTextFieldErrorMessage; + private JLabel codeTextFieldErrorMessage; private JLabel dataPatchNameTextFieldErrorMessage; private JLabel groupTextFieldErrorMessage; private JLabel sourceModelDirectoryTextFieldErrorMessage; @@ -86,24 +110,250 @@ public class NewCategoryEavAttributeDialog extends EavAttributeDialog { /** * Constructor. * - * @param project Project - * @param directory PsiDirectory - * @param actionName String + * @param project Project + * @param directory PsiDirectory */ public NewCategoryEavAttributeDialog( final Project project, final PsiDirectory directory, final String actionName ) { - super(project, directory, actionName); + super(project); + + this.project = project; + this.actionName = actionName; + this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); + this.sourceModelData = new SourceModelData(); + + setTitle(actionName); + init(); } - @Override - protected void initBaseDialogState() { - super.initBaseDialogState(); + /** + * Open dialog window. + * + * @param project Project + * @param directory PsiDirectory + * @param actionName String + */ + public static void open( + final Project project, + final PsiDirectory directory, + final String actionName + ) { + final NewCategoryEavAttributeDialog dialog = new NewCategoryEavAttributeDialog( + project, + directory, + actionName + ); + dialog.initDialogState(); + dialog.showDialog(); + } + + /** + * Initialize dialog state. + */ + protected void initDialogState() { + fillAttributeTypeComboBox(); + fillAttributeInputComboBox(); + initPropertiesTable(); + setAttributeInputComboBoxAction(); + setSourceComboBoxAction(); + setSourceModelPanelAction(); + addOptionPanelListener(); + setDefaultSources(); + setAutocompleteListenerForAttributeCodeField(); + setAutocompleteListenerForDataPathNameField(); + setAutocompleteListenerForSourceModelNameField(); fillAttributeScopeComboBoxes(); } + /** + * Fill attribute type combo box. + */ + protected void fillAttributeTypeComboBox() { + if (typeComboBox == null) { + return; + } + + for (final AttributeType typeValue : AttributeType.values()) { + typeComboBox.addItem( + new ComboBoxItemData(typeValue.getType(), typeValue.getType()) + ); + } + } + + /** + * Fill attribute input combo box. + */ + protected void fillAttributeInputComboBox() { + if (inputComboBox == null) { + return; + } + + for (final AttributeInput inputValue : AttributeInput.values()) { + inputComboBox.addItem( + new ComboBoxItemData(inputValue.getInput(), inputValue.getInput()) + ); + } + } + + /** + * Initialize properties table. + */ + protected void initPropertiesTable() { + // Initialize entity properties Table Group + entityPropertiesTableGroupWrapper = new TableGroupWrapper( + optionsTable, + addNewOptionButton, + new LinkedList<>(Arrays.asList( + "Value", + "Sort Order" + )), + getDefaultColumnsValues(), + getColumnsSources() + ); + entityPropertiesTableGroupWrapper.initTableGroup(); + } + + /** + * Get default columns values. + * + * @return Map + */ + protected Map getDefaultColumnsValues() { + return new HashMap<>(); + } + + /** + * Get columns sources. + * + * @return Map> + */ + protected Map> getColumnsSources() { + return new HashMap<>(); + } + + /** + * Set attribute input combo box action. + */ + protected void setAttributeInputComboBoxAction() { + if (sourceComboBox == null || inputComboBox == null) { + return; + } + + inputComboBox.addItemListener( + new EavAttributeInputItemListener(sourceComboBox) + ); + } + + /** + * Set source combo box action. + */ + protected void setSourceComboBoxAction() { + if (sourceComboBox == null) { + return; + } + + sourceComboBox.addItemListener( + new AttributeSourceRelationsItemListener(customSourceModelPanel) + ); + } + + /** + * Set source model panel action. + */ + protected void setSourceModelPanelAction() { + if (customSourceModelPanel == null || sourceModelDirectoryTextField == null) { + return; + } + + customSourceModelPanel.addComponentListener( + new AttributeSourcePanelComponentListener(sourceModelDirectoryTextField) + ); + } + + /** + * Add option panel listener. + */ + protected void addOptionPanelListener() { + if (sourceComboBox == null + || inputComboBox == null + || optionsPanel == null + ) { + return; + } + + sourceComboBox.addItemListener( + new OptionsPanelVisibilityChangeListener( + optionsPanel, + inputComboBox + ) + ); + } + + /** + * Set default sources. + */ + protected void setDefaultSources() { + if (sourceComboBox == null) { + return; + } + + final ComboBoxItemData generateSourceItem = new ComboBoxItemData( + AttributeSourceModel.GENERATE_SOURCE.getSource(), + AttributeSourceModel.GENERATE_SOURCE.getSource() + ); + final ComboBoxItemData defaultSourceItem = new ComboBoxItemData( + AttributeSourceModel.NULLABLE_SOURCE.name(), + AttributeSourceModel.NULLABLE_SOURCE.getSource() + ); + + sourceComboBox.addItem(defaultSourceItem); + sourceComboBox.addItem(generateSourceItem); + + sourceComboBox.setSelectedItem(defaultSourceItem); + } + + /** + * Set autocomplete listener for attribute code field. + */ + protected void setAutocompleteListenerForAttributeCodeField() { + if (labelTextField == null || codeTextField == null) { + return; + } + + labelTextField.getDocument() + .addDocumentListener(new AttributeCodeAdapter(codeTextField)); + } + + /** + * Set autocomplete listener for data path name field. + */ + protected void setAutocompleteListenerForDataPathNameField() { + if (codeTextField == null || dataPatchNameTextField == null) { + return; + } + + codeTextField.getDocument() + .addDocumentListener(new DataPatchNameAdapter(dataPatchNameTextField, getEntityName())); + } + + /** + * Set autocomplete listener for source model name field. + */ + protected void setAutocompleteListenerForSourceModelNameField() { + if (codeTextField == null || sourceModelNameTextField == null) { + return; + } + + codeTextField.getDocument() + .addDocumentListener(new SourceModelNameAdapter(sourceModelNameTextField)); + } + + /** + * Fill attribute scope combo boxes. + */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") protected void fillAttributeScopeComboBoxes() { for (final AttributeScope globalValue : AttributeScope.values()) { @@ -113,114 +363,223 @@ protected void fillAttributeScopeComboBoxes() { } } - @Override - protected JPanel getDialogPanel() { - return contentPanel; + /** + * Get data patch name. + * + * @return String + */ + protected String getDataPatchName() { + return dataPatchNameTextField == null + ? "" : dataPatchNameTextField.getText().trim(); } - @Override - protected JButton getButtonOk() { - return buttonOK; + /** + * Get attribute code. + * + * @return String + */ + protected String getAttributeCode() { + return codeTextField == null + ? "" : codeTextField.getText().trim(); } - @Override - protected JButton getButtonCancel() { - return buttonCancel; + /** + * Get attribute label. + * + * @return String + */ + protected String getAttributeLabel() { + return labelTextField == null + ? "" : labelTextField.getText().trim(); } - @Override - protected JComboBox getAttributeTypeCompoBox() { - return typeComboBox; + /** + * Get attribute sort order. + * + * @return int + */ + protected int getAttributeSortOrder() { + return sortOrderTextField == null + ? 0 : Integer.parseInt(sortOrderTextField.getText().trim()); } - @Override - protected JComboBox getAttributeInputComboBox() { - return inputComboBox; + /** + * Is required attribute. + * + * @return boolean + */ + protected boolean isRequiredAttribute() { + return requiredCheckBox != null && requiredCheckBox.isSelected(); } - @Override - protected JTable getOptionsTable() { - return optionsTable; + /** + * Is visible attribute. + * + * @return boolean + */ + protected boolean isVisibleAttribute() { + return visibleCheckBox != null && visibleCheckBox.isSelected(); } - @Override - protected JButton getNewOptionButton() { - return addNewOptionButton; + /** + * Get attribute backend type. + * + * @return String + */ + protected String getAttributeBackendType() { + return AttributeUtil.getBackendTypeBySelectedItem( + (ComboBoxItemData) typeComboBox.getSelectedItem() + ); } - @Override - protected JComboBox getAttributeSourceComboBox() { - return sourceComboBox; + /** + * Get attribute input. + * + * @return String + */ + protected String getAttributeInput() { + return AttributeUtil.getInputTypeBySelectedItem( + (ComboBoxItemData) inputComboBox.getSelectedItem() + ); } - @Override - protected JTextField getAttributeSourceModelNameTexField() { - return sourceModelNameTextField; + /** + * Get attribute source. + * + * @param sourceModelData SourceModelData + * @return String + */ + protected String getAttributeSource(final SourceModelData sourceModelData) { + return AttributeUtil.getSourceClassBySelectedItem( + (ComboBoxItemData) sourceComboBox.getSelectedItem(), + sourceModelData + ); } - @Override - protected JTextField getSourceModelDirectoryTextField() { - return sourceModelDirectoryTextField; + /** + * Get attribute options. + * + * @param entityPropertiesTableGroupWrapper TableGroupWrapper + * @return Map + */ + protected Map getAttributeOptions( + final TableGroupWrapper entityPropertiesTableGroupWrapper + ) { + return GetAttributeOptionPropertiesUtil.getValues( + entityPropertiesTableGroupWrapper.getColumnsData() + ); } - @Override - protected JPanel getAttributeCustomSourceModelPanel() { - return customSourceModelPanel; + /** + * Get attribute options sort orders. + * + * @param entityPropertiesTableGroupWrapper TableGroupWrapper + * @return Map + */ + protected Map getAttributeOptionsSortOrders( + final TableGroupWrapper entityPropertiesTableGroupWrapper + ) { + return GetAttributeOptionPropertiesUtil.getSortOrders( + entityPropertiesTableGroupWrapper.getColumnsData() + ); } - @Override - protected JPanel getAttributeOptionsPanel() { - return optionsPanel; + /** + * Stop options table editing. + */ + private void stopOptionsTableEditing() { + if (optionsTable != null && optionsTable.isEditing()) { + optionsTable.getCellEditor().stopCellEditing(); + } } - @Override - protected JTextField getAttributeCodeTextField() { - return codeTextField; - } + /** + * Generate source model file. + */ + protected void generateSourceModelFile() { + final ComboBoxItemData selectedSource = + (ComboBoxItemData) sourceComboBox.getSelectedItem(); + + if (selectedSource == null + || !selectedSource.getText().equals( + AttributeSourceModel.GENERATE_SOURCE.getSource() + )) { + return; + } - @Override - protected JTextField getDataPatchNameTextField() { - return dataPatchNameTextField; - } + sourceModelData.setModuleName(moduleName); + sourceModelData.setClassName(sourceModelNameTextField.getText().trim()); + sourceModelData.setDirectory(sourceModelDirectoryTextField.getText().trim()); - @Override - protected JTextField getSourceModelNameTextField() { - return sourceModelNameTextField; + new SourceModelGenerator(sourceModelData, project, true) + .generate(actionName, false); } - @Override - protected JTextField getAttributeLabelTexField() { - return labelTextField; + /** + * Generate data patch file. + * + * @param eavEntityDataInterface EavEntityDataInterface + */ + protected void generateDataPatchFile(final EavEntityDataInterface eavEntityDataInterface) { + new EavAttributeSetupPatchGenerator( + eavEntityDataInterface, + project, + true + ).generate(actionName, true); } - @Override - protected JTextField getAttributeSortOrderTextField() { - return sortOrderTextField; + /** + * Generate extra files before data patch generation. + */ + protected void generateExtraFilesBeforeDataPatchGeneration() { + generateSourceModelFile(); } - @Override - protected JCheckBox getAttributeRequiredCheckBox() { - return requiredCheckBox; - } + /** + * Generate extra files after data patch generation. + * + * @param eavEntityDataInterface EavEntityDataInterface + */ + protected void generateExtraFilesAfterDataPatchGeneration( + final EavEntityDataInterface eavEntityDataInterface + ) {} + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable @Override - protected JCheckBox getAttributeVisibleBox() { - return visibleCheckBox; + protected JComponent createCenterPanel() { + return contentPanel; } - @Override + /** + * Get entity name. + * + * @return String + */ protected String getEntityName() { return ENTITY_NAME; } - @Override + /** + * Get EAV entity data. + * + * @return EavEntityDataInterface + */ protected EavEntityDataInterface getEavEntityData() { return populateCategoryEntityData(new CategoryEntityData()); } - private CategoryEntityData populateCategoryEntityData( - final CategoryEntityData categoryEntityData - ) { + /** + * Populate category entity data. + * + * @param categoryEntityData CategoryEntityData + * @return CategoryEntityData + */ + private CategoryEntityData populateCategoryEntityData(final CategoryEntityData categoryEntityData) { categoryEntityData.setModuleName(moduleName); categoryEntityData.setDataPatchName(getDataPatchName()); @@ -229,6 +588,7 @@ private CategoryEntityData populateCategoryEntityData( categoryEntityData.setSortOrder(getAttributeSortOrder()); categoryEntityData.setRequired(isRequiredAttribute()); categoryEntityData.setVisible(isVisibleAttribute()); + categoryEntityData.setGroup(groupTextField.getText().trim()); categoryEntityData.setType(getAttributeBackendType()); categoryEntityData.setInput(getAttributeInput()); categoryEntityData.setScope( @@ -244,31 +604,20 @@ private CategoryEntityData populateCategoryEntityData( getAttributeOptionsSortOrders(entityPropertiesTableGroupWrapper) ); - categoryEntityData.setGroup(groupTextField.getText().trim()); - return categoryEntityData; } + /** + * On write action OK. + */ @Override - protected void generateExtraFilesAfterDataPatchGeneration( - final EavEntityDataInterface eavEntityDataInterface - ) { - super.generateExtraFilesAfterDataPatchGeneration(eavEntityDataInterface); - generateCategoryAdminForm((CategoryEntityData) eavEntityDataInterface); - } - - private void generateCategoryAdminForm(final CategoryEntityData categoryEntityData) { - final CategoryFormXmlData categoryFormXmlData = new CategoryFormXmlData( - categoryEntityData.getGroup(), - categoryEntityData.getCode(), - categoryEntityData.getInput(), - categoryEntityData.getSortOrder() - ); - - new CategoryFormXmlGenerator( - categoryFormXmlData, - project, - moduleName - ).generate(actionName, false); + protected void onWriteActionOK() { + stopOptionsTableEditing(); + generateExtraFilesBeforeDataPatchGeneration(); + final EavEntityDataInterface eavEntityDataInterface = getEavEntityData(); + generateDataPatchFile(eavEntityDataInterface); + generateExtraFilesAfterDataPatchGeneration(eavEntityDataInterface); + + exit(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java index c47d974df..8433f4993 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java @@ -9,26 +9,43 @@ import com.intellij.psi.PsiDirectory; import com.magento.idea.magento2plugin.actions.generation.data.CustomerEntityData; import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; +import com.magento.idea.magento2plugin.actions.generation.data.SourceModelData; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; -import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeCodeAdapter; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourcePanelComponentListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourceRelationsItemListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.DataPatchNameAdapter; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.EavAttributeInputItemListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.OptionsPanelVisibilityChangeListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.SourceModelNameAdapter; +import com.magento.idea.magento2plugin.actions.generation.dialog.util.eavdialog.AttributeUtil; 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.Lowercase; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; import com.magento.idea.magento2plugin.actions.generation.generator.CustomerEavAttributePatchGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.GetAttributeOptionPropertiesUtil; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; -import com.magento.idea.magento2plugin.magento.packages.uicomponent.AvailableSourcesByInput; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType; +import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; +import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; import java.util.List; +import java.util.Map; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; +import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.JTextField; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -36,9 +53,15 @@ "PMD.TooManyMethods", "PMD.UnusedPrivateField" }) -public class NewCustomerEavAttributeDialog extends EavAttributeDialog { +public class NewCustomerEavAttributeDialog extends AbstractDialog { private static final String ENTITY_NAME = "Customer"; + private String moduleName; + private Project project; + private String actionName; + private TableGroupWrapper entityPropertiesTableGroupWrapper; + private SourceModelData sourceModelData; + private JPanel contentPanel; private JButton buttonOK; private JButton buttonCancel; @@ -55,14 +78,21 @@ public class NewCustomerEavAttributeDialog extends EavAttributeDialog { private JTextField dataPatchNameTextField; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) - @FieldValidation(rule = RuleRegistry.ALPHANUMERIC, - message = {NotEmptyRule.MESSAGE, "Attribute Sort Order"}) private JTextField sortOrderTextField; private JComboBox inputComboBox; private JComboBox typeComboBox; private JComboBox sourceComboBox; private JCheckBox requiredCheckBox; private JCheckBox visibleCheckBox; + private JCheckBox userDefineCheckBox; + private JCheckBox useInGridCheckBox; + private JCheckBox visibleInGridCheckBox; + private JCheckBox filterableInGridCheckBox; + private JCheckBox systemAttributeCheckBox; + private JCheckBox useInAdminhtmlCustomerCheckBox; + private JCheckBox useInAdminhtmlCheckoutCheckBox; + private JCheckBox useInCustomerAccountCreateCheckBox; + private JCheckBox useInCustomerAccountEditCheckBox; private JPanel sourcePanel; private JPanel customSourceModelPanel; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, @@ -74,138 +104,413 @@ public class NewCustomerEavAttributeDialog extends EavAttributeDialog { private JTable optionsTable; private JButton addNewOptionButton; private JPanel optionsPanel; - private JLabel codeTextFieldErrorMessage; private JLabel labelTextFieldErrorMessage; + private JLabel codeTextFieldErrorMessage; private JLabel dataPatchNameTextFieldErrorMessage; private JLabel sourceModelDirectoryTextFieldErrorMessage; private JLabel sourceModelNameTextFieldErrorMessage; private JLabel sortOrderTextFieldErrorMessage; - private JCheckBox userDefineCheckBox; - private JCheckBox useInAdminhtmlCustomerCheckBox; - private JCheckBox useInCustomerAccountCreateCheckBox; - private JCheckBox useInCustomerAccountEditCheckBox; - private JCheckBox useInGridCheckBox; - private JCheckBox filterableInGridCheckBox; - private JCheckBox visibleInGridCheckBox; - private JCheckBox systemAttributeCheckBox; - private JCheckBox useInAdminhtmlCheckoutCheckBox; /** * Constructor. * - * @param project Project - * @param directory PsiDirectory - * @param actionName String + * @param project Project + * @param directory PsiDirectory */ public NewCustomerEavAttributeDialog( final Project project, final PsiDirectory directory, final String actionName ) { - super(project, directory, actionName); + super(project); + + this.project = project; + this.actionName = actionName; + this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); + this.sourceModelData = new SourceModelData(); + + setTitle(actionName); + init(); } - @Override - protected JPanel getDialogPanel() { - return contentPanel; + /** + * Open dialog window. + * + * @param project Project + * @param directory PsiDirectory + * @param actionName String + */ + public static void open( + final Project project, + final PsiDirectory directory, + final String actionName + ) { + final NewCustomerEavAttributeDialog dialog = new NewCustomerEavAttributeDialog( + project, + directory, + actionName + ); + dialog.initDialogState(); + dialog.showDialog(); } - @Override - protected JButton getButtonOk() { - return buttonOK; + /** + * Initialize dialog state. + */ + protected void initDialogState() { + fillAttributeTypeComboBox(); + fillAttributeInputComboBox(); + initPropertiesTable(); + setAttributeInputComboBoxAction(); + setSourceComboBoxAction(); + setSourceModelPanelAction(); + addOptionPanelListener(); + setDefaultSources(); + setAutocompleteListenerForAttributeCodeField(); + setAutocompleteListenerForDataPathNameField(); + setAutocompleteListenerForSourceModelNameField(); } - @Override - protected JButton getButtonCancel() { - return buttonCancel; + /** + * Fill attribute type combo box. + */ + protected void fillAttributeTypeComboBox() { + if (typeComboBox == null) { + return; + } + + for (final AttributeType typeValue : AttributeType.values()) { + typeComboBox.addItem( + new ComboBoxItemData(typeValue.getType(), typeValue.getType()) + ); + } } - @Override - protected JComboBox getAttributeTypeCompoBox() { - return typeComboBox; + /** + * Fill attribute input combo box. + */ + protected void fillAttributeInputComboBox() { + if (inputComboBox == null) { + return; + } + + for (final AttributeInput inputValue : AttributeInput.values()) { + inputComboBox.addItem( + new ComboBoxItemData(inputValue.getInput(), inputValue.getInput()) + ); + } } - @Override - protected JComboBox getAttributeInputComboBox() { - return inputComboBox; + /** + * Initialize properties table. + */ + protected void initPropertiesTable() { + // Initialize entity properties Table Group + entityPropertiesTableGroupWrapper = new TableGroupWrapper( + optionsTable, + addNewOptionButton, + new LinkedList<>(Arrays.asList( + "Value", + "Sort Order" + )), + getDefaultColumnsValues(), + getColumnsSources() + ); + entityPropertiesTableGroupWrapper.initTableGroup(); } - @Override - protected JTable getOptionsTable() { - return optionsTable; + /** + * Get default columns values. + * + * @return Map + */ + protected Map getDefaultColumnsValues() { + return new HashMap<>(); } - @Override - protected JButton getNewOptionButton() { - return addNewOptionButton; + /** + * Get columns sources. + * + * @return Map> + */ + protected Map> getColumnsSources() { + return new HashMap<>(); } - @Override - protected JComboBox getAttributeSourceComboBox() { - return sourceComboBox; + /** + * Set attribute input combo box action. + */ + protected void setAttributeInputComboBoxAction() { + if (sourceComboBox == null || inputComboBox == null) { + return; + } + + inputComboBox.addItemListener( + new EavAttributeInputItemListener(sourceComboBox) + ); } - @Override - protected JTextField getAttributeSourceModelNameTexField() { - return sourceModelNameTextField; + /** + * Set source combo box action. + */ + protected void setSourceComboBoxAction() { + if (sourceComboBox == null) { + return; + } + + sourceComboBox.addItemListener( + new AttributeSourceRelationsItemListener(customSourceModelPanel) + ); } - @Override - protected JTextField getSourceModelDirectoryTextField() { - return sourceModelDirectoryTextField; + /** + * Set source model panel action. + */ + protected void setSourceModelPanelAction() { + if (customSourceModelPanel == null || sourceModelDirectoryTextField == null) { + return; + } + + customSourceModelPanel.addComponentListener( + new AttributeSourcePanelComponentListener(sourceModelDirectoryTextField) + ); } - @Override - protected JPanel getAttributeCustomSourceModelPanel() { - return customSourceModelPanel; + /** + * Add option panel listener. + */ + protected void addOptionPanelListener() { + if (sourceComboBox == null + || inputComboBox == null + || optionsPanel == null + ) { + return; + } + + sourceComboBox.addItemListener( + new OptionsPanelVisibilityChangeListener( + optionsPanel, + inputComboBox + ) + ); } - @Override - protected JPanel getAttributeOptionsPanel() { - return optionsPanel; + /** + * Set default sources. + */ + protected void setDefaultSources() { + if (sourceComboBox == null) { + return; + } + + final ComboBoxItemData generateSourceItem = new ComboBoxItemData( + AttributeSourceModel.GENERATE_SOURCE.getSource(), + AttributeSourceModel.GENERATE_SOURCE.getSource() + ); + final ComboBoxItemData defaultSourceItem = new ComboBoxItemData( + AttributeSourceModel.NULLABLE_SOURCE.name(), + AttributeSourceModel.NULLABLE_SOURCE.getSource() + ); + + sourceComboBox.addItem(defaultSourceItem); + sourceComboBox.addItem(generateSourceItem); + + sourceComboBox.setSelectedItem(defaultSourceItem); } - @Override - protected JTextField getAttributeCodeTextField() { - return codeTextField; + /** + * Set autocomplete listener for attribute code field. + */ + protected void setAutocompleteListenerForAttributeCodeField() { + if (labelTextField == null || codeTextField == null) { + return; + } + + labelTextField.getDocument() + .addDocumentListener(new AttributeCodeAdapter(codeTextField)); } - @Override - protected JTextField getDataPatchNameTextField() { - return dataPatchNameTextField; + /** + * Set autocomplete listener for data path name field. + */ + protected void setAutocompleteListenerForDataPathNameField() { + if (codeTextField == null || dataPatchNameTextField == null) { + return; + } + + codeTextField.getDocument() + .addDocumentListener(new DataPatchNameAdapter(dataPatchNameTextField, getEntityName())); } - @Override - protected JTextField getSourceModelNameTextField() { - return sourceModelNameTextField; + /** + * Set autocomplete listener for source model name field. + */ + protected void setAutocompleteListenerForSourceModelNameField() { + if (codeTextField == null || sourceModelNameTextField == null) { + return; + } + + codeTextField.getDocument() + .addDocumentListener(new SourceModelNameAdapter(sourceModelNameTextField)); } - @Override - protected JTextField getAttributeLabelTexField() { - return labelTextField; + /** + * Get data patch name. + * + * @return String + */ + protected String getDataPatchName() { + return dataPatchNameTextField == null + ? "" : dataPatchNameTextField.getText().trim(); } - @Override - protected JTextField getAttributeSortOrderTextField() { - return sortOrderTextField; + /** + * Get attribute code. + * + * @return String + */ + protected String getAttributeCode() { + return codeTextField == null + ? "" : codeTextField.getText().trim(); } - @Override - protected JCheckBox getAttributeRequiredCheckBox() { - return requiredCheckBox; + /** + * Get attribute label. + * + * @return String + */ + protected String getAttributeLabel() { + return labelTextField == null + ? "" : labelTextField.getText().trim(); } - @Override - protected JCheckBox getAttributeVisibleBox() { - return visibleCheckBox; + /** + * Get attribute sort order. + * + * @return int + */ + protected int getAttributeSortOrder() { + return sortOrderTextField == null + ? 0 : Integer.parseInt(sortOrderTextField.getText().trim()); } - @Override - protected String getEntityName() { - return ENTITY_NAME; + /** + * Is required attribute. + * + * @return boolean + */ + protected boolean isRequiredAttribute() { + return requiredCheckBox != null && requiredCheckBox.isSelected(); } - @Override + /** + * Is visible attribute. + * + * @return boolean + */ + protected boolean isVisibleAttribute() { + return visibleCheckBox != null && visibleCheckBox.isSelected(); + } + + /** + * Get attribute backend type. + * + * @return String + */ + protected String getAttributeBackendType() { + return AttributeUtil.getBackendTypeBySelectedItem( + (ComboBoxItemData) typeComboBox.getSelectedItem() + ); + } + + /** + * Get attribute input. + * + * @return String + */ + protected String getAttributeInput() { + return AttributeUtil.getInputTypeBySelectedItem( + (ComboBoxItemData) inputComboBox.getSelectedItem() + ); + } + + /** + * Get attribute source. + * + * @param sourceModelData SourceModelData + * @return String + */ + protected String getAttributeSource(final SourceModelData sourceModelData) { + return AttributeUtil.getSourceClassBySelectedItem( + (ComboBoxItemData) sourceComboBox.getSelectedItem(), + sourceModelData + ); + } + + /** + * Get attribute options. + * + * @param entityPropertiesTableGroupWrapper TableGroupWrapper + * @return Map + */ + protected Map getAttributeOptions( + final TableGroupWrapper entityPropertiesTableGroupWrapper + ) { + return GetAttributeOptionPropertiesUtil.getValues( + entityPropertiesTableGroupWrapper.getColumnsData() + ); + } + + /** + * Get attribute options sort orders. + * + * @param entityPropertiesTableGroupWrapper TableGroupWrapper + * @return Map + */ + protected Map getAttributeOptionsSortOrders( + final TableGroupWrapper entityPropertiesTableGroupWrapper + ) { + return GetAttributeOptionPropertiesUtil.getSortOrders( + entityPropertiesTableGroupWrapper.getColumnsData() + ); + } + + /** + * Stop options table editing. + */ + private void stopOptionsTableEditing() { + if (optionsTable != null && optionsTable.isEditing()) { + optionsTable.getCellEditor().stopCellEditing(); + } + } + + /** + * Generate source model file. + */ + protected void generateSourceModelFile() { + final ComboBoxItemData selectedSource = + (ComboBoxItemData) sourceComboBox.getSelectedItem(); + + if (selectedSource == null + || !selectedSource.getText().equals( + AttributeSourceModel.GENERATE_SOURCE.getSource() + )) { + return; + } + + sourceModelData.setModuleName(moduleName); + sourceModelData.setClassName(sourceModelNameTextField.getText().trim()); + sourceModelData.setDirectory(sourceModelDirectoryTextField.getText().trim()); + + new SourceModelGenerator(sourceModelData, project, true) + .generate(actionName, false); + } + + /** + * Generate data patch file. + * + * @param eavEntityDataInterface EavEntityDataInterface + */ protected void generateDataPatchFile(final EavEntityDataInterface eavEntityDataInterface) { new CustomerEavAttributePatchGenerator( eavEntityDataInterface, @@ -214,22 +519,67 @@ protected void generateDataPatchFile(final EavEntityDataInterface eavEntityDataI ).generate(actionName, true); } + /** + * Generate extra files before data patch generation. + */ + protected void generateExtraFilesBeforeDataPatchGeneration() { + generateSourceModelFile(); + } + + /** + * Generate extra files after data patch generation. + * + * @param eavEntityDataInterface EavEntityDataInterface + */ + protected void generateExtraFilesAfterDataPatchGeneration( + final EavEntityDataInterface eavEntityDataInterface + ) {} + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable @Override + protected JComponent createCenterPanel() { + return contentPanel; + } + + /** + * Get entity name. + * + * @return String + */ + protected String getEntityName() { + return ENTITY_NAME; + } + + /** + * Get EAV entity data. + * + * @return EavEntityDataInterface + */ protected EavEntityDataInterface getEavEntityData() { - return populateCategoryEntityData(new CustomerEntityData()); + return populateCustomerEntityData(new CustomerEntityData()); } - private CustomerEntityData populateCategoryEntityData( - final CustomerEntityData customerEntityData - ) { + /** + * Populate customer entity data. + * + * @param customerEntityData CustomerEntityData + * @return CustomerEntityData + */ + private CustomerEntityData populateCustomerEntityData(final CustomerEntityData customerEntityData) { customerEntityData.setModuleName(moduleName); - customerEntityData.setType(getAttributeBackendType()); + customerEntityData.setDataPatchName(getDataPatchName()); customerEntityData.setCode(getAttributeCode()); customerEntityData.setLabel(getAttributeLabel()); customerEntityData.setSortOrder(getAttributeSortOrder()); customerEntityData.setRequired(isRequiredAttribute()); customerEntityData.setVisible(isVisibleAttribute()); + customerEntityData.setType(getAttributeBackendType()); customerEntityData.setInput(getAttributeInput()); customerEntityData.setSource(getAttributeSource(sourceModelData)); customerEntityData.setOptions( @@ -239,100 +589,29 @@ private CustomerEntityData populateCategoryEntityData( getAttributeOptionsSortOrders(entityPropertiesTableGroupWrapper) ); customerEntityData.setUserDefined(userDefineCheckBox.isSelected()); - customerEntityData.setUseInAdminhtmlCustomerForm( - useInAdminhtmlCustomerCheckBox.isSelected() - ); - customerEntityData.setUseInAdminhtmlCheckoutForm( - useInAdminhtmlCheckoutCheckBox.isSelected() - ); - customerEntityData.setUseInCustomerAccountCreateForm( - useInCustomerAccountCreateCheckBox.isSelected() - ); - customerEntityData.setUseInCustomerAccountEditForm( - useInCustomerAccountEditCheckBox.isSelected() - ); - customerEntityData.setVisibleInGrid(visibleInGridCheckBox.isSelected()); customerEntityData.setUsedInGrid(useInGridCheckBox.isSelected()); + customerEntityData.setVisibleInGrid(visibleInGridCheckBox.isSelected()); customerEntityData.setFilterableInGrid(filterableInGridCheckBox.isSelected()); customerEntityData.setSystem(systemAttributeCheckBox.isSelected()); + customerEntityData.setUseInAdminhtmlCustomerForm(useInAdminhtmlCustomerCheckBox.isSelected()); + customerEntityData.setUseInAdminhtmlCheckoutForm(useInAdminhtmlCheckoutCheckBox.isSelected()); + customerEntityData.setUseInCustomerAccountCreateForm(useInCustomerAccountCreateCheckBox.isSelected()); + customerEntityData.setUseInCustomerAccountEditForm(useInCustomerAccountEditCheckBox.isSelected()); return customerEntityData; } + /** + * On write action OK. + */ @Override - protected void addOptionPanelListener( - final JComboBox attributeSourceComboBox, - final JComboBox attributeInputComboBox, - final JPanel attributeOptionsPanel - ) { - if (attributeSourceComboBox == null - || attributeInputComboBox == null - || attributeOptionsPanel == null - ) { - return; - } - - attributeSourceComboBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(final ItemEvent itemEvent) { - final ComboBoxItemData selectedInputItem = - (ComboBoxItemData) attributeInputComboBox.getSelectedItem(); - final String selectedInput = selectedInputItem == null - ? "" : selectedInputItem.toString(); - final boolean isAllowedInput = - AttributeInput.SELECT.getInput().equals(selectedInput) - || AttributeInput.MULTISELECT.getInput().equals(selectedInput); - - attributeOptionsPanel.setVisible(isAllowedInput); - } - }); - } - - @Override - protected void setAttributeInputComboBoxAction( - final JComboBox sourceComboBox, - final JComboBox inputComboBox - ) { - if (sourceComboBox == null || inputComboBox == null) { - return; - } - - inputComboBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(final ItemEvent itemEvent) { - final String selectedInput = itemEvent.getItem().toString(); - - final List availableSources = - new AvailableSourcesByInput(selectedInput).getItems(); - sourceComboBox.removeAllItems(); - - if (!selectedInput.equals(AttributeInput.SELECT.getInput()) - || !selectedInput.equals(AttributeInput.MULTISELECT.getInput())) { - final ComboBoxItemData defaultSourceItem = new ComboBoxItemData( - AttributeSourceModel.NULLABLE_SOURCE.name(), - AttributeSourceModel.NULLABLE_SOURCE.getSource() - ); - - sourceComboBox.addItem(defaultSourceItem); - sourceComboBox.setSelectedItem(defaultSourceItem); - } - - if (availableSources.isEmpty()) { - return; - } - - for (final ComboBoxItemData comboBoxItemData : availableSources) { - sourceComboBox.addItem(comboBoxItemData); - - if (comboBoxItemData.getText().equals(AttributeSourceModel.TABLE.getSource())) { - sourceComboBox.setSelectedItem(comboBoxItemData); - } - } - } - }); - } - - private void createUIComponents() { //NOPMD - suppressed UnusedPrivateMethod - // TODO: place custom component creation code here + protected void onWriteActionOK() { + stopOptionsTableEditing(); + generateExtraFilesBeforeDataPatchGeneration(); + final EavEntityDataInterface eavEntityDataInterface = getEavEntityData(); + generateDataPatchFile(eavEntityDataInterface); + generateExtraFilesAfterDataPatchGeneration(eavEntityDataInterface); + + exit(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java index 42d3ead74..20a29dfed 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java @@ -9,27 +9,48 @@ import com.intellij.psi.PsiDirectory; import com.magento.idea.magento2plugin.actions.generation.data.EavEntityDataInterface; import com.magento.idea.magento2plugin.actions.generation.data.ProductEntityData; +import com.magento.idea.magento2plugin.actions.generation.data.SourceModelData; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; -import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.ApplyToVisibleListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeCodeAdapter; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourcePanelComponentListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.AttributeSourceRelationsItemListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.DataPatchNameAdapter; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.EavAttributeInputItemListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.OptionsPanelVisibilityChangeListener; +import com.magento.idea.magento2plugin.actions.generation.dialog.event.eavdialog.SourceModelNameAdapter; import com.magento.idea.magento2plugin.actions.generation.dialog.util.eavdialog.AttributeUtil; 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.CommaSeparatedStringRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.Lowercase; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; +import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.GetAttributeOptionPropertiesUtil; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; +import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType; +import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; +import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; import com.magento.idea.magento2plugin.util.magento.GetProductTypesListUtil; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; import java.util.List; +import java.util.Map; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; +import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.JTextField; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -37,9 +58,15 @@ "PMD.TooManyMethods", "PMD.UnusedPrivateField" }) -public class NewProductEavAttributeDialog extends EavAttributeDialog { +public class NewProductEavAttributeDialog extends AbstractDialog { private static final String ENTITY_NAME = "Product"; + private String moduleName; + private Project project; + private String actionName; + private TableGroupWrapper entityPropertiesTableGroupWrapper; + private SourceModelData sourceModelData; + private JPanel contentPanel; private JButton buttonOK; private JButton buttonCancel; @@ -108,17 +135,251 @@ public NewProductEavAttributeDialog( final PsiDirectory directory, final String actionName ) { - super(project, directory, actionName); + super(project); + + this.project = project; + this.actionName = actionName; + this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); + this.sourceModelData = new SourceModelData(); + + setTitle(actionName); + init(); } - @Override - protected void initBaseDialogState() { - super.initBaseDialogState(); + /** + * Open dialog window. + * + * @param project Project + * @param directory PsiDirectory + * @param actionName String + */ + public static void open( + final Project project, + final PsiDirectory directory, + final String actionName + ) { + final NewProductEavAttributeDialog dialog = new NewProductEavAttributeDialog( + project, + directory, + actionName + ); + dialog.initDialogState(); + dialog.showDialog(); + } + + /** + * Create UI Components. + */ + private void createUIComponents() { + // Initialize UI components + } + + /** + * Initialize dialog state. + */ + protected void initDialogState() { + fillAttributeTypeComboBox(); + fillAttributeInputComboBox(); + initPropertiesTable(); + setAttributeInputComboBoxAction(); + setSourceComboBoxAction(); + setSourceModelPanelAction(); + addOptionPanelListener(); + setDefaultSources(); + setAutocompleteListenerForAttributeCodeField(); + setAutocompleteListenerForDataPathNameField(); + setAutocompleteListenerForSourceModelNameField(); fillAttributeScopeComboBoxes(); addApplyToVisibilityAction(); fillProductsTypesList(); } + /** + * Fill attribute type combo box. + */ + protected void fillAttributeTypeComboBox() { + if (typeComboBox == null) { + return; + } + + for (final AttributeType typeValue : AttributeType.values()) { + typeComboBox.addItem( + new ComboBoxItemData(typeValue.getType(), typeValue.getType()) + ); + } + } + + /** + * Fill attribute input combo box. + */ + protected void fillAttributeInputComboBox() { + if (inputComboBox == null) { + return; + } + + for (final AttributeInput inputValue : AttributeInput.values()) { + inputComboBox.addItem( + new ComboBoxItemData(inputValue.getInput(), inputValue.getInput()) + ); + } + } + + /** + * Initialize properties table. + */ + protected void initPropertiesTable() { + // Initialize entity properties Table Group + entityPropertiesTableGroupWrapper = new TableGroupWrapper( + optionsTable, + addNewOptionButton, + new LinkedList<>(Arrays.asList( + "Value", + "Sort Order" + )), + getDefaultColumnsValues(), + getColumnsSources() + ); + entityPropertiesTableGroupWrapper.initTableGroup(); + } + + /** + * Get default columns values. + * + * @return Map + */ + protected Map getDefaultColumnsValues() { + return new HashMap<>(); + } + + /** + * Get columns sources. + * + * @return Map> + */ + protected Map> getColumnsSources() { + return new HashMap<>(); + } + + /** + * Set attribute input combo box action. + */ + protected void setAttributeInputComboBoxAction() { + if (sourceComboBox == null || inputComboBox == null) { + return; + } + + inputComboBox.addItemListener( + new EavAttributeInputItemListener(sourceComboBox) + ); + } + + /** + * Set source combo box action. + */ + protected void setSourceComboBoxAction() { + if (sourceComboBox == null) { + return; + } + + sourceComboBox.addItemListener( + new AttributeSourceRelationsItemListener(customSourceModelPanel) + ); + } + + /** + * Set source model panel action. + */ + protected void setSourceModelPanelAction() { + if (customSourceModelPanel == null || sourceModelDirectoryTextField == null) { + return; + } + + customSourceModelPanel.addComponentListener( + new AttributeSourcePanelComponentListener(sourceModelDirectoryTextField) + ); + } + + /** + * Add option panel listener. + */ + protected void addOptionPanelListener() { + if (sourceComboBox == null + || inputComboBox == null + || optionsPanel == null + ) { + return; + } + + sourceComboBox.addItemListener( + new OptionsPanelVisibilityChangeListener( + optionsPanel, + inputComboBox + ) + ); + } + + /** + * Set default sources. + */ + protected void setDefaultSources() { + if (sourceComboBox == null) { + return; + } + + final ComboBoxItemData generateSourceItem = new ComboBoxItemData( + AttributeSourceModel.GENERATE_SOURCE.getSource(), + AttributeSourceModel.GENERATE_SOURCE.getSource() + ); + final ComboBoxItemData defaultSourceItem = new ComboBoxItemData( + AttributeSourceModel.NULLABLE_SOURCE.name(), + AttributeSourceModel.NULLABLE_SOURCE.getSource() + ); + + sourceComboBox.addItem(defaultSourceItem); + sourceComboBox.addItem(generateSourceItem); + + sourceComboBox.setSelectedItem(defaultSourceItem); + } + + /** + * Set autocomplete listener for attribute code field. + */ + protected void setAutocompleteListenerForAttributeCodeField() { + if (labelTextField == null || codeTextField == null) { + return; + } + + labelTextField.getDocument() + .addDocumentListener(new AttributeCodeAdapter(codeTextField)); + } + + /** + * Set autocomplete listener for data path name field. + */ + protected void setAutocompleteListenerForDataPathNameField() { + if (codeTextField == null || dataPatchNameTextField == null) { + return; + } + + codeTextField.getDocument() + .addDocumentListener(new DataPatchNameAdapter(dataPatchNameTextField, getEntityName())); + } + + /** + * Set autocomplete listener for source model name field. + */ + protected void setAutocompleteListenerForSourceModelNameField() { + if (codeTextField == null || sourceModelNameTextField == null) { + return; + } + + codeTextField.getDocument() + .addDocumentListener(new SourceModelNameAdapter(sourceModelNameTextField)); + } + + /** + * Fill attribute scope combo boxes. + */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") protected void fillAttributeScopeComboBoxes() { for (final AttributeScope globalValue : AttributeScope.values()) { @@ -128,111 +389,241 @@ protected void fillAttributeScopeComboBoxes() { } } - @Override - protected JPanel getDialogPanel() { - return contentPanel; + /** + * Add apply to visibility action. + */ + protected void addApplyToVisibilityAction() { + applyToAllProductsCheckBox.addChangeListener(new ApplyToVisibleListener(applyToPanel)); } - @Override - protected JButton getButtonOk() { - return buttonOK; - } + /** + * Fill products types list. + */ + private void fillProductsTypesList() { + final List productTypes = GetProductTypesListUtil.execute(project); - @Override - protected JButton getButtonCancel() { - return buttonCancel; + final DefaultListModel listModel = new DefaultListModel<>(); + listModel.addAll(productTypes); + productsTypesList.setModel(listModel); + productsTypesList.setSelectedIndex(0); } - @Override - protected JComboBox getAttributeTypeCompoBox() { - return typeComboBox; + /** + * Get data patch name. + * + * @return String + */ + protected String getDataPatchName() { + return dataPatchNameTextField == null + ? "" : dataPatchNameTextField.getText().trim(); } - @Override - protected JComboBox getAttributeInputComboBox() { - return inputComboBox; + /** + * Get attribute code. + * + * @return String + */ + protected String getAttributeCode() { + return codeTextField == null + ? "" : codeTextField.getText().trim(); } - @Override - protected JTable getOptionsTable() { - return optionsTable; + /** + * Get attribute label. + * + * @return String + */ + protected String getAttributeLabel() { + return labelTextField == null + ? "" : labelTextField.getText().trim(); } - @Override - protected JButton getNewOptionButton() { - return addNewOptionButton; + /** + * Get attribute sort order. + * + * @return int + */ + protected int getAttributeSortOrder() { + return sortOrderTextField == null + ? 0 : Integer.parseInt(sortOrderTextField.getText().trim()); } - @Override - protected JComboBox getAttributeSourceComboBox() { - return sourceComboBox; + /** + * Is required attribute. + * + * @return boolean + */ + protected boolean isRequiredAttribute() { + return requiredCheckBox != null && requiredCheckBox.isSelected(); } - @Override - protected JTextField getAttributeSourceModelNameTexField() { - return sourceModelNameTextField; + /** + * Is visible attribute. + * + * @return boolean + */ + protected boolean isVisibleAttribute() { + return visibleCheckBox != null && visibleCheckBox.isSelected(); } - @Override - protected JTextField getSourceModelDirectoryTextField() { - return sourceModelDirectoryTextField; + /** + * Get attribute backend type. + * + * @return String + */ + protected String getAttributeBackendType() { + return AttributeUtil.getBackendTypeBySelectedItem( + (ComboBoxItemData) typeComboBox.getSelectedItem() + ); } - @Override - protected JPanel getAttributeCustomSourceModelPanel() { - return customSourceModelPanel; + /** + * Get attribute input. + * + * @return String + */ + protected String getAttributeInput() { + return AttributeUtil.getInputTypeBySelectedItem( + (ComboBoxItemData) inputComboBox.getSelectedItem() + ); } - @Override - protected JPanel getAttributeOptionsPanel() { - return optionsPanel; + /** + * Get attribute source. + * + * @param sourceModelData SourceModelData + * @return String + */ + protected String getAttributeSource(final SourceModelData sourceModelData) { + return AttributeUtil.getSourceClassBySelectedItem( + (ComboBoxItemData) sourceComboBox.getSelectedItem(), + sourceModelData + ); } - @Override - protected JTextField getAttributeCodeTextField() { - return codeTextField; + /** + * Get attribute options. + * + * @param entityPropertiesTableGroupWrapper TableGroupWrapper + * @return Map + */ + protected Map getAttributeOptions( + final TableGroupWrapper entityPropertiesTableGroupWrapper + ) { + return GetAttributeOptionPropertiesUtil.getValues( + entityPropertiesTableGroupWrapper.getColumnsData() + ); } - @Override - protected JTextField getDataPatchNameTextField() { - return dataPatchNameTextField; + /** + * Get attribute options sort orders. + * + * @param entityPropertiesTableGroupWrapper TableGroupWrapper + * @return Map + */ + protected Map getAttributeOptionsSortOrders( + final TableGroupWrapper entityPropertiesTableGroupWrapper + ) { + return GetAttributeOptionPropertiesUtil.getSortOrders( + entityPropertiesTableGroupWrapper.getColumnsData() + ); } - @Override - protected JTextField getSourceModelNameTextField() { - return sourceModelNameTextField; + /** + * Stop options table editing. + */ + private void stopOptionsTableEditing() { + if (optionsTable != null && optionsTable.isEditing()) { + optionsTable.getCellEditor().stopCellEditing(); + } } - @Override - protected JTextField getAttributeLabelTexField() { - return labelTextField; + /** + * Generate source model file. + */ + protected void generateSourceModelFile() { + final ComboBoxItemData selectedSource = + (ComboBoxItemData) sourceComboBox.getSelectedItem(); + + if (selectedSource == null + || !selectedSource.getText().equals( + AttributeSourceModel.GENERATE_SOURCE.getSource() + )) { + return; + } + + sourceModelData.setModuleName(moduleName); + sourceModelData.setClassName(sourceModelNameTextField.getText().trim()); + sourceModelData.setDirectory(sourceModelDirectoryTextField.getText().trim()); + + new SourceModelGenerator(sourceModelData, project, true) + .generate(actionName, false); } - @Override - protected JTextField getAttributeSortOrderTextField() { - return sortOrderTextField; + /** + * Generate data patch file. + * + * @param eavEntityDataInterface EavEntityDataInterface + */ + protected void generateDataPatchFile(final EavEntityDataInterface eavEntityDataInterface) { + new EavAttributeSetupPatchGenerator( + eavEntityDataInterface, + project, + true + ).generate(actionName, true); } - @Override - protected JCheckBox getAttributeRequiredCheckBox() { - return requiredCheckBox; + /** + * Generate extra files before data patch generation. + */ + protected void generateExtraFilesBeforeDataPatchGeneration() { + generateSourceModelFile(); } + /** + * Generate extra files after data patch generation. + * + * @param eavEntityDataInterface EavEntityDataInterface + */ + protected void generateExtraFilesAfterDataPatchGeneration( + final EavEntityDataInterface eavEntityDataInterface + ) {} + + /** + * Create center panel. + * + * @return JComponent + */ + @Nullable @Override - protected JCheckBox getAttributeVisibleBox() { - return visibleCheckBox; + protected JComponent createCenterPanel() { + return contentPanel; } - @Override + /** + * Get entity name. + * + * @return String + */ protected String getEntityName() { return ENTITY_NAME; } - @Override + /** + * Get EAV entity data. + * + * @return EavEntityDataInterface + */ protected EavEntityDataInterface getEavEntityData() { return populateProductEntityData(new ProductEntityData()); } + /** + * Populate product entity data. + * + * @param productEntityData ProductEntityData + * @return ProductEntityData + */ private ProductEntityData populateProductEntityData(final ProductEntityData productEntityData) { productEntityData.setModuleName(moduleName); @@ -272,16 +663,17 @@ private ProductEntityData populateProductEntityData(final ProductEntityData prod return productEntityData; } - protected void addApplyToVisibilityAction() { - applyToAllProductsCheckBox.addChangeListener(new ApplyToVisibleListener(applyToPanel)); - } - - private void fillProductsTypesList() { - final List productTypes = GetProductTypesListUtil.execute(project); - - final DefaultListModel listModel = new DefaultListModel<>(); - listModel.addAll(productTypes); - productsTypesList.setModel(listModel); - productsTypesList.setSelectedIndex(0); + /** + * On write action OK. + */ + @Override + protected void onWriteActionOK() { + stopOptionsTableEditing(); + generateExtraFilesBeforeDataPatchGeneration(); + final EavEntityDataInterface eavEntityDataInterface = getEavEntityData(); + generateDataPatchFile(eavEntityDataInterface); + generateExtraFilesAfterDataPatchGeneration(eavEntityDataInterface); + + exit(); } } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java index 446247f02..decb7ff36 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewCategoryEavAttributeAction.java @@ -5,13 +5,19 @@ package com.magento.idea.magento2plugin.actions.generation.eavattribute; +import com.intellij.ide.IdeView; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; import com.magento.idea.magento2plugin.MagentoIcons; import com.magento.idea.magento2plugin.actions.generation.dialog.NewCategoryEavAttributeDialog; -import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; +import org.jetbrains.annotations.NotNull; -public class NewCategoryEavAttributeAction extends NewEavAttributeAction { +public class NewCategoryEavAttributeAction extends AnAction { public static final String ACTION_NAME = "Category Attribute"; public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Catalog Attribute"; @@ -21,10 +27,27 @@ public NewCategoryEavAttributeAction() { } @Override - protected EavAttributeDialog getDialogWindow( - final Project project, - final PsiDirectory directory - ) { - return new NewCategoryEavAttributeDialog(project, directory, ACTION_NAME); + public void actionPerformed(final @NotNull AnActionEvent event) { + final DataContext dataContext = event.getDataContext(); + final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); + if (view == null) { + return; + } + + final Project project = CommonDataKeys.PROJECT.getData(dataContext); + if (project == null) { + return; + } + + final PsiDirectory directory = view.getOrChooseDirectory(); + if (directory == null) { + return; + } + + NewCategoryEavAttributeDialog.open( + project, + directory, + ACTION_NAME + ); } } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java index 1fa44915c..dd67ed0f1 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/eavattribute/NewProductEavAttributeAction.java @@ -5,13 +5,19 @@ package com.magento.idea.magento2plugin.actions.generation.eavattribute; +import com.intellij.ide.IdeView; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; import com.magento.idea.magento2plugin.MagentoIcons; import com.magento.idea.magento2plugin.actions.generation.dialog.NewProductEavAttributeDialog; -import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog; +import org.jetbrains.annotations.NotNull; -public class NewProductEavAttributeAction extends NewEavAttributeAction { +public class NewProductEavAttributeAction extends AnAction { public static final String ACTION_NAME = "Product Attribute"; public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Product Attribute"; @@ -21,10 +27,27 @@ public NewProductEavAttributeAction() { } @Override - protected EavAttributeDialog getDialogWindow( - final Project project, - final PsiDirectory directory - ) { - return new NewProductEavAttributeDialog(project, directory, ACTION_NAME); + public void actionPerformed(final @NotNull AnActionEvent event) { + final DataContext dataContext = event.getDataContext(); + final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); + if (view == null) { + return; + } + + final Project project = CommonDataKeys.PROJECT.getData(dataContext); + if (project == null) { + return; + } + + final PsiDirectory directory = view.getOrChooseDirectory(); + if (directory == null) { + return; + } + + NewProductEavAttributeDialog.open( + project, + directory, + ACTION_NAME + ); } } From 5921c02e78c7369c8d7b59ff4aba9200d0953e1b Mon Sep 17 00:00:00 2001 From: Vitaliy Boyrko Date: Sat, 24 May 2025 20:24:17 +0300 Subject: [PATCH 06/30] 2080: bumped up version --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- src/main/resources/META-INF/plugin.xml | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbb5bac18..a77bb3025 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). +## 2025.2.0 + ## 2025.1.1 ### Fixed diff --git a/gradle.properties b/gradle.properties index c14a88efe..e35da741d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ pluginGroup = com.magento.idea.magento2plugin pluginName = Magento PhpStorm pluginRepositoryUrl = https://github.com/magento/magento2-phpstorm-plugin -pluginVersion = 2025.1.1 +pluginVersion = 2025.2.0 pluginSinceBuild = 243.3 pluginUntilBuild = 258.* platformType = PS diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 60be06cf8..97948e2ea 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -7,7 +7,7 @@ com.magento.idea.magento2plugin Magento PhpStorm - 2025.1.1 + 2025.2.0 Magento Inc. Date: Mon, 26 May 2025 12:19:17 +0300 Subject: [PATCH 07/30] Code style fixes --- .../dialog/GatherArrayValuesDialog.java | 6 +--- .../dialog/NewArgumentInjectionDialog.java | 6 +--- .../dialog/NewCategoryEavAttributeDialog.java | 18 ++++++---- .../dialog/NewCustomerEavAttributeDialog.java | 35 ++++++++++++------- .../dialog/NewProductEavAttributeDialog.java | 12 ++++--- .../dialog/NewWebApiDeclarationDialog.java | 6 +--- 6 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java index 7197389cd..2016a4389 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java @@ -13,11 +13,7 @@ import com.magento.idea.magento2plugin.bundles.ValidatorBundle; import com.magento.idea.magento2plugin.magento.packages.DiArgumentType; import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; -import org.jetbrains.annotations.Nullable; import java.awt.Color; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -30,9 +26,9 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; -import javax.swing.KeyStroke; import javax.swing.table.DefaultTableModel; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class GatherArrayValuesDialog extends AbstractDialog { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.java index 4e72de3f5..f67fe9cb4 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.java @@ -36,9 +36,6 @@ import com.magento.idea.magento2plugin.ui.FilteredComboBox; import com.magento.idea.magento2plugin.util.php.PhpTypeMetadataParserUtil; import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -51,7 +48,6 @@ import javax.swing.JRadioButton; import javax.swing.JTextArea; import javax.swing.JTextField; -import javax.swing.KeyStroke; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -353,7 +349,7 @@ protected JComponent createCenterPanel() { * Fire generation process if all fields are valid. */ protected void onWriteActionOK() { - final DiArgumentData data = getDialogDataObject(); + final DiArgumentData data = getDialogDataObject(); if (data == null) { return; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java index 9c886d92e..28781dbb5 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java @@ -219,7 +219,7 @@ protected void initPropertiesTable() { /** * Get default columns values. * - * @return Map + * @return Map of String to String */ protected Map getDefaultColumnsValues() { return new HashMap<>(); @@ -228,7 +228,7 @@ protected Map getDefaultColumnsValues() { /** * Get columns sources. * - * @return Map> + * @return Map of String to List of String */ protected Map> getColumnsSources() { return new HashMap<>(); @@ -336,7 +336,9 @@ protected void setAutocompleteListenerForDataPathNameField() { } codeTextField.getDocument() - .addDocumentListener(new DataPatchNameAdapter(dataPatchNameTextField, getEntityName())); + .addDocumentListener( + new DataPatchNameAdapter(dataPatchNameTextField, getEntityName()) + ); } /** @@ -460,7 +462,7 @@ protected String getAttributeSource(final SourceModelData sourceModelData) { * Get attribute options. * * @param entityPropertiesTableGroupWrapper TableGroupWrapper - * @return Map + * @return Map of Integer to String */ protected Map getAttributeOptions( final TableGroupWrapper entityPropertiesTableGroupWrapper @@ -474,7 +476,7 @@ protected Map getAttributeOptions( * Get attribute options sort orders. * * @param entityPropertiesTableGroupWrapper TableGroupWrapper - * @return Map + * @return Map of Integer to String */ protected Map getAttributeOptionsSortOrders( final TableGroupWrapper entityPropertiesTableGroupWrapper @@ -579,7 +581,9 @@ protected EavEntityDataInterface getEavEntityData() { * @param categoryEntityData CategoryEntityData * @return CategoryEntityData */ - private CategoryEntityData populateCategoryEntityData(final CategoryEntityData categoryEntityData) { + private CategoryEntityData populateCategoryEntityData( + final CategoryEntityData categoryEntityData + ) { categoryEntityData.setModuleName(moduleName); categoryEntityData.setDataPatchName(getDataPatchName()); @@ -620,4 +624,4 @@ protected void onWriteActionOK() { exit(); } -} \ No newline at end of file +} diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java index 8433f4993..0100a553b 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java @@ -27,7 +27,6 @@ import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.util.GetAttributeOptionPropertiesUtil; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput; -import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel; import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType; import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; @@ -222,7 +221,7 @@ protected void initPropertiesTable() { /** * Get default columns values. * - * @return Map + * @return Map of String to String */ protected Map getDefaultColumnsValues() { return new HashMap<>(); @@ -231,7 +230,7 @@ protected Map getDefaultColumnsValues() { /** * Get columns sources. * - * @return Map> + * @return Map of String to List of String */ protected Map> getColumnsSources() { return new HashMap<>(); @@ -339,7 +338,9 @@ protected void setAutocompleteListenerForDataPathNameField() { } codeTextField.getDocument() - .addDocumentListener(new DataPatchNameAdapter(dataPatchNameTextField, getEntityName())); + .addDocumentListener( + new DataPatchNameAdapter(dataPatchNameTextField, getEntityName()) + ); } /** @@ -451,7 +452,7 @@ protected String getAttributeSource(final SourceModelData sourceModelData) { * Get attribute options. * * @param entityPropertiesTableGroupWrapper TableGroupWrapper - * @return Map + * @return Map of Integer to String */ protected Map getAttributeOptions( final TableGroupWrapper entityPropertiesTableGroupWrapper @@ -465,7 +466,7 @@ protected Map getAttributeOptions( * Get attribute options sort orders. * * @param entityPropertiesTableGroupWrapper TableGroupWrapper - * @return Map + * @return Map of Integer to String */ protected Map getAttributeOptionsSortOrders( final TableGroupWrapper entityPropertiesTableGroupWrapper @@ -570,7 +571,9 @@ protected EavEntityDataInterface getEavEntityData() { * @param customerEntityData CustomerEntityData * @return CustomerEntityData */ - private CustomerEntityData populateCustomerEntityData(final CustomerEntityData customerEntityData) { + private CustomerEntityData populateCustomerEntityData( + final CustomerEntityData customerEntityData + ) { customerEntityData.setModuleName(moduleName); customerEntityData.setDataPatchName(getDataPatchName()); @@ -593,10 +596,18 @@ private CustomerEntityData populateCustomerEntityData(final CustomerEntityData c customerEntityData.setVisibleInGrid(visibleInGridCheckBox.isSelected()); customerEntityData.setFilterableInGrid(filterableInGridCheckBox.isSelected()); customerEntityData.setSystem(systemAttributeCheckBox.isSelected()); - customerEntityData.setUseInAdminhtmlCustomerForm(useInAdminhtmlCustomerCheckBox.isSelected()); - customerEntityData.setUseInAdminhtmlCheckoutForm(useInAdminhtmlCheckoutCheckBox.isSelected()); - customerEntityData.setUseInCustomerAccountCreateForm(useInCustomerAccountCreateCheckBox.isSelected()); - customerEntityData.setUseInCustomerAccountEditForm(useInCustomerAccountEditCheckBox.isSelected()); + customerEntityData.setUseInAdminhtmlCustomerForm( + useInAdminhtmlCustomerCheckBox.isSelected() + ); + customerEntityData.setUseInAdminhtmlCheckoutForm( + useInAdminhtmlCheckoutCheckBox.isSelected() + ); + customerEntityData.setUseInCustomerAccountCreateForm( + useInCustomerAccountCreateCheckBox.isSelected() + ); + customerEntityData.setUseInCustomerAccountEditForm( + useInCustomerAccountEditCheckBox.isSelected() + ); return customerEntityData; } @@ -614,4 +625,4 @@ protected void onWriteActionOK() { exit(); } -} \ No newline at end of file +} diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java index 20a29dfed..7a9cf05f5 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java @@ -245,7 +245,7 @@ protected void initPropertiesTable() { /** * Get default columns values. * - * @return Map + * @return Map of String to String */ protected Map getDefaultColumnsValues() { return new HashMap<>(); @@ -254,7 +254,7 @@ protected Map getDefaultColumnsValues() { /** * Get columns sources. * - * @return Map> + * @return Map of String to List of String */ protected Map> getColumnsSources() { return new HashMap<>(); @@ -362,7 +362,9 @@ protected void setAutocompleteListenerForDataPathNameField() { } codeTextField.getDocument() - .addDocumentListener(new DataPatchNameAdapter(dataPatchNameTextField, getEntityName())); + .addDocumentListener( + new DataPatchNameAdapter(dataPatchNameTextField, getEntityName()) + ); } /** @@ -505,7 +507,7 @@ protected String getAttributeSource(final SourceModelData sourceModelData) { * Get attribute options. * * @param entityPropertiesTableGroupWrapper TableGroupWrapper - * @return Map + * @return Map of Integer to String */ protected Map getAttributeOptions( final TableGroupWrapper entityPropertiesTableGroupWrapper @@ -519,7 +521,7 @@ protected Map getAttributeOptions( * Get attribute options sort orders. * * @param entityPropertiesTableGroupWrapper TableGroupWrapper - * @return Map + * @return Map of Integer to String */ protected Map getAttributeOptionsSortOrders( final TableGroupWrapper entityPropertiesTableGroupWrapper diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java index 9e00e6a2e..a50424f1c 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java @@ -20,10 +20,6 @@ import com.magento.idea.magento2plugin.magento.packages.WebApiResource; import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import org.jetbrains.annotations.Nullable; -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; @@ -31,8 +27,8 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings("PMD.TooManyFields") public class NewWebApiDeclarationDialog extends AbstractDialog { From 01a3f3cc8569d0ba0b883a5a022e87a0ce297b14 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Mon, 26 May 2025 17:57:36 +0300 Subject: [PATCH 08/30] 2880: Refactor code formatting for improved readability Reorganized line breaks in multiple dialog classes to enhance code clarity and maintain consistency. No functional changes were introduced, ensuring behavior remains unchanged. --- .../generation/dialog/AbstractDialog.java | 3 ++- .../dialog/NewCategoryEavAttributeDialog.java | 5 ++++- .../dialog/NewCustomerEavAttributeDialog.java | 17 +++++++++++++---- .../dialog/NewProductEavAttributeDialog.java | 5 ++++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java index 6d9919ef2..8a3928ded 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java @@ -70,7 +70,8 @@ public AbstractDialog() { /** * Center the dialog on the screen. - * Note: This is handled automatically by DialogWrapper, so this method is kept for compatibility. + * Note: This is handled automatically by DialogWrapper, + * so this method is kept for compatibility. * * @param dialog AbstractDialog */ diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java index 28781dbb5..df42d29b4 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java @@ -337,7 +337,10 @@ protected void setAutocompleteListenerForDataPathNameField() { codeTextField.getDocument() .addDocumentListener( - new DataPatchNameAdapter(dataPatchNameTextField, getEntityName()) + new DataPatchNameAdapter( + dataPatchNameTextField, + getEntityName() + ) ); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java index 0100a553b..2eaed9152 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java @@ -339,7 +339,10 @@ protected void setAutocompleteListenerForDataPathNameField() { codeTextField.getDocument() .addDocumentListener( - new DataPatchNameAdapter(dataPatchNameTextField, getEntityName()) + new DataPatchNameAdapter( + dataPatchNameTextField, + getEntityName() + ) ); } @@ -591,9 +594,15 @@ private CustomerEntityData populateCustomerEntityData( customerEntityData.setOptionsSortOrder( getAttributeOptionsSortOrders(entityPropertiesTableGroupWrapper) ); - customerEntityData.setUserDefined(userDefineCheckBox.isSelected()); - customerEntityData.setUsedInGrid(useInGridCheckBox.isSelected()); - customerEntityData.setVisibleInGrid(visibleInGridCheckBox.isSelected()); + customerEntityData.setUserDefined( + userDefineCheckBox.isSelected() + ); + customerEntityData.setUsedInGrid( + useInGridCheckBox.isSelected() + ); + customerEntityData.setVisibleInGrid( + visibleInGridCheckBox.isSelected() + ); customerEntityData.setFilterableInGrid(filterableInGridCheckBox.isSelected()); customerEntityData.setSystem(systemAttributeCheckBox.isSelected()); customerEntityData.setUseInAdminhtmlCustomerForm( diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java index 7a9cf05f5..80d467c63 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java @@ -363,7 +363,10 @@ protected void setAutocompleteListenerForDataPathNameField() { codeTextField.getDocument() .addDocumentListener( - new DataPatchNameAdapter(dataPatchNameTextField, getEntityName()) + new DataPatchNameAdapter( + dataPatchNameTextField, + getEntityName() + ) ); } From b86cf57e643f872ce5fdfdb06ed5f87e78ec628e Mon Sep 17 00:00:00 2001 From: vitaliy Date: Mon, 26 May 2025 18:44:18 +0300 Subject: [PATCH 09/30] 2880: Remove unused Swing imports and simplify dialog classes Unused Swing-related imports (e.g., JButton, KeyEvent) and redundant code were removed across multiple dialog classes, improving code readability and maintainability. Additionally, some fields were marked as final where applicable and PMD suppressions were updated for better clarity. --- check_modified.sh | 11 +++++++ .../dialog/CreateAnObserverDialog.java | 4 --- .../dialog/GatherArrayValuesDialog.java | 2 -- .../dialog/NewCLICommandDialog.java | 7 ----- .../dialog/NewCategoryEavAttributeDialog.java | 24 +++++++++++---- .../dialog/NewControllerDialog.java | 8 ----- .../dialog/NewEmailTemplateDialog.java | 3 -- .../generation/dialog/NewEntityDialog.java | 30 ------------------- .../generation/dialog/NewModuleDialog.java | 3 -- .../generation/dialog/NewObserverDialog.java | 8 ----- .../dialog/NewUiComponentGridDialog.java | 3 -- .../OverrideClassByAPreferenceDialog.java | 3 -- .../dialog/OverrideLayoutInThemeDialog.java | 5 ---- .../dialog/OverrideTemplateInThemeDialog.java | 8 ----- .../magento2uct/ui/ConfigurationDialog.java | 2 -- .../idea/magento2uct/ui/ReindexDialog.java | 2 -- 16 files changed, 29 insertions(+), 94 deletions(-) create mode 100755 check_modified.sh diff --git a/check_modified.sh b/check_modified.sh new file mode 100755 index 000000000..847e6f789 --- /dev/null +++ b/check_modified.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Get the list of modified files +MODIFIED_FILES=$(git diff --name-only HEAD | grep -E '\.java$' | sed 's/^/"/;s/$/"/' | tr '\n' ',' | sed 's/,$//') +MODIFIED_FILES="[$MODIFIED_FILES]" + +# Export the environment variable +export MODIFIED_FILES + +# Run the checkstyle and PMD tasks +./gradlew checkstyleCI pmdCI \ No newline at end of file diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java index b0679f01f..6f99e0adf 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java @@ -24,9 +24,6 @@ import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.ui.FilteredComboBox; -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; @@ -34,7 +31,6 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java index 2016a4389..4673d2629 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java @@ -40,8 +40,6 @@ public class GatherArrayValuesDialog extends AbstractDialog { private final DiArrayValueData arrayValueData; private JPanel contentPane; - private JButton buttonCancel; - private JButton buttonOK; private JPanel itemsPane;// NOPMD private JScrollPane itemsScrollPane;// NOPMD private JTable itemsTable; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java index 68f43c02d..8551b0460 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java @@ -24,18 +24,13 @@ import com.magento.idea.magento2plugin.util.CamelCaseToSnakeCase; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.Locale; -import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; -import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -48,8 +43,6 @@ public class NewCLICommandDialog extends AbstractDialog { private static final String COMMAND_DESCRIPTION = "description"; private JPanel contentPane; - private JButton buttonCancel; - private JButton buttonOK; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, CLASS_NAME}) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java index df42d29b4..f06f503d4 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java @@ -47,20 +47,26 @@ import javax.swing.JTextField; import org.jetbrains.annotations.Nullable; +/** + * This class handles the creation and configuration of Category EAV attributes. + * Note: This class is flagged as a "God Class" by PMD due to its complexity. + * A proper refactoring into smaller, more focused classes would be a better long-term solution. + */ @SuppressWarnings({ "PMD.TooManyFields", "PMD.ExcessiveImports", "PMD.TooManyMethods", - "PMD.UnusedPrivateField" + "PMD.UnusedPrivateField", + "PMD.GodClass" }) public class NewCategoryEavAttributeDialog extends AbstractDialog { private static final String ENTITY_NAME = "Category"; - private String moduleName; - private Project project; - private String actionName; + private final String moduleName; + private final Project project; + private final String actionName; private TableGroupWrapper entityPropertiesTableGroupWrapper; - private SourceModelData sourceModelData; + private final SourceModelData sourceModelData; private JPanel contentPanel; private JButton buttonOK; @@ -171,6 +177,7 @@ protected void initDialogState() { /** * Fill attribute type combo box. */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") protected void fillAttributeTypeComboBox() { if (typeComboBox == null) { return; @@ -186,6 +193,7 @@ protected void fillAttributeTypeComboBox() { /** * Fill attribute input combo box. */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") protected void fillAttributeInputComboBox() { if (inputComboBox == null) { return; @@ -542,12 +550,16 @@ protected void generateExtraFilesBeforeDataPatchGeneration() { /** * Generate extra files after data patch generation. + * This is a hook method for subclasses to override and generate additional files. + * The base implementation does nothing. * * @param eavEntityDataInterface EavEntityDataInterface */ protected void generateExtraFilesAfterDataPatchGeneration( final EavEntityDataInterface eavEntityDataInterface - ) {} + ) { + // No additional files to generate in the base implementation + } /** * Create center panel. diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java index f32949ea2..bbb91a32c 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java @@ -23,20 +23,14 @@ import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.ui.FilteredComboBox; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.KeyStroke; import org.jetbrains.annotations.Nullable; @SuppressWarnings({ @@ -49,8 +43,6 @@ public class NewControllerDialog extends AbstractDialog { private final String moduleName; private final Project project; private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; private FilteredComboBox controllerAreaSelect; private FilteredComboBox httpMethodSelect; private JCheckBox inheritClass; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java index 6e0d9594a..983033476 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java @@ -22,12 +22,9 @@ import com.magento.idea.magento2plugin.ui.FilteredComboBox; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index a087ee405..3375ba6f7 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -54,12 +54,9 @@ import com.magento.idea.magento2plugin.util.CamelCaseToSnakeCase; import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.Cursor; import java.awt.event.ActionEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; @@ -358,25 +355,6 @@ private void initPropertiesTable() { entityPropertiesTableGroupWrapper.initTableGroup(); } - /** - * Generate new entity files. - * - * @param event ActionEvent - */ - @SuppressWarnings("PMD.UnusedFormalParameter") - private void generateNewEntityFiles(final @NotNull ActionEvent event) { - if (!onOkActionFired.isInProgress()) { - if (propertyTable.isEditing()) { - propertyTable.getCellEditor().stopCellEditing(); - } - - new ProcessWorker( - this::onOK, - this::releaseDialogAfterGeneration, - onOkActionFired - ).execute(); - } - } /** * Perform code generation using input data. @@ -417,14 +395,6 @@ protected boolean validateFormFields() { return true; } - /** - * Release dialog buttons and hide. - */ - private void releaseDialogAfterGeneration() { - if (onOkActionFired.isFinished()) { - exit(); - } - } /** * Get entity creator context data. diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java index 26ff7187f..4b2022abe 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java @@ -32,11 +32,8 @@ import com.magento.idea.magento2plugin.util.magento.MagentoVersionUtil; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.List; import java.util.Vector; -import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JLabel; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java index a8b5b21cd..cea9b1ec3 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java @@ -34,22 +34,16 @@ import com.magento.idea.magento2plugin.stubs.indexes.EventNameIndex; import com.magento.idea.magento2plugin.ui.FilteredComboBox; import com.magento.idea.magento2plugin.util.CamelCaseToSnakeCase; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Locale; -import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.KeyStroke; import javax.swing.event.DocumentEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -69,8 +63,6 @@ public class NewObserverDialog extends AbstractDialog { private final String moduleName; private final String modulePackage; private JPanel contentPanel; - private JButton buttonOK; - private JButton buttonCancel; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, OBSERVER_NAME}) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java index 9221e8ce1..bb7ab518d 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java @@ -55,14 +55,11 @@ import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; import com.magento.idea.magento2plugin.util.magento.GetResourceCollections; import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; -import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JLabel; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java index 0017a9b2d..118e05c41 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java @@ -29,10 +29,7 @@ import com.magento.idea.magento2plugin.ui.FilteredComboBox; import java.awt.event.ActionEvent; 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.JCheckBox; import javax.swing.JComboBox; import javax.swing.JComponent; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java index e6dc2ff05..2f629f8a3 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java @@ -19,17 +19,12 @@ import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; import java.awt.event.ActionEvent; -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; import javax.swing.JRadioButton; -import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java index b5790e5e5..d5984ea3d 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java @@ -19,17 +19,11 @@ import com.magento.idea.magento2plugin.magento.packages.OverridableFileType; import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; -import java.awt.event.ActionEvent; -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; -import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; public class OverrideTemplateInThemeDialog extends AbstractDialog { @@ -39,8 +33,6 @@ public class OverrideTemplateInThemeDialog extends AbstractDialog { private final @NotNull Project project; private final PsiFile psiFile; private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; private JLabel selectTheme; //NOPMD @FieldValidation(rule = RuleRegistry.NOT_EMPTY, diff --git a/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java b/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java index 5717b8d54..13ade7893 100644 --- a/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java +++ b/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java @@ -24,8 +24,6 @@ import com.magento.idea.magento2uct.util.module.UctModulePathValidatorUtil; import java.awt.Color; import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.Objects; import javax.swing.JButton; import javax.swing.JCheckBox; diff --git a/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java b/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java index 3271c3bd5..608041434 100644 --- a/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java +++ b/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java @@ -16,8 +16,6 @@ import com.magento.idea.magento2uct.packages.IndexRegistry; import com.magento.idea.magento2uct.packages.SupportedVersion; import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; From 9649908817f190a2d23651e068340f684126cefb Mon Sep 17 00:00:00 2001 From: vitaliy Date: Mon, 26 May 2025 21:53:19 +0300 Subject: [PATCH 10/30] 2880: static fixes --- .github/workflows/gradle.yml | 27 ++++++++++++++-- build.gradle.kts | 1 + .../generation/dialog/AbstractDialog.java | 17 +++++++--- .../dialog/InjectAViewModelDialog.java | 1 - .../generation/dialog/NewBlockDialog.java | 8 ----- .../generation/dialog/NewCronGroupDialog.java | 10 ++---- .../generation/dialog/NewCronjobDialog.java | 16 +++------- .../dialog/NewCustomerEavAttributeDialog.java | 23 ++++++++------ .../generation/dialog/NewDataModelDialog.java | 13 +++----- .../generation/dialog/NewDbSchemaDialog.java | 8 ----- .../dialog/NewGraphQlResolverDialog.java | 7 ----- .../dialog/NewLayoutTemplateDialog.java | 15 +++------ .../dialog/NewMessageQueueDialog.java | 8 ----- .../generation/dialog/NewModelsDialog.java | 3 -- .../dialog/NewProductEavAttributeDialog.java | 31 ++++++++----------- .../dialog/NewSetupDataPatchDialog.java | 4 --- .../dialog/NewUiComponentFormDialog.java | 11 ++----- .../generation/dialog/NewViewModelDialog.java | 8 ----- 18 files changed, 82 insertions(+), 129 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 9d7bb2fa4..a72be00a7 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -111,12 +111,35 @@ jobs: run: chmod +x gradlew - id: file_changes uses: trilom/file-changes-action@v1.2.4 + - name: Filter Java Files + id: filter_java_files + run: | + # Get modified and added files + MODIFIED_FILES=${{ steps.file_changes.outputs.files_modified }} + ADDED_FILES=${{ steps.file_changes.outputs.files_added }} + + echo "Modified files: $MODIFIED_FILES" + echo "Added files: $ADDED_FILES" + + # Combine and filter for .java files + # Make sure we handle empty arrays properly + if [ "$MODIFIED_FILES" == "[]" ]; then + MODIFIED_FILES="[]" + fi + if [ "$ADDED_FILES" == "[]" ]; then + ADDED_FILES="[]" + fi + + # Combine arrays and filter for .java files + COMBINED_FILES=$(echo "$MODIFIED_FILES $ADDED_FILES" | jq -s 'add | map(select(endswith(".java")))') + echo "JAVA_FILES=$COMBINED_FILES" >> $GITHUB_ENV + echo "Filtered Java Files: $COMBINED_FILES" - name: Run Code Style Check run: ./gradlew checkstyleCI --no-daemon env: - MODIFIED_FILES: ${{ steps.file_changes.outputs.files}} + MODIFIED_FILES: ${{ env.JAVA_FILES }} ACTIONS_STEP_DEBUG: true - name: Run PMD Quality Check run: ./gradlew pmdCI --no-daemon env: - MODIFIED_FILES: ${{ steps.file_changes.outputs.files}} + MODIFIED_FILES: ${{ env.JAVA_FILES }} diff --git a/build.gradle.kts b/build.gradle.kts index 3b80d81f5..c2943a35c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -208,6 +208,7 @@ tasks.withType(Pmd::class).configureEach { // Specify all files that should be checked classpath = files() setSource("${project.rootDir}") + maxHeapSize = "12g" } // Execute PMD on all files diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java index 8a3928ded..affe8b7e6 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java @@ -74,9 +74,18 @@ public AbstractDialog() { * so this method is kept for compatibility. * * @param dialog AbstractDialog + * @deprecated This method is no longer needed as DialogWrapper handles centering automatically. + * It is kept for backward compatibility with existing code. */ + @Deprecated + @SuppressWarnings({ + "PMD.UncommentedEmptyMethod", + "PMD.EmptyMethodInAbstractClassShouldBeAbstract" + }) protected void centerDialog(final AbstractDialog dialog) { // DialogWrapper handles centering automatically + // This method is intentionally left with minimal implementation + // as it's deprecated and only kept for backward compatibility } /** @@ -87,9 +96,7 @@ protected void centerDialog(final AbstractDialog dialog) { */ @Nullable @Override - protected JComponent createCenterPanel() { - return null; // Subclasses must override this method - } + protected abstract JComponent createCenterPanel(); /** * Default on cancel action. @@ -157,8 +164,8 @@ public void doCancelAction() { "PMD.CognitiveComplexity" }) protected boolean validateFormFields() { - boolean dialogHasErrors; - isValidationErrorShown = dialogHasErrors = false; + boolean dialogHasErrors = false; + isValidationErrorShown = false; clearValidationHighlighting(); for (final FieldValidationData fieldValidationData : getFieldsToValidate()) { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java index b1f3db5ab..84f8bae59 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java @@ -25,7 +25,6 @@ import com.magento.idea.magento2plugin.magento.packages.XsiTypes; import com.magento.idea.magento2plugin.util.FirstLetterToLowercaseUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java index f3b8c0cbc..5376a6345 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java @@ -19,18 +19,12 @@ import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.JTextPane; -import javax.swing.KeyStroke; import org.jetbrains.annotations.Nullable; public class NewBlockDialog extends AbstractDialog { @@ -38,8 +32,6 @@ public class NewBlockDialog extends AbstractDialog { private final PsiDirectory baseDir; private final String moduleName; private JPanel contentPanel; - private JButton buttonOK; - private JButton buttonCancel; private final Project project; private JTextPane warning;//NOPMD private JRadioButton adminhtmlRadioButton;//NOPMD diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java index 3e9eafe22..b75e18fd4 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java @@ -16,35 +16,29 @@ import com.magento.idea.magento2plugin.actions.generation.generator.ModuleCronGroupXmlGenerator; import com.magento.idea.magento2plugin.ui.FilteredComboBox; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSpinner; import javax.swing.JTextField; -import javax.swing.KeyStroke; import javax.swing.SpinnerNumberModel; import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", "PMD.TooManyMethods", - "PMD.ExcessiveImports," + "PMD.ExcessiveImports", + "PMD.ImmutableField" }) public class NewCronGroupDialog extends AbstractDialog { private final String moduleName; private final Project project; private JPanel contentPanel; - private JButton buttonOK; - private JButton buttonCancel; private static final String NAME = "name"; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, NAME}) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java index d15bb89f7..df37fbb3f 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java @@ -26,12 +26,8 @@ import com.magento.idea.magento2plugin.ui.FilteredComboBox; import com.magento.idea.magento2plugin.util.CamelCaseToSnakeCase; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.ActionEvent; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; -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.JComponent; @@ -40,7 +36,6 @@ import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; -import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -63,8 +58,8 @@ public class NewCronjobDialog extends AbstractDialog { private final CamelCaseToSnakeCase camelCaseToSnakeCase; private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; + private JButton buttonOK;//NOPMD + private JButton buttonCancel;//NOPMD private JRadioButton fixedScheduleRadioButton; private JRadioButton configurableScheduleRadioButton; private JRadioButton everyMinuteRadioButton; @@ -265,16 +260,15 @@ private String suggestCronjobName(final String cronjobClassname) { } if (cronjobClassname == null || cronjobClassname.isEmpty()) { - return moduleName.toLowerCase(new java.util.Locale("en","EN")); + return moduleName.toLowerCase(java.util.Locale.ENGLISH); } final String cronjobClassnameToSnakeCase = this.camelCaseToSnakeCase.convert( cronjobClassname ); - return moduleName.toLowerCase(new java.util.Locale("en","EN")) - + "_" - + cronjobClassnameToSnakeCase; + final String moduleNameLower = moduleName.toLowerCase(java.util.Locale.ENGLISH); + return moduleNameLower + "_" + cronjobClassnameToSnakeCase; } /** diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java index 2eaed9152..3e991c3e4 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java @@ -55,11 +55,11 @@ public class NewCustomerEavAttributeDialog extends AbstractDialog { private static final String ENTITY_NAME = "Customer"; - private String moduleName; - private Project project; - private String actionName; + private final String moduleName; + private final Project project; + private final String actionName; private TableGroupWrapper entityPropertiesTableGroupWrapper; - private SourceModelData sourceModelData; + private final SourceModelData sourceModelData; private JPanel contentPanel; private JButton buttonOK; @@ -179,9 +179,9 @@ protected void fillAttributeTypeComboBox() { } for (final AttributeType typeValue : AttributeType.values()) { - typeComboBox.addItem( - new ComboBoxItemData(typeValue.getType(), typeValue.getType()) - ); + final String type = typeValue.getType(); + final ComboBoxItemData item = new ComboBoxItemData(type, type); + typeComboBox.addItem(item); } } @@ -194,9 +194,9 @@ protected void fillAttributeInputComboBox() { } for (final AttributeInput inputValue : AttributeInput.values()) { - inputComboBox.addItem( - new ComboBoxItemData(inputValue.getInput(), inputValue.getInput()) - ); + final String input = inputValue.getInput(); + final ComboBoxItemData item = new ComboBoxItemData(input, input); + inputComboBox.addItem(item); } } @@ -532,6 +532,9 @@ protected void generateExtraFilesBeforeDataPatchGeneration() { /** * Generate extra files after data patch generation. + * This method is intentionally left empty as no extra files need to be generated + * after the data patch for customer EAV attributes. Subclasses may override this + * method to provide specific implementation if needed. * * @param eavEntityDataInterface EavEntityDataInterface */ diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java index 692d91ca2..f65986360 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java @@ -31,10 +31,6 @@ import com.magento.idea.magento2plugin.ui.table.TableButton; import com.magento.idea.magento2plugin.util.RegExUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.List; import javax.swing.JButton; @@ -45,7 +41,6 @@ import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.JTextField; -import javax.swing.KeyStroke; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import org.jetbrains.annotations.NotNull; @@ -53,7 +48,8 @@ @SuppressWarnings({ "PMD.ExcessiveImports", - "PMD.ConstructorCallsOverridableMethod" + "PMD.ConstructorCallsOverridableMethod", + "PMD.ImmutableField" }) public class NewDataModelDialog extends AbstractDialog { @@ -148,10 +144,9 @@ protected void onWriteActionOK() { @Override protected boolean validateFormFields() { - boolean valid = false; + boolean valid = super.validateFormFields(); - if (super.validateFormFields()) { - valid = true; + if (valid) { final String errorTitle = commonBundle.message("common.error"); final int column = 0; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java index d1a6e0f66..3affcaca9 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java @@ -25,9 +25,6 @@ import com.magento.idea.magento2plugin.magento.packages.database.TableResources; import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; @@ -41,7 +38,6 @@ import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; -import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -54,10 +50,6 @@ public class NewDbSchemaDialog extends AbstractDialog { private final String moduleName; private JPanel contentPanel; - // Buttons - private JButton buttonOK; - private JButton buttonCancel; - // Fields @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, TABLE_NAME}) @FieldValidation(rule = RuleRegistry.LOWERCASE, message = {Lowercase.MESSAGE, TABLE_NAME}) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java index 4eeec965d..a9a6036e7 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java @@ -19,16 +19,11 @@ import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,8 +32,6 @@ public class NewGraphQlResolverDialog extends AbstractDialog { private final PsiDirectory baseDir; private final String moduleName; private JPanel contentPanel; - private JButton buttonOK; - private JButton buttonCancel; private final Project project; private static final String CLASS_NAME = "class name"; private static final String PARENT_DIRECTORY = "directory"; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java index 831cec63f..3a2061ab6 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java @@ -18,18 +18,13 @@ import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlTemplateGenerator; import com.magento.idea.magento2plugin.magento.packages.Areas; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.HashMap; import java.util.Map; -import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.KeyStroke; import org.jetbrains.annotations.Nullable; @SuppressWarnings({ @@ -38,7 +33,8 @@ "PMD.ConstructorCallsOverridableMethod", "PMD.ExcessiveImports", "PMD.SingularField", - "PMD.GodClass" + "PMD.GodClass", + "PMD.ImmutableField" }) public class NewLayoutTemplateDialog extends AbstractDialog { @@ -174,10 +170,7 @@ private String[] getLayoutNameParts() { } private String getArea() { - return area.getSelectedItem().toString(); - } - - private void run() { - area.requestFocusInWindow(); + final ComboBoxItemData selectedItem = (ComboBoxItemData) area.getSelectedItem(); + return selectedItem.getKey(); } } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java index 2b5b39390..9cc6fa16a 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java @@ -33,17 +33,11 @@ import com.magento.idea.magento2plugin.magento.files.MessageQueueClassPhp; import com.magento.idea.magento2plugin.magento.packages.MessageQueueConnections; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.KeyStroke; import javax.swing.event.DocumentEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -138,8 +132,6 @@ public class NewMessageQueueDialog extends AbstractDialog { private JTextField handlerDirectory; private JPanel contentPanel; - private JButton buttonOK; - private JButton buttonCancel; private JLabel consumerDirectoryLabel; private JLabel consumerClassLabel; private JLabel maxMessagesLabel; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java index be6c23318..fc8e34c4f 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java @@ -23,9 +23,6 @@ import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java index 80d467c63..e3b7c9d86 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java @@ -61,15 +61,13 @@ public class NewProductEavAttributeDialog extends AbstractDialog { private static final String ENTITY_NAME = "Product"; - private String moduleName; - private Project project; - private String actionName; + private final String moduleName; + private final Project project; + private final String actionName; private TableGroupWrapper entityPropertiesTableGroupWrapper; - private SourceModelData sourceModelData; + private final SourceModelData sourceModelData; private JPanel contentPanel; - private JButton buttonOK; - private JButton buttonCancel; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, "Attribute Code"}) @FieldValidation(rule = RuleRegistry.LOWERCASE, @@ -167,12 +165,6 @@ public static void open( dialog.showDialog(); } - /** - * Create UI Components. - */ - private void createUIComponents() { - // Initialize UI components - } /** * Initialize dialog state. @@ -203,9 +195,9 @@ protected void fillAttributeTypeComboBox() { } for (final AttributeType typeValue : AttributeType.values()) { - typeComboBox.addItem( - new ComboBoxItemData(typeValue.getType(), typeValue.getType()) - ); + final String type = typeValue.getType(); + final ComboBoxItemData item = new ComboBoxItemData(type, type); + typeComboBox.addItem(item); } } @@ -218,9 +210,9 @@ protected void fillAttributeInputComboBox() { } for (final AttributeInput inputValue : AttributeInput.values()) { - inputComboBox.addItem( - new ComboBoxItemData(inputValue.getInput(), inputValue.getInput()) - ); + final String input = inputValue.getInput(); + final ComboBoxItemData item = new ComboBoxItemData(input, input); + inputComboBox.addItem(item); } } @@ -587,6 +579,9 @@ protected void generateExtraFilesBeforeDataPatchGeneration() { /** * Generate extra files after data patch generation. + * This method is intentionally left empty as no extra files need to be generated + * after the data patch for product EAV attributes. Subclasses may override this + * method to provide specific implementation if needed. * * @param eavEntityDataInterface EavEntityDataInterface */ diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java index bc7f94bda..6feb57e95 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java @@ -17,15 +17,11 @@ import com.magento.idea.magento2plugin.actions.generation.generator.ModuleSetupDataPatchGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; import com.magento.idea.magento2plugin.magento.files.ModuleSetupDataPatchFile; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.KeyStroke; import org.jetbrains.annotations.Nullable; @SuppressWarnings({ diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java index d6be29c36..28eee6f85 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java @@ -53,11 +53,7 @@ import com.magento.idea.magento2plugin.ui.table.TableButton; import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -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.ArrayList; import java.util.Arrays; import java.util.List; @@ -79,7 +75,8 @@ "PMD.TooManyMethods", "PMD.ConstructorCallsOverridableMethod", "PMD.ExcessiveImports", - "PMD.GodClass" + "PMD.GodClass", + "PMD.ImmutableField" }) public class NewUiComponentFormDialog extends AbstractDialog { @@ -298,9 +295,7 @@ protected void initFieldSetsTable() { model.addRow(new Object[] {"", "", rowPosition + 10, DELETE_COLUMN}); }); model.addTableModelListener( - event -> { - initFieldsetsColumn(); - } + event -> initFieldsetsColumn() ); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java index a37462596..578d552e8 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java @@ -21,16 +21,10 @@ import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.KeyStroke; import org.jetbrains.annotations.Nullable; public class NewViewModelDialog extends AbstractDialog { @@ -43,8 +37,6 @@ public class NewViewModelDialog extends AbstractDialog { private final String moduleName; private JPanel contentPanel; - private JButton buttonOK; - private JButton buttonCancel; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, VIEW_MODEL_NAME}) From 4deb98718531e053874962b782946801658e793b Mon Sep 17 00:00:00 2001 From: vitaliy Date: Mon, 26 May 2025 21:59:28 +0300 Subject: [PATCH 11/30] 2880: static fixes 2 --- .github/workflows/gradle.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index a72be00a7..2c0ef56f1 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -131,7 +131,8 @@ jobs: fi # Combine arrays and filter for .java files - COMBINED_FILES=$(echo "$MODIFIED_FILES $ADDED_FILES" | jq -s 'add | map(select(endswith(".java")))') + # Ensure proper JSON formatting by using jq to process each array separately + COMBINED_FILES=$(jq -n --argjson mod "$MODIFIED_FILES" --argjson add "$ADDED_FILES" '$mod + $add | map(select(endswith(".java")))') echo "JAVA_FILES=$COMBINED_FILES" >> $GITHUB_ENV echo "Filtered Java Files: $COMBINED_FILES" - name: Run Code Style Check From e9fe89cb490e1ba76e681acc185d8039937d61c3 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Mon, 26 May 2025 22:06:14 +0300 Subject: [PATCH 12/30] 2880: static fixes 3 --- .github/workflows/gradle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 2c0ef56f1..9b2dd74c6 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -131,8 +131,8 @@ jobs: fi # Combine arrays and filter for .java files - # Ensure proper JSON formatting by using jq to process each array separately - COMBINED_FILES=$(jq -n --argjson mod "$MODIFIED_FILES" --argjson add "$ADDED_FILES" '$mod + $add | map(select(endswith(".java")))') + # Use a more robust approach that doesn't rely on --argjson + COMBINED_FILES=$(echo '{"files":'"$MODIFIED_FILES"', "added":'"$ADDED_FILES"'}' | jq '.files + .added | map(select(endswith(".java")))') echo "JAVA_FILES=$COMBINED_FILES" >> $GITHUB_ENV echo "Filtered Java Files: $COMBINED_FILES" - name: Run Code Style Check From 54240301c4bb63fab2fea23e09366d2e905a9544 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Mon, 26 May 2025 22:12:13 +0300 Subject: [PATCH 13/30] 2880: static fixes 4 --- .github/workflows/gradle.yml | 38 ++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 9b2dd74c6..d010e1390 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -121,20 +121,34 @@ jobs: echo "Modified files: $MODIFIED_FILES" echo "Added files: $ADDED_FILES" - # Combine and filter for .java files - # Make sure we handle empty arrays properly - if [ "$MODIFIED_FILES" == "[]" ]; then - MODIFIED_FILES="[]" - fi - if [ "$ADDED_FILES" == "[]" ]; then - ADDED_FILES="[]" + # Simple approach using shell commands to filter Java files + # Remove brackets and quotes from the JSON arrays + MODIFIED_FILES=$(echo "$MODIFIED_FILES" | sed 's/^\[//;s/\]$//;s/"//g;s/,/ /g') + ADDED_FILES=$(echo "$ADDED_FILES" | sed 's/^\[//;s/\]$//;s/"//g;s/,/ /g') + + # Combine the files and filter for .java files + ALL_FILES="$MODIFIED_FILES $ADDED_FILES" + JAVA_FILES="" + + # If there are files to process + if [ ! -z "$ALL_FILES" ]; then + # Filter for Java files and format as JSON array + for file in $ALL_FILES; do + if [[ "$file" == *.java ]]; then + if [ -z "$JAVA_FILES" ]; then + JAVA_FILES="\"$file\"" + else + JAVA_FILES="$JAVA_FILES,\"$file\"" + fi + fi + done fi - # Combine arrays and filter for .java files - # Use a more robust approach that doesn't rely on --argjson - COMBINED_FILES=$(echo '{"files":'"$MODIFIED_FILES"', "added":'"$ADDED_FILES"'}' | jq '.files + .added | map(select(endswith(".java")))') - echo "JAVA_FILES=$COMBINED_FILES" >> $GITHUB_ENV - echo "Filtered Java Files: $COMBINED_FILES" + # Create a proper JSON array + JAVA_FILES="[$JAVA_FILES]" + + echo "JAVA_FILES=$JAVA_FILES" >> $GITHUB_ENV + echo "Filtered Java Files: $JAVA_FILES" - name: Run Code Style Check run: ./gradlew checkstyleCI --no-daemon env: From 588a321b5e40b9d64c1d09d350c33157d27ed960 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Mon, 26 May 2025 22:20:24 +0300 Subject: [PATCH 14/30] 2880: static fixes 5 --- .../actions/generation/dialog/CreateAPluginDialog.java | 8 -------- .../actions/generation/dialog/InjectAViewModelDialog.java | 7 ------- .../generation/dialog/NewGraphQlResolverDialog.java | 1 - .../generation/dialog/NewInterfaceForServiceDialog.java | 2 -- .../generation/dialog/NewWebApiDeclarationDialog.java | 3 --- 5 files changed, 21 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java index 87f095245..e653a71a3 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java @@ -28,19 +28,13 @@ import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.ui.FilteredComboBox; import com.magento.idea.magento2plugin.util.php.PhpTypeMetadataParserUtil; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.List; -import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -56,8 +50,6 @@ public class CreateAPluginDialog extends AbstractDialog { private Method targetMethod; private final PhpClass targetClass; private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; private JComboBox pluginType; private JComboBox pluginArea; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java index 84f8bae59..2efe8e50b 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java @@ -25,16 +25,11 @@ import com.magento.idea.magento2plugin.magento.packages.XsiTypes; import com.magento.idea.magento2plugin.util.FirstLetterToLowercaseUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.KeyStroke; import javax.swing.event.DocumentEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -47,8 +42,6 @@ public class InjectAViewModelDialog extends AbstractDialog { private final Project project; private final XmlTag targetBlockTag; private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; private final CommonBundle commonBundle; private final ValidatorBundle validatorBundle; private JLabel inheritClassLabel;//NOPMD diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java index a9a6036e7..155cf2035 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java @@ -19,7 +19,6 @@ import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java index 71474d427..196a415bc 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java @@ -21,8 +21,6 @@ import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; import com.magento.idea.magento2plugin.util.php.PhpTypeMetadataParserUtil; import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; import java.util.Arrays; import java.util.LinkedList; import java.util.List; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java index a50424f1c..15a9755c8 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java @@ -21,7 +21,6 @@ import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; import java.util.List; -import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; @@ -41,8 +40,6 @@ public class NewWebApiDeclarationDialog extends AbstractDialog { private final String methodName; private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, ROUTE_URL}) @FieldValidation(rule = RuleRegistry.IDENTIFIER_WITH_FORWARD_SLASH, From 03f90039332ed9ec0384cca366a67782ebe0298e Mon Sep 17 00:00:00 2001 From: vitaliy Date: Mon, 26 May 2025 22:27:01 +0300 Subject: [PATCH 15/30] 2880: static fixes 6 --- .../dialog/NewCustomerEavAttributeDialog.java | 11 +++++++++-- .../dialog/NewProductEavAttributeDialog.java | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java index 3e991c3e4..cdfd02f8f 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java @@ -50,7 +50,8 @@ "PMD.TooManyFields", "PMD.ExcessiveImports", "PMD.TooManyMethods", - "PMD.UnusedPrivateField" + "PMD.UnusedPrivateField", + "PMD.GodClass" }) public class NewCustomerEavAttributeDialog extends AbstractDialog { @@ -173,6 +174,7 @@ protected void initDialogState() { /** * Fill attribute type combo box. */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") protected void fillAttributeTypeComboBox() { if (typeComboBox == null) { return; @@ -188,6 +190,7 @@ protected void fillAttributeTypeComboBox() { /** * Fill attribute input combo box. */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") protected void fillAttributeInputComboBox() { if (inputComboBox == null) { return; @@ -540,7 +543,11 @@ protected void generateExtraFilesBeforeDataPatchGeneration() { */ protected void generateExtraFilesAfterDataPatchGeneration( final EavEntityDataInterface eavEntityDataInterface - ) {} + ) { + // This method is intentionally left empty. + // No additional files need to be generated after the data patch for customer EAV attributes. + // Subclasses may override this method to provide specific implementation if needed. + } /** * Create center panel. diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java index e3b7c9d86..38d65a68b 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java @@ -56,7 +56,8 @@ "PMD.TooManyFields", "PMD.ExcessiveImports", "PMD.TooManyMethods", - "PMD.UnusedPrivateField" + "PMD.UnusedPrivateField", + "PMD.GodClass" }) public class NewProductEavAttributeDialog extends AbstractDialog { @@ -189,6 +190,7 @@ protected void initDialogState() { /** * Fill attribute type combo box. */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") protected void fillAttributeTypeComboBox() { if (typeComboBox == null) { return; @@ -204,6 +206,7 @@ protected void fillAttributeTypeComboBox() { /** * Fill attribute input combo box. */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") protected void fillAttributeInputComboBox() { if (inputComboBox == null) { return; @@ -587,7 +590,11 @@ protected void generateExtraFilesBeforeDataPatchGeneration() { */ protected void generateExtraFilesAfterDataPatchGeneration( final EavEntityDataInterface eavEntityDataInterface - ) {} + ) { + // This method is intentionally left empty. + // No additional files need to be generated after the data patch for product EAV attributes. + // Subclasses may override this method to provide specific implementation if needed. + } /** * Create center panel. From 771260f9d98b41927a4c214c0a32594549101442 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Mon, 26 May 2025 22:30:59 +0300 Subject: [PATCH 16/30] 2880: static fixes 7 --- .../generation/dialog/NewCustomerEavAttributeDialog.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java index cdfd02f8f..dc331d98f 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java @@ -545,7 +545,8 @@ protected void generateExtraFilesAfterDataPatchGeneration( final EavEntityDataInterface eavEntityDataInterface ) { // This method is intentionally left empty. - // No additional files need to be generated after the data patch for customer EAV attributes. + // No additional files need to be generated after the data patch for customer EAV + // attributes. // Subclasses may override this method to provide specific implementation if needed. } From 2ee1355e530e5cde400f057f39f41cd51e463100 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sun, 1 Jun 2025 10:51:58 +0300 Subject: [PATCH 17/30] 2080: bumped up version of phpstorm --- build.gradle.kts | 5 +++-- gradle.properties | 4 ++-- gradle/libs.versions.toml | 2 +- src/main/resources/META-INF/plugin.xml | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c2943a35c..2b2cd2ebb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,6 +31,7 @@ repositories { intellijPlatform { defaultRepositories() + maven("https://www.jetbrains.com/intellij-repository/snapshots") } } @@ -51,12 +52,12 @@ dependencies { bundledPlugins(providers.gradleProperty("platformBundledPlugins").map { it.split(',') }) plugins(providers.gradleProperty("platformPlugins").map { it.split(',') }) - plugin("com.intellij.lang.jsgraphql", "243.21565.122") + plugin("com.intellij.lang.jsgraphql", "252.18003.27") pluginVerifier() zipSigner() testFramework(TestFrameworkType.Platform) - phpstorm("2024.3") + phpstorm("252.18003.43") } } diff --git a/gradle.properties b/gradle.properties index e35da741d..7ff6e7598 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,10 +2,10 @@ pluginGroup = com.magento.idea.magento2plugin pluginName = Magento PhpStorm pluginRepositoryUrl = https://github.com/magento/magento2-phpstorm-plugin pluginVersion = 2025.2.0 -pluginSinceBuild = 243.3 +pluginSinceBuild = 251.* pluginUntilBuild = 258.* platformType = PS -platformVersion = 2024.3 +platformVersion = 252.18003.43 platformPlugins = platformBundledPlugins = com.intellij.modules.json,com.jetbrains.php,JavaScript,com.intellij.copyright gradleVersion = 8.10.2 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 66ad4ce0f..85d571563 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,7 +5,7 @@ junit = "4.13.2" # plugins changelog = "2.2.1" intelliJPlatform = "2.4.0" -kotlin = "1.9.25" +kotlin = "2.0.0" kover = "0.8.3" qodana = "2024.2.3" diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 97948e2ea..79979e9bc 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -24,7 +24,7 @@ - + From f3b22e74d7b10fa1fe698a8616199b2d50f3b73a Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sun, 1 Jun 2025 11:13:26 +0300 Subject: [PATCH 18/30] 2080: updated SharedSteps.kt asn gradle plugin version --- build.gradle.kts | 6 ++---- gradle.properties | 2 +- gradle/libs.versions.toml | 4 ++-- .../com/magento/idea/magento2plugin/steps/SharedSteps.kt | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 2b2cd2ebb..0932cde32 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,12 +52,9 @@ dependencies { bundledPlugins(providers.gradleProperty("platformBundledPlugins").map { it.split(',') }) plugins(providers.gradleProperty("platformPlugins").map { it.split(',') }) - plugin("com.intellij.lang.jsgraphql", "252.18003.27") pluginVerifier() zipSigner() testFramework(TestFrameworkType.Platform) - - phpstorm("252.18003.43") } } @@ -175,6 +172,8 @@ intellijPlatformTesting { "-Dide.mac.message.dialogs.as.sheets=false", "-Djb.privacy.policy.text=", "-Djb.consents.confirmation.enabled=false", + "-Deap.require.license=false", + "-Dide.show.tips.on.startup.default.value=false" ) } } @@ -209,7 +208,6 @@ tasks.withType(Pmd::class).configureEach { // Specify all files that should be checked classpath = files() setSource("${project.rootDir}") - maxHeapSize = "12g" } // Execute PMD on all files diff --git a/gradle.properties b/gradle.properties index 7ff6e7598..0d4707a69 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ pluginSinceBuild = 251.* pluginUntilBuild = 258.* platformType = PS platformVersion = 252.18003.43 -platformPlugins = +platformPlugins = com.intellij.lang.jsgraphql:252.18003.27 platformBundledPlugins = com.intellij.modules.json,com.jetbrains.php,JavaScript,com.intellij.copyright gradleVersion = 8.10.2 kotlin.stdlib.default.dependency = false diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 85d571563..e1ec9ec04 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,8 +4,8 @@ junit = "4.13.2" # plugins changelog = "2.2.1" -intelliJPlatform = "2.4.0" -kotlin = "2.0.0" +intelliJPlatform = "2.6.0" +kotlin = "2.1.0" kover = "0.8.3" qodana = "2024.2.3" diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt b/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt index 3c7286ed0..fb6da3f33 100644 --- a/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt +++ b/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt @@ -35,7 +35,7 @@ class SharedSteps(private val remoteRobot: RemoteRobot) { ContainerFixture::class.java, byXpath("//div[@visible_text='New Project']") ) - newProjectButton.click() + newProjectButton.click(Point(15, -15)) Thread.sleep(2_000) val jTextFieldFixture = find(byXpath("//div[@class='TextFieldWithBrowseButton']")) From 117e67f12a7fb949c4d98be46ef9954c20943101 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sun, 1 Jun 2025 18:53:25 +0300 Subject: [PATCH 19/30] 2080: removed license activation --- .../idea/magento2plugin/steps/SharedSteps.kt | 71 ++++++------------- 1 file changed, 20 insertions(+), 51 deletions(-) diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt b/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt index fb6da3f33..38fc02682 100644 --- a/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt +++ b/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt @@ -31,11 +31,20 @@ class SharedSteps(private val remoteRobot: RemoteRobot) { step("Create Or Open Test Project", Runnable { try { remoteRobot.welcomeFrame { - val newProjectButton = remoteRobot.find( - ContainerFixture::class.java, - byXpath("//div[@visible_text='New Project']") - ) - newProjectButton.click(Point(15, -15)) + try { + val newProjectIcon = remoteRobot.find( + ContainerFixture::class.java, + byXpath("//div[@defaulticon='createNewProjectTab.svg']") + ); + newProjectIcon.click(); + } catch (exception: Exception) { + val newProjectButton = remoteRobot.find( + ContainerFixture::class.java, + byXpath("//div[@visible_text='New Project']") + ) + newProjectButton.click(); + } + Thread.sleep(2_000) val jTextFieldFixture = find(byXpath("//div[@class='TextFieldWithBrowseButton']")) @@ -54,19 +63,6 @@ class SharedSteps(private val remoteRobot: RemoteRobot) { enableMagentoSupport() } } catch (exception: Exception) { - // temporary workaround until we get license for CI - activateIde() - // end temporary workaround - try { - val launchedFromScript = remoteRobot.find( - ContainerFixture::class.java, - byXpath("//div[@class='LinkLabel']") - ) - launchedFromScript.click() - } catch (e: Exception) { - // Element does not exist, continue without failing the test - } - createProjectFromExistingFiles() enableMagentoSupport() } @@ -102,38 +98,18 @@ class SharedSteps(private val remoteRobot: RemoteRobot) { ) } - private fun activateIde() { - if ("true" == System.getenv("GITHUB_ACTIONS")) { - val startTrial = - remoteRobot.find(ContainerFixture::class.java, byXpath("//div[@visible_text='Start trial']")) - startTrial.click() - - val startTrialFree = remoteRobot.find(ContainerFixture::class.java, byXpath("//div[@class='s']")) - startTrialFree.click() - - val dialog = remoteRobot.find( - DialogFixture::class.java, byXpath("//div[@class='MyDialog']") - ) - dialog.button("Close").click() - closeBrowser() - - try { - Thread.sleep(10000) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - throw RuntimeException(e) - } - } else { - closeBrowser() + private fun enableMagentoSupport() { + try { + //closing AI adv popup val dialog = remoteRobot.find( DialogFixture::class.java, byXpath("//div[@class='MyDialog']") ) - dialog.button("Activate").click() dialog.button("Close").click() + } catch (e: Exception) { + //do nothing } - } - private fun enableMagentoSupport() { + remoteRobot.idea { step("Enable Magento Integration") { waitFor(ofMinutes(1)) { isDumbMode().not() } @@ -152,13 +128,6 @@ class SharedSteps(private val remoteRobot: RemoteRobot) { private fun createProjectFromExistingFiles() { remoteRobot.welcomeFrame { - try { - val launchedFromScript = find(byXpath("//div[@class='LinkLabel']")) - launchedFromScript.click() - } catch (e: Exception) { - // Element does not exist, continue without failing the test - } - createNewProjectFromExistingFilesLink.click() selectProjectPath() } From 03df6c80c6c4b732c227d21ead38f3883182386a Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sun, 8 Jun 2025 13:59:28 +0300 Subject: [PATCH 20/30] 2080: fixed UI tests --- .../pages/CreateANewModuleDialogFixture.kt | 2 +- .../pages/CreateAPluginDialogFixture.kt | 4 +-- .../magento2plugin/pages/DialogFixture.kt | 4 +-- .../idea/magento2plugin/pages/IdeaFrame.kt | 4 +-- .../idea/magento2plugin/steps/SharedSteps.kt | 34 ++++--------------- 5 files changed, 13 insertions(+), 35 deletions(-) diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateANewModuleDialogFixture.kt b/src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateANewModuleDialogFixture.kt index 6a92523bb..12d113675 100644 --- a/src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateANewModuleDialogFixture.kt +++ b/src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateANewModuleDialogFixture.kt @@ -19,7 +19,7 @@ fun RemoteRobot.createAModuleDialog(function: CreateAModuleDialogFixture.() -> U } @FixtureName("CreateAModuleDialog") -@DefaultXpath("CreateAModuleDialog type", "//div[@class='NewModuleDialog']") +@DefaultXpath("CreateAModuleDialog type", "//div[@class='MyDialog']") class CreateAModuleDialogFixture( remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : CommonContainerFixture(remoteRobot, remoteComponent) { diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateAPluginDialogFixture.kt b/src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateAPluginDialogFixture.kt index 09e11673b..d9d255632 100644 --- a/src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateAPluginDialogFixture.kt +++ b/src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateAPluginDialogFixture.kt @@ -19,7 +19,7 @@ fun RemoteRobot.createAPluginDialog(function: CreateAPluginDialogFixture.() -> U } @FixtureName("CreateAPluginDialog") -@DefaultXpath("CreateAPluginDialog type", "//div[@class='CreateAPluginDialog']") +@DefaultXpath("CreateAPluginDialog type", "//div[@class='MyDialog']") class CreateAPluginDialogFixture( remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : CommonContainerFixture(remoteRobot, remoteComponent) { @@ -32,4 +32,4 @@ class CreateAPluginDialogFixture( val pluginName get() = find(byXpath("FilteredComboBox", "//div[@tooltiptext='Plugin name in di.xml']")) -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/pages/DialogFixture.kt b/src/test/kotlin/com/magento/idea/magento2plugin/pages/DialogFixture.kt index b76cdf71f..b4368e6b4 100644 --- a/src/test/kotlin/com/magento/idea/magento2plugin/pages/DialogFixture.kt +++ b/src/test/kotlin/com/magento/idea/magento2plugin/pages/DialogFixture.kt @@ -37,6 +37,6 @@ class DialogFixture( fun byTitle(title: String) = byXpath("title $title", "//div[@title='$title' and @class='MyDialog']") @JvmStatic - fun getJDialog(title: String) = byXpath("title $title", "//div[@title='$title' and @class='JDialog']") + fun getJDialog(title: String) = byXpath("title $title", "//div[@title='$title']") } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/pages/IdeaFrame.kt b/src/test/kotlin/com/magento/idea/magento2plugin/pages/IdeaFrame.kt index adf3af637..f21523292 100644 --- a/src/test/kotlin/com/magento/idea/magento2plugin/pages/IdeaFrame.kt +++ b/src/test/kotlin/com/magento/idea/magento2plugin/pages/IdeaFrame.kt @@ -29,12 +29,12 @@ class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : val projectViewTree get() = try { - find(byXpath("//div[@class='ProjectViewTree']")) + find(byXpath("//div[@class='MyProjectViewTree']")) } catch (e: Exception) { keyboard { hotKey(VK_ALT, VK_1) } - find(byXpath("//div[@class='ProjectViewTree']")) + find(byXpath("//div[@class='MyProjectViewTree']")) } fun isProjectViewVisible(): Boolean { diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt b/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt index 38fc02682..8ec419a04 100644 --- a/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt +++ b/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt @@ -17,7 +17,6 @@ import com.magento.idea.magento2plugin.pages.* import java.awt.Point import java.awt.event.KeyEvent.* import java.io.File -import java.io.IOException import java.nio.file.Paths import java.time.Duration.ofMinutes import java.util.* @@ -99,17 +98,19 @@ class SharedSteps(private val remoteRobot: RemoteRobot) { } private fun enableMagentoSupport() { + Thread.sleep(7_000) + try { //closing AI adv popup val dialog = remoteRobot.find( - DialogFixture::class.java, byXpath("//div[@class='MyDialog']") + DialogFixture::class.java, byXpath("//div[@name='dialog2']") ) - dialog.button("Close").click() + dialog.click() + dialog.keyboard { key(VK_ESCAPE) } } catch (e: Exception) { //do nothing } - remoteRobot.idea { step("Enable Magento Integration") { waitFor(ofMinutes(1)) { isDumbMode().not() } @@ -148,27 +149,4 @@ class SharedSteps(private val remoteRobot: RemoteRobot) { trustProjectLink.click() } } - - /** - * Closes the browser by terminating its process based on the operating system. - */ - fun closeBrowser() { - val os = System.getProperty("os.name").lowercase(Locale.getDefault()) - - try { - if (os.contains("win")) { - // For Windows: Close common browsers like Chrome, Firefox, etc. - Runtime.getRuntime().exec("taskkill /F /IM edge.exe") - } else if (os.contains("mac")) { - // For macOS: Kill browsers using `pkill` - Runtime.getRuntime().exec("killall -9 safari") - } else if (os.contains("nix") || os.contains("nux")) { - // For Linux-based systems: Kill typical browser processes - Runtime.getRuntime().exec("killall -9 firefox") - Runtime.getRuntime().exec("killall -9 chrome") - } - } catch (e: IOException) { - e.printStackTrace() - } - } -} \ No newline at end of file +} From 90b2f5e8bdb79f87035de6472ac97bc1c5c59037 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sun, 8 Jun 2025 17:38:23 +0300 Subject: [PATCH 21/30] 2080: debug --- .github/workflows/uitests.yml | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/uitests.yml b/.github/workflows/uitests.yml index 1e3cb8e49..6b0a00e52 100644 --- a/.github/workflows/uitests.yml +++ b/.github/workflows/uitests.yml @@ -68,17 +68,11 @@ jobs: export DISPLAY=:99.0 ./gradlew test -PexcludeTests="**/reference/**,**/linemarker/**,**/inspections/**,**/completion/**,**/actions/**" -# Uncomment if investigation is needed: -# -# - name: Capture Test Artifacts on Failure -# if: failure() && matrix.os == 'ubuntu-latest' -# run: tar -cvzf video.tgz ./video -# shell: bash -# -# - name: Upload Test Video Artifact -# if: failure() && matrix.os == 'ubuntu-latest' -# uses: actions/upload-artifact@v4 -# with: -# name: latest-test-video -# path: video.tgz -# overwrite: true + #Uncomment if investigation is needed: + - name: Upload Test Video Artifact + if: failure() && matrix.os == 'ubuntu-latest' + uses: actions/upload-artifact@v4 + with: + name: latest-test-video + path: ./video + overwrite: true From 0ec28cb76efef22c313931485f2ba05cf6c1759c Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sun, 8 Jun 2025 17:49:45 +0300 Subject: [PATCH 22/30] 2080: debug 2 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 0932cde32..8db0aa00c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -172,7 +172,7 @@ intellijPlatformTesting { "-Dide.mac.message.dialogs.as.sheets=false", "-Djb.privacy.policy.text=", "-Djb.consents.confirmation.enabled=false", - "-Deap.require.license=false", + "-Deap.require.license=true", "-Dide.show.tips.on.startup.default.value=false" ) } From 6d7fa79955c1dd30fbaafbcf7c6c9c1690bc5977 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sat, 2 Aug 2025 14:51:31 +0300 Subject: [PATCH 23/30] Removed UI tests, since there is no way to get license for CI --- .github/workflows/uitests.yml | 78 -------- CHANGELOG.md | 5 + README.md | 1 + .../pages/ContextMenuFixture.kt | 32 ---- .../pages/CreateANewModuleDialogFixture.kt | 32 ---- .../pages/CreateAPluginDialogFixture.kt | 35 ---- .../magento2plugin/pages/DialogFixture.kt | 42 ----- .../pages/FilteredComboBoxFixture.kt | 24 --- .../idea/magento2plugin/pages/IdeaFrame.kt | 65 ------- .../idea/magento2plugin/pages/WelcomeFrame.kt | 25 --- .../idea/magento2plugin/steps/SharedSteps.kt | 152 ---------------- .../codeGeneration/NewModuleActionTest.kt | 157 ---------------- .../content/MarkDirectoryAsMagentoRootTest.kt | 168 ------------------ .../utils/RemoteRobotExtension.kt | 141 --------------- .../idea/magento2plugin/utils/StepsLogger.kt | 20 --- 15 files changed, 6 insertions(+), 971 deletions(-) delete mode 100644 .github/workflows/uitests.yml delete mode 100644 src/test/kotlin/com/magento/idea/magento2plugin/pages/ContextMenuFixture.kt delete mode 100644 src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateANewModuleDialogFixture.kt delete mode 100644 src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateAPluginDialogFixture.kt delete mode 100644 src/test/kotlin/com/magento/idea/magento2plugin/pages/DialogFixture.kt delete mode 100644 src/test/kotlin/com/magento/idea/magento2plugin/pages/FilteredComboBoxFixture.kt delete mode 100644 src/test/kotlin/com/magento/idea/magento2plugin/pages/IdeaFrame.kt delete mode 100644 src/test/kotlin/com/magento/idea/magento2plugin/pages/WelcomeFrame.kt delete mode 100644 src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt delete mode 100644 src/test/kotlin/com/magento/idea/magento2plugin/userInterface/codeGeneration/NewModuleActionTest.kt delete mode 100644 src/test/kotlin/com/magento/idea/magento2plugin/userInterface/content/MarkDirectoryAsMagentoRootTest.kt delete mode 100644 src/test/kotlin/com/magento/idea/magento2plugin/utils/RemoteRobotExtension.kt delete mode 100644 src/test/kotlin/com/magento/idea/magento2plugin/utils/StepsLogger.kt diff --git a/.github/workflows/uitests.yml b/.github/workflows/uitests.yml deleted file mode 100644 index 6b0a00e52..000000000 --- a/.github/workflows/uitests.yml +++ /dev/null @@ -1,78 +0,0 @@ -# This workflow will build a Java project with Gradle -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle - -name: Run automated tests - -on: - pull_request: - branches: [ master, '*-develop', 'mainline*' ] - -jobs: - - testUI: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - include: - - os: ubuntu-latest - runIde: | - export DISPLAY=:99.0 - Xvfb -ac :99 -screen 0 1920x1080x24 & - sleep 10 - ./gradlew runIdeForUiTests & -# TODO: fix for windows is needed, currently Gradle can't process .form files for windows - -# - os: windows-latest -# runIde: start gradlew.bat runIdeForUiTests -# - os: macos-latest -# runIde: ./gradlew runIdeForUiTests & - - steps: - - # Check out the current repository - - name: Fetch Sources - uses: actions/checkout@v4 - - # Set up Java environment for the next steps - - name: Setup Java - uses: actions/setup-java@v4 - with: - distribution: zulu - java-version: 17 - - # Setup Gradle - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v4 - - # Run IDEA prepared for UI testing - - name: Run IDE - run: ${{ matrix.runIde }} - - # Wait for IDEA to be started - - name: Health Check - uses: jtalk/url-health-check-action@v4 - with: - url: http://127.0.0.1:8082 - max-attempts: 15 - retry-delay: 30s - - # Run tests - - name: Tests - if: matrix.os != 'ubuntu-latest' - run: ./gradlew uiTests - - - name: Tests Ubuntu - if: matrix.os == 'ubuntu-latest' - run: | - export DISPLAY=:99.0 - ./gradlew test -PexcludeTests="**/reference/**,**/linemarker/**,**/inspections/**,**/completion/**,**/actions/**" - - #Uncomment if investigation is needed: - - name: Upload Test Video Artifact - if: failure() && matrix.os == 'ubuntu-latest' - uses: actions/upload-artifact@v4 - with: - name: latest-test-video - path: ./video - overwrite: true diff --git a/CHANGELOG.md b/CHANGELOG.md index a77bb3025..7124599e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). ## 2025.2.0 +### Fixed + +- Thread context was already set [#2550](https://github.com/magento/magento2-phpstorm-plugin/pull/2550) +- Argument for @NotNull parameter 'psiDirectory' [#2553](https://github.com/magento/magento2-phpstorm-plugin/pull/2553) + ## 2025.1.1 ### Fixed diff --git a/README.md b/README.md index 288c9d783..2be9e1e49 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@

Thank you to our sponsors—your support means everything:

Lucas van Staden

Ivan Chepurnyi

+

Michael Ryvlin

diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/pages/ContextMenuFixture.kt b/src/test/kotlin/com/magento/idea/magento2plugin/pages/ContextMenuFixture.kt deleted file mode 100644 index e3ac8b483..000000000 --- a/src/test/kotlin/com/magento/idea/magento2plugin/pages/ContextMenuFixture.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.pages - -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.data.RemoteComponent -import com.intellij.remoterobot.fixtures.ComponentFixture -import com.intellij.remoterobot.fixtures.FixtureName -import com.intellij.remoterobot.search.locators.byXpath -import com.intellij.remoterobot.utils.waitFor - -fun RemoteRobot.contextMenuItem(text: String): ContextMenuItemFixture { - val xpath = byXpath("text '$text'", "//div[@class='ActionMenuItem' and @text='$text']") - waitFor { - findAll(xpath).isNotEmpty() - } - return findAll(xpath).first() -} - -fun RemoteRobot.contextMenu(text: String): ContextMenuItemFixture { - val xpath = byXpath("text '$text'", "//div[@class='ActionMenu' and @text='$text']") - waitFor { - findAll(xpath).isNotEmpty() - } - return findAll(xpath).first() -} - -@FixtureName("ContextMenuItem") -class ContextMenuItemFixture(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : ComponentFixture(remoteRobot, remoteComponent) \ No newline at end of file diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateANewModuleDialogFixture.kt b/src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateANewModuleDialogFixture.kt deleted file mode 100644 index 12d113675..000000000 --- a/src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateANewModuleDialogFixture.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.pages - -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.data.RemoteComponent -import com.intellij.remoterobot.fixtures.CommonContainerFixture -import com.intellij.remoterobot.fixtures.DefaultXpath -import com.intellij.remoterobot.fixtures.FixtureName -import com.intellij.remoterobot.fixtures.JTextFieldFixture -import com.intellij.remoterobot.search.locators.byXpath -import java.time.Duration - -fun RemoteRobot.createAModuleDialog(function: CreateAModuleDialogFixture.() -> Unit) { - find(timeout = Duration.ofSeconds(10)).apply(function) -} - -@FixtureName("CreateAModuleDialog") -@DefaultXpath("CreateAModuleDialog type", "//div[@class='MyDialog']") -class CreateAModuleDialogFixture( - remoteRobot: RemoteRobot, - remoteComponent: RemoteComponent) : CommonContainerFixture(remoteRobot, remoteComponent) { - - val packageName - get() = find(byXpath("FilteredComboBox", "//div[@name='Package Name']")) - - val moduleName - get() = find(byXpath("FilteredComboBox", "//div[@name='Module Name']")) -} \ No newline at end of file diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateAPluginDialogFixture.kt b/src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateAPluginDialogFixture.kt deleted file mode 100644 index d9d255632..000000000 --- a/src/test/kotlin/com/magento/idea/magento2plugin/pages/CreateAPluginDialogFixture.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.pages - -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.data.RemoteComponent -import com.intellij.remoterobot.fixtures.CommonContainerFixture -import com.intellij.remoterobot.fixtures.DefaultXpath -import com.intellij.remoterobot.fixtures.FixtureName -import com.intellij.remoterobot.fixtures.JTextFieldFixture -import com.intellij.remoterobot.search.locators.byXpath -import java.time.Duration - -fun RemoteRobot.createAPluginDialog(function: CreateAPluginDialogFixture.() -> Unit) { - find(timeout = Duration.ofSeconds(10)).apply(function) -} - -@FixtureName("CreateAPluginDialog") -@DefaultXpath("CreateAPluginDialog type", "//div[@class='MyDialog']") -class CreateAPluginDialogFixture( - remoteRobot: RemoteRobot, - remoteComponent: RemoteComponent) : CommonContainerFixture(remoteRobot, remoteComponent) { - - val targetModule - get() = find(byXpath("FilteredComboBox", "//div[@class='FilteredComboBox']")) - - val className - get() = find(byXpath("FilteredComboBox", "//div[@name='Class Name']")) - - val pluginName - get() = find(byXpath("FilteredComboBox", "//div[@tooltiptext='Plugin name in di.xml']")) -} diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/pages/DialogFixture.kt b/src/test/kotlin/com/magento/idea/magento2plugin/pages/DialogFixture.kt deleted file mode 100644 index b4368e6b4..000000000 --- a/src/test/kotlin/com/magento/idea/magento2plugin/pages/DialogFixture.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.pages - -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.data.RemoteComponent -import com.intellij.remoterobot.fixtures.CommonContainerFixture -import com.intellij.remoterobot.fixtures.ContainerFixture -import com.intellij.remoterobot.fixtures.FixtureName -import com.intellij.remoterobot.search.locators.byXpath -import com.intellij.remoterobot.stepsProcessing.step -import java.time.Duration - -fun ContainerFixture.dialog( - title: String, - timeout: Duration = Duration.ofSeconds(20), - function: DialogFixture.() -> Unit = {}): DialogFixture = step("Search for dialog with title $title") { - find(DialogFixture.byTitle(title), timeout).apply(function) -} - -fun ContainerFixture.errorDialog( - timeout: Duration = Duration.ofSeconds(20), - function: DialogFixture.() -> Unit = {}): DialogFixture = step("Search for error dialog") { - find(DialogFixture.getJDialog("Error"), timeout).apply(function) -} - -@FixtureName("Dialog") -class DialogFixture( - remoteRobot: RemoteRobot, - remoteComponent: RemoteComponent) : CommonContainerFixture(remoteRobot, remoteComponent) { - - companion object { - @JvmStatic - fun byTitle(title: String) = byXpath("title $title", "//div[@title='$title' and @class='MyDialog']") - - @JvmStatic - fun getJDialog(title: String) = byXpath("title $title", "//div[@title='$title']") - } -} diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/pages/FilteredComboBoxFixture.kt b/src/test/kotlin/com/magento/idea/magento2plugin/pages/FilteredComboBoxFixture.kt deleted file mode 100644 index a55da468d..000000000 --- a/src/test/kotlin/com/magento/idea/magento2plugin/pages/FilteredComboBoxFixture.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.pages - -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.data.RemoteComponent -import com.intellij.remoterobot.fixtures.ComponentFixture -import com.intellij.remoterobot.fixtures.DefaultXpath -import com.intellij.remoterobot.fixtures.FixtureName -import com.intellij.remoterobot.fixtures.JLabelFixture -import com.intellij.remoterobot.search.locators.Locator -import com.intellij.remoterobot.stepsProcessing.step -import com.intellij.remoterobot.utils.Locators -import com.intellij.remoterobot.utils.RelativeLocators -import com.magento.idea.magento2plugin.ui.FilteredComboBox - -@DefaultXpath(by = "FilteredComboBox type", xpath = "//div[@class='FilteredComboBox']") -@FixtureName("FilteredComboBoxFixture") -open class FilteredComboBoxFixture(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : - ComponentFixture(remoteRobot, remoteComponent) { -} diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/pages/IdeaFrame.kt b/src/test/kotlin/com/magento/idea/magento2plugin/pages/IdeaFrame.kt deleted file mode 100644 index f21523292..000000000 --- a/src/test/kotlin/com/magento/idea/magento2plugin/pages/IdeaFrame.kt +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.pages - -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.data.RemoteComponent -import com.intellij.remoterobot.fixtures.* -import com.intellij.remoterobot.search.locators.byXpath -import com.intellij.remoterobot.utils.keyboard -import java.awt.event.KeyEvent.VK_ALT -import java.awt.event.KeyEvent.VK_1 -import java.time.Duration - - -fun RemoteRobot.idea(function: IdeaFrame.() -> Unit) { - find(timeout = Duration.ofSeconds(10)).apply(function) -} - -@FixtureName("Idea frame") -@DefaultXpath("IdeFrameImpl type", "//div[@class='IdeFrameImpl']") -class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : - CommonContainerFixture(remoteRobot, remoteComponent) { - - val enableSupportLink - get() = actionLink(byXpath("//div[@accessiblename='Enable Magento support for this project?' and @class='JEditorPane']")) - - val projectViewTree - get() = try { - find(byXpath("//div[@class='MyProjectViewTree']")) - } catch (e: Exception) { - keyboard { - hotKey(VK_ALT, VK_1) - } - find(byXpath("//div[@class='MyProjectViewTree']")) - } - - fun isProjectViewVisible(): Boolean { - return try { - with(projectViewTree) { - findText("vendor") - true - } - } catch (e: Exception) { - false - } - } - - - fun isDumbMode(): Boolean { - return callJs( - """ - const frameHelper = com.intellij.openapi.wm.impl.ProjectFrameHelper.getFrameHelper(component) - if (frameHelper) { - const project = frameHelper.getProject() - project ? com.intellij.openapi.project.DumbService.isDumb(project) : true - } else { - true - } - """, true - ) - } -} \ No newline at end of file diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/pages/WelcomeFrame.kt b/src/test/kotlin/com/magento/idea/magento2plugin/pages/WelcomeFrame.kt deleted file mode 100644 index 9dd311cdd..000000000 --- a/src/test/kotlin/com/magento/idea/magento2plugin/pages/WelcomeFrame.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.pages - -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.data.RemoteComponent -import com.intellij.remoterobot.fixtures.* -import com.intellij.remoterobot.search.locators.byXpath -import java.time.Duration - -fun RemoteRobot.welcomeFrame(function: WelcomeFrame.()-> Unit) { - find(WelcomeFrame::class.java, Duration.ofSeconds(10)).apply(function) -} - -@FixtureName("Welcome Frame") -@DefaultXpath("type", "//div[@class='FlatWelcomeFrame']") -class WelcomeFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : CommonContainerFixture(remoteRobot, remoteComponent) { - val createNewProjectFromExistingFilesLink - get() = actionLink(byXpath("//div[@defaulticon='open.svg']")) - val trustProjectLink - get() = actionLink(byXpath("//div[@text='Trust Project']")) -} \ No newline at end of file diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt b/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt deleted file mode 100644 index 8ec419a04..000000000 --- a/src/test/kotlin/com/magento/idea/magento2plugin/steps/SharedSteps.kt +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.steps - -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.fixtures.ContainerFixture -import com.intellij.remoterobot.fixtures.JTextFieldFixture -import com.intellij.remoterobot.search.locators.byXpath -import com.intellij.remoterobot.steps.CommonSteps -import com.intellij.remoterobot.stepsProcessing.step -import com.intellij.remoterobot.utils.keyboard -import com.intellij.remoterobot.utils.waitFor -import com.magento.idea.magento2plugin.pages.* -import java.awt.Point -import java.awt.event.KeyEvent.* -import java.io.File -import java.nio.file.Paths -import java.time.Duration.ofMinutes -import java.util.* - -class SharedSteps(private val remoteRobot: RemoteRobot) { - private lateinit var tempProjectDir: File - - fun createOrOpenTestProject(): File { - setupTemporaryMagentoProject() - - step("Create Or Open Test Project", Runnable { - try { - remoteRobot.welcomeFrame { - try { - val newProjectIcon = remoteRobot.find( - ContainerFixture::class.java, - byXpath("//div[@defaulticon='createNewProjectTab.svg']") - ); - newProjectIcon.click(); - } catch (exception: Exception) { - val newProjectButton = remoteRobot.find( - ContainerFixture::class.java, - byXpath("//div[@visible_text='New Project']") - ) - newProjectButton.click(); - } - - Thread.sleep(2_000) - - val jTextFieldFixture = find(byXpath("//div[@class='TextFieldWithBrowseButton']")) - jTextFieldFixture.click() - jTextFieldFixture.keyboard { - hotKey(VK_CONTROL, VK_A) - key(VK_DELETE) - enterText(tempProjectDir.absolutePath.toString().replace("\\", "\\\\")) - } - keyboard { key(VK_ENTER) } - - dialog("Directory Is Not Empty") { - button("Create from Existing Sources").click() - } - - enableMagentoSupport() - } - } catch (exception: Exception) { - createProjectFromExistingFiles() - enableMagentoSupport() - } - }) - - return tempProjectDir; - } - - fun closeProject() { - CommonSteps(remoteRobot).closeProject() - } - - private fun setupTemporaryMagentoProject() { - // Create a parent directory and a random child directory inside it - val parentDir = Paths.get("intellij-test-project").toFile() - if (parentDir.exists()) { - parentDir.deleteRecursively() - } - parentDir.mkdirs() - - // Create a randomly named child directory inside the parent directory - tempProjectDir = File(parentDir, UUID.randomUUID().toString()).apply { - mkdirs() - } - - // Define the source directory for the test data - val sourceDir = File("testData/project/magento2") - - // Copy the test data to the temporary directory - sourceDir.copyRecursively( - target = tempProjectDir, - overwrite = true - ) - } - - private fun enableMagentoSupport() { - Thread.sleep(7_000) - - try { - //closing AI adv popup - val dialog = remoteRobot.find( - DialogFixture::class.java, byXpath("//div[@name='dialog2']") - ) - dialog.click() - dialog.keyboard { key(VK_ESCAPE) } - } catch (e: Exception) { - //do nothing - } - - remoteRobot.idea { - step("Enable Magento Integration") { - waitFor(ofMinutes(1)) { isDumbMode().not() } - Thread.sleep(5_000) - enableSupportLink.click(Point(1, 1)) - waitFor(ofMinutes(1)) { isDumbMode().not() } - - if (!isProjectViewVisible()) { - keyboard { - hotKey(VK_ALT, VK_1) - } - } - } - } - } - - private fun createProjectFromExistingFiles() { - remoteRobot.welcomeFrame { - createNewProjectFromExistingFilesLink.click() - selectProjectPath() - } - } - - private fun WelcomeFrame.selectProjectPath() { - dialog("Open File or Project") { - // Set the path for the copied test data - val comboBox = find(byXpath("//div[@class='BorderlessTextField']")) - comboBox.click() // Focus on the comboBox - comboBox.keyboard { - hotKey(VK_CONTROL, VK_A) // Select all text - key(VK_DELETE) // Delete selected text - enterText(tempProjectDir.absolutePath.toString().replace("\\", "\\\\")) - } - - button("OK").click() - trustProjectLink.click() - } - } -} diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/userInterface/codeGeneration/NewModuleActionTest.kt b/src/test/kotlin/com/magento/idea/magento2plugin/userInterface/codeGeneration/NewModuleActionTest.kt deleted file mode 100644 index 24f9049a9..000000000 --- a/src/test/kotlin/com/magento/idea/magento2plugin/userInterface/codeGeneration/NewModuleActionTest.kt +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.userInterface.codeGeneration - -import com.automation.remarks.junit5.Video -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.stepsProcessing.step -import com.intellij.remoterobot.utils.keyboard -import com.intellij.remoterobot.utils.waitForIgnoringError -import com.magento.idea.magento2plugin.magento.files.ComposerJson -import com.magento.idea.magento2plugin.magento.files.ModuleXml -import com.magento.idea.magento2plugin.magento.files.RegistrationPhp -import com.magento.idea.magento2plugin.magento.packages.File -import com.magento.idea.magento2plugin.magento.packages.Package -import com.magento.idea.magento2plugin.pages.* -import com.magento.idea.magento2plugin.steps.SharedSteps -import com.magento.idea.magento2plugin.utils.RemoteRobotExtension -import com.magento.idea.magento2plugin.utils.StepsLogger -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import java.time.Duration.ofMinutes - -@ExtendWith(RemoteRobotExtension::class) -class NewModuleActionTest { - private lateinit var tempProjectDir: java.io.File - - init { - StepsLogger.init() - } - - @BeforeEach - fun waitForIde(remoteRobot: RemoteRobot) { - waitForIgnoringError(ofMinutes(3)) { remoteRobot.callJs("true") } - } - - @AfterEach - fun closeProject(remoteRobot: RemoteRobot) = with(remoteRobot) { - SharedSteps(remoteRobot).closeProject() - } - - @Test - @Video - fun testNewModuleAction(remoteRobot: RemoteRobot) = with(remoteRobot) { - tempProjectDir = SharedSteps(remoteRobot).createOrOpenTestProject() - - idea { - step("Create A new Module") { - with(projectViewTree) { - findText("app").doubleClick() - findText("code").rightClick() - } - - contextMenu("New").click() - contextMenuItem("Magento 2 Module").click() - - createAModuleDialog { - step("Ensure target module includes 'Magento_Catalog'") { - packageName.click() - packageName.keyboard { - enterText("MyTestVendor") - } - - moduleName.click() - moduleName.keyboard { - enterText("MyTestModule") - button("OK").click() - } - } - } - } - - step("Check Generated Files") { - checkRegistrationPhp() - checkModuleXml() - checkComposerJson() - } - } - } - - private fun checkRegistrationPhp() { - val registrationPhp = java.io.File( - getModulePath() + - File.separator + - RegistrationPhp.FILE_NAME - ) - - val expected = "\n" + - "\n" + - " \n" + - "\n" - val actual = xmlFile.readText() - if (actual != expected) { - throw AssertionError("The content of registration.php does not match the expected content.\nExpected:\n$expected\nActual:\n$actual") - } - } - - private fun checkComposerJson() { - val composerJsonFile = java.io.File( - getModulePath() + - File.separator + - ComposerJson.FILE_NAME - ) - - val expected = "{\n" + - " \"name\": \"my-test-vendor/module-my-test-module\",\n" + - " \"version\": \"1.0.0\",\n" + - " \"description\": \"N/A\",\n" + - " \"type\": \"magento2-module\",\n" + - " \"require\": {\n" + - " \"magento/framework\": \"*\"\n" + - " },\n" + - " \"license\": [\n" + - " \"\"\n" + - " ],\n" + - " \"autoload\": {\n" + - " \"files\": [\n" + - " \"registration.php\"\n" + - " ],\n" + - " \"psr-4\": {\n" + - " \"MyTestVendor\\\\MyTestModule\\\\\": \"\"\n" + - " }\n" + - " }\n" + - "}\n" - val actual = composerJsonFile.readText() - if (actual != expected) { - throw AssertionError("The content of registration.php does not match the expected content.\nExpected:\n$expected\nActual:\n$actual") - } - } - - private fun getModulePath() = tempProjectDir.path + "/app/code/MyTestVendor/MyTestModule" -} diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/userInterface/content/MarkDirectoryAsMagentoRootTest.kt b/src/test/kotlin/com/magento/idea/magento2plugin/userInterface/content/MarkDirectoryAsMagentoRootTest.kt deleted file mode 100644 index 938421cf7..000000000 --- a/src/test/kotlin/com/magento/idea/magento2plugin/userInterface/content/MarkDirectoryAsMagentoRootTest.kt +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.userInterface.content - -import com.automation.remarks.junit5.Video -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.stepsProcessing.step -import com.intellij.remoterobot.utils.keyboard -import com.intellij.remoterobot.utils.waitForIgnoringError -import com.magento.idea.magento2plugin.pages.* -import com.magento.idea.magento2plugin.steps.SharedSteps -import com.magento.idea.magento2plugin.utils.RemoteRobotExtension -import com.magento.idea.magento2plugin.utils.StepsLogger -import java.awt.event.KeyEvent.VK_A -import java.awt.event.KeyEvent.VK_CONTROL -import java.awt.event.KeyEvent.VK_DELETE -import java.time.Duration.ofMinutes -import org.assertj.swing.core.MouseButton -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import java.nio.file.Paths - -@ExtendWith(RemoteRobotExtension::class) -class MarkDirectoryAsMagentoRootTest { - init { - StepsLogger.init() - } - - @BeforeEach - fun waitForIde(remoteRobot: RemoteRobot) { - waitForIgnoringError(ofMinutes(3)) { remoteRobot.callJs("true") } - } - - @AfterEach - fun closeProject(remoteRobot: RemoteRobot) = with(remoteRobot) { - SharedSteps(remoteRobot).closeProject() - } - - @Test - @Video - fun testMarkDirectoryAsMagentoRoot(remoteRobot: RemoteRobot) = with(remoteRobot) { - SharedSteps(remoteRobot).createOrOpenTestProject() - - idea { - step("Create a new Plugin") { - with(projectViewTree) { - findText("vendor").doubleClick() - findText("module-catalog").doubleClick() - findText("Block").doubleClick() - findText("Navigation.php").doubleClick() - } - - createAPluginWithoutMagentoRootInVendor(this@idea, remoteRobot) - - with(projectViewTree) { - //add magento code to project - findText("magento").click(MouseButton.RIGHT_BUTTON) - contextMenu("Mark Directory as").click() - contextMenuItem("Sources Root").click() - - findText("module-catalog").click(MouseButton.RIGHT_BUTTON) - contextMenu("Mark Directory as").click() - contextMenuItem("Mark Directory As Magento Code Root").click() - } - - with(textEditor()) { - step("Create a new Plugin with marking as code root") { - Thread.sleep(1_000) - editor.findText("someMethod").click(MouseButton.RIGHT_BUTTON) - contextMenuItem("Create a new Plugin").click() - - createAPluginDialog { - step("Ensure target module includes 'Magento_Catalog'") { - pluginName.click() - pluginName.keyboard { - enterText("test_plugin") - } - className.click() - className.keyboard { - enterText("TestPlugin") - } - - targetModule.click() - targetModule.keyboard { - hotKey(VK_CONTROL, VK_A) // Select all text - key(VK_DELETE) // Delete selected text - enterText("Magento_Catalog") - button("OK").click() - } - } - } - } - } - - with(projectViewTree) { - findText("Plugin").doubleClick() - findText("TestPlugin.php").doubleClick() - } - - with(textEditor()) { - step("Check created files") { - editor.findText("beforeSomeMethod") - } - } - - with(projectViewTree) { - findText("module-catalog").click(MouseButton.RIGHT_BUTTON) - contextMenu("Mark Directory as").click() - contextMenuItem("Unmark Directory As Magento Code Root").click() - findText("Navigation.php").doubleClick() - } - - createAPluginWithoutMagentoRootInVendor(this@idea, remoteRobot) - } - } - } - - /** - * Creates a new plugin in a project without marking the target module as a Magento code root. - * - * @param ideaFrame - * @param remoteRobot - */ - private fun createAPluginWithoutMagentoRootInVendor( - ideaFrame: IdeaFrame, - remoteRobot1: RemoteRobot - ) { - with(ideaFrame.textEditor()) { - step("Create a new Plugin without marking as code root") { - Thread.sleep(1_000) - editor.findText("someMethod").click(MouseButton.RIGHT_BUTTON) - remoteRobot1.contextMenuItem("Create a new Plugin").click() - - remoteRobot1.createAPluginDialog { - step("Ensure target module does not include 'Magento_Catalog'") { - pluginName.click() - pluginName.keyboard { - enterText("test_plugin") - } - className.click() - className.keyboard { - enterText("TestPlugin") - } - - targetModule.click() - targetModule.keyboard { - hotKey(VK_CONTROL, VK_A) // Select all text - key(VK_DELETE) // Delete selected text - enterText("Magento_Catalog") - button("OK").click() - - errorDialog { - button("OK").click() - } - - button("Cancel").click() - } - } - } - } - } - } -} diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/utils/RemoteRobotExtension.kt b/src/test/kotlin/com/magento/idea/magento2plugin/utils/RemoteRobotExtension.kt deleted file mode 100644 index a38ae7228..000000000 --- a/src/test/kotlin/com/magento/idea/magento2plugin/utils/RemoteRobotExtension.kt +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.utils - -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.fixtures.ContainerFixture -import com.intellij.remoterobot.search.locators.byXpath -import okhttp3.OkHttpClient -import okhttp3.Request -import okhttp3.logging.HttpLoggingInterceptor -import org.junit.jupiter.api.extension.AfterTestExecutionCallback -import org.junit.jupiter.api.extension.ExtensionContext -import org.junit.jupiter.api.extension.ParameterContext -import org.junit.jupiter.api.extension.ParameterResolver -import java.awt.image.BufferedImage -import java.io.ByteArrayOutputStream -import java.io.File -import java.lang.IllegalStateException -import java.lang.reflect.Method -import javax.imageio.ImageIO - -class RemoteRobotExtension : AfterTestExecutionCallback, ParameterResolver { - private val url: String = System.getProperty("remote-robot-url") ?: "http://127.0.0.1:8082" - private val remoteRobot: RemoteRobot = if (System.getProperty("debug-retrofit")?.equals("enable") == true) { - val interceptor: HttpLoggingInterceptor = HttpLoggingInterceptor().apply { - this.level = HttpLoggingInterceptor.Level.BODY - } - val client = OkHttpClient.Builder().apply { - this.addInterceptor(interceptor) - }.build() - RemoteRobot(url, client) - } else { - RemoteRobot(url) - } - private val client = OkHttpClient() - - override fun supportsParameter(parameterContext: ParameterContext?, extensionContext: ExtensionContext?): Boolean { - return parameterContext?.parameter?.type?.equals(RemoteRobot::class.java) ?: false - } - - override fun resolveParameter(parameterContext: ParameterContext?, extensionContext: ExtensionContext?): Any { - return remoteRobot - } - - override fun afterTestExecution(context: ExtensionContext?) { - val testMethod: Method = context?.requiredTestMethod ?: throw IllegalStateException("test method is null") - val testMethodName = testMethod.name - val testFailed: Boolean = context.executionException?.isPresent ?: false - if (testFailed) { - saveScreenshot(testMethodName) - saveIdeaFrames(testMethodName) - saveHierarchy(testMethodName) - } - } - - private fun saveScreenshot(testName: String) { - fetchScreenShot().save(testName) - } - - private fun saveHierarchy(testName: String) { - val hierarchySnapshot = - saveFile(url, "build/reports", "hierarchy-$testName.html") - if (File("build/reports/styles.css").exists().not()) { - saveFile("$url/styles.css", "build/reports", "styles.css") - } - println("Hierarchy snapshot: ${hierarchySnapshot.absolutePath}") - } - - private fun saveFile(url: String, folder: String, name: String): File { - val response = client.newCall(Request.Builder().url(url).build()).execute() - return File(folder).apply { - mkdirs() - }.resolve(name).apply { - writeText(response.body.string()) - } - } - - private fun BufferedImage.save(name: String) { - val bytes = ByteArrayOutputStream().use { b -> - ImageIO.write(this, "png", b) - b.toByteArray() - } - File("build/reports").apply { mkdirs() }.resolve("$name.png").writeBytes(bytes) - } - - private fun saveIdeaFrames(testName: String) { - remoteRobot.findAll(byXpath("//div[@class='IdeFrameImpl']")).forEachIndexed { n, frame -> - val pic = try { - frame.callJs( - """ - importPackage(java.io) - importPackage(javax.imageio) - importPackage(java.awt.image) - const screenShot = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB); - component.paint(screenShot.getGraphics()) - let pictureBytes; - const baos = new ByteArrayOutputStream(); - try { - ImageIO.write(screenShot, "png", baos); - pictureBytes = baos.toByteArray(); - } finally { - baos.close(); - } - pictureBytes; - """, true - ) - } catch (e: Throwable) { - e.printStackTrace() - throw e - } - pic.inputStream().use { - ImageIO.read(it) - }.save(testName + "_" + n) - } - } - - private fun fetchScreenShot(): BufferedImage { - return remoteRobot.callJs( - """ - importPackage(java.io) - importPackage(javax.imageio) - const screenShot = new java.awt.Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); - let pictureBytes; - const baos = new ByteArrayOutputStream(); - try { - ImageIO.write(screenShot, "png", baos); - pictureBytes = baos.toByteArray(); - } finally { - baos.close(); - } - pictureBytes; - """ - ).inputStream().use { - ImageIO.read(it) - } - } -} - diff --git a/src/test/kotlin/com/magento/idea/magento2plugin/utils/StepsLogger.kt b/src/test/kotlin/com/magento/idea/magento2plugin/utils/StepsLogger.kt deleted file mode 100644 index 80fff7d58..000000000 --- a/src/test/kotlin/com/magento/idea/magento2plugin/utils/StepsLogger.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.utils - -import com.intellij.remoterobot.stepsProcessing.StepLogger -import com.intellij.remoterobot.stepsProcessing.StepWorker - -object StepsLogger { - private var initialized = false - @JvmStatic - fun init() { - if (initialized.not()) { - StepWorker.registerProcessor(StepLogger()) - initialized = true - } - } -} \ No newline at end of file From 7170c3f2e36b88ca54769853e82454b13cbd9c58 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sat, 2 Aug 2025 15:22:49 +0300 Subject: [PATCH 24/30] Fixed tests --- gradle/libs.versions.toml | 2 +- .../generation/generator/util/FileFromTemplateGenerator.java | 3 ++- .../idea/magento2plugin/magento/files/ModuleReadmeMdFile.java | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e1ec9ec04..cea49783e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,7 +4,7 @@ junit = "4.13.2" # plugins changelog = "2.2.1" -intelliJPlatform = "2.6.0" +intelliJPlatform = "2.7.0" kotlin = "2.1.0" kover = "0.8.3" qodana = "2024.2.3" diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/generator/util/FileFromTemplateGenerator.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/generator/util/FileFromTemplateGenerator.java index 7d59a65c8..9997f6446 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/generator/util/FileFromTemplateGenerator.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/generator/util/FileFromTemplateGenerator.java @@ -20,6 +20,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.util.IncorrectOperationException; import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; +import com.magento.idea.magento2plugin.magento.files.ModuleReadmeMdFile; import com.magento.idea.magento2plugin.magento.packages.File; import java.io.IOException; import java.util.List; @@ -161,7 +162,7 @@ public PsiFile createFileFromTemplate( false ); - if (fileTemplate.isReformatCode()) { + if (fileTemplate.isReformatCode() && !fileName.endsWith(ModuleReadmeMdFile.EXTENSION)) { CodeStyleManager.getInstance(project).reformat(file); } diff --git a/src/main/java/com/magento/idea/magento2plugin/magento/files/ModuleReadmeMdFile.java b/src/main/java/com/magento/idea/magento2plugin/magento/files/ModuleReadmeMdFile.java index cd0d27b8f..e02be525f 100644 --- a/src/main/java/com/magento/idea/magento2plugin/magento/files/ModuleReadmeMdFile.java +++ b/src/main/java/com/magento/idea/magento2plugin/magento/files/ModuleReadmeMdFile.java @@ -12,6 +12,7 @@ public class ModuleReadmeMdFile implements ModuleFileInterface { public static final String FILE_NAME = "README.md"; public static final String TEMPLATE = "Magento Module Readme File MD"; + public static final String EXTENSION = ".md"; @Override public String getFileName() { From aa7f733499270ddde42c90a141b89e89e4059ebc Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sat, 2 Aug 2025 15:27:02 +0300 Subject: [PATCH 25/30] Updated gradle.properties --- gradle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 0d4707a69..180322ed9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,11 +2,11 @@ pluginGroup = com.magento.idea.magento2plugin pluginName = Magento PhpStorm pluginRepositoryUrl = https://github.com/magento/magento2-phpstorm-plugin pluginVersion = 2025.2.0 -pluginSinceBuild = 251.* +pluginSinceBuild = 250.* pluginUntilBuild = 258.* platformType = PS -platformVersion = 252.18003.43 -platformPlugins = com.intellij.lang.jsgraphql:252.18003.27 +platformVersion = 2025.1.3 +platformPlugins = com.intellij.lang.jsgraphql:251.26927.39,org.jetbrains.junie:251.204.104 platformBundledPlugins = com.intellij.modules.json,com.jetbrains.php,JavaScript,com.intellij.copyright gradleVersion = 8.10.2 kotlin.stdlib.default.dependency = false From a4dfdd4fccaae3b7a8b1d005e822c7f2f381f841 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sat, 2 Aug 2025 15:42:08 +0300 Subject: [PATCH 26/30] Adjusted new entity dialog --- .../actions/generation/dialog/NewEntityDialog.java | 1 + .../generation/generator/util/FileFromTemplateGenerator.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 3375ba6f7..2cde1cd3f 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -384,6 +384,7 @@ protected void onWriteActionOK() { generatorPoolHandler.run(); onOkActionFired.setFinished(true); + exit(); } @Override diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/generator/util/FileFromTemplateGenerator.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/generator/util/FileFromTemplateGenerator.java index 9997f6446..92abcaf73 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/generator/util/FileFromTemplateGenerator.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/generator/util/FileFromTemplateGenerator.java @@ -150,7 +150,7 @@ public PsiFile createFileFromTemplate( fileTemplate = templateManager.getInstance(project).getCodeTemplate(templateName); } - Properties mergedProperties = new Properties(); + final Properties mergedProperties = new Properties(); mergedProperties.putAll(FileTemplateManager.getInstance(project).getDefaultProperties()); mergedProperties.putAll(properties); final String fileTemplateText = fileTemplate.getText(mergedProperties); From 632a103b007fc4aed64890db25a7fb4c8f4394f7 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sat, 2 Aug 2025 16:34:54 +0300 Subject: [PATCH 27/30] Adjusted new entity dialog --- gradle.properties | 2 +- .../magento2plugin/BaseProjectTestCase.java | 10 ++ .../magento2plugin/util/PhpBundleMocker.java | 101 ++++++++++++++++++ .../util/ResourceBundleMock.java | 47 ++++++++ 4 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java create mode 100644 src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java diff --git a/gradle.properties b/gradle.properties index 180322ed9..acb468e0e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ pluginVersion = 2025.2.0 pluginSinceBuild = 250.* pluginUntilBuild = 258.* platformType = PS -platformVersion = 2025.1.3 +platformVersion = 2025.1.4.1 platformPlugins = com.intellij.lang.jsgraphql:251.26927.39,org.jetbrains.junie:251.204.104 platformBundledPlugins = com.intellij.modules.json,com.jetbrains.php,JavaScript,com.intellij.copyright gradleVersion = 8.10.2 diff --git a/src/test/java/com/magento/idea/magento2plugin/BaseProjectTestCase.java b/src/test/java/com/magento/idea/magento2plugin/BaseProjectTestCase.java index 427237113..fb8da010d 100644 --- a/src/test/java/com/magento/idea/magento2plugin/BaseProjectTestCase.java +++ b/src/test/java/com/magento/idea/magento2plugin/BaseProjectTestCase.java @@ -12,6 +12,7 @@ import com.magento.idea.magento2plugin.indexes.IndexManager; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.project.Settings; +import com.magento.idea.magento2plugin.util.PhpBundleMocker; /** * Configure test environment with Magento 2 project. @@ -28,6 +29,15 @@ public void setUp() throws Exception { super.setUp(); copyMagento2ToTestProject(); enablePluginAndReindex(); + + // Mock the PhpBundle to avoid issues with missing message keys + try { + PhpBundleMocker.mockPhpBundle(); + } catch (Exception e) { + // Log the exception but continue with the test + System.err.println("Failed to mock PhpBundle: " + e.getMessage()); + e.printStackTrace(); + } } private void copyMagento2ToTestProject() { diff --git a/src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java b/src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java new file mode 100644 index 000000000..caf6b2b8e --- /dev/null +++ b/src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java @@ -0,0 +1,101 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.util; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Utility class for mocking the PhpBundle in tests. + * + * This class provides methods to set up a mock for the PhpBundle, + * which will return a fixed value for any key, avoiding the need for actual message keys in tests. + */ +public final class PhpBundleMocker { + + private static final String PHP_BUNDLE_NAME = "messages.PhpBundle"; + private static final String DEFAULT_MOCK_VALUE = "mocked value"; + + private PhpBundleMocker() { + // Private constructor to prevent instantiation + } + + /** + * Set up a mock for the PhpBundle that returns a fixed value for any key. + * + * @param mockValue The value to return for any key + * @throws Exception If an error occurs while setting up the mock + */ + public static void mockPhpBundle(final String mockValue) throws Exception { + // Create a mock bundle + final ResourceBundle mockBundle = new ResourceBundleMock(mockValue); + + // Clear the ResourceBundle cache to ensure our mock is used + clearResourceBundleCache(); + + // Install our custom ResourceBundle.Control that returns the mock bundle for PhpBundle + ResourceBundle.getBundle(PHP_BUNDLE_NAME, new ResourceBundle.Control() { + @Override + public ResourceBundle newBundle( + final String baseName, + final Locale locale, + final String format, + final ClassLoader loader, + final boolean reload + ) throws IllegalAccessException, InstantiationException, IOException { + if (PHP_BUNDLE_NAME.equals(baseName)) { + return mockBundle; + } + return super.newBundle(baseName, locale, format, loader, reload); + } + }); + } + + /** + * Set up a mock for the PhpBundle that returns "mocked value for [key]" for any key. + * + * @throws Exception If an error occurs while setting up the mock + */ + public static void mockPhpBundle() throws Exception { + mockPhpBundle(DEFAULT_MOCK_VALUE); + } + + /** + * Clear the ResourceBundle cache to ensure our mock is used. + * + * @throws Exception If an error occurs while clearing the cache + */ + private static void clearResourceBundleCache() throws Exception { + try { + // Get the cacheList field from ResourceBundle + final Field cacheListField = ResourceBundle.class.getDeclaredField("cacheList"); + cacheListField.setAccessible(true); + + // Get the cache map + final Map cacheList = (Map) cacheListField.get(null); + + // Clear the cache + cacheList.clear(); + } catch (final NoSuchFieldException e) { + // If cacheList field is not found, try the newer implementation (Java 9+) + try { + // Get the clearCache method + final Method clearCacheMethod = ResourceBundle.class.getDeclaredMethod("clearCache"); + clearCacheMethod.setAccessible(true); + + // Call the method to clear the cache + clearCacheMethod.invoke(null); + } catch (final NoSuchMethodException e2) { + throw new Exception("Failed to clear ResourceBundle cache", e2); + } + } + } +} \ No newline at end of file diff --git a/src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java b/src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java new file mode 100644 index 000000000..b816eff69 --- /dev/null +++ b/src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java @@ -0,0 +1,47 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.util; + +import java.util.Collections; +import java.util.Enumeration; +import java.util.ResourceBundle; + +/** + * Mock implementation of ResourceBundle for testing. + * + * This class provides a dummy ResourceBundle that returns a fixed value for any key, + * avoiding the need for actual message keys in tests. + */ +public class ResourceBundleMock extends ResourceBundle { + + private final String defaultValue; + + /** + * Constructor with default value. + * + * @param defaultValue String value to return for any key + */ + public ResourceBundleMock(final String defaultValue) { + this.defaultValue = defaultValue; + } + + /** + * Default constructor that returns the key as the value. + */ + public ResourceBundleMock() { + this.defaultValue = null; + } + + @Override + protected Object handleGetObject(final String key) { + return defaultValue != null ? defaultValue : "mocked value for " + key; + } + + @Override + public Enumeration getKeys() { + return Collections.emptyEnumeration(); + } +} \ No newline at end of file From 76b19318058e06c4fd1c00b468b1618dc3f44b1d Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sat, 2 Aug 2025 16:39:56 +0300 Subject: [PATCH 28/30] Static fixes --- .../magento/idea/magento2plugin/util/PhpBundleMocker.java | 5 +++-- .../magento/idea/magento2plugin/util/ResourceBundleMock.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java b/src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java index caf6b2b8e..1d6ba271f 100644 --- a/src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java +++ b/src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java @@ -15,7 +15,7 @@ /** * Utility class for mocking the PhpBundle in tests. - * + *

* This class provides methods to set up a mock for the PhpBundle, * which will return a fixed value for any key, avoiding the need for actual message keys in tests. */ @@ -88,7 +88,8 @@ private static void clearResourceBundleCache() throws Exception { // If cacheList field is not found, try the newer implementation (Java 9+) try { // Get the clearCache method - final Method clearCacheMethod = ResourceBundle.class.getDeclaredMethod("clearCache"); + final Method clearCacheMethod = + ResourceBundle.class.getDeclaredMethod("clearCache"); clearCacheMethod.setAccessible(true); // Call the method to clear the cache diff --git a/src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java b/src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java index b816eff69..0629d63fd 100644 --- a/src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java +++ b/src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java @@ -11,7 +11,7 @@ /** * Mock implementation of ResourceBundle for testing. - * + *

* This class provides a dummy ResourceBundle that returns a fixed value for any key, * avoiding the need for actual message keys in tests. */ From dfcb1992bc3b7348639ba0cdbd60e65b128f4d75 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sat, 2 Aug 2025 16:50:27 +0300 Subject: [PATCH 29/30] Static fixes 2 --- .../com/magento/idea/magento2plugin/util/PhpBundleMocker.java | 4 ++-- .../magento/idea/magento2plugin/util/ResourceBundleMock.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java b/src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java index 1d6ba271f..9f5ced3ad 100644 --- a/src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java +++ b/src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java @@ -15,8 +15,8 @@ /** * Utility class for mocking the PhpBundle in tests. - *

- * This class provides methods to set up a mock for the PhpBundle, + * + *

This class provides methods to set up a mock for the PhpBundle, * which will return a fixed value for any key, avoiding the need for actual message keys in tests. */ public final class PhpBundleMocker { diff --git a/src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java b/src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java index 0629d63fd..ea6a2afb6 100644 --- a/src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java +++ b/src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java @@ -11,8 +11,8 @@ /** * Mock implementation of ResourceBundle for testing. - *

- * This class provides a dummy ResourceBundle that returns a fixed value for any key, + * + *

This class provides a dummy ResourceBundle that returns a fixed value for any key, * avoiding the need for actual message keys in tests. */ public class ResourceBundleMock extends ResourceBundle { From 9e2dd923df73f4b519ae11756259459518a82db0 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sat, 2 Aug 2025 20:54:58 +0300 Subject: [PATCH 30/30] Removed mocker --- .../magento2plugin/BaseProjectTestCase.java | 10 -- .../magento2plugin/util/PhpBundleMocker.java | 102 ------------------ .../util/ResourceBundleMock.java | 47 -------- 3 files changed, 159 deletions(-) delete mode 100644 src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java delete mode 100644 src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java diff --git a/src/test/java/com/magento/idea/magento2plugin/BaseProjectTestCase.java b/src/test/java/com/magento/idea/magento2plugin/BaseProjectTestCase.java index fb8da010d..427237113 100644 --- a/src/test/java/com/magento/idea/magento2plugin/BaseProjectTestCase.java +++ b/src/test/java/com/magento/idea/magento2plugin/BaseProjectTestCase.java @@ -12,7 +12,6 @@ import com.magento.idea.magento2plugin.indexes.IndexManager; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.project.Settings; -import com.magento.idea.magento2plugin.util.PhpBundleMocker; /** * Configure test environment with Magento 2 project. @@ -29,15 +28,6 @@ public void setUp() throws Exception { super.setUp(); copyMagento2ToTestProject(); enablePluginAndReindex(); - - // Mock the PhpBundle to avoid issues with missing message keys - try { - PhpBundleMocker.mockPhpBundle(); - } catch (Exception e) { - // Log the exception but continue with the test - System.err.println("Failed to mock PhpBundle: " + e.getMessage()); - e.printStackTrace(); - } } private void copyMagento2ToTestProject() { diff --git a/src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java b/src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java deleted file mode 100644 index 9f5ced3ad..000000000 --- a/src/test/java/com/magento/idea/magento2plugin/util/PhpBundleMocker.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.util; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Utility class for mocking the PhpBundle in tests. - * - *

This class provides methods to set up a mock for the PhpBundle, - * which will return a fixed value for any key, avoiding the need for actual message keys in tests. - */ -public final class PhpBundleMocker { - - private static final String PHP_BUNDLE_NAME = "messages.PhpBundle"; - private static final String DEFAULT_MOCK_VALUE = "mocked value"; - - private PhpBundleMocker() { - // Private constructor to prevent instantiation - } - - /** - * Set up a mock for the PhpBundle that returns a fixed value for any key. - * - * @param mockValue The value to return for any key - * @throws Exception If an error occurs while setting up the mock - */ - public static void mockPhpBundle(final String mockValue) throws Exception { - // Create a mock bundle - final ResourceBundle mockBundle = new ResourceBundleMock(mockValue); - - // Clear the ResourceBundle cache to ensure our mock is used - clearResourceBundleCache(); - - // Install our custom ResourceBundle.Control that returns the mock bundle for PhpBundle - ResourceBundle.getBundle(PHP_BUNDLE_NAME, new ResourceBundle.Control() { - @Override - public ResourceBundle newBundle( - final String baseName, - final Locale locale, - final String format, - final ClassLoader loader, - final boolean reload - ) throws IllegalAccessException, InstantiationException, IOException { - if (PHP_BUNDLE_NAME.equals(baseName)) { - return mockBundle; - } - return super.newBundle(baseName, locale, format, loader, reload); - } - }); - } - - /** - * Set up a mock for the PhpBundle that returns "mocked value for [key]" for any key. - * - * @throws Exception If an error occurs while setting up the mock - */ - public static void mockPhpBundle() throws Exception { - mockPhpBundle(DEFAULT_MOCK_VALUE); - } - - /** - * Clear the ResourceBundle cache to ensure our mock is used. - * - * @throws Exception If an error occurs while clearing the cache - */ - private static void clearResourceBundleCache() throws Exception { - try { - // Get the cacheList field from ResourceBundle - final Field cacheListField = ResourceBundle.class.getDeclaredField("cacheList"); - cacheListField.setAccessible(true); - - // Get the cache map - final Map cacheList = (Map) cacheListField.get(null); - - // Clear the cache - cacheList.clear(); - } catch (final NoSuchFieldException e) { - // If cacheList field is not found, try the newer implementation (Java 9+) - try { - // Get the clearCache method - final Method clearCacheMethod = - ResourceBundle.class.getDeclaredMethod("clearCache"); - clearCacheMethod.setAccessible(true); - - // Call the method to clear the cache - clearCacheMethod.invoke(null); - } catch (final NoSuchMethodException e2) { - throw new Exception("Failed to clear ResourceBundle cache", e2); - } - } - } -} \ No newline at end of file diff --git a/src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java b/src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java deleted file mode 100644 index ea6a2afb6..000000000 --- a/src/test/java/com/magento/idea/magento2plugin/util/ResourceBundleMock.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.util; - -import java.util.Collections; -import java.util.Enumeration; -import java.util.ResourceBundle; - -/** - * Mock implementation of ResourceBundle for testing. - * - *

This class provides a dummy ResourceBundle that returns a fixed value for any key, - * avoiding the need for actual message keys in tests. - */ -public class ResourceBundleMock extends ResourceBundle { - - private final String defaultValue; - - /** - * Constructor with default value. - * - * @param defaultValue String value to return for any key - */ - public ResourceBundleMock(final String defaultValue) { - this.defaultValue = defaultValue; - } - - /** - * Default constructor that returns the key as the value. - */ - public ResourceBundleMock() { - this.defaultValue = null; - } - - @Override - protected Object handleGetObject(final String key) { - return defaultValue != null ? defaultValue : "mocked value for " + key; - } - - @Override - public Enumeration getKeys() { - return Collections.emptyEnumeration(); - } -} \ No newline at end of file