Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/com/magento/idea/magento2uct/settings/UctSettingsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public class UctSettingsService implements PersistentStateComponent<UctSettingsS
@Property
private Boolean ignoreCurrentVersion;

@Property
private Boolean hasAdditionalPath;

@Property
private String additionalPath;

@SuppressWarnings("PMD.UncommentedEmptyConstructor")
public UctSettingsService() {
}
Expand Down Expand Up @@ -249,4 +255,40 @@ public void setIgnoreCurrentVersion(final boolean ignoreCurrentVersion) {
public @Nullable Boolean shouldIgnoreCurrentVersion() {
return ignoreCurrentVersion;
}

/**
* Set if show additional path
*
* @param hasAdditionalPath boolean
*/
public void setHasAdditionalPath(final boolean hasAdditionalPath) {
this.hasAdditionalPath = hasAdditionalPath;
}

/**
* Check if show additional path
*
* @return boolean
*/
public @Nullable Boolean getHasAdditionalPath() {
return hasAdditionalPath;
}

/**
* Set path to analyse.
*
* @param additionalPath String
*/
public void setAdditionalPath(final @NotNull String additionalPath) {
this.additionalPath = additionalPath;
}

/**
* Get target module path (path to analyse).
*
* @return String
*/
public @Nullable String getAdditionalPath() {
return additionalPath;
}
}
66 changes: 52 additions & 14 deletions src/com/magento/idea/magento2uct/ui/ConfigurationDialog.form
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="20" y="20" width="688" height="400"/>
<xy x="20" y="20" width="719" height="500"/>
</constraints>
<properties>
<preferredSize width="580" height="300"/>
<minimumSize width="559" height="300"/>
<preferredSize width="580" height="380"/>
<requestFocusEnabled value="true"/>
</properties>
<border type="none"/>
<children>
<grid id="d41a9" layout-manager="GridLayoutManager" row-count="9" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="d41a9" layout-manager="GridLayoutManager" row-count="12" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand All @@ -20,15 +22,15 @@
<children>
<component id="28e30" class="javax.swing.JCheckBox" binding="enable">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Enable the built-in Upgrade Compatibility Tool"/>
</properties>
</component>
<component id="dda21" class="javax.swing.JComboBox" binding="currentVersion" custom-create="true">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="3" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
Expand All @@ -43,7 +45,7 @@
</component>
<component id="dede1" class="javax.swing.JComboBox" binding="targetVersion" custom-create="true">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="4" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
Expand All @@ -58,11 +60,13 @@
</component>
<component id="d5e0b" class="com.intellij.openapi.ui.LabeledComponent" binding="modulePath" custom-create="true">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="5" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
<properties>
<enabled value="true"/>
</properties>
</component>
<component id="f4311" class="javax.swing.JLabel" binding="modulePathLabel">
<constraints>
Expand All @@ -74,13 +78,13 @@
</component>
<component id="70b2b" class="javax.swing.JComboBox" binding="issueSeverityLevel" custom-create="true">
<constraints>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="10" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="bd4f" class="javax.swing.JLabel" binding="issueSeverityLevelLabel">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="70b2b"/>
Expand All @@ -89,23 +93,23 @@
</component>
<component id="3c2d0" class="javax.swing.JCheckBox" binding="ignoreCurrentVersion">
<constraints>
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="11" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Ignore current version compatibility issues"/>
</properties>
</component>
<component id="2d9d9" class="javax.swing.JLabel" binding="modulePathError">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="6" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Label"/>
</properties>
</component>
<component id="6f213" class="javax.swing.JLabel" binding="enableComment">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
Expand All @@ -116,14 +120,48 @@
</component>
<component id="1b278" class="javax.swing.JLabel" binding="enableCommentPath">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
<font size="12"/>
<text value="Preferences -&gt; Editor -&gt; Inspections -&gt; UCT"/>
</properties>
</component>
<component id="3b634" class="javax.swing.JLabel" binding="additionalPathLabel">
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Path To Analyse"/>
</properties>
</component>
<component id="ab5bd" class="com.intellij.openapi.ui.LabeledComponent" binding="additionalPath" custom-create="true">
<constraints>
<grid row="8" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<enabled value="true"/>
</properties>
</component>
<component id="c2187" class="javax.swing.JCheckBox" binding="hasAdditionalPath">
<constraints>
<grid row="7" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Add additional path to analyse"/>
</properties>
</component>
<component id="9ba03" class="javax.swing.JLabel" binding="additionalPathError">
<constraints>
<grid row="9" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Label"/>
</properties>
</component>
</children>
</grid>
<vspacer id="9089b">
Expand Down
51 changes: 43 additions & 8 deletions src/com/magento/idea/magento2uct/ui/ConfigurationDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, do not use wildcard imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your code review. I fixed. Please check.

import org.jetbrains.annotations.NotNull;

@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"})
Expand All @@ -44,7 +38,9 @@ public class ConfigurationDialog extends AbstractDialog {

private JCheckBox enable;
private LabeledComponent<TextFieldWithBrowseButton> modulePath;
private LabeledComponent<TextFieldWithBrowseButton> additionalPath;
private JCheckBox ignoreCurrentVersion;
private JCheckBox hasAdditionalPath;
private JComboBox<ComboBoxItemData> currentVersion;
private JComboBox<ComboBoxItemData> targetVersion;
private JComboBox<ComboBoxItemData> issueSeverityLevel;
Expand All @@ -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.
Expand All @@ -76,6 +74,7 @@ public ConfigurationDialog(final @NotNull Project project) {
setTitle(ConfigureUctAction.ACTION_NAME);
getRootPane().setDefaultButton(buttonOk);

hasAdditionalPath.addActionListener(event -> refreshAdditionalFields(hasAdditionalPath.isSelected()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, call this method refreshAdditionalFields in the constructor. So we will get saved state of this component.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pay attention, this method should be called after setDefaultValues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your code review. I fixed. Please check.

buttonOk.addActionListener(event -> onOK());
buttonCancel.addActionListener(event -> onCancel());

Expand All @@ -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());
}

/**
Expand All @@ -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 =
Expand Down Expand Up @@ -155,7 +165,8 @@ private void onOK() {
)
);
settingsService.setIgnoreCurrentVersion(ignoreCurrentVersion.isSelected());

settingsService.setHasAdditionalPath(hasAdditionalPath.isSelected());
settingsService.setAdditionalPath(additionalPath.getComponent().getText());
exit();
}

Expand Down Expand Up @@ -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());
}
}

/**
Expand Down Expand Up @@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add additionalPath.setVisible(isEnabled);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your code review. I fixed. Please check.

additionalPath.setVisible(isEnabled);
additionalPathLabel.setVisible(isEnabled);
additionalPathError.setVisible(isEnabled);
}
}