diff --git a/plugins/performanceTesting/remote-driver/src/com/jetbrains/performancePlugin/remotedriver/fixtures/JChangesListViewFixture.kt b/plugins/performanceTesting/remote-driver/src/com/jetbrains/performancePlugin/remotedriver/fixtures/JChangesListViewFixture.kt index dc3baead5c6b..b91bbf3abd68 100644 --- a/plugins/performanceTesting/remote-driver/src/com/jetbrains/performancePlugin/remotedriver/fixtures/JChangesListViewFixture.kt +++ b/plugins/performanceTesting/remote-driver/src/com/jetbrains/performancePlugin/remotedriver/fixtures/JChangesListViewFixture.kt @@ -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")