Skip to content

Commit eb6597f

Browse files
committed
Add a node in Explorer CloudFormation section to navigate user to the new CFN panel
1 parent 70e513c commit eb6597f

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ cloudformation.explorer.stacks.load_more_stacks=Load More Stacks
570570
cloudformation.explorer.stacks.node_name=Stacks
571571
cloudformation.explorer.stacks.refresh=Refresh Stacks
572572
cloudformation.explorer.tab.title=CloudFormation
573+
cloudformation.explorer.try_new_panel=Try the new CloudFormation panel
574+
cloudformation.explorer.try_new_panel.tooltip=Double-click to open the CloudFormation panel
573575
cloudformation.invalid_property=Property {0} has invalid value {1}
574576
cloudformation.key_not_found={0} not found on resource {1}
575577
cloudformation.lsp.action.configure_node=Configure Node.js

plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/core/explorer/DefaultAwsExplorerTreeStructureProvider.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ package software.aws.toolkits.jetbrains.core.explorer
66
import com.intellij.ide.util.treeView.AbstractTreeNode
77

88
class DefaultAwsExplorerTreeStructureProvider : AwsExplorerTreeStructureProvider() {
9-
// By default sort the children in alphabetical order
109
override fun modify(parent: AbstractTreeNode<*>, children: MutableCollection<AbstractTreeNode<*>>): MutableCollection<AbstractTreeNode<*>> =
11-
children.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.toString() }).toMutableList()
10+
children.sortedWith(
11+
compareBy<AbstractTreeNode<*>> { it !is PinnedFirstNode }
12+
.thenComparing(compareBy(String.CASE_INSENSITIVE_ORDER) { it.toString() })
13+
).toMutableList()
1214
}
15+
16+
/**
17+
* Marker interface for nodes that should always appear first in alphabetically sorted lists.
18+
*/
19+
interface PinnedFirstNode

plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/cloudformation/CloudFormationExplorerNodes.kt

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,29 @@
33

44
package software.aws.toolkits.jetbrains.services.cloudformation
55

6+
import com.intellij.icons.AllIcons
7+
import com.intellij.ide.projectView.PresentationData
68
import com.intellij.openapi.project.Project
9+
import com.intellij.ui.SimpleTextAttributes
10+
import com.intellij.ui.treeStructure.Tree
11+
import com.intellij.util.ui.UIUtil
12+
import com.intellij.util.ui.tree.TreeUtil
713
import icons.AwsIcons
814
import software.amazon.awssdk.services.cloudformation.CloudFormationClient
915
import software.amazon.awssdk.services.cloudformation.model.StackStatus
1016
import software.amazon.awssdk.services.cloudformation.model.StackSummary
17+
import software.aws.toolkits.jetbrains.core.explorer.AwsToolkitExplorerToolWindow
18+
import software.aws.toolkits.jetbrains.core.explorer.PinnedFirstNode
19+
import software.aws.toolkits.jetbrains.core.explorer.ToolkitToolWindowTab
1120
import software.aws.toolkits.jetbrains.core.explorer.nodes.AwsExplorerNode
1221
import software.aws.toolkits.jetbrains.core.explorer.nodes.AwsExplorerResourceNode
1322
import software.aws.toolkits.jetbrains.core.explorer.nodes.AwsExplorerServiceNode
1423
import software.aws.toolkits.jetbrains.core.explorer.nodes.CacheBackedAwsExplorerServiceRootNode
1524
import software.aws.toolkits.jetbrains.services.cloudformation.resources.CloudFormationResources
1625
import software.aws.toolkits.jetbrains.services.cloudformation.stack.StackWindowManager
1726
import software.aws.toolkits.jetbrains.utils.toHumanReadable
18-
import software.aws.toolkits.resources.message
27+
import software.aws.toolkits.resources.AwsToolkitBundle.message
28+
import javax.swing.JComponent
1929

2030
class CloudFormationServiceNode(project: Project, service: AwsExplorerServiceNode) : CacheBackedAwsExplorerServiceRootNode<StackSummary>(
2131
project,
@@ -24,6 +34,17 @@ class CloudFormationServiceNode(project: Project, service: AwsExplorerServiceNod
2434
) {
2535
override fun displayName(): String = message("explorer.node.cloudformation")
2636
override fun toNode(child: StackSummary): AwsExplorerNode<*> = CloudFormationStackNode(nodeProject, child.stackName(), child.stackStatus(), child.stackId())
37+
38+
override fun getChildren(): List<AwsExplorerNode<*>> {
39+
val hasCfnPanel = ToolkitToolWindowTab.EP_NAME.extensionList.any {
40+
it.tabId == message("cloudformation.explorer.tab.title") && it.enabled()
41+
}
42+
return if (hasCfnPanel) {
43+
listOf(TryCloudFormationPanelNode(nodeProject)) + super.getChildren()
44+
} else {
45+
super.getChildren()
46+
}
47+
}
2748
}
2849

2950
class CloudFormationStackNode(
@@ -49,3 +70,32 @@ class CloudFormationStackNode(
4970
StackWindowManager.getInstance(nodeProject).openStack(stackName, stackId)
5071
}
5172
}
73+
74+
class TryCloudFormationPanelNode(project: Project) :
75+
AwsExplorerNode<String>(project, "try-cfn-panel", AllIcons.Nodes.Favorite), PinnedFirstNode {
76+
77+
override fun getChildren(): List<AwsExplorerNode<*>> = emptyList()
78+
79+
override fun isAlwaysLeaf(): Boolean = true
80+
81+
override fun displayName(): String = message("cloudformation.explorer.try_new_panel")
82+
83+
override fun update(presentation: PresentationData) {
84+
presentation.setIcon(AllIcons.Nodes.Favorite)
85+
presentation.addText(displayName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES)
86+
presentation.tooltip = message("cloudformation.explorer.try_new_panel.tooltip")
87+
}
88+
89+
override fun onDoubleClick() {
90+
val toolWindow = AwsToolkitExplorerToolWindow.toolWindow(nodeProject)
91+
toolWindow.activate {
92+
val explorerWindow = AwsToolkitExplorerToolWindow.getInstance(nodeProject)
93+
val tabComponent = explorerWindow.selectTab(message("cloudformation.explorer.tab.title"))
94+
(tabComponent as? JComponent)?.let { component ->
95+
UIUtil.findComponentOfType(component, Tree::class.java)?.let { tree ->
96+
TreeUtil.expand(tree, 1)
97+
}
98+
}
99+
}
100+
}
101+
}

0 commit comments

Comments
 (0)