1
- // Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1
+ // Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
+
3
4
package software.aws.toolkits.jetbrains.settings
4
5
5
6
import com.intellij.ide.BrowserUtil
@@ -10,15 +11,12 @@ import com.intellij.openapi.options.ConfigurationException
10
11
import com.intellij.openapi.options.SearchableConfigurable
11
12
import com.intellij.openapi.ui.ComboBox
12
13
import com.intellij.openapi.ui.TextFieldWithBrowseButton
13
- import com.intellij.openapi.util.Comparing
14
14
import com.intellij.openapi.util.text.StringUtil
15
- import com.intellij.ui.IdeBorderFactory
16
- import com.intellij.ui.components.ActionLink
17
15
import com.intellij.ui.components.JBCheckBox
18
16
import com.intellij.ui.components.JBTextField
19
- import com.intellij.util.ui.SwingHelper
17
+ import com.intellij.ui.dsl.builder.AlignX
18
+ import com.intellij.ui.dsl.builder.panel
20
19
import software.aws.toolkits.jetbrains.core.executables.ExecutableInstance
21
- import software.aws.toolkits.jetbrains.core.executables.ExecutableInstance.BadExecutable
22
20
import software.aws.toolkits.jetbrains.core.executables.ExecutableInstance.ExecutableWithPath
23
21
import software.aws.toolkits.jetbrains.core.executables.ExecutableManager
24
22
import software.aws.toolkits.jetbrains.core.executables.ExecutableType
@@ -30,58 +28,60 @@ import java.nio.file.Path
30
28
import java.nio.file.Paths
31
29
import java.util.concurrent.CompletionException
32
30
import javax.swing.JComponent
33
- import javax.swing.JPanel
34
31
35
32
class AwsSettingsConfigurable : SearchableConfigurable {
36
- private lateinit var panel: JPanel
37
- private lateinit var samHelp: JComponent
38
- private lateinit var serverlessSettings: JPanel
39
- private lateinit var applicationLevelSettings: JPanel
40
- private lateinit var defaultRegionHandling: ComboBox <UseAwsCredentialRegion >
41
- private lateinit var profilesNotification: ComboBox <ProfilesNotification >
42
- lateinit var samExecutablePath: TextFieldWithBrowseButton
43
- private set
44
- lateinit var enableTelemetry: JBCheckBox
45
- private set
46
33
private val samExecutableInstance: SamExecutable
47
34
get() = ExecutableType .getExecutable(SamExecutable ::class .java)
48
- private val samTextboxInput: String?
49
- get() = StringUtil .nullize(samExecutablePath.text.trim { it <= ' ' })
50
-
51
- override fun createComponent (): JComponent = panel
52
-
53
- private fun createUIComponents () {
54
- samHelp = createHelpLink(HelpIds .SAM_CLI_INSTALL )
55
- samExecutablePath = createCliConfigurationElement(samExecutableInstance, SAM )
56
- defaultRegionHandling = ComboBox (UseAwsCredentialRegion .values())
57
- profilesNotification = ComboBox (ProfilesNotification .values())
58
- }
35
+ val samExecutablePath: TextFieldWithBrowseButton = createCliConfigurationElement(samExecutableInstance, SAM )
36
+
37
+ private val defaultRegionHandling: ComboBox <UseAwsCredentialRegion > = ComboBox (UseAwsCredentialRegion .values())
38
+ private val profilesNotification: ComboBox <ProfilesNotification > = ComboBox (ProfilesNotification .values())
39
+
40
+ val enableTelemetry: JBCheckBox = JBCheckBox ()
41
+ override fun createComponent (): JComponent = panel {
42
+ group(message(" aws.settings.serverless_label" )) {
43
+ row {
44
+ label(message(" aws.settings.sam.location" ))
45
+ // samExecutablePath = createCliConfigurationElement(samExecutableInstance, SAM)
46
+ cell(samExecutablePath).align(AlignX .FILL ).resizableColumn()
47
+ browserLink(message(" aws.settings.learn_more" ), HelpIds .SAM_CLI_INSTALL .url)
48
+ }
49
+ }
50
+ group(message(" aws.settings.global_label" )) {
51
+ row {
52
+ label(message(" settings.credentials.prompt_for_default_region_switch.setting_label" ))
53
+ cell(defaultRegionHandling).resizableColumn().align(AlignX .FILL ).applyToComponent {
54
+ this .selectedItem = AwsSettings .getInstance().useDefaultCredentialRegion ? : UseAwsCredentialRegion .Never
55
+ }
56
+ }
57
+ row {
58
+ label(message(" settings.profiles.label" ))
59
+ cell(profilesNotification).resizableColumn().align(AlignX .FILL ).applyToComponent {
60
+ this .selectedItem = AwsSettings .getInstance().profilesNotification ? : ProfilesNotification .Always
61
+ }
62
+ }
59
63
60
- init {
61
- applicationLevelSettings.border = IdeBorderFactory .createTitledBorder(message(" aws.settings.global_label" ))
62
- serverlessSettings.border = IdeBorderFactory .createTitledBorder(message(" aws.settings.serverless_label" ))
63
- SwingHelper .setPreferredWidth(samExecutablePath, panel.width)
64
+ row {
65
+ cell(enableTelemetry).applyToComponent { this .isSelected = AwsSettings .getInstance().isTelemetryEnabled }
66
+ text(message(" aws.settings.telemetry.option" ) + " <a>${message(" general.details" )} </a>" ) {
67
+ BrowserUtil .open(" https://docs.aws.amazon.com/sdkref/latest/guide/support-maint-idetoolkits.html" )
68
+ }
69
+ }
70
+ }
64
71
}
65
72
66
- override fun getId (): String = " aws"
67
- override fun getDisplayName (): String = message(" aws.settings.title" )
68
-
69
- override fun isModified (): Boolean {
70
- val awsSettings = AwsSettings .getInstance()
71
- return samTextboxInput != getSavedExecutablePath(samExecutableInstance, false ) ||
72
- isModified(enableTelemetry, awsSettings.isTelemetryEnabled) ||
73
- // isModified for ComboBoxes is removed from 2021.3
74
- ! Comparing .equal(defaultRegionHandling.selectedItem, awsSettings.useDefaultCredentialRegion) ||
75
- ! Comparing .equal(profilesNotification.selectedItem, awsSettings.profilesNotification)
76
- }
73
+ override fun isModified (): Boolean = getSamPathWithoutSpaces() != getSavedExecutablePath(samExecutableInstance, false ) ||
74
+ defaultRegionHandling.selectedItem != AwsSettings .getInstance().useDefaultCredentialRegion ||
75
+ profilesNotification.selectedItem != AwsSettings .getInstance().profilesNotification ||
76
+ enableTelemetry.isSelected != AwsSettings .getInstance().isTelemetryEnabled
77
77
78
78
override fun apply () {
79
79
validateAndSaveCliSettings(
80
80
samExecutablePath.textField as JBTextField ,
81
81
" sam" ,
82
82
samExecutableInstance,
83
83
getSavedExecutablePath(samExecutableInstance, false ),
84
- samTextboxInput
84
+ getSamPathWithoutSpaces()
85
85
)
86
86
saveAwsSettings()
87
87
}
@@ -94,7 +94,9 @@ class AwsSettingsConfigurable : SearchableConfigurable {
94
94
profilesNotification.selectedItem = awsSettings.profilesNotification
95
95
}
96
96
97
- private fun createHelpLink (helpId : HelpIds ): JComponent = ActionLink (message(" aws.settings.learn_more" )) { BrowserUtil .browse(helpId.url) }
97
+ override fun getDisplayName (): String = message(" aws.settings.title" )
98
+
99
+ override fun getId (): String = " aws"
98
100
99
101
private fun createCliConfigurationElement (executableType : ExecutableType <* >, cliName : String ): TextFieldWithBrowseButton {
100
102
val autoDetectPath = getSavedExecutablePath(executableType, true )
@@ -176,21 +178,22 @@ class AwsSettingsConfigurable : SearchableConfigurable {
176
178
throw ConfigurationException (message(" aws.settings.executables.executable_invalid" , executableName, currentInput))
177
179
}
178
180
val instance = ExecutableManager .getInstance().validateExecutablePath(executableType, path)
179
- if (instance is BadExecutable ) {
181
+ if (instance is ExecutableInstance . BadExecutable ) {
180
182
throw ConfigurationException (instance.validationError)
181
183
}
182
184
183
185
// We have validated so now we can set
184
186
ExecutableManager .getInstance().setExecutablePath(executableType, path)
185
187
}
186
-
187
188
private fun saveAwsSettings () {
188
189
val awsSettings = AwsSettings .getInstance()
189
190
awsSettings.isTelemetryEnabled = enableTelemetry.isSelected
190
191
awsSettings.useDefaultCredentialRegion = defaultRegionHandling.selectedItem as ? UseAwsCredentialRegion ? : UseAwsCredentialRegion .Never
191
192
awsSettings.profilesNotification = profilesNotification.selectedItem as ? ProfilesNotification ? : ProfilesNotification .Always
192
193
}
193
194
195
+ private fun getSamPathWithoutSpaces () = StringUtil .nullize(samExecutablePath.text.trim { it <= ' ' })
196
+
194
197
companion object {
195
198
private const val SAM = " sam"
196
199
}
0 commit comments