Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,8 @@ cloudformation.explorer.stacks.load_more_stacks=Load More Stacks
cloudformation.explorer.stacks.node_name=Stacks
cloudformation.explorer.stacks.refresh=Refresh Stacks
cloudformation.explorer.tab.title=CloudFormation
cloudformation.explorer.try_new_panel=Try the new CloudFormation panel
cloudformation.explorer.try_new_panel.tooltip=Double-click to open the CloudFormation panel
cloudformation.invalid_property=Property {0} has invalid value {1}
cloudformation.key_not_found={0} not found on resource {1}
cloudformation.lsp.action.configure_node=Configure Node.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ package software.aws.toolkits.jetbrains.core.explorer
import com.intellij.ide.util.treeView.AbstractTreeNode

class DefaultAwsExplorerTreeStructureProvider : AwsExplorerTreeStructureProvider() {
// By default sort the children in alphabetical order
override fun modify(parent: AbstractTreeNode<*>, children: MutableCollection<AbstractTreeNode<*>>): MutableCollection<AbstractTreeNode<*>> =
children.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.toString() }).toMutableList()
children.sortedWith(
compareBy<AbstractTreeNode<*>> { it !is PinnedFirstNode }
.thenComparing(compareBy(String.CASE_INSENSITIVE_ORDER) { it.toString() })
).toMutableList()
}

/**
* Marker interface for nodes that should always appear first in alphabetically sorted lists.
*/
interface PinnedFirstNode
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@

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

import com.intellij.icons.AllIcons
import com.intellij.ide.projectView.PresentationData
import com.intellij.openapi.project.Project
import com.intellij.ui.SimpleTextAttributes
import com.intellij.ui.treeStructure.Tree
import com.intellij.util.ui.UIUtil
import com.intellij.util.ui.tree.TreeUtil
import icons.AwsIcons
import software.amazon.awssdk.services.cloudformation.CloudFormationClient
import software.amazon.awssdk.services.cloudformation.model.StackStatus
import software.amazon.awssdk.services.cloudformation.model.StackSummary
import software.aws.toolkit.jetbrains.utils.toHumanReadable
import software.aws.toolkits.jetbrains.core.explorer.AwsToolkitExplorerToolWindow
import software.aws.toolkits.jetbrains.core.explorer.PinnedFirstNode
import software.aws.toolkits.jetbrains.core.explorer.ToolkitToolWindowTab
import software.aws.toolkits.jetbrains.core.explorer.nodes.AwsExplorerNode
import software.aws.toolkits.jetbrains.core.explorer.nodes.AwsExplorerResourceNode
import software.aws.toolkits.jetbrains.core.explorer.nodes.AwsExplorerServiceNode
import software.aws.toolkits.jetbrains.core.explorer.nodes.CacheBackedAwsExplorerServiceRootNode
import software.aws.toolkits.jetbrains.services.cloudformation.resources.CloudFormationResources
import software.aws.toolkits.jetbrains.services.cloudformation.stack.StackWindowManager
import software.aws.toolkits.resources.message
import software.aws.toolkits.resources.AwsToolkitBundle.message
import javax.swing.JComponent

class CloudFormationServiceNode(project: Project, service: AwsExplorerServiceNode) : CacheBackedAwsExplorerServiceRootNode<StackSummary>(
project,
Expand All @@ -24,6 +34,17 @@ class CloudFormationServiceNode(project: Project, service: AwsExplorerServiceNod
) {
override fun displayName(): String = message("explorer.node.cloudformation")
override fun toNode(child: StackSummary): AwsExplorerNode<*> = CloudFormationStackNode(nodeProject, child.stackName(), child.stackStatus(), child.stackId())

override fun getChildren(): List<AwsExplorerNode<*>> {
val hasCfnPanel = ToolkitToolWindowTab.EP_NAME.extensionList.any {
it.tabId == message("cloudformation.explorer.tab.title") && it.enabled()
}
return if (hasCfnPanel) {
listOf(TryCloudFormationPanelNode(nodeProject)) + super.getChildren()
} else {
super.getChildren()
}
}
}

class CloudFormationStackNode(
Expand All @@ -49,3 +70,32 @@ class CloudFormationStackNode(
StackWindowManager.getInstance(nodeProject).openStack(stackName, stackId)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add conditional logic to only have this appear for versions 253+?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hasCfnPanel condition above will be false since the tool window is registered only for 253+.

class TryCloudFormationPanelNode(project: Project) :
AwsExplorerNode<String>(project, "try-cfn-panel", AllIcons.Nodes.Favorite), PinnedFirstNode {

override fun getChildren(): List<AwsExplorerNode<*>> = emptyList()

override fun isAlwaysLeaf(): Boolean = true

override fun displayName(): String = message("cloudformation.explorer.try_new_panel")

override fun update(presentation: PresentationData) {
presentation.setIcon(AllIcons.Nodes.Favorite)
presentation.addText(displayName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES)
presentation.tooltip = message("cloudformation.explorer.try_new_panel.tooltip")
}

override fun onDoubleClick() {
val toolWindow = AwsToolkitExplorerToolWindow.toolWindow(nodeProject)
toolWindow.activate {
val explorerWindow = AwsToolkitExplorerToolWindow.getInstance(nodeProject)
val tabComponent = explorerWindow.selectTab(message("cloudformation.explorer.tab.title"))
(tabComponent as? JComponent)?.let { component ->
UIUtil.findComponentOfType(component, Tree::class.java)?.let { tree ->
TreeUtil.expand(tree, 1)
}
}
}
}
}
Loading