From 11606af2f6ad0d2e18fc5549b114dbbe4ee54203 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Fri, 4 Mar 2022 19:18:32 +0200 Subject: [PATCH 1/2] 1023: Added additional fields for UCT configuration dialog --- .../settings/UctSettingsService.java | 42 ++++++++++++ .../magento2uct/ui/ConfigurationDialog.form | 66 +++++++++++++++---- .../magento2uct/ui/ConfigurationDialog.java | 52 ++++++++++++--- 3 files changed, 138 insertions(+), 22 deletions(-) diff --git a/src/com/magento/idea/magento2uct/settings/UctSettingsService.java b/src/com/magento/idea/magento2uct/settings/UctSettingsService.java index fb2d24100..4b2e41528 100644 --- a/src/com/magento/idea/magento2uct/settings/UctSettingsService.java +++ b/src/com/magento/idea/magento2uct/settings/UctSettingsService.java @@ -42,6 +42,12 @@ public class UctSettingsService implements PersistentStateComponent - + - + + + - + @@ -20,7 +22,7 @@ - + @@ -28,7 +30,7 @@ - + @@ -43,7 +45,7 @@ - + @@ -58,11 +60,13 @@ - + - + + + @@ -74,13 +78,13 @@ - + - + @@ -89,7 +93,7 @@ - + @@ -97,7 +101,7 @@ - + @@ -105,7 +109,7 @@ - + @@ -116,7 +120,7 @@ - + @@ -124,6 +128,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java b/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java index 039b430ba..390d9741c 100644 --- a/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java +++ b/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java @@ -27,13 +27,7 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Objects; -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.KeyStroke; +import javax.swing.*; import org.jetbrains.annotations.NotNull; @SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) @@ -44,6 +38,7 @@ public class ConfigurationDialog extends AbstractDialog { private JCheckBox enable; private LabeledComponent modulePath; + private LabeledComponent additionalPath; private JCheckBox ignoreCurrentVersion; private JComboBox currentVersion; private JComboBox targetVersion; @@ -59,6 +54,9 @@ public class ConfigurationDialog extends AbstractDialog { private JLabel modulePathError;//NOPMD private JLabel enableComment;//NOPMD private JLabel enableCommentPath;//NOPMD + private JCheckBox hasAdditionalPath; + private JLabel additionalPathLabel;//NOPMD + private JLabel additionalPathError;//NOPMD /** * Configuration dialog. @@ -76,6 +74,7 @@ public ConfigurationDialog(final @NotNull Project project) { setTitle(ConfigureUctAction.ACTION_NAME); getRootPane().setDefaultButton(buttonOk); + hasAdditionalPath.addActionListener(event -> refreshAdditionalFields(hasAdditionalPath.isSelected())); buttonOk.addActionListener(event -> onOK()); buttonCancel.addActionListener(event -> onCancel()); @@ -98,6 +97,9 @@ public void windowClosing(final WindowEvent event) { modulePathError.setText(""); modulePathError.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL)); modulePathError.setForeground(new Color(252, 119, 83)); + additionalPathError.setText(""); + additionalPathError.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL)); + additionalPathError.setForeground(new Color(252, 119, 83)); enableComment.setForeground(JBColor.blue); enableCommentPath.setForeground(JBColor.blue); setDefaultValues(); @@ -120,12 +122,18 @@ public static void open(final @NotNull Project project) { */ private void onOK() { modulePathError.setText(""); + additionalPathError.setText(""); if (modulePath.getComponent().getText().isEmpty() || !UctModulePathValidatorUtil.validate(modulePath.getComponent().getText())) { modulePathError.setText("The `Path To Analyse` field is empty or invalid"); return; } + if (additionalPath.getComponent().getText().isEmpty() + || !UctModulePathValidatorUtil.validate(additionalPath.getComponent().getText())) { + additionalPathError.setText("The `Path To Analyse` field is empty or invalid"); + return; + } settingsService.setEnabled(enable.isSelected()); final ComboBoxItemData currentVersionItemData = @@ -155,7 +163,8 @@ private void onOK() { ) ); settingsService.setIgnoreCurrentVersion(ignoreCurrentVersion.isSelected()); - + settingsService.setHasAdditionalPath(hasAdditionalPath.isSelected()); + settingsService.setAdditionalPath(additionalPath.getComponent().getText()); exit(); } @@ -221,6 +230,21 @@ private void setDefaultValues() { } final Boolean shouldIgnore = settingsService.shouldIgnoreCurrentVersion(); ignoreCurrentVersion.setSelected(Objects.requireNonNullElse(shouldIgnore, false)); + + final Boolean isShowAdditionalPath = settingsService.getHasAdditionalPath(); + additionalPath.setEnabled( + Objects.requireNonNullElse(isShowAdditionalPath, false) + ); + + if (settingsService.getAdditionalPath() == null) { + final String basePath = Settings.getMagentoPath(project); + + if (basePath != null) { + additionalPath.getComponent().setText(basePath); + } + } else { + additionalPath.getComponent().setText(settingsService.getAdditionalPath()); + } } /** @@ -271,5 +295,17 @@ private void createUIComponents() { new FileChooserDescriptor(false, true, false, false, false, false) ) ); + + additionalPath = new LabeledComponent<>(); + additionalPath.setComponent(new TextFieldWithBrowseButton()); + additionalPath.getComponent().addBrowseFolderListener( + new TextBrowseFolderListener( + new FileChooserDescriptor(false, true, false, false, false, false) + ) + ); + } + + private void refreshAdditionalFields(final boolean isEnabled) { + additionalPath.setEnabled(isEnabled); } } From a17258a5b128697d2871c2c647ee37719bbde278 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Sat, 5 Mar 2022 19:59:12 +0200 Subject: [PATCH 2/2] 1023: update logic and code style --- .../magento2uct/ui/ConfigurationDialog.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java b/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java index 390d9741c..8ded3e1c6 100644 --- a/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java +++ b/src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java @@ -40,6 +40,7 @@ public class ConfigurationDialog extends AbstractDialog { private LabeledComponent modulePath; private LabeledComponent additionalPath; private JCheckBox ignoreCurrentVersion; + private JCheckBox hasAdditionalPath; private JComboBox currentVersion; private JComboBox targetVersion; private JComboBox issueSeverityLevel; @@ -54,7 +55,6 @@ public class ConfigurationDialog extends AbstractDialog { private JLabel modulePathError;//NOPMD private JLabel enableComment;//NOPMD private JLabel enableCommentPath;//NOPMD - private JCheckBox hasAdditionalPath; private JLabel additionalPathLabel;//NOPMD private JLabel additionalPathError;//NOPMD @@ -103,6 +103,7 @@ public void windowClosing(final WindowEvent event) { enableComment.setForeground(JBColor.blue); enableCommentPath.setForeground(JBColor.blue); setDefaultValues(); + refreshAdditionalFields(hasAdditionalPath.isSelected()); } /** @@ -129,8 +130,9 @@ private void onOK() { modulePathError.setText("The `Path To Analyse` field is empty or invalid"); return; } - if (additionalPath.getComponent().getText().isEmpty() - || !UctModulePathValidatorUtil.validate(additionalPath.getComponent().getText())) { + if (hasAdditionalPath.isSelected() && additionalPath.getComponent().getText().isEmpty() + || hasAdditionalPath.isSelected() + && !UctModulePathValidatorUtil.validate(additionalPath.getComponent().getText())) { additionalPathError.setText("The `Path To Analyse` field is empty or invalid"); return; } @@ -232,17 +234,11 @@ private void setDefaultValues() { ignoreCurrentVersion.setSelected(Objects.requireNonNullElse(shouldIgnore, false)); final Boolean isShowAdditionalPath = settingsService.getHasAdditionalPath(); - additionalPath.setEnabled( + hasAdditionalPath.setSelected( Objects.requireNonNullElse(isShowAdditionalPath, false) ); - if (settingsService.getAdditionalPath() == null) { - final String basePath = Settings.getMagentoPath(project); - - if (basePath != null) { - additionalPath.getComponent().setText(basePath); - } - } else { + if (settingsService.getAdditionalPath() != null) { additionalPath.getComponent().setText(settingsService.getAdditionalPath()); } } @@ -307,5 +303,8 @@ private void createUIComponents() { private void refreshAdditionalFields(final boolean isEnabled) { additionalPath.setEnabled(isEnabled); + additionalPath.setVisible(isEnabled); + additionalPathLabel.setVisible(isEnabled); + additionalPathError.setVisible(isEnabled); } }