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..8ded3e1c6 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,7 +38,9 @@ public class ConfigurationDialog extends AbstractDialog { private JCheckBox enable; private LabeledComponent modulePath; + private LabeledComponent additionalPath; private JCheckBox ignoreCurrentVersion; + private JCheckBox hasAdditionalPath; private JComboBox currentVersion; private JComboBox targetVersion; private JComboBox issueSeverityLevel; @@ -59,6 +55,8 @@ public class ConfigurationDialog extends AbstractDialog { private JLabel modulePathError;//NOPMD private JLabel enableComment;//NOPMD private JLabel enableCommentPath;//NOPMD + 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,9 +97,13 @@ 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(); + refreshAdditionalFields(hasAdditionalPath.isSelected()); } /** @@ -120,12 +123,19 @@ 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 (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; + } settingsService.setEnabled(enable.isSelected()); final ComboBoxItemData currentVersionItemData = @@ -155,7 +165,8 @@ private void onOK() { ) ); settingsService.setIgnoreCurrentVersion(ignoreCurrentVersion.isSelected()); - + settingsService.setHasAdditionalPath(hasAdditionalPath.isSelected()); + settingsService.setAdditionalPath(additionalPath.getComponent().getText()); exit(); } @@ -221,6 +232,15 @@ private void setDefaultValues() { } final Boolean shouldIgnore = settingsService.shouldIgnoreCurrentVersion(); ignoreCurrentVersion.setSelected(Objects.requireNonNullElse(shouldIgnore, false)); + + final Boolean isShowAdditionalPath = settingsService.getHasAdditionalPath(); + hasAdditionalPath.setSelected( + Objects.requireNonNullElse(isShowAdditionalPath, false) + ); + + if (settingsService.getAdditionalPath() != null) { + additionalPath.getComponent().setText(settingsService.getAdditionalPath()); + } } /** @@ -271,5 +291,20 @@ 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); + additionalPath.setVisible(isEnabled); + additionalPathLabel.setVisible(isEnabled); + additionalPathError.setVisible(isEnabled); } }