From 3b0b1914ec95a7265d33c80e96e941d9bc43d5b8 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Tue, 21 Dec 2021 23:07:22 +0200 Subject: [PATCH 01/10] 873: Code refactoring --- .../generation/NewEmailTemplateAction.java | 7 +++--- .../dialog/NewEmailTemplateDialog.java | 25 ++++++++----------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/NewEmailTemplateAction.java b/src/com/magento/idea/magento2plugin/actions/generation/NewEmailTemplateAction.java index 78a99904b..ca7007625 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/NewEmailTemplateAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/NewEmailTemplateAction.java @@ -16,8 +16,8 @@ import com.magento.idea.magento2plugin.MagentoIcons; import com.magento.idea.magento2plugin.actions.generation.dialog.NewEmailTemplateDialog; -@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.FieldNamingConventions"}) public class NewEmailTemplateAction extends AnAction { + public static final String ACTION_NAME = "Magento 2 Email Template"; public static final String ACTION_DESCRIPTION = "Create a new Magento 2 email template"; @@ -36,17 +36,16 @@ public void actionPerformed(final AnActionEvent event) { if (view == null) { return; } - final Project project = CommonDataKeys.PROJECT.getData(dataContext); + if (project == null) { return; } - final PsiDirectory directory = view.getOrChooseDirectory(); + if (directory == null) { return; } - NewEmailTemplateDialog.open(project, directory); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java index 2ee468ebf..c12f14cb3 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java @@ -21,8 +21,6 @@ import com.magento.idea.magento2plugin.magento.packages.Areas; import com.magento.idea.magento2plugin.ui.FilteredComboBox; 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; @@ -36,15 +34,18 @@ import javax.swing.KeyStroke; public class NewEmailTemplateDialog extends AbstractDialog { - private final String moduleName; - private final Project project; - private final NewEmailTemplateDialogValidator validator; + private static final String EMAIL_TEMPLATE_ID = "id"; private static final String LABEL = "label"; private static final String FILENAME = "file name"; + + private final String moduleName; + 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}) @FieldValidation(rule = RuleRegistry.IDENTIFIER, @@ -58,6 +59,7 @@ public class NewEmailTemplateDialog extends AbstractDialog { @FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE, FILENAME}) private JTextField fileName; + private FilteredComboBox area; private FilteredComboBox templateType; private JTextField subject; @@ -83,6 +85,8 @@ public NewEmailTemplateDialog(final Project project, final PsiDirectory director // call onCancel() when cross is clicked setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { + + @Override public void windowClosing(final WindowEvent windowEvent) { onCancel(); } @@ -90,11 +94,7 @@ public void windowClosing(final WindowEvent windowEvent) { // call onCancel() on ESCAPE contentPane.registerKeyboardAction( - new ActionListener() { - public void actionPerformed(final ActionEvent actionEvent) { - onCancel(); - } - }, + actionEvent -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); @@ -230,11 +230,6 @@ private void generateFile() { xmlGenerator.generate(NewEmailTemplateAction.ACTION_NAME, true); } - protected void onCancel() { - // add your code here if necessary - dispose(); - } - @SuppressWarnings({"PMD.UnusedPrivateMethod"}) private void createUIComponents() { this.area = new FilteredComboBox(getAreaList()); From 8e92c6388303d95422ee39e2743bf742afcafa77 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Tue, 21 Dec 2021 23:16:05 +0200 Subject: [PATCH 02/10] 873: Enhanced error outputting for new Magento 2 email template generation --- .../dialog/NewEmailTemplateDialog.form | 52 ++++++++++++++----- .../dialog/NewEmailTemplateDialog.java | 9 +++- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.form index 1c074587b..411ec0e9d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.form @@ -3,9 +3,11 @@ - + - + + + @@ -49,7 +51,7 @@ - + @@ -75,7 +77,7 @@ - + @@ -83,7 +85,7 @@ - + @@ -91,7 +93,7 @@ - + @@ -99,7 +101,7 @@ - + @@ -107,7 +109,7 @@ - + @@ -115,7 +117,7 @@ - + @@ -123,7 +125,7 @@ - + @@ -134,7 +136,7 @@ - + @@ -145,7 +147,7 @@ - + @@ -153,12 +155,36 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java index c12f14cb3..461f3588f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java @@ -29,6 +29,7 @@ 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; @@ -51,9 +52,11 @@ public class NewEmailTemplateDialog extends AbstractDialog { @FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE, EMAIL_TEMPLATE_ID}) private JTextField identifier; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, LABEL}) private JTextField label; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, FILENAME}) @FieldValidation(rule = RuleRegistry.IDENTIFIER, @@ -64,6 +67,10 @@ public class NewEmailTemplateDialog extends AbstractDialog { private FilteredComboBox templateType; private JTextField subject; + private JLabel identifierErrorMessage;//NOPMD + private JLabel labelErrorMessage;//NOPMD + private JLabel fileNameErrorMessage;//NOPMD + /** * New email template dialog. * @@ -208,11 +215,9 @@ private void onOK() { final boolean emailTemplateCanBeDeclared = !this.validator.validate(this); if (!validateFormFields() || emailTemplateCanBeDeclared) { - exit(); return; } generateFile(); - exit(); } From 457429ae3412f6537c5c0c13e6fbffa2e668581d Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Tue, 21 Dec 2021 23:20:59 +0200 Subject: [PATCH 03/10] 874: Code refactoring --- .../actions/generation/NewModelsAction.java | 6 +++--- .../actions/generation/dialog/NewModelsDialog.java | 8 ++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/NewModelsAction.java b/src/com/magento/idea/magento2plugin/actions/generation/NewModelsAction.java index e9034f882..1567d41eb 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/NewModelsAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/NewModelsAction.java @@ -17,6 +17,7 @@ import com.magento.idea.magento2plugin.actions.generation.dialog.NewModelsDialog; public class NewModelsAction extends AnAction { + public static final String ACTION_NAME = "Magento 2 Models"; public static final String ACTION_DESCRIPTION = "Create a new Magento 2 models"; @@ -35,17 +36,16 @@ public void actionPerformed(final AnActionEvent event) { if (view == null) { return; } - final Project project = CommonDataKeys.PROJECT.getData(dataContext); + if (project == null) { return; } - final PsiDirectory directory = view.getOrChooseDirectory(); + if (directory == null) { return; } - NewModelsDialog.open(project, directory); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java index 518522798..e16df74a7 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java @@ -35,6 +35,7 @@ @SuppressWarnings("PMD.TooManyFields") public class NewModelsDialog extends AbstractDialog { + private final String moduleName; private final Project project; private JPanel contentPane; @@ -160,11 +161,6 @@ public static void open( dialog.setVisible(true); } - @Override - protected void onCancel() { - dispose(); - } - /** * Process generation. */ @@ -173,8 +169,8 @@ private void onOK() { generateModelFile(); generateResourceModelFile(); generateCollectionFile(); + exit(); } - exit(); } /** From e83ab093d2cb161345ca56ab0f6d8562b63dabc2 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Tue, 21 Dec 2021 23:26:06 +0200 Subject: [PATCH 04/10] 874: Enhanced error outputting for new Magento 2 models generation --- .../generation/dialog/NewModelsDialog.form | 74 +++++++++++++++---- .../generation/dialog/NewModelsDialog.java | 6 ++ 2 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.form index ec6e68d88..da7a3a909 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.form @@ -3,10 +3,10 @@ - + - + @@ -51,7 +51,7 @@ - + @@ -77,7 +77,7 @@ - + @@ -85,7 +85,7 @@ - + @@ -93,7 +93,7 @@ - + @@ -101,7 +101,7 @@ - + @@ -109,7 +109,7 @@ - + @@ -119,7 +119,7 @@ - + @@ -127,7 +127,7 @@ - + @@ -137,7 +137,7 @@ - + @@ -145,7 +145,7 @@ - + @@ -155,12 +155,60 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java index e16df74a7..ca47d35b7 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java @@ -92,6 +92,12 @@ public class NewModelsDialog extends AbstractDialog { private JLabel entityIdColumnLabel;//NOPMD private JLabel collectionDirectoryLabel;//NOPMD private JLabel collectionNameLabel;//NOPMD + private JLabel modelNameErrorMessage;//NOPMD + private JLabel resourceModelNameErrorMessage;//NOPMD + private JLabel dbTableNameErrorMessage;//NOPMD + private JLabel entityIdColumnErrorMessage;//NOPMD + private JLabel collectionDirectoryErrorMessage;//NOPMD + private JLabel collectionNameErrorMessage;//NOPMD /** * Open new dialog for adding new controller. From 58d6269fbe5e54cd2d9db88a9cd7e9927c34859b Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 22 Dec 2021 17:40:51 +0200 Subject: [PATCH 05/10] 875: Code refactoring --- .../generation/NewDataModelAction.java | 10 +++--- .../generation/dialog/NewDataModelDialog.java | 36 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/NewDataModelAction.java b/src/com/magento/idea/magento2plugin/actions/generation/NewDataModelAction.java index e15ff1551..cd3393b26 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/NewDataModelAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/NewDataModelAction.java @@ -18,6 +18,7 @@ import org.jetbrains.annotations.NotNull; public class NewDataModelAction extends AnAction { + public static final String ACTION_NAME = "Magento 2 Data Model"; public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Data Model"; @@ -29,24 +30,23 @@ public NewDataModelAction() { } @Override - public void actionPerformed(@NotNull final AnActionEvent event) { + 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; } - NewDataModelDialog.open(project, directory); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java index 040572b21..d9389495b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java @@ -47,24 +47,25 @@ import javax.swing.KeyStroke; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; +import org.jetbrains.annotations.NotNull; @SuppressWarnings({ "PMD.ExcessiveImports" }) public class NewDataModelDialog extends AbstractDialog { - private final Project project; - private final String moduleName; - private final ValidatorBundle validatorBundle; - private final CommonBundle commonBundle; - private final List properties; - private static final String MODEL_NAME = "Model Name"; private static final String PROPERTY_NAME = "Name"; private static final String PROPERTY_TYPE = "Type"; private static final String PROPERTY_ACTION = "Action"; private static final String PROPERTY_DELETE = "Delete"; + private final Project project; + private final String moduleName; + private final ValidatorBundle validatorBundle; + private final CommonBundle commonBundle; + private final List properties; + private JPanel contentPanel; private JButton buttonOK; private JButton buttonCancel; @@ -72,16 +73,17 @@ public class NewDataModelDialog extends AbstractDialog { private JButton addProperty; private JCheckBox createInterface; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, MODEL_NAME}) - @FieldValidation(rule = RuleRegistry.PHP_CLASS, - message = {PhpClassRule.MESSAGE, MODEL_NAME}) + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, MODEL_NAME}) + @FieldValidation(rule = RuleRegistry.PHP_CLASS, message = {PhpClassRule.MESSAGE, MODEL_NAME}) private JTextField modelName; /** * Constructor. */ - public NewDataModelDialog(final Project project, final PsiDirectory directory) { + public NewDataModelDialog( + final @NotNull Project project, + final @NotNull PsiDirectory directory + ) { super(); this.project = project; @@ -122,7 +124,10 @@ public void windowClosing(final WindowEvent event) { /** * Opens the dialog window. */ - public static void open(final Project project, final PsiDirectory directory) { + public static void open( + final @NotNull Project project, + final @NotNull PsiDirectory directory + ) { final NewDataModelDialog dialog = new NewDataModelDialog(project, directory); dialog.pack(); dialog.centerDialog(dialog); @@ -145,8 +150,8 @@ private void onOK() { generateDataModelInterfaceFile(); generatePreferenceForInterface(); } + exit(); } - exit(); } @Override @@ -190,11 +195,6 @@ protected boolean validateFormFields() { return valid; } - @Override - public void onCancel() { - dispose(); - } - /** * Generate DTO interface file. */ From cc135f0601f7076754905cb3646e4c23881c72ed Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 22 Dec 2021 17:50:24 +0200 Subject: [PATCH 06/10] 875: Enhanced error outputting for new Magento 2 data model generation --- resources/magento2/validation.properties | 1 + .../generation/dialog/NewDataModelDialog.form | 10 +++++++++- .../generation/dialog/NewDataModelDialog.java | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/resources/magento2/validation.properties b/resources/magento2/validation.properties index 9e7a095d5..b868b58fb 100644 --- a/resources/magento2/validation.properties +++ b/resources/magento2/validation.properties @@ -1,6 +1,7 @@ validator.notEmpty=The {0} field must not be empty validator.box.notEmpty=The {0} field must contain a valid selection from the dropdown validator.package.validPath=Please specify a valid Magento 2 installation path +validator.properties.notEmpty=The properties must not be empty validator.alphaNumericCharacters=The {0} field must contain letters and numbers only validator.alphaNumericAndUnderscoreCharacters={0} must contain letters, numbers and underscores only validator.alphaAndPeriodCharacters=The {0} field must contain alphabets and periods only diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.form index 9d58d7228..b9b2cb84b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.form @@ -10,7 +10,7 @@ - + @@ -36,6 +36,14 @@ + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java index d9389495b..1c907d7a9 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java @@ -40,6 +40,7 @@ import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComponent; +import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTable; @@ -77,6 +78,8 @@ public class NewDataModelDialog extends AbstractDialog { @FieldValidation(rule = RuleRegistry.PHP_CLASS, message = {PhpClassRule.MESSAGE, MODEL_NAME}) private JTextField modelName; + private JLabel modelNameErrorMessage;//NOPMD + /** * Constructor. */ @@ -162,6 +165,17 @@ protected boolean validateFormFields() { valid = true; final String errorTitle = commonBundle.message("common.error"); final int column = 0; + + if (propertyTable.getRowCount() == 0) { + valid = false; + JOptionPane.showMessageDialog( + null, + validatorBundle.message("validator.properties.notEmpty"), + errorTitle, + JOptionPane.ERROR_MESSAGE + ); + } + for (int row = 0; row < propertyTable.getRowCount(); row++) { final String propertyName = ((String) propertyTable.getValueAt(row, column)).trim(); if (propertyName.isEmpty()) { From 533e98c786598ae63933793a3563f9d48d00beb0 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 22 Dec 2021 17:58:10 +0200 Subject: [PATCH 07/10] 876: Code refactoring --- .../generation/NewMessageQueueAction.java | 10 +++---- .../dialog/NewMessageQueueDialog.java | 29 ++++++++++++------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/NewMessageQueueAction.java b/src/com/magento/idea/magento2plugin/actions/generation/NewMessageQueueAction.java index d562f076a..f66d9f1d0 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/NewMessageQueueAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/NewMessageQueueAction.java @@ -18,6 +18,7 @@ import org.jetbrains.annotations.NotNull; public class NewMessageQueueAction extends AnAction { + public static final String ACTION_NAME = "Magento 2 Message Queue"; public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Message Queue"; @@ -29,24 +30,23 @@ public NewMessageQueueAction() { } @Override - public void actionPerformed(@NotNull final AnActionEvent event) { + 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; } - NewMessageQueueDialog.open(project, directory); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java index e7954d2c5..e246e2cac 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java @@ -52,6 +52,7 @@ "PMD.ExcessiveImports", }) public class NewMessageQueueDialog extends AbstractDialog { + private static final String TOPIC_NAME = "Topic Name"; private static final String HANDLER_NAME = "Handler Name"; private static final String HANDLER_TYPE = "Handler Type"; @@ -64,6 +65,8 @@ public class NewMessageQueueDialog extends AbstractDialog { private static final String BINDING_TOPIC = "Binding Topic"; private JComboBox connectionName; + private final Project project; + private final String moduleName; /* TODO: Improve validation */ @FieldValidation(rule = RuleRegistry.NOT_EMPTY, @@ -146,13 +149,16 @@ public class NewMessageQueueDialog extends AbstractDialog { private JLabel consumerNameLabel;//NOPMD private JLabel handlerDirectoryLabel;//NOPMD - private final Project project; - private final String moduleName; - /** * Constructor. + * + * @param project Project + * @param directory PsiDirectory */ - public NewMessageQueueDialog(final Project project, final PsiDirectory directory) { + public NewMessageQueueDialog( + final @NotNull Project project, + final @NotNull PsiDirectory directory + ) { super(); this.project = project; @@ -224,19 +230,20 @@ private void toggleConsumer() { /** * Opens the dialog window. + * + * @param project Project + * @param directory PsiDirectory */ - public static void open(final Project project, final PsiDirectory directory) { + public static void open( + final @NotNull Project project, + final @NotNull PsiDirectory directory + ) { final NewMessageQueueDialog dialog = new NewMessageQueueDialog(project, directory); dialog.pack(); dialog.centerDialog(dialog); dialog.setVisible(true); } - @Override - public void onCancel() { - dispose(); - } - private void onOK() { if (validateFormFields()) { generateCommunication(); @@ -248,8 +255,8 @@ private void onOK() { if (getConnectionName().equals(MessageQueueConnections.DB.getType())) { generateConsumerClass(); } + exit(); } - exit(); } private void generateCommunication() { From 01738e9f84d3f8029e564d8e90db587f7b4fffdf Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 22 Dec 2021 20:51:13 +0200 Subject: [PATCH 08/10] 876: Enhanced error outputting for new Magento 2 message queue generation --- .../dialog/NewMessageQueueDialog.form | 143 +++++++++++++++--- .../dialog/NewMessageQueueDialog.java | 55 ++++--- 2 files changed, 153 insertions(+), 45 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form index ab56c7f34..13e9efda6 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form @@ -7,11 +7,12 @@ + - + @@ -21,7 +22,7 @@ - + @@ -32,7 +33,7 @@ - + @@ -44,7 +45,7 @@ - + @@ -53,7 +54,7 @@ - + @@ -63,7 +64,7 @@ - + @@ -71,7 +72,7 @@ - + @@ -103,7 +104,7 @@ - + @@ -113,7 +114,7 @@ - + @@ -121,7 +122,7 @@ - + @@ -129,7 +130,7 @@ - + @@ -139,7 +140,7 @@ - + @@ -147,7 +148,7 @@ - + @@ -155,7 +156,7 @@ - + @@ -163,12 +164,76 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -212,7 +277,7 @@ - + @@ -222,7 +287,7 @@ - + @@ -232,7 +297,7 @@ - + @@ -240,7 +305,7 @@ - + @@ -253,7 +318,7 @@ - + @@ -270,7 +335,7 @@ - + @@ -280,7 +345,7 @@ - + @@ -288,7 +353,7 @@ - + @@ -312,6 +377,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java index e246e2cac..816079a41 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java @@ -19,6 +19,7 @@ import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphaWithDashRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphaWithPeriodRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphanumericWithUnderscoreRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule; 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.dialog.validator.rule.NumericRule; @@ -55,10 +56,12 @@ public class NewMessageQueueDialog extends AbstractDialog { private static final String TOPIC_NAME = "Topic Name"; private static final String HANDLER_NAME = "Handler Name"; - private static final String HANDLER_TYPE = "Handler Type"; + private static final String HANDLER_TYPE = "Handler Class"; + private static final String HANDLER_DIR = "Handler Directory"; private static final String CONSUMER_NAME = "Consumer Name"; private static final String QUEUE_NAME = "Queue Name"; - private static final String CONSUMER_TYPE = "Consumer Type"; + private static final String CONSUMER_TYPE = "Consumer Class"; + private static final String CONSUMER_DIR = "Consumer Directory"; private static final String MAX_MESSAGES = "Maximum Messages"; private static final String EXCHANGE_NAME = "Exchange Name"; private static final String BINDING_ID = "Binding ID"; @@ -69,22 +72,18 @@ public class NewMessageQueueDialog extends AbstractDialog { private final String moduleName; /* TODO: Improve validation */ - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, TOPIC_NAME}) + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, TOPIC_NAME}) @FieldValidation(rule = RuleRegistry.ALPHA_WITH_PERIOD, message = {AlphaWithPeriodRule.MESSAGE, TOPIC_NAME}) - @FieldValidation(rule = RuleRegistry.LOWERCASE, - message = {Lowercase.MESSAGE, TOPIC_NAME}) + @FieldValidation(rule = RuleRegistry.LOWERCASE, message = {Lowercase.MESSAGE, TOPIC_NAME}) private JTextField topicName; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, HANDLER_NAME}) + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, HANDLER_NAME}) @FieldValidation(rule = RuleRegistry.ALPHA_WITH_PERIOD, message = {AlphanumericWithUnderscoreRule.MESSAGE, HANDLER_NAME}) private JTextField handlerName; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, HANDLER_TYPE}) + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, HANDLER_TYPE}) @FieldValidation(rule = RuleRegistry.PHP_CLASS, message = {PhpClassFqnRule.MESSAGE, HANDLER_TYPE}) private JTextField handlerClass; @@ -93,16 +92,13 @@ public class NewMessageQueueDialog extends AbstractDialog { message = {NotEmptyRule.MESSAGE, CONSUMER_NAME}) @FieldValidation(rule = RuleRegistry.ALPHA_WITH_PERIOD, message = {AlphaWithPeriodRule.MESSAGE, CONSUMER_NAME}) - @FieldValidation(rule = RuleRegistry.LOWERCASE, - message = {Lowercase.MESSAGE, CONSUMER_NAME}) + @FieldValidation(rule = RuleRegistry.LOWERCASE, message = {Lowercase.MESSAGE, CONSUMER_NAME}) private JTextField consumerName; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, QUEUE_NAME}) + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, QUEUE_NAME}) @FieldValidation(rule = RuleRegistry.ALPHA_WITH_PERIOD, message = {AlphaWithPeriodRule.MESSAGE, QUEUE_NAME}) - @FieldValidation(rule = RuleRegistry.LOWERCASE, - message = {Lowercase.MESSAGE, QUEUE_NAME}) + @FieldValidation(rule = RuleRegistry.LOWERCASE, message = {Lowercase.MESSAGE, QUEUE_NAME}) private JTextField queueName; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, @@ -111,10 +107,8 @@ public class NewMessageQueueDialog extends AbstractDialog { message = {PhpClassFqnRule.MESSAGE, CONSUMER_TYPE}) private JTextField consumerClass; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, MAX_MESSAGES}) - @FieldValidation(rule = RuleRegistry.NUMERIC, - message = {NumericRule.MESSAGE, MAX_MESSAGES}) + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, MAX_MESSAGES}) + @FieldValidation(rule = RuleRegistry.NUMERIC, message = {NumericRule.MESSAGE, MAX_MESSAGES}) private JTextField maxMessages; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, @@ -123,8 +117,7 @@ public class NewMessageQueueDialog extends AbstractDialog { message = {AlphaWithDashRule.MESSAGE, EXCHANGE_NAME}) private JTextField exchangeName; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, BINDING_ID}) + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, BINDING_ID}) @FieldValidation(rule = RuleRegistry.ALPHANUMERIC_WITH_UNDERSCORE, message = {AlphaWithDashRule.MESSAGE, BINDING_ID}) private JTextField bindingId; @@ -135,7 +128,12 @@ public class NewMessageQueueDialog extends AbstractDialog { message = {AlphanumericWithUnderscoreRule.MESSAGE, BINDING_TOPIC}) private JTextField bindingTopic; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, CONSUMER_DIR}) + @FieldValidation(rule = RuleRegistry.DIRECTORY, message = {DirectoryRule.MESSAGE, CONSUMER_DIR}) private JTextField consumerDirectory; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, HANDLER_DIR}) + @FieldValidation(rule = RuleRegistry.DIRECTORY, message = {DirectoryRule.MESSAGE, HANDLER_DIR}) private JTextField handlerDirectory; private JPanel contentPanel; @@ -149,6 +147,19 @@ public class NewMessageQueueDialog extends AbstractDialog { private JLabel consumerNameLabel;//NOPMD private JLabel handlerDirectoryLabel;//NOPMD + private JLabel topicNameErrorMessage;//NOPMD + private JLabel handlerNameErrorMessage;//NOPMD + private JLabel handlerClassErrorMessage;//NOPMD + private JLabel consumerNameErrorMessage;//NOPMD + private JLabel queueNameErrorMessage;//NOPMD + private JLabel consumerClassErrorMessage;//NOPMD + private JLabel maxMessagesErrorMessage;//NOPMD + private JLabel exchangeNameErrorMessage;//NOPMD + private JLabel bindingIdErrorMessage;//NOPMD + private JLabel bindingTopicErrorMessage;//NOPMD + private JLabel consumerDirectoryErrorMessage;//NOPMD + private JLabel handlerDirectoryErrorMessage;//NOPMD + /** * Constructor. * From d890d835dc43ebe7c0e1d027ca0f89c3d6a04828 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 23 Dec 2021 09:31:16 +0200 Subject: [PATCH 09/10] 877: Code refactoring --- .../actions/generation/NewDbSchemaAction.java | 6 ++++-- .../actions/generation/dialog/NewDbSchemaDialog.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/NewDbSchemaAction.java b/src/com/magento/idea/magento2plugin/actions/generation/NewDbSchemaAction.java index f2a76930f..ee2997166 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/NewDbSchemaAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/NewDbSchemaAction.java @@ -18,6 +18,7 @@ import org.jetbrains.annotations.NotNull; public class NewDbSchemaAction extends AnAction { + public static final String ACTION_NAME = "Magento 2 Declarative Schema XML"; public static final String ACTION_DESCRIPTION = "Create a new declarative schema XML"; @@ -32,16 +33,17 @@ public NewDbSchemaAction() { 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; } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java index f48820135..00bf34911 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java @@ -150,8 +150,8 @@ private void onOK() { return; } generateWhitelistJsonFile(dbSchemaXmlData); + exit(); } - exit(); } /** From 63ef611d2f4fc57c9d890c8b444283a2a502301b Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 23 Dec 2021 09:35:18 +0200 Subject: [PATCH 10/10] 877: Enhanced error outputting for new Magento 2 db schema generation --- .../generation/dialog/NewDbSchemaDialog.form | 18 +++++++++++++----- .../generation/dialog/NewDbSchemaDialog.java | 2 ++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.form index 7c48e7d9b..78ac30fdd 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.form @@ -56,7 +56,7 @@ - + @@ -92,7 +92,7 @@ - + @@ -101,7 +101,7 @@ - + @@ -110,7 +110,7 @@ - + @@ -118,7 +118,7 @@ - + @@ -128,6 +128,14 @@ + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java index 00bf34911..020b17443 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java @@ -46,6 +46,7 @@ @SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) public class NewDbSchemaDialog extends AbstractDialog { + private static final String TABLE_NAME = "Table Name"; private final Project project; @@ -85,6 +86,7 @@ public class NewDbSchemaDialog extends AbstractDialog { private JLabel tableResourceLabel;//NOPMD private JLabel tableCommentLabel;//NOPMD private JLabel tableColumnsLabel;//NOPMD + private JLabel tableNameErrorMessage;//NOPMD /** * Constructor.