Skip to content

Commit 58c4157

Browse files
authored
Make the schema panel lazy in the project wizard (#2374)
- Make all of the panels lazy so they aren't initialized unless the user goes into the aws wizard - Make schemas only load once a template that supports them is selected
1 parent 3976e1f commit 58c4157

File tree

4 files changed

+37
-21
lines changed

4 files changed

+37
-21
lines changed

jetbrains-core/src/software/aws/toolkits/jetbrains/services/lambda/wizard/SamInitSelectionPanel.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,11 @@ class SamInitSelectionPanel(
151151
val selectedRuntime = runtimes.selected
152152
val selectedTemplate = templateComboBox.selectedItem as? SamProjectTemplate
153153
wizardFragments.forEach { (wizardFragment, jComponent) ->
154-
wizardFragment.updateUi(projectLocation, selectedRuntime?.runtimeGroup, selectedTemplate)
155-
jComponent.isVisible = wizardFragment.isApplicable(selectedTemplate)
154+
val isApplicable = wizardFragment.isApplicable(selectedTemplate)
155+
if (isApplicable) {
156+
wizardFragment.updateUi(projectLocation, selectedRuntime?.runtimeGroup, selectedTemplate)
157+
}
158+
jComponent.isVisible = isApplicable
156159
}
157160
wizardUpdateCallback()
158161
}

jetbrains-core/src/software/aws/toolkits/jetbrains/services/lambda/wizard/SchemaResourceSelector.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,25 @@ import software.aws.toolkits.jetbrains.ui.ResourceSelector
1515
import javax.swing.JComponent
1616

1717
class SchemaResourceSelector {
18-
private var currentAwsConnection: ConnectionSettings? = null
18+
var awsConnection: ConnectionSettings? = null
1919

2020
internal val schemasSelector = initializeSchemasSelector()
2121
@TestOnly
2222
get() = field
2323

2424
val component: JComponent = schemasSelector
2525

26+
fun reload() = schemasSelector.reload()
27+
2628
private fun initializeSchemasSelector(): ResourceSelector<SchemaSelectionItem> = ResourceSelector.builder()
2729
.resource(SchemasResources.LIST_REGISTRIES_AND_SCHEMAS)
2830
.comboBoxModel(SchemaSelectionComboBoxModel())
2931
.customRenderer(SchemaSelectionListCellRenderer())
3032
.disableAutomaticLoading()
3133
.disableAutomaticSorting()
32-
.awsConnection { currentAwsConnection }
34+
.awsConnection { awsConnection }
3335
.build()
3436

35-
fun reloadSchemas(awsConnection: ConnectionSettings?) {
36-
currentAwsConnection = awsConnection
37-
schemasSelector.reload()
38-
}
39-
4037
fun registryName(): String? = when (val selected = schemasSelector.selected()) {
4138
is SchemaSelectionItem.SchemaItem -> selected.registryName
4239
else -> null
@@ -59,7 +56,7 @@ class SchemaResourceSelector {
5956

6057
val schemaDownloader = SchemaDownloader()
6158
val describeSchemaResponse =
62-
schemaDownloader.getSchemaContent(registryName, schemaName, connectionSettings = currentAwsConnection!!).toCompletableFuture().get()
59+
schemaDownloader.getSchemaContent(registryName, schemaName, connectionSettings = awsConnection!!).toCompletableFuture().get()
6360
val latestSchemaVersion = describeSchemaResponse.schemaVersion()
6461

6562
val schemaNode = schemaDownloader.getSchemaContentAsJson(describeSchemaResponse)

jetbrains-core/src/software/aws/toolkits/jetbrains/services/lambda/wizard/SchemaSelectionPanel.kt

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package software.aws.toolkits.jetbrains.services.lambda.wizard
55

66
import com.intellij.openapi.progress.ProgressIndicator
77
import com.intellij.openapi.roots.ModifiableRootModel
8+
import com.intellij.openapi.ui.TextFieldWithBrowseButton
89
import com.intellij.openapi.ui.ValidationInfo
910
import com.intellij.openapi.vfs.VfsUtil
1011
import com.intellij.ui.layout.panel
@@ -23,17 +24,26 @@ import javax.swing.JComponent
2324
* A panel encapsulating AWS credential selection during SAM new project creation wizard
2425
*/
2526
class SchemaSelectionPanel : WizardFragment {
26-
private val schemaSelector = SchemaResourceSelector()
27-
private val awsConnectionSelector = AwsConnectionSettingsSelector(
28-
null,
29-
schemaSelector::reloadSchemas
30-
)
31-
private val component = panel {
32-
row {
33-
awsConnectionSelector.selectorPanel()(grow)
27+
private val schemaSelector by lazy { SchemaResourceSelector() }
28+
private val awsConnectionSelector by lazy {
29+
AwsConnectionSettingsSelector(
30+
null
31+
) {
32+
val prev = schemaSelector.awsConnection
33+
schemaSelector.awsConnection = it
34+
if (prev != null) {
35+
schemaSelector.reload()
36+
}
3437
}
35-
row(message("sam.init.schema.label")) {
36-
schemaSelector.component(grow)
38+
}
39+
private val component by lazy {
40+
panel {
41+
row {
42+
awsConnectionSelector.selectorPanel()(grow)
43+
}
44+
row(message("sam.init.schema.label")) {
45+
schemaSelector.component(grow)
46+
}
3747
}
3848
}
3949

@@ -56,6 +66,11 @@ class SchemaSelectionPanel : WizardFragment {
5666

5767
override fun isApplicable(template: SamProjectTemplate?): Boolean = template?.supportsDynamicSchemas() == true
5868

69+
override fun updateUi(projectLocation: TextFieldWithBrowseButton?, runtimeGroup: RuntimeGroup?, template: SamProjectTemplate?) {
70+
super.updateUi(projectLocation, runtimeGroup, template)
71+
schemaSelector.reload()
72+
}
73+
5974
override fun postProjectGeneration(model: ModifiableRootModel, template: SamProjectTemplate, runtime: LambdaRuntime, progressIndicator: ProgressIndicator) {
6075
if (!template.supportsDynamicSchemas()) {
6176
return

jetbrains-core/tst/software/aws/toolkits/jetbrains/services/lambda/wizard/SchemaSelectionPanelTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ class SchemaSelectionPanelTest {
228228

229229
private fun load() {
230230
initMockResourceCache()
231-
schemaSelectionPanel.reloadSchemas(connectionManager.settingsManager.connectionSettings())
231+
schemaSelectionPanel.awsConnection = connectionManager.settingsManager.connectionSettings()
232+
schemaSelectionPanel.reload()
232233
schemaSelectionPanel.schemasSelector.waitToLoad()
233234
}
234235
}

0 commit comments

Comments
 (0)