Skip to content

Commit 6bf459f

Browse files
committed
feat(cloudformation): add try new CloudFormation node to Explorer
1 parent 292181d commit 6bf459f

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
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
@@ -573,6 +573,8 @@ cloudformation.explorer.stacks.load_more_stacks=Load More Stacks
573573
cloudformation.explorer.stacks.node_name=Stacks
574574
cloudformation.explorer.stacks.refresh=Refresh Stacks
575575
cloudformation.explorer.tab.title=CloudFormation
576+
cloudformation.explorer.try_new_panel=Try the new CloudFormation panel
577+
cloudformation.explorer.try_new_panel.tooltip=Double-click to open the CloudFormation panel
576578
cloudformation.invalid_property=Property {0} has invalid value {1}
577579
cloudformation.key_not_found={0} not found on resource {1}
578580
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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,37 @@
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+
<<<<<<< Updated upstream
1118
import software.aws.toolkit.jetbrains.utils.toHumanReadable
19+
=======
20+
import software.aws.toolkits.jetbrains.core.explorer.AwsToolkitExplorerToolWindow
21+
import software.aws.toolkits.jetbrains.core.explorer.PinnedFirstNode
22+
import software.aws.toolkits.jetbrains.core.explorer.ToolkitToolWindowTab
23+
>>>>>>> Stashed changes
1224
import software.aws.toolkits.jetbrains.core.explorer.nodes.AwsExplorerNode
1325
import software.aws.toolkits.jetbrains.core.explorer.nodes.AwsExplorerResourceNode
1426
import software.aws.toolkits.jetbrains.core.explorer.nodes.AwsExplorerServiceNode
1527
import software.aws.toolkits.jetbrains.core.explorer.nodes.CacheBackedAwsExplorerServiceRootNode
1628
import software.aws.toolkits.jetbrains.services.cloudformation.resources.CloudFormationResources
1729
import software.aws.toolkits.jetbrains.services.cloudformation.stack.StackWindowManager
30+
<<<<<<< Updated upstream
1831
import software.aws.toolkits.resources.message
32+
=======
33+
import software.aws.toolkits.jetbrains.utils.toHumanReadable
34+
import software.aws.toolkits.resources.AwsToolkitBundle.message
35+
import javax.swing.JComponent
36+
>>>>>>> Stashed changes
1937

2038
class CloudFormationServiceNode(project: Project, service: AwsExplorerServiceNode) : CacheBackedAwsExplorerServiceRootNode<StackSummary>(
2139
project,
@@ -24,6 +42,17 @@ class CloudFormationServiceNode(project: Project, service: AwsExplorerServiceNod
2442
) {
2543
override fun displayName(): String = message("explorer.node.cloudformation")
2644
override fun toNode(child: StackSummary): AwsExplorerNode<*> = CloudFormationStackNode(nodeProject, child.stackName(), child.stackStatus(), child.stackId())
45+
46+
override fun getChildren(): List<AwsExplorerNode<*>> {
47+
val hasCfnPanel = ToolkitToolWindowTab.EP_NAME.extensionList.any {
48+
it.tabId == message("cloudformation.explorer.tab.title") && it.enabled()
49+
}
50+
return if (hasCfnPanel) {
51+
listOf(TryCloudFormationPanelNode(nodeProject)) + super.getChildren()
52+
} else {
53+
super.getChildren()
54+
}
55+
}
2756
}
2857

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

0 commit comments

Comments
 (0)