Skip to content

Commit d34711e

Browse files
authored
Change dialogs from ui dsl v1 to v2 (#3824)
* initial changes * adjusted width of fields in creation panel * fixed dialogs * removed comments
1 parent 5ed381d commit d34711e

File tree

6 files changed

+108
-102
lines changed

6 files changed

+108
-102
lines changed

jetbrains-core/src/software/aws/toolkits/jetbrains/services/apprunner/actions/PauseServiceAction.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import com.intellij.openapi.project.DumbAware
88
import com.intellij.openapi.project.Project
99
import com.intellij.openapi.ui.DialogWrapper
1010
import com.intellij.openapi.ui.Messages
11-
import com.intellij.ui.components.JBLabel
12-
import com.intellij.ui.layout.panel
11+
import com.intellij.ui.dsl.builder.panel
1312
import kotlinx.coroutines.launch
1413
import software.amazon.awssdk.services.apprunner.AppRunnerClient
1514
import software.amazon.awssdk.services.apprunner.model.AppRunnerException
@@ -49,11 +48,10 @@ class PauseServiceAction :
4948
override fun getHelpId(): String = HelpIds.APPRUNNER_PAUSE_RESUME.id
5049
override fun createCenterPanel(): JComponent = panel {
5150
row {
52-
JBLabel().apply {
53-
text = message("apprunner.pause.warning", selected.service.serviceName())
51+
label(message("apprunner.pause.warning", selected.service.serviceName())).applyToComponent {
5452
icon = Messages.getWarningIcon()
5553
iconTextGap = 8
56-
}(grow)
54+
}
5755
}
5856
}
5957
}

jetbrains-core/src/software/aws/toolkits/jetbrains/services/apprunner/actions/ResumeServiceAction.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import com.intellij.openapi.project.DumbAware
88
import com.intellij.openapi.project.Project
99
import com.intellij.openapi.ui.DialogWrapper
1010
import com.intellij.openapi.ui.Messages
11-
import com.intellij.ui.components.JBLabel
12-
import com.intellij.ui.layout.panel
11+
import com.intellij.ui.dsl.builder.panel
1312
import kotlinx.coroutines.launch
1413
import software.amazon.awssdk.services.apprunner.AppRunnerClient
1514
import software.amazon.awssdk.services.apprunner.model.AppRunnerException
@@ -49,11 +48,10 @@ class ResumeServiceAction :
4948
override fun getHelpId(): String = HelpIds.APPRUNNER_PAUSE_RESUME.id
5049
override fun createCenterPanel(): JComponent = panel {
5150
row {
52-
JBLabel().apply {
53-
text = message("apprunner.resume.warning", selected.service.serviceName())
51+
label(message("apprunner.resume.warning", selected.service.serviceName())).applyToComponent {
5452
icon = Messages.getWarningIcon()
5553
iconTextGap = 8
56-
}(grow)
54+
}
5755
}
5856
}
5957
}

jetbrains-core/src/software/aws/toolkits/jetbrains/services/apprunner/ui/CreationPanel.kt

Lines changed: 90 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ import com.intellij.openapi.project.Project
77
import com.intellij.openapi.ui.DialogPanel
88
import com.intellij.ui.SimpleListCellRenderer
99
import com.intellij.ui.components.JBRadioButton
10-
import com.intellij.ui.layout.GrowPolicy
10+
import com.intellij.ui.dsl.builder.Align
11+
import com.intellij.ui.dsl.builder.AlignX
12+
import com.intellij.ui.dsl.builder.BottomGap
13+
import com.intellij.ui.dsl.builder.bindIntText
14+
import com.intellij.ui.dsl.builder.bindItem
15+
import com.intellij.ui.dsl.builder.bindText
16+
import com.intellij.ui.dsl.builder.columns
17+
import com.intellij.ui.dsl.builder.panel
1118
import com.intellij.ui.layout.or
12-
import com.intellij.ui.layout.panel
1319
import com.intellij.ui.layout.selected
1420
import software.amazon.awssdk.services.apprunner.model.ConnectionSummary
1521
import software.amazon.awssdk.services.apprunner.model.Runtime
@@ -25,7 +31,6 @@ import software.aws.toolkits.jetbrains.ui.KeyValueTextField
2531
import software.aws.toolkits.jetbrains.ui.ResourceSelector
2632
import software.aws.toolkits.jetbrains.ui.intTextField
2733
import software.aws.toolkits.jetbrains.utils.toHumanReadable
28-
import software.aws.toolkits.jetbrains.utils.ui.contextualHelp
2934
import software.aws.toolkits.jetbrains.utils.ui.installOnParent
3035
import software.aws.toolkits.jetbrains.utils.ui.selected
3136
import software.aws.toolkits.jetbrains.utils.ui.visibleIf
@@ -90,20 +95,23 @@ class CreationPanel(private val project: Project, ecrUri: String? = null) {
9095

9196
val imagePanel = panel {
9297
row(message("apprunner.creation.panel.image.uri")) {
93-
textField(::containerUri)
98+
textField()
9499
.apply { component.emptyText.text = "111111111111.dkr.ecr.us-east-1.amazonaws.com/name:tag" }
95-
.withErrorOnApplyIf(message("apprunner.creation.panel.image.uri.missing")) { it.text.isBlank() }
96-
.constraints(pushX)
100+
.bindText(::containerUri)
101+
.errorOnApply(message("apprunner.creation.panel.image.uri.missing")) { it.text.isBlank() }
102+
.align(AlignX.FILL)
97103
}
98104

99105
row(message("apprunner.creation.panel.start_command")) {
100-
textField({ startCommand ?: "" }, { startCommand = it })
106+
textField()
101107
.apply { component.toolTipText = message("apprunner.creation.panel.start_command.image.tooltip") }
102-
.constraints(pushX)
108+
.bindText({ startCommand ?: "" }, { startCommand = it })
109+
.align(AlignX.FILL)
103110
}
104111

105112
row(message("apprunner.creation.panel.port")) {
106-
intTextField(::port, range = IntRange(1, 65535))
113+
intTextField(range = IntRange(1, 65535)).bindIntText(::port)
114+
.align(AlignX.FILL)
107115
}
108116

109117
row {
@@ -120,10 +128,10 @@ class CreationPanel(private val project: Project, ecrUri: String? = null) {
120128
selectedItem { it.name == APPRUNNER_ECR_DEFAULT_ROLE_NAME }
121129
toolTipText = message("apprunner.creation.panel.image.access_role.tooltip")
122130
}
123-
ecrPolicy(grow)
124-
.growPolicy(GrowPolicy.MEDIUM_TEXT)
125-
.withErrorOnApplyIf(message("apprunner.creation.panel.image.access_role.missing")) { it.selected() == null }
131+
cell(ecrPolicy)
132+
.errorOnApply(message("apprunner.creation.panel.image.access_role.missing")) { it.selected() == null && ecr.isSelected }
126133
.visibleIf(ecr.selected)
134+
.columns(40)
127135
button(message("general.create_button")) {
128136
val iamRoleDialog = CreateIamServiceRoleDialog(
129137
project,
@@ -142,128 +150,126 @@ class CreationPanel(private val project: Project, ecrUri: String? = null) {
142150
}
143151
row {
144152
label(message("apprunner.creation.panel.cpu"))
145-
comboBox(DefaultComboBoxModel(CreationPanel.cpuValues.toTypedArray()), { cpu }, { it?.let { cpu = it } })
146-
.withErrorOnApplyIf(message("apprunner.creation.panel.cpu.missing")) { it.selected() == null }
147-
.constraints(pushX, growX)
153+
comboBox(DefaultComboBoxModel(CreationPanel.cpuValues.toTypedArray())).bindItem({ cpu }, { it?.let { cpu = it } }).errorOnApply(
154+
message("apprunner.creation.panel.cpu.missing")
155+
) { it.selected() == null }
148156
label(message("apprunner.creation.panel.memory"))
149-
comboBox(DefaultComboBoxModel(CreationPanel.memoryValues.toTypedArray()), { memory }, { it?.let { memory = it } })
150-
.withErrorOnApplyIf(message("apprunner.creation.panel.memory.missing")) { it.selected() == null }
151-
.constraints(pushX, growX)
157+
comboBox(DefaultComboBoxModel(CreationPanel.memoryValues.toTypedArray())).bindItem({ memory }, { it?.let { memory = it } })
158+
.errorOnApply(message("apprunner.creation.panel.memory.missing")) { it.selected() == null }
152159
}
153160
}
154161

155162
val repoSettings = panel {
156163
row(message("apprunner.creation.panel.repository.runtime")) {
157-
comboBox(DefaultComboBoxModel(Runtime.knownValues().toTypedArray()), { runtime }, { runtime = it })
164+
comboBox(DefaultComboBoxModel(Runtime.knownValues().toTypedArray())).bindItem({ runtime }, { runtime = it })
158165
.apply {
159166
component.toolTipText = message("apprunner.creation.panel.repository.runtime.tooltip")
160167
component.renderer = SimpleListCellRenderer.create("") { it?.toString()?.toHumanReadable() }
161168
}
162-
.withErrorOnApplyIf(message("apprunner.creation.panel.repository.runtime.missing")) { it.selected() == null }
163-
.constraints(pushX, growX)
169+
.errorOnApply(message("apprunner.creation.panel.repository.runtime.missing")) { it.selected() == null }
170+
.columns(35)
171+
164172
label(message("apprunner.creation.panel.port"))
165-
intTextField(::port, range = IntRange(1, 65535))
173+
intTextField(range = IntRange(1, 65535)).bindIntText(::port)
166174
}
167175
row(message("apprunner.creation.panel.repository.build_command")) {
168-
textField(::buildCommand)
176+
textField().bindText(::buildCommand)
169177
.apply { component.toolTipText = message("apprunner.creation.panel.repository.build_command.tooltip") }
170-
.withErrorOnApplyIf(message("apprunner.creation.panel.repository.build_command.missing")) { it.text.isBlank() }
171-
.constraints(pushX, growX)
178+
.errorOnApply(message("apprunner.creation.panel.repository.build_command.missing")) { it.text.isBlank() }
179+
.resizableColumn()
180+
.align(Align.FILL)
172181
}
173182
row(message("apprunner.creation.panel.start_command")) {
174-
textField({ startCommand ?: "" }, { startCommand = it })
183+
textField().bindText({ startCommand ?: "" }, { startCommand = it })
175184
.apply { component.toolTipText = message("apprunner.creation.panel.start_command.repo.tooltip") }
176-
.withErrorOnApplyIf(message("apprunner.creation.panel.start_command.missing")) { it.text.isBlank() }
177-
.constraints(pushX, growX)
178-
}.largeGapAfter()
185+
.errorOnApply(message("apprunner.creation.panel.start_command.missing")) { it.text.isBlank() }
186+
.resizableColumn()
187+
.align(Align.FILL)
188+
}.bottomGap(BottomGap.MEDIUM)
179189
}
180190

181191
val repoPanel = panel {
182-
row(message("apprunner.creation.panel.repository.connection")) {
183-
cell(isFullWidth = true) {
184-
connection = ResourceSelector.builder()
185-
.resource { AppRunnerResources.LIST_CONNECTIONS }
186-
.customRenderer(SimpleListCellRenderer.create("") { "${it.connectionName()} (${it.providerTypeAsString().toHumanReadable()})" })
187-
.awsConnection(project)
188-
.build()
189-
connection(growX, pushX)
190-
.withErrorOnApplyIf(message("apprunner.creation.panel.repository.connection.missing")) { it.isLoading || it.selected() == null }
191-
contextualHelp(message("apprunner.creation.panel.repository.connection.help"))
192-
}
193-
}
192+
row {
193+
label(message("apprunner.creation.panel.repository.connection"))
194+
connection = ResourceSelector.builder()
195+
.resource { AppRunnerResources.LIST_CONNECTIONS }
196+
.customRenderer(SimpleListCellRenderer.create("") { "${it.connectionName()} (${it.providerTypeAsString().toHumanReadable()})" })
197+
.awsConnection(project)
198+
.build()
199+
cell(connection)
200+
.errorOnApply(message("apprunner.creation.panel.repository.connection.missing")) { it.isLoading || it.selected() == null }
201+
.resizableColumn()
202+
.align(Align.FILL)
203+
}.contextHelp(message("apprunner.creation.panel.repository.connection.help"))
194204
row {
195205
label(message("apprunner.creation.panel.repository.url")).apply {
196206
component.toolTipText = message("apprunner.creation.panel.repository.url.tooltip")
197207
}
198-
textField(::repository, columns = 20).constraints(growX)
208+
textField().bindText(::repository).columns(20)
199209
label(message("apprunner.creation.panel.repository.branch"))
200-
textField(::branch, columns = 15).constraints(growX)
210+
textField().bindText(::branch).columns(15)
201211
}
202-
row(message("apprunner.creation.panel.repository.configuration")) {
203-
buttonGroup {
204-
cell(isFullWidth = true) {
205-
repoConfigFromSettings()
206-
repoConfigFromFile()
207-
}
212+
buttonsGroup {
213+
row(message("apprunner.creation.panel.repository.configuration")) {
214+
cell(repoConfigFromSettings)
215+
cell(repoConfigFromFile)
208216
}
209217
}
218+
210219
row {
211-
repoSettings(growX)
220+
cell(repoSettings)
212221
.installOnParent { repoConfigFromSettings.isSelected }
213222
.visibleIf(repoConfigFromSettings.selected)
214223
}
215224
row {
216225
label(message("apprunner.creation.panel.cpu"))
217-
comboBox(DefaultComboBoxModel(CreationPanel.cpuValues.toTypedArray()), { cpu }, { it?.let { cpu = it } })
218-
.withErrorOnApplyIf(message("apprunner.creation.panel.cpu.missing")) { it.selected() == null }
219-
.constraints(pushX, growX)
226+
comboBox(DefaultComboBoxModel(CreationPanel.cpuValues.toTypedArray())).bindItem({ cpu }, { it?.let { cpu = it } })
227+
.errorOnApply(message("apprunner.creation.panel.cpu.missing")) { it.selected() == null }
228+
.resizableColumn().align(Align.FILL)
220229
label(message("apprunner.creation.panel.memory"))
221-
comboBox(DefaultComboBoxModel(CreationPanel.memoryValues.toTypedArray()), { memory }, { it?.let { memory = it } })
222-
.withErrorOnApplyIf(message("apprunner.creation.panel.memory.missing")) { it.selected() == null }
223-
.constraints(pushX, growX)
230+
comboBox(DefaultComboBoxModel(CreationPanel.memoryValues.toTypedArray())).bindItem({ memory }, { it?.let { memory = it } })
231+
.errorOnApply(message("apprunner.creation.panel.memory.missing")) { it.selected() == null }
224232
}
225233
}
226234

227235
val component: DialogPanel = panel {
228236
row(message("apprunner.creation.panel.name")) {
229-
textField(::name)
230-
.withErrorOnApplyIf(message("apprunner.creation.panel.name.missing")) { it.text.isNullOrBlank() }
231-
.constraints(pushX)
237+
textField().bindText(::name)
238+
.errorOnApply(message("apprunner.creation.panel.name.missing")) { it.text.isNullOrBlank() }
239+
.columns(40)
232240
}
233-
row(message("apprunner.creation.panel.source")) {
234-
buttonGroup {
235-
cell {
236-
ecr()
237-
ecrPublic()
238-
repo()
239-
}
241+
buttonsGroup {
242+
row(message("apprunner.creation.panel.source")) {
243+
cell(ecr)
244+
cell(ecrPublic)
245+
cell(repo)
240246
}
241247
}
242-
row(message("apprunner.creation.panel.deployment")) {
248+
249+
buttonsGroup {
243250
// ECR public disables selecting deployment options
244-
buttonGroup {
245-
cell {
246-
manualDeployment()
247-
automaticDeployment()
248-
}
251+
row(message("apprunner.creation.panel.deployment")) {
252+
cell(manualDeployment)
253+
cell(automaticDeployment)
249254
}
250255
}.visibleIf(ecr.selected.or(repo.selected))
256+
251257
row {
252-
subRowIndent = 0
253-
cell(isFullWidth = true) {
254-
// TODO HACK making this flow right means we don't have issues with weird spacing above or
255-
// to the left
256-
repoPanel(grow)
257-
.installOnParent { repo.isSelected }
258-
.visibleIf(repo.selected)
258+
cell(repoPanel)
259+
.installOnParent { repo.isSelected }
260+
.visibleIf(repo.selected)
261+
.resizableColumn()
262+
.align(Align.FILL)
259263

260-
imagePanel(grow)
261-
.installOnParent { ecr.isSelected || ecrPublic.isSelected }
262-
.visibleIf(ecr.selected.or(ecrPublic.selected))
263-
}
264+
cell(imagePanel)
265+
.installOnParent { ecr.isSelected || ecrPublic.isSelected }
266+
.visibleIf(ecr.selected.or(ecrPublic.selected))
267+
.resizableColumn()
268+
.align(Align.FILL)
264269
}
265270
row(message("apprunner.creation.panel.environment")) {
266-
environmentVariables(growX)
271+
cell(environmentVariables)
272+
.resizableColumn().align(Align.FILL)
267273
}
268274
}
269275
}

jetbrains-core/src/software/aws/toolkits/jetbrains/services/ecr/CreateEcrRepoDialog.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import com.intellij.openapi.application.ModalityState
88
import com.intellij.openapi.project.Project
99
import com.intellij.openapi.ui.DialogWrapper
1010
import com.intellij.openapi.ui.ValidationInfo
11-
import com.intellij.ui.layout.panel
11+
import com.intellij.ui.dsl.builder.bindText
12+
import com.intellij.ui.dsl.builder.panel
1213
import org.jetbrains.annotations.TestOnly
1314
import software.amazon.awssdk.services.ecr.EcrClient
1415
import software.aws.toolkits.jetbrains.core.explorer.refreshAwsTree
@@ -28,15 +29,16 @@ class CreateEcrRepoDialog(
2829

2930
private val panel = panel {
3031
row(message("general.name.label")) {
31-
textField(::repoName)
32+
textField()
3233
.focused()
33-
.withValidationOnApply {
34+
.validationOnApply {
3435
if (it.text.isBlank()) {
3536
error(message("ecr.create.repo.validation.empty"))
3637
} else {
3738
null
3839
}
3940
}
41+
.bindText(::repoName)
4042
}
4143
}
4244

jetbrains-core/src/software/aws/toolkits/jetbrains/services/iam/CreateIamServiceRoleDialog.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ package software.aws.toolkits.jetbrains.services.iam
55

66
import com.intellij.openapi.project.Project
77
import com.intellij.openapi.ui.DialogWrapper
8-
import com.intellij.ui.layout.panel
8+
import com.intellij.ui.dsl.builder.bindText
9+
import com.intellij.ui.dsl.builder.columns
10+
import com.intellij.ui.dsl.builder.panel
911
import kotlinx.coroutines.launch
1012
import kotlinx.coroutines.runBlocking
1113
import software.amazon.awssdk.services.iam.IamClient
@@ -33,13 +35,13 @@ class CreateIamServiceRoleDialog(
3335
// make the width the widest string. Columns don't map entirely to text width (since text is variable width) but it looks better
3436
val size = max(serviceUri.length, managedPolicyName.length)
3537
row(message("iam.create.role.name.label")) {
36-
textField(::name, size).withErrorOnApplyIf(message("iam.create.role.missing.role.name")) { it.text.isNullOrBlank() }
38+
textField().bindText(::name).columns(size).errorOnApply(message("iam.create.role.missing.role.name")) { it.text.isNullOrBlank() }
3739
}
3840
row(message("iam.create.role.managed_policies")) {
39-
textField({ managedPolicyName }, {}, size).apply { component.isEditable = false }
41+
textField().bindText({ managedPolicyName }, {}).columns(size).apply { component.isEditable = false }
4042
}
4143
row(message("iam.create.role.trust.editor.name")) {
42-
textField({ serviceUri }, {}, size).apply { component.isEditable = false }
44+
textField().bindText({ serviceUri }, {}).columns(size).apply { component.isEditable = false }
4345
}
4446
}
4547

resources/resources/software/aws/toolkits/resources/MessagesBundle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ apprunner.creation.panel.repository.build_command=Build Command:
6161
apprunner.creation.panel.repository.build_command.missing=Enter a build command
6262
apprunner.creation.panel.repository.build_command.tooltip=This command runs in the root directory of your repository when a new code version is deployed. Use it to install dependencies or compile your code.
6363
apprunner.creation.panel.repository.configuration=Configuration:
64-
apprunner.creation.panel.repository.connection=Connection:
64+
apprunner.creation.panel.repository.connection=Connection:
6565
apprunner.creation.panel.repository.connection.help=App Runner deploys your source code by installing an app called "AWS Connector for GitHub" in your GitHub account. This connection must be set up through the console.
6666
apprunner.creation.panel.repository.connection.missing=Select a connection
6767
apprunner.creation.panel.repository.file=Provide a configuration file

0 commit comments

Comments
 (0)