diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 9d7bb2fa4..d010e1390 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -111,12 +111,50 @@ 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" + + # 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 + + # 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: - 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/.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 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/build.gradle.kts b/build.gradle.kts index 3b80d81f5..8db0aa00c 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,9 @@ dependencies { bundledPlugins(providers.gradleProperty("platformBundledPlugins").map { it.split(',') }) plugins(providers.gradleProperty("platformPlugins").map { it.split(',') }) - plugin("com.intellij.lang.jsgraphql", "243.21565.122") pluginVerifier() zipSigner() testFramework(TestFrameworkType.Platform) - - phpstorm("2024.3") } } @@ -174,6 +172,8 @@ intellijPlatformTesting { "-Dide.mac.message.dialogs.as.sheets=false", "-Djb.privacy.policy.text=", "-Djb.consents.confirmation.enabled=false", + "-Deap.require.license=true", + "-Dide.show.tips.on.startup.default.value=false" ) } } 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/gradle.properties b/gradle.properties index c14a88efe..0d4707a69 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,12 +1,12 @@ pluginGroup = com.magento.idea.magento2plugin pluginName = Magento PhpStorm pluginRepositoryUrl = https://github.com/magento/magento2-phpstorm-plugin -pluginVersion = 2025.1.1 -pluginSinceBuild = 243.3 +pluginVersion = 2025.2.0 +pluginSinceBuild = 251.* pluginUntilBuild = 258.* platformType = PS -platformVersion = 2024.3 -platformPlugins = +platformVersion = 252.18003.43 +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 66ad4ce0f..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 = "1.9.25" +intelliJPlatform = "2.6.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/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/AbstractDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java index b2a9af39b..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 @@ -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; @@ -17,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; @@ -26,12 +27,11 @@ 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 +39,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,21 +50,54 @@ 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 + * @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) { - 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 + // This method is intentionally left with minimal implementation + // as it's deprecated and only kept for backward compatibility } + /** + * Create the center panel for the dialog. + * This method must be implemented by subclasses to provide the content panel. + * + * @return JComponent + */ + @Nullable + @Override + protected abstract JComponent createCenterPanel(); + /** * Default on cancel action. */ @@ -76,7 +109,7 @@ protected void onCancel() { * Right way to hide dialog window. */ protected void exit() { - dispose(); + close(CANCEL_EXIT_CODE); } /** @@ -102,6 +135,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. * @@ -113,8 +164,8 @@ protected final void onOK() { "PMD.CognitiveComplexity" }) protected boolean validateFormFields() { - boolean dialogHasErrors; - isValidationErrorShown = dialogHasErrors = false; + boolean dialogHasErrors = false; + isValidationErrorShown = false; clearValidationHighlighting(); for (final FieldValidationData fieldValidationData : getFieldsToValidate()) { @@ -217,11 +268,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 +352,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 +370,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 +380,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.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/CreateAPluginDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java index c727712c8..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,20 +28,15 @@ 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; @SuppressWarnings({ "PMD.TooManyFields", @@ -55,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; @@ -122,15 +115,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 +128,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 +245,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.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/CreateAnObserverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java index 63c06470d..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,8 +31,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", @@ -93,35 +90,17 @@ 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 - ); + // DialogWrapper handles button actions and ESC key automatically - addComponentListener(new FocusOnAFieldListener(() -> observerName.requestFocusInWindow())); + init(); } /** @@ -132,9 +111,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 +204,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.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/GatherArrayValuesDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java index df2746624..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 @@ -14,9 +14,6 @@ import com.magento.idea.magento2plugin.magento.packages.DiArgumentType; import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; 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; @@ -29,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 { @@ -43,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; @@ -61,38 +56,20 @@ 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(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically initTable(); itemsTableErrorMessage.setVisible(false); itemsTableErrorMessage.setText(""); + + init(); } /** @@ -106,9 +83,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.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/InjectAViewModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java index 316b6c8c7..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,19 +25,14 @@ 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; -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; @SuppressWarnings({ "PMD.ExcessiveImports" @@ -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 @@ -87,7 +80,7 @@ public InjectAViewModelDialog( final @NotNull Project project, final XmlTag targetBlockTag ) { - super(); + super(project); this.project = project; this.targetBlockTag = targetBlockTag; @@ -102,31 +95,11 @@ 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()); + // DialogWrapper handles button actions and ESC key automatically - 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 +178,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.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/NewArgumentInjectionDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.java index 7599dce4f..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,9 +48,9 @@ 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; @SuppressWarnings({ "PMD.TooManyFields", @@ -172,38 +169,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,16 +330,26 @@ 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; } /** * 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/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/NewBlockDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java index bde6a9a4a..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,26 +19,19 @@ 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 { 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 @@ -64,38 +57,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(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically - addComponentListener(new FocusOnAFieldListener(() -> blockName.requestFocusInWindow())); + init(); } /** @@ -106,9 +79,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.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/NewCLICommandDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java index b90199442..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,19 +24,15 @@ 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; @SuppressWarnings({"PMD.MissingSerialVersionUID", "PMD.ExcessiveImports"}) public class NewCLICommandDialog extends AbstractDialog { @@ -47,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}) @@ -92,37 +86,17 @@ 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 - ); + // DialogWrapper handles button actions and ESC key automatically - addComponentListener( - new FocusOnAFieldListener(() -> cliCommandClassNameField.requestFocusInWindow()) - ); + init(); } /** @@ -133,10 +107,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.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/NewCategoryEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCategoryEavAttributeDialog.java index 494e5c28e..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 @@ -8,34 +8,66 @@ 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; +/** + * 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 EavAttributeDialog { +public class NewCategoryEavAttributeDialog extends AbstractDialog { private static final String ENTITY_NAME = "Category"; + private final String moduleName; + private final Project project; + private final String actionName; + private TableGroupWrapper entityPropertiesTableGroupWrapper; + private final SourceModelData sourceModelData; + private JPanel contentPanel; private JButton buttonOK; private JButton buttonCancel; @@ -55,8 +87,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 +105,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 +116,257 @@ 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. + */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + 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. + */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + 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 of String to String + */ + protected Map getDefaultColumnsValues() { + return new HashMap<>(); + } + + /** + * Get columns sources. + * + * @return Map of String to List of String + */ + 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,111 +376,226 @@ protected void fillAttributeScopeComboBoxes() { } } - @Override - protected JPanel getContentPanel() { - 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 of Integer to String + */ + 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 of Integer to String + */ + 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. + * 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. + * + * @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()); } + /** + * Populate category entity data. + * + * @param categoryEntityData CategoryEntityData + * @return CategoryEntityData + */ private CategoryEntityData populateCategoryEntityData( final CategoryEntityData categoryEntityData ) { @@ -229,6 +607,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 +623,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(); } } 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/NewControllerDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java index 19a562284..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,15 @@ 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({ "PMD.TooManyFields", @@ -48,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; @@ -82,40 +75,18 @@ 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()); inheritClass.addActionListener(e -> toggleAdminPanel()); - buttonOK.addActionListener(e -> onOK()); - buttonCancel.addActionListener(e -> onCancel()); + // DialogWrapper handles button actions and ESC key automatically - // 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(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); - - addComponentListener( - new FocusOnAFieldListener(() -> controllerAreaSelect.requestFocusInWindow()) - ); + init(); } private String getModuleName() { @@ -193,9 +164,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.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/NewCronGroupDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java index 1a90b96f0..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,34 +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}) @@ -74,38 +69,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); - buttonOK.addActionListener(event -> onOK()); - buttonCancel.addActionListener(event -> onCancel()); + setTitle(NewCronGroupAction.ACTION_DESCRIPTION); + + // DialogWrapper handles button actions and ESC key automatically 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(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); - - addComponentListener( - new FocusOnAFieldListener(() -> cronGroupName.requestFocusInWindow()) - ); + init(); } /** @@ -136,9 +110,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.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/NewCronjobDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java index f2db9e980..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,8 +36,8 @@ 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; @SuppressWarnings({ "PMD.UncommentedEmptyMethodBody", @@ -62,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; @@ -129,19 +125,15 @@ 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); - buttonOK.addActionListener(e -> onOK()); - buttonCancel.addActionListener(e -> onCancel()); + // DialogWrapper handles button actions automatically fixedScheduleRadioButton.addActionListener(e -> { configurableSchedulePanel.setVisible(false); @@ -187,25 +179,9 @@ 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(); - } - }); + // DialogWrapper handles ESC key automatically - // call onCancel() on ESCAPE - contentPane.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); - - addComponentListener( - new FocusOnAFieldListener(() -> cronjobClassNameField.requestFocusInWindow()) - ); + init(); } /** @@ -216,9 +192,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() { @@ -274,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.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/NewCustomerEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java index 47da9a97b..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 @@ -9,36 +9,59 @@ 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.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", "PMD.ExcessiveImports", "PMD.TooManyMethods", - "PMD.UnusedPrivateField" + "PMD.UnusedPrivateField", + "PMD.GodClass" }) -public class NewCustomerEavAttributeDialog extends EavAttributeDialog { +public class NewCustomerEavAttributeDialog extends AbstractDialog { private static final String ENTITY_NAME = "Customer"; + private final String moduleName; + private final Project project; + private final String actionName; + private TableGroupWrapper entityPropertiesTableGroupWrapper; + private final 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,420 @@ 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 getContentPanel() { - 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. + */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + protected void fillAttributeTypeComboBox() { + if (typeComboBox == null) { + return; + } + + for (final AttributeType typeValue : AttributeType.values()) { + final String type = typeValue.getType(); + final ComboBoxItemData item = new ComboBoxItemData(type, type); + typeComboBox.addItem(item); + } } - @Override - protected JComboBox getAttributeTypeCompoBox() { - return typeComboBox; + /** + * Fill attribute input combo box. + */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + protected void fillAttributeInputComboBox() { + if (inputComboBox == null) { + return; + } + + for (final AttributeInput inputValue : AttributeInput.values()) { + final String input = inputValue.getInput(); + final ComboBoxItemData item = new ComboBoxItemData(input, input); + inputComboBox.addItem(item); + } } - @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 of String to String + */ + protected Map getDefaultColumnsValues() { + return new HashMap<>(); } - @Override - protected JButton getNewOptionButton() { - return addNewOptionButton; + /** + * Get columns sources. + * + * @return Map of String to List of String + */ + 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 of Integer to String + */ + protected Map getAttributeOptions( + final TableGroupWrapper entityPropertiesTableGroupWrapper + ) { + return GetAttributeOptionPropertiesUtil.getValues( + entityPropertiesTableGroupWrapper.getColumnsData() + ); + } + + /** + * Get attribute options sort orders. + * + * @param entityPropertiesTableGroupWrapper TableGroupWrapper + * @return Map of Integer to String + */ + 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 +526,77 @@ 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. + * 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 + */ + 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. + * + * @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( + /** + * 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( @@ -238,7 +605,17 @@ private CustomerEntityData populateCategoryEntityData( customerEntityData.setOptionsSortOrder( getAttributeOptionsSortOrders(entityPropertiesTableGroupWrapper) ); - customerEntityData.setUserDefined(userDefineCheckBox.isSelected()); + customerEntityData.setUserDefined( + userDefineCheckBox.isSelected() + ); + customerEntityData.setUsedInGrid( + useInGridCheckBox.isSelected() + ); + customerEntityData.setVisibleInGrid( + visibleInGridCheckBox.isSelected() + ); + customerEntityData.setFilterableInGrid(filterableInGridCheckBox.isSelected()); + customerEntityData.setSystem(systemAttributeCheckBox.isSelected()); customerEntityData.setUseInAdminhtmlCustomerForm( useInAdminhtmlCustomerCheckBox.isSelected() ); @@ -251,88 +628,21 @@ private CustomerEntityData populateCategoryEntityData( customerEntityData.setUseInCustomerAccountEditForm( useInCustomerAccountEditCheckBox.isSelected() ); - customerEntityData.setVisibleInGrid(visibleInGridCheckBox.isSelected()); - customerEntityData.setUsedInGrid(useInGridCheckBox.isSelected()); - customerEntityData.setFilterableInGrid(filterableInGridCheckBox.isSelected()); - customerEntityData.setSystem(systemAttributeCheckBox.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(); } } 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/NewDataModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java index 932aaa277..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,14 +41,15 @@ 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; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.ExcessiveImports", - "PMD.ConstructorCallsOverridableMethod" + "PMD.ConstructorCallsOverridableMethod", + "PMD.ImmutableField" }) public class NewDataModelDialog extends AbstractDialog { @@ -88,7 +85,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 +93,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 +119,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(); } /** @@ -161,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.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/NewDbSchemaDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java index bb048e498..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,8 +38,8 @@ 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; @SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) public class NewDbSchemaDialog extends AbstractDialog { @@ -53,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}) @@ -98,36 +91,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 +148,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.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 8ff41ca92..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,17 +22,15 @@ 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; import javax.swing.JTextField; import javax.swing.KeyStroke; +import org.jetbrains.annotations.Nullable; public class NewEmailTemplateDialog extends AbstractDialog { @@ -44,8 +42,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}) @@ -78,27 +74,12 @@ 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); - 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(); - } - }); + setTitle(NewEmailTemplateAction.ACTION_DESCRIPTION); // call onCancel() on ESCAPE contentPane.registerKeyboardAction( @@ -107,7 +88,7 @@ public void windowClosing(final WindowEvent windowEvent) { JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener(new FocusOnAFieldListener(() -> identifier.requestFocusInWindow())); + init(); } /** @@ -203,9 +184,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.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 6a068732b..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; @@ -85,6 +82,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", @@ -100,8 +98,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; @@ -227,35 +223,15 @@ 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 +265,8 @@ protected void textChanged(final @NotNull DocumentEvent event) { registerTabbedPane(tabbedPane1); sortOrder.setText(DEFAULT_MENU_SORT_ORDER); + + init(); } /** @@ -299,9 +277,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; } /** @@ -367,35 +355,11 @@ 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()) { - buttonOK.setEnabled(false); - buttonCancel.setEnabled(false); - - if (propertyTable.isEditing()) { - propertyTable.getCellEditor().stopCellEditing(); - } - - new ProcessWorker( - this::onOK, - this::releaseDialogAfterGeneration, - onOkActionFired - ).execute(); - } - } /** * Perform code generation using input data. */ protected void onWriteActionOK() { - setCursor(new Cursor(Cursor.WAIT_CURSOR)); - formatProperties(); final NewEntityDialogData dialogData = getNewEntityDialogData(); @@ -431,18 +395,6 @@ protected boolean validateFormFields() { return true; } - /** - * Release dialog buttons and hide. - */ - private void releaseDialogAfterGeneration() { - setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); - buttonCancel.setEnabled(true); - buttonOK.setEnabled(true); - - if (onOkActionFired.isFinished()) { - exit(); - } - } /** * Get entity creator context data. 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 13f467c98..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,25 +19,18 @@ 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; 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"; @@ -67,40 +60,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(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically - addComponentListener( - new FocusOnAFieldListener(() -> graphQlResolverClassName.requestFocusInWindow()) - ); + init(); } /** @@ -111,14 +82,19 @@ 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); + dialog.showDialog(); + } - // 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); - } + /** + * 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/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 a3275cc69..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; @@ -34,6 +32,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 { @@ -48,8 +47,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; @@ -86,31 +83,17 @@ 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 +103,7 @@ public void windowClosing(final WindowEvent event) { fillPredefinedValuesAndDisableInputs(); - addComponentListener(new FocusOnAFieldListener(() -> nameField.requestFocusInWindow())); + init(); } /** @@ -137,9 +120,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.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 8f76987b5..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,14 @@ 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({ "PMD.TooManyFields", @@ -37,7 +33,8 @@ "PMD.ConstructorCallsOverridableMethod", "PMD.ExcessiveImports", "PMD.SingularField", - "PMD.GodClass" + "PMD.GodClass", + "PMD.ImmutableField" }) public class NewLayoutTemplateDialog extends AbstractDialog { @@ -48,8 +45,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( @@ -72,37 +67,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 +86,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; } /** @@ -187,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.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/NewMessageQueueDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java index 99569c28c..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,19 +33,14 @@ 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; @SuppressWarnings({ "PMD.TooManyFields", @@ -137,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; @@ -170,38 +163,18 @@ 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); } - 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(), - 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 @@ -218,7 +191,7 @@ protected void textChanged(final @NotNull DocumentEvent event) { connectionName.addActionListener(e -> toggleConsumer()); - addComponentListener(new FocusOnAFieldListener(() -> topicName.requestFocusInWindow())); + init(); } private void toggleConsumer() { @@ -250,9 +223,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.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 b30c084a2..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; @@ -33,6 +30,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 { @@ -40,8 +38,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"; @@ -107,25 +103,11 @@ 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( @@ -141,7 +123,7 @@ protected void textChanged(final @NotNull DocumentEvent event) { } }); - addComponentListener(new FocusOnAFieldListener(() -> modelName.requestFocusInWindow())); + init(); } /** @@ -164,9 +146,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.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 48cb03485..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; @@ -50,6 +47,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", @@ -108,8 +106,6 @@ public class NewModuleDialog extends AbstractDialog implements ListSelectionList private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; private JCheckBox moduleReadmeMdCheckbox; @NotNull @@ -130,47 +126,27 @@ 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(); moduleLicenseCustom.setToolTipText("Custom License Name"); moduleLicenseCustom.setText(Settings.getDefaultLicenseName(project)); - 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 +337,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.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/NewObserverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java index 0c0fce903..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,24 +34,19 @@ 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; @SuppressWarnings({ "PMD.TooManyFields", @@ -68,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}) @@ -107,36 +100,16 @@ 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(), - 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") @@ -146,9 +119,7 @@ public void textChanged(final @NotNull DocumentEvent event) { } }); - addComponentListener( - new FocusOnAFieldListener(() -> className.requestFocusInWindow()) - ); + init(); } /** @@ -169,9 +140,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.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/NewProductEavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewProductEavAttributeDialog.java index faba8d9a1..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 @@ -9,40 +9,66 @@ 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", "PMD.ExcessiveImports", "PMD.TooManyMethods", - "PMD.UnusedPrivateField" + "PMD.UnusedPrivateField", + "PMD.GodClass" }) -public class NewProductEavAttributeDialog extends EavAttributeDialog { +public class NewProductEavAttributeDialog extends AbstractDialog { private static final String ENTITY_NAME = "Product"; + private final String moduleName; + private final Project project; + private final String actionName; + private TableGroupWrapper entityPropertiesTableGroupWrapper; + 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, @@ -108,17 +134,252 @@ 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(); + } + + + /** + * 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. + */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + protected void fillAttributeTypeComboBox() { + if (typeComboBox == null) { + return; + } + + for (final AttributeType typeValue : AttributeType.values()) { + final String type = typeValue.getType(); + final ComboBoxItemData item = new ComboBoxItemData(type, type); + typeComboBox.addItem(item); + } + } + + /** + * Fill attribute input combo box. + */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + protected void fillAttributeInputComboBox() { + if (inputComboBox == null) { + return; + } + + for (final AttributeInput inputValue : AttributeInput.values()) { + final String input = inputValue.getInput(); + final ComboBoxItemData item = new ComboBoxItemData(input, input); + inputComboBox.addItem(item); + } + } + + /** + * 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 of String to String + */ + protected Map getDefaultColumnsValues() { + return new HashMap<>(); + } + + /** + * Get columns sources. + * + * @return Map of String to List of String + */ + 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,248 @@ protected void fillAttributeScopeComboBoxes() { } } - @Override - protected JPanel getContentPanel() { - 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); + + final DefaultListModel listModel = new DefaultListModel<>(); + listModel.addAll(productTypes); + productsTypesList.setModel(listModel); + productsTypesList.setSelectedIndex(0); } - @Override - protected JButton getButtonCancel() { - return buttonCancel; + /** + * Get data patch name. + * + * @return String + */ + protected String getDataPatchName() { + return dataPatchNameTextField == null + ? "" : dataPatchNameTextField.getText().trim(); } - @Override - protected JComboBox getAttributeTypeCompoBox() { - return typeComboBox; + /** + * Get attribute code. + * + * @return String + */ + protected String getAttributeCode() { + return codeTextField == null + ? "" : codeTextField.getText().trim(); } - @Override - protected JComboBox getAttributeInputComboBox() { - return inputComboBox; + /** + * Get attribute label. + * + * @return String + */ + protected String getAttributeLabel() { + return labelTextField == null + ? "" : labelTextField.getText().trim(); } - @Override - protected JTable getOptionsTable() { - return optionsTable; + /** + * Get attribute sort order. + * + * @return int + */ + protected int getAttributeSortOrder() { + return sortOrderTextField == null + ? 0 : Integer.parseInt(sortOrderTextField.getText().trim()); } - @Override - protected JButton getNewOptionButton() { - return addNewOptionButton; + /** + * Is required attribute. + * + * @return boolean + */ + protected boolean isRequiredAttribute() { + return requiredCheckBox != null && requiredCheckBox.isSelected(); } - @Override - protected JComboBox getAttributeSourceComboBox() { - return sourceComboBox; + /** + * Is visible attribute. + * + * @return boolean + */ + protected boolean isVisibleAttribute() { + return visibleCheckBox != null && visibleCheckBox.isSelected(); } - @Override - protected JTextField getAttributeSourceModelNameTexField() { - return sourceModelNameTextField; + /** + * Get attribute backend type. + * + * @return String + */ + protected String getAttributeBackendType() { + return AttributeUtil.getBackendTypeBySelectedItem( + (ComboBoxItemData) typeComboBox.getSelectedItem() + ); } - @Override - protected JTextField getSourceModelDirectoryTextField() { - return sourceModelDirectoryTextField; + /** + * Get attribute input. + * + * @return String + */ + protected String getAttributeInput() { + return AttributeUtil.getInputTypeBySelectedItem( + (ComboBoxItemData) inputComboBox.getSelectedItem() + ); } - @Override - protected JPanel getAttributeCustomSourceModelPanel() { - return customSourceModelPanel; + /** + * Get attribute source. + * + * @param sourceModelData SourceModelData + * @return String + */ + protected String getAttributeSource(final SourceModelData sourceModelData) { + return AttributeUtil.getSourceClassBySelectedItem( + (ComboBoxItemData) sourceComboBox.getSelectedItem(), + sourceModelData + ); } - @Override - protected JPanel getAttributeOptionsPanel() { - return optionsPanel; + /** + * Get attribute options. + * + * @param entityPropertiesTableGroupWrapper TableGroupWrapper + * @return Map of Integer to String + */ + protected Map getAttributeOptions( + final TableGroupWrapper entityPropertiesTableGroupWrapper + ) { + return GetAttributeOptionPropertiesUtil.getValues( + entityPropertiesTableGroupWrapper.getColumnsData() + ); } - @Override - protected JTextField getAttributeCodeTextField() { - return codeTextField; + /** + * Get attribute options sort orders. + * + * @param entityPropertiesTableGroupWrapper TableGroupWrapper + * @return Map of Integer to String + */ + protected Map getAttributeOptionsSortOrders( + final TableGroupWrapper entityPropertiesTableGroupWrapper + ) { + return GetAttributeOptionPropertiesUtil.getSortOrders( + entityPropertiesTableGroupWrapper.getColumnsData() + ); } - @Override - protected JTextField getDataPatchNameTextField() { - return dataPatchNameTextField; + /** + * Stop options table editing. + */ + private void stopOptionsTableEditing() { + if (optionsTable != null && optionsTable.isEditing()) { + optionsTable.getCellEditor().stopCellEditing(); + } } - @Override - protected JTextField getSourceModelNameTextField() { - return sourceModelNameTextField; + /** + * 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 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. + * 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 + */ + 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. + * + * @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 +670,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/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/NewSetupDataPatchDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java index 9af505a39..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,12 @@ 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({ "PMD.ConstructorCallsOverridableMethod" @@ -64,40 +61,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()); + // DialogWrapper handles button actions and ESC key automatically - // 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 - ); - - addComponentListener(new FocusOnAFieldListener(() -> { - className.requestFocusInWindow(); - })); + init(); } /** @@ -115,9 +90,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.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 7327446ca..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; @@ -72,13 +68,15 @@ import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", "PMD.TooManyMethods", "PMD.ConstructorCallsOverridableMethod", "PMD.ExcessiveImports", - "PMD.GodClass" + "PMD.GodClass", + "PMD.ImmutableField" }) public class NewUiComponentFormDialog extends AbstractDialog { @@ -106,8 +104,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"}) @@ -218,29 +214,14 @@ 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(); @@ -248,12 +229,7 @@ public void windowClosing(final WindowEvent event) { // 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 +238,7 @@ public void actionPerformed(final ActionEvent event) { formAreaSelect.setEnabled(false); acl.setText(getModuleName() + "::manage"); - addComponentListener(new FocusOnAFieldListener(() -> formName.requestFocusInWindow())); + init(); } protected void initButtonsTable() { @@ -319,9 +295,7 @@ protected void initFieldSetsTable() { model.addRow(new Object[] {"", "", rowPosition + 10, DELETE_COLUMN}); }); model.addTableModelListener( - event -> { - initFieldsetsColumn(); - } + event -> initFieldsetsColumn() ); } @@ -418,9 +392,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.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 c4059f1ee..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; @@ -70,6 +67,7 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.TooManyFields", @@ -89,8 +87,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; @@ -212,30 +208,15 @@ 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(); - 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 +231,7 @@ public void windowClosing(final WindowEvent event) { dataProviderParentDirectory.setVisible(false); dataProviderParentDirectoryLabel.setVisible(false); - addComponentListener( - new FocusOnAFieldListener(() -> uiComponentName.requestFocusInWindow()) - ); + init(); } /** @@ -266,9 +245,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.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/NewViewModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java index 7072a4df3..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,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.Nullable; public class NewViewModelDialog extends AbstractDialog { @@ -42,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}) @@ -71,40 +64,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(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + // DialogWrapper handles button actions and ESC key automatically - addComponentListener( - new FocusOnAFieldListener(() -> viewModelName.requestFocusInWindow()) - ); + init(); } /** @@ -115,9 +86,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.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/NewWebApiDeclarationDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java index cf3bd8a36..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 @@ -20,18 +20,14 @@ 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 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.JTextField; -import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings("PMD.TooManyFields") public class NewWebApiDeclarationDialog extends AbstractDialog { @@ -44,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, @@ -80,40 +74,20 @@ 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(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + + // DialogWrapper handles button actions and ESC key automatically fillPredefinedValuesAndDisableInputs(); - addComponentListener(new FocusOnAFieldListener(() -> routeUrl.requestFocusInWindow())); + init(); } /** @@ -132,9 +106,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.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 55af630a2..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; @@ -42,6 +39,7 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "PMD.UnusedPrivateMethod", @@ -53,8 +51,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; @@ -96,7 +92,7 @@ public OverrideClassByAPreferenceDialog( final @NotNull Project project, final PhpClass targetClass ) { - super(); + super(project); this.project = project; this.targetClass = targetClass; @@ -104,10 +100,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); @@ -119,26 +112,13 @@ public OverrideClassByAPreferenceDialog( suggestPreferenceClassName(targetClass); suggestPreferenceDirectory(targetClass); - 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 +212,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/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 a69b60586..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,18 +19,14 @@ 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; public class OverrideLayoutInThemeDialog extends AbstractDialog { @@ -39,8 +35,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, @@ -59,38 +53,20 @@ 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()); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); - 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 - ); + // DialogWrapper handles ESC key automatically - addComponentListener(new FocusOnAFieldListener(() -> theme.requestFocusInWindow())); + init(); } /** @@ -102,9 +78,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.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 ef067ba34..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, @@ -57,14 +49,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); @@ -73,27 +62,22 @@ public OverrideTemplateInThemeDialog( } else if (OverridableFileType.isFileStyle(fileType)) { setTitle(OverrideTemplateInThemeAction.ACTION_STYLES_DESCRIPTION); } - getRootPane().setDefaultButton(buttonOK); - fillThemeOptions(); - buttonOK.addActionListener((final ActionEvent event) -> onOK()); - buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); + fillThemeOptions(); - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); + // DialogWrapper handles button actions and ESC key automatically - contentPane.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); + init(); + } - addComponentListener(new FocusOnAFieldListener(() -> theme.requestFocusInWindow())); + /** + * Create center panel. + * + * @return JComponent + */ + @Override + protected JComponent createCenterPanel() { + return contentPane; } /** @@ -105,9 +89,8 @@ public void windowClosing(final WindowEvent event) { 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.setVisible(true); + dialog.showDialog(); } protected void onWriteActionOK() { 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 ff6d4b899..000000000 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java +++ /dev/null @@ -1,520 +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; - -@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 getContentPanel(); - - 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(); - - this.project = project; - this.actionName = actionName; - this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); - this.sourceModelData = new SourceModelData(); - } - - /** - * Open dialog window. - */ - public void open() { - this.initBaseDialogState(); - pack(); - centerDialog(this); - setTitle(actionName); - setVisible(true); - } - - 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() { - setContentPane(this.getContentPanel()); - setModal(this.isModalWindow()); - getRootPane().setDefaultButton(this.getButtonOk()); - } - - 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() { - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent event) { - onCancel(); - } - }); - } - - protected void addCancelActionForEsc() { - getContentPanel().registerKeyboardAction( - event -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - ); - } - - 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/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/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/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 + ); } } 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 94f3fc123..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; @@ -70,30 +68,18 @@ 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); hasAdditionalPath.addActionListener(event -> refreshAdditionalFields(hasAdditionalPath.isSelected())); 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(), @@ -120,9 +106,18 @@ public void windowClosing(final WindowEvent event) { */ 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 + */ + @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 bff6e8507..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; @@ -49,34 +47,24 @@ 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(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); + + init(); } /** @@ -93,9 +81,18 @@ public static void open( project, directory ); - dialog.pack(); dialog.centerDialog(dialog); - dialog.setVisible(true); + dialog.showDialog(); + } + + /** + * Create center panel. + * + * @return JComponent + */ + @Override + protected JComponent createCenterPanel() { + return contentPanel; } /** diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 2011ea5f0..79979e9bc 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. - + @@ -110,7 +110,7 @@ - + @@ -711,4 +711,4 @@ - \ 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 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 3c7286ed0..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.* @@ -31,11 +30,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() + 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 +62,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 +97,20 @@ 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() + private fun enableMagentoSupport() { + Thread.sleep(7_000) - try { - Thread.sleep(10000) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - throw RuntimeException(e) - } - } else { - closeBrowser() + 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("Activate").click() - dialog.button("Close").click() + dialog.click() + dialog.keyboard { key(VK_ESCAPE) } + } catch (e: Exception) { + //do nothing } - } - private fun enableMagentoSupport() { remoteRobot.idea { step("Enable Magento Integration") { waitFor(ofMinutes(1)) { isDumbMode().not() } @@ -152,13 +129,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() } @@ -179,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 +}