IJPL-197333 JChangesListViewFixture: handleCheckBoxWithFileName: InvocationTargetException

GitOrigin-RevId: b846f12072e48c041a19ea1d51d7287c0ccde7b4
This commit is contained in:
Dmitry Batrak
2025-08-04 11:05:20 +00:00
committed by intellij-monorepo-bot
parent 1c8f862f8f
commit d2fc5633df
@@ -5,7 +5,6 @@ import com.intellij.util.ui.tree.TreeUtil
import com.jetbrains.performancePlugin.remotedriver.dataextractor.computeOnEdt
import org.assertj.swing.core.Robot
import java.awt.Point
import java.awt.Rectangle
import javax.swing.JCheckBox
import javax.swing.JPanel
import javax.swing.JTree
@@ -23,37 +22,39 @@ class JChangesListViewFixture(private val robot: Robot, private val component: J
}
private fun handleCheckBoxWithFileName(fileName: String, setEnabled: Boolean) {
val fileTreePathLocation = computeOnEdt {
calcClickPoint(fileName, setEnabled)
}
if (fileTreePathLocation != null) {
robot.click(component, fileTreePathLocation)
}
}
private fun calcClickPoint(fileName: String, setEnabled: Boolean) : Point? {
val root = component.model.root as DefaultMutableTreeNode
val node = TreeUtil.findNode(root) { it.toString().contains(fileName) } ?: error("Node with name containing $fileName is not found")
val fileTreePath = TreePath(node.path)
val checkbox = getCheckBoxForNode(node, fileTreePath)
if (checkbox.isSelected != setEnabled) {
val fileTreePathLocation = computeOnEdt {
component.getPathBounds(fileTreePath) ?: error("Have not found bounds")
}
clickOnCheckbox(checkbox, fileTreePathLocation)
}
}
if (checkbox.isSelected == setEnabled) return null
private fun clickOnCheckbox(checkbox: JCheckBox, fileTreePathLocation: Rectangle) {
val fileTreePathLocation = component.getPathBounds(fileTreePath) ?: error("Have not found bounds")
val checkBoxBounds = checkbox.bounds
val clickX = fileTreePathLocation.x + checkBoxBounds.width / 2
val clickY = fileTreePathLocation.y + checkBoxBounds.height / 2
robot.click(component, Point(clickX, clickY))
return Point(clickX, clickY)
}
private fun getCheckBoxForNode(node: DefaultMutableTreeNode?, fileTreePath: TreePath): JCheckBox {
val renderer = computeOnEdt {
component.cellRenderer.getTreeCellRendererComponent(component, node,
component.isPathSelected(fileTreePath), component.isExpanded(fileTreePath),
component.model.isLeaf(node),
component.getRowForPath(fileTreePath),
component.isPathEditable(fileTreePath))
}
val renderer = component.cellRenderer.getTreeCellRendererComponent(component, node,
component.isPathSelected(fileTreePath),
component.isExpanded(fileTreePath),
component.model.isLeaf(node),
component.getRowForPath(fileTreePath),
component.isPathEditable(fileTreePath))
val jpanel = renderer as? JPanel ?: error("Only JPanel is currently supported")
val checkbox = jpanel.components.singleOrNull { it is JCheckBox } as? JCheckBox ?: error("Only JCheckBox is currently supported")