mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
GUI-44 Generalize inspectionTree to tableTree
This commit is contained in:
+30
-234
@@ -15,15 +15,11 @@
|
||||
*/
|
||||
package com.intellij.testGuiFramework.driver
|
||||
|
||||
import com.intellij.testGuiFramework.cellReader.ExtendedJTreeCellReader
|
||||
import com.intellij.testGuiFramework.impl.GuiTestUtilKt.computeOnEdt
|
||||
import com.intellij.testGuiFramework.impl.GuiTestUtilKt.computeOnEdtWithTry
|
||||
import com.intellij.testGuiFramework.impl.GuiTestUtilKt.runOnEdt
|
||||
import com.intellij.ui.LoadingNode
|
||||
import com.intellij.ui.treeStructure.treetable.TreeTableTree
|
||||
import org.fest.assertions.Assertions
|
||||
import org.fest.reflect.core.Reflection
|
||||
import org.fest.swing.cell.JTreeCellReader
|
||||
import org.fest.swing.core.MouseButton
|
||||
import org.fest.swing.core.MouseClickInfo
|
||||
import org.fest.swing.core.Robot
|
||||
@@ -39,15 +35,12 @@ import org.fest.swing.util.Pair
|
||||
import org.fest.swing.util.Triple
|
||||
import org.fest.util.Lists
|
||||
import org.fest.util.Preconditions
|
||||
import java.awt.Dimension
|
||||
import java.awt.Point
|
||||
import java.awt.Rectangle
|
||||
import javax.annotation.Nonnull
|
||||
import javax.swing.JPopupMenu
|
||||
import javax.swing.JTree
|
||||
import javax.swing.plaf.basic.BasicTreeUI
|
||||
import javax.swing.tree.DefaultTreeModel
|
||||
import javax.swing.tree.TreeNode
|
||||
import javax.swing.tree.TreePath
|
||||
|
||||
/**
|
||||
@@ -70,14 +63,7 @@ open class ExtendedJTreeDriver(robot: Robot) : JTreeDriver(robot) {
|
||||
times: Int = 1,
|
||||
attempts: Int = DEFAULT_FIND_PATH_ATTEMPTS) {
|
||||
val point = scrollToPath(tree, pathStrings)
|
||||
if (tree is TreeTableTree) {
|
||||
val inspectionPanelHeight = tree.treeTable.visibleRect.height
|
||||
tree.treeTable.scrollRectToVisible(Rectangle(Point(0, point.y + inspectionPanelHeight / 2), Dimension(0, 0)))
|
||||
robot.click(tree.treeTable, point, button, times)
|
||||
}
|
||||
else {
|
||||
robot.click(tree, point, button, times)
|
||||
}
|
||||
robot.click(tree, point, button, times)
|
||||
//check that path is selected or click it again
|
||||
if (!checkPathIsSelected(tree, pathStrings)) {
|
||||
if (attempts == 0) throw Exception(
|
||||
@@ -305,195 +291,6 @@ open class ExtendedJTreeDriver(robot: Robot) : JTreeDriver(robot) {
|
||||
return changed
|
||||
}
|
||||
|
||||
internal class ExtendedJTreePathFinder {
|
||||
|
||||
private var cellReader: JTreeCellReader? = null
|
||||
|
||||
init {
|
||||
this.replaceCellReader(ExtendedJTreeCellReader())
|
||||
}
|
||||
|
||||
fun findMatchingPath(tree: JTree, pathStrings: List<String>): TreePath {
|
||||
|
||||
val model = tree.model
|
||||
val newPathValues = Lists.newArrayList<Any>()
|
||||
var node: Any = model.root
|
||||
val pathElementCount = pathStrings.size
|
||||
|
||||
for (stringIndex in 0..pathElementCount - 1) {
|
||||
val pathString = pathStrings[stringIndex]
|
||||
if (stringIndex == 0 && tree.isRootVisible) {
|
||||
if (pathString != value(tree, node)) throw pathNotFound(pathStrings)
|
||||
newPathValues.add(node)
|
||||
}
|
||||
else {
|
||||
try {
|
||||
node = traverseChildren(tree, node, pathString) ?: throw pathNotFound(pathStrings)
|
||||
}
|
||||
catch (e: LoadingNodeException) { //if we met loading node let's tell it to caller and probably expand path to clarify this node
|
||||
e.treePath = TreePath(newPathValues.toTypedArray())
|
||||
throw e
|
||||
}
|
||||
newPathValues.add(node)
|
||||
}
|
||||
}
|
||||
return TreePath(newPathValues.toTypedArray())
|
||||
}
|
||||
|
||||
private fun traverseChildren(tree: JTree,
|
||||
node: Any,
|
||||
pathString: String): Any? {
|
||||
var match: Any? = null
|
||||
val model = tree.model
|
||||
val childCount = model.getChildCount(node)
|
||||
|
||||
for (childIndex in 0..childCount - 1) {
|
||||
val child = model.getChild(node, childIndex)
|
||||
if (child is LoadingNode) throw LoadingNodeException(child, null)
|
||||
if (pathString == value(tree, child)) {
|
||||
if (match != null) throw multipleMatchingNodes(pathString, value(tree, node))
|
||||
match = child
|
||||
}
|
||||
}
|
||||
|
||||
return match
|
||||
}
|
||||
|
||||
|
||||
fun findMatchingPath(tree: JTree, pathStrings: List<String>, isUniquePath: Boolean = true): TreePath {
|
||||
if (isUniquePath) return findMatchingPath(tree, pathStrings)
|
||||
|
||||
//remove node order if path is a not unique
|
||||
val pathStringsWithoutOrder = if (isUniquePath) pathStrings else pathStrings.map { it.getWithoutOrder() }
|
||||
|
||||
val model = tree.model
|
||||
if (tree.isRootVisible) {
|
||||
if (pathStringsWithoutOrder[0] != value(tree, model.root)) throw pathNotFound(pathStringsWithoutOrder)
|
||||
if (pathStringsWithoutOrder.size == 1) return TreePath(arrayOf<Any>(model.root))
|
||||
val result: TreePath = findMatchingPath(tree, model.root,
|
||||
pathStringsWithoutOrder.subList(1, pathStringsWithoutOrder.size)) ?: throw pathNotFound(
|
||||
pathStringsWithoutOrder)
|
||||
return TreePath(arrayOf<Any>(model.root, *result.path))
|
||||
}
|
||||
else {
|
||||
return findMatchingPath(tree, model.root, pathStringsWithoutOrder) ?: throw pathNotFound(pathStringsWithoutOrder)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* this method tries to find any path. If tree contains multiple of searchable path it still accepts.
|
||||
*/
|
||||
private fun findMatchingPath(tree: JTree, node: Any, pathStrings: List<String>): TreePath? {
|
||||
val model = tree.model
|
||||
val childCount = model.getChildCount(node)
|
||||
|
||||
for (childIndex in 0..childCount - 1) {
|
||||
val child = model.getChild(node, childIndex)
|
||||
if (child is LoadingNode) throw LoadingNodeException(child, getPathToNode(tree, node))
|
||||
if (pathStrings.size == 1 && value(tree, child) == pathStrings[0]) {
|
||||
|
||||
return TreePath(arrayOf<Any>(child))
|
||||
}
|
||||
else {
|
||||
if (pathStrings[0] == value(tree, child)) {
|
||||
val childResult = findMatchingPath(tree, child, pathStrings.subList(1, pathStrings.size))
|
||||
if (childResult != null) return TreePath(arrayOf<Any>(child, *childResult.path))
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun getPathToNode(tree: JTree, node: Any): TreePath {
|
||||
val treeModel = tree.model as DefaultTreeModel
|
||||
var path = treeModel.getPathToRoot(node as TreeNode)
|
||||
if (!tree.isRootVisible) path = path.sliceArray(1..path.size - 1)
|
||||
return TreePath(path)
|
||||
}
|
||||
|
||||
fun findMatchingXPath(tree: JTree, xPathStrings: List<String>): TreePath {
|
||||
val model = tree.model
|
||||
if (tree.isRootVisible) {
|
||||
if (xPathStrings[0] != value(tree, model.root)) throw pathNotFound(xPathStrings)
|
||||
if (xPathStrings.size == 1) return TreePath(arrayOf<Any>(model.root))
|
||||
|
||||
val result: TreePath = findMatchingXPath(tree, model.root, xPathStrings.subList(1, xPathStrings.size)) ?: throw pathNotFound(
|
||||
xPathStrings)
|
||||
return TreePath(arrayOf<Any>(model.root, *result.path))
|
||||
}
|
||||
else {
|
||||
return findMatchingXPath(tree, model.root, xPathStrings) ?: throw pathNotFound(xPathStrings)
|
||||
}
|
||||
}
|
||||
|
||||
private fun findMatchingXPath(tree: JTree, node: Any, xPathStrings: List<String>): TreePath? {
|
||||
val model = tree.model
|
||||
val childCount = model.getChildCount(node)
|
||||
|
||||
val order = xPathStrings[0].getOrder() ?: 0
|
||||
val original = getWithoutOrder(xPathStrings[0], order)
|
||||
var currentOrder = 0
|
||||
|
||||
for (childIndex in 0..childCount - 1) {
|
||||
val child = model.getChild(node, childIndex)
|
||||
if (original == value(tree, child)) {
|
||||
if (currentOrder == order) {
|
||||
if (xPathStrings.size == 1) {
|
||||
return TreePath(arrayOf<Any>(child))
|
||||
}
|
||||
else {
|
||||
val childResult = findMatchingXPath(tree, child, xPathStrings.subList(1, xPathStrings.size))
|
||||
if (childResult != null) return TreePath(arrayOf<Any>(child, *childResult.path))
|
||||
}
|
||||
}
|
||||
else {
|
||||
currentOrder++
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun getWithoutOrder(potentiallyOrderedNode: String, order: Int): CharSequence {
|
||||
return if (potentiallyOrderedNode.hasOrder()) potentiallyOrderedNode.subSequence(0,
|
||||
potentiallyOrderedNode.length - 2 - (order.toString().length))
|
||||
else potentiallyOrderedNode
|
||||
}
|
||||
|
||||
private fun String.getWithoutOrder(): String = getWithoutOrder(this, this.getOrder() ?: 0).toString()
|
||||
|
||||
private fun String.hasOrder(): Boolean =
|
||||
Regex("\\(\\d\\)").find(this)?.value?.isNotEmpty() ?: false
|
||||
|
||||
|
||||
private fun String.getOrder(): Int? {
|
||||
val find: MatchResult = Regex("\\(\\d\\)").find(this) ?: return null
|
||||
return find.value.removeSurrounding("(", ")").toInt()
|
||||
}
|
||||
|
||||
private fun pathNotFound(path: List<String>): LocationUnavailableException {
|
||||
throw LocationUnavailableException("Unable to find path \"$path\"")
|
||||
}
|
||||
|
||||
private fun multipleMatchingNodes(pathString: String, parentText: Any): LocationUnavailableException {
|
||||
throw LocationUnavailableException("There is more than one node with value '$pathString' under \"$parentText\"")
|
||||
}
|
||||
|
||||
private fun value(tree: JTree, modelValue: Any): String {
|
||||
return eraseZeroSpaceSymbols(cellReader!!.valueAt(tree, modelValue)!!)
|
||||
}
|
||||
|
||||
private fun eraseZeroSpaceSymbols(string: String): String = string.replace("\u200B", "")
|
||||
|
||||
fun replaceCellReader(newCellReader: JTreeCellReader) {
|
||||
cellReader = newCellReader
|
||||
}
|
||||
|
||||
fun cellReader(): JTreeCellReader {
|
||||
return cellReader!!
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* node that has as child LoadingNode
|
||||
*/
|
||||
@@ -524,10 +321,7 @@ open class ExtendedJTreeDriver(robot: Robot) : JTreeDriver(robot) {
|
||||
|
||||
private fun verifyJTreeIsReadyAndFindMatchingPath(tree: JTree, pathStrings: List<String>): TreePath {
|
||||
return computeOnEdt {
|
||||
if (tree is TreeTableTree)
|
||||
ComponentPreconditions.checkEnabledAndShowing(tree.treeTable)
|
||||
else
|
||||
ComponentPreconditions.checkEnabledAndShowing(tree)
|
||||
ComponentPreconditions.checkEnabledAndShowing(tree)
|
||||
matchingPathWithRootIfInvisible(tree, pathStrings, true)
|
||||
}!!
|
||||
}
|
||||
@@ -561,40 +355,17 @@ open class ExtendedJTreeDriver(robot: Robot) : JTreeDriver(robot) {
|
||||
|
||||
private fun matchingPathWithRootIfInvisible(tree: JTree, pathStrings: List<String>, isUniquePath: Boolean): TreePath {
|
||||
val matchingPath = pathFinder.findMatchingPath(tree, pathStrings, isUniquePath)
|
||||
return addRootIfInvisible(tree, matchingPath)
|
||||
return Companion.addRootIfInvisible(tree, matchingPath)
|
||||
}
|
||||
|
||||
private fun matchingXPathWithRootIfInvisible(tree: JTree, xPathStrings: List<String>, isUniquePath: Boolean): TreePath {
|
||||
val matchingPath = pathFinder.findMatchingXPath(tree, xPathStrings)
|
||||
return addRootIfInvisible(tree, matchingPath)
|
||||
}
|
||||
|
||||
private fun addRootIfInvisible(@Nonnull tree: JTree, @Nonnull path: TreePath): TreePath {
|
||||
val root = tree.model.root
|
||||
if (!tree.isRootVisible && root != null) {
|
||||
if (path.pathCount > 0 && root === path.getPathComponent(0)) {
|
||||
return path
|
||||
}
|
||||
else {
|
||||
val pathAsArray = path.path
|
||||
if (pathAsArray == null) {
|
||||
return TreePath(Lists.newArrayList(*arrayOf(root)))
|
||||
}
|
||||
else {
|
||||
val newPath = Lists.newArrayList(*pathAsArray)
|
||||
newPath.add(0, root)
|
||||
return TreePath(newPath.toTypedArray())
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return path
|
||||
}
|
||||
return Companion.addRootIfInvisible(tree, matchingPath)
|
||||
}
|
||||
|
||||
private fun expandTreePath(tree: JTree, path: TreePath) {
|
||||
runOnEdt {
|
||||
val realPath = addRootIfInvisible(tree, path)
|
||||
val realPath = Companion.addRootIfInvisible(tree, path)
|
||||
if (!tree.isExpanded(path)) tree.expandPath(realPath)
|
||||
}
|
||||
}
|
||||
@@ -648,5 +419,30 @@ open class ExtendedJTreeDriver(robot: Robot) : JTreeDriver(robot) {
|
||||
})
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun addRootIfInvisible(@Nonnull tree: JTree, @Nonnull path: TreePath): TreePath {
|
||||
val root = tree.model.root
|
||||
if (!tree.isRootVisible && root != null) {
|
||||
if (path.pathCount > 0 && root === path.getPathComponent(0)) {
|
||||
return path
|
||||
}
|
||||
else {
|
||||
val pathAsArray = path.path
|
||||
if (pathAsArray == null) {
|
||||
return TreePath(Lists.newArrayList(*arrayOf(root)))
|
||||
}
|
||||
else {
|
||||
val newPath = Lists.newArrayList(*pathAsArray)
|
||||
newPath.add(0, root)
|
||||
return TreePath(newPath.toTypedArray())
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+206
@@ -0,0 +1,206 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.testGuiFramework.driver
|
||||
|
||||
import com.intellij.testGuiFramework.cellReader.ExtendedJTreeCellReader
|
||||
import com.intellij.ui.LoadingNode
|
||||
import org.fest.swing.cell.JTreeCellReader
|
||||
import org.fest.swing.exception.LocationUnavailableException
|
||||
import org.fest.util.Lists
|
||||
import javax.swing.JTree
|
||||
import javax.swing.tree.DefaultTreeModel
|
||||
import javax.swing.tree.TreeNode
|
||||
import javax.swing.tree.TreePath
|
||||
|
||||
class ExtendedJTreePathFinder {
|
||||
|
||||
private var cellReader: JTreeCellReader? = null
|
||||
|
||||
init {
|
||||
this.replaceCellReader(ExtendedJTreeCellReader())
|
||||
}
|
||||
|
||||
fun findMatchingPath(tree: JTree, pathStrings: List<String>): TreePath {
|
||||
|
||||
val model = tree.model
|
||||
val newPathValues = Lists.newArrayList<Any>()
|
||||
var node: Any = model.root
|
||||
val pathElementCount = pathStrings.size
|
||||
|
||||
for (stringIndex in 0..pathElementCount - 1) {
|
||||
val pathString = pathStrings[stringIndex]
|
||||
if (stringIndex == 0 && tree.isRootVisible) {
|
||||
if (pathString != value(tree, node)) throw pathNotFound(pathStrings)
|
||||
newPathValues.add(node)
|
||||
}
|
||||
else {
|
||||
try {
|
||||
node = traverseChildren(tree, node, pathString) ?: throw pathNotFound(pathStrings)
|
||||
}
|
||||
catch (e: ExtendedJTreeDriver.LoadingNodeException) { //if we met loading node let's tell it to caller and probably expand path to clarify this node
|
||||
e.treePath = TreePath(newPathValues.toTypedArray())
|
||||
throw e
|
||||
}
|
||||
newPathValues.add(node)
|
||||
}
|
||||
}
|
||||
return TreePath(newPathValues.toTypedArray())
|
||||
}
|
||||
|
||||
private fun traverseChildren(tree: JTree,
|
||||
node: Any,
|
||||
pathString: String): Any? {
|
||||
var match: Any? = null
|
||||
val model = tree.model
|
||||
val childCount = model.getChildCount(node)
|
||||
|
||||
for (childIndex in 0..childCount - 1) {
|
||||
val child = model.getChild(node, childIndex)
|
||||
if (child is LoadingNode) throw ExtendedJTreeDriver.LoadingNodeException(child,
|
||||
null)
|
||||
if (pathString == value(tree, child)) {
|
||||
if (match != null) throw multipleMatchingNodes(pathString, value(tree, node))
|
||||
match = child
|
||||
}
|
||||
}
|
||||
|
||||
return match
|
||||
}
|
||||
|
||||
|
||||
fun findMatchingPath(tree: JTree, pathStrings: List<String>, isUniquePath: Boolean = true): TreePath {
|
||||
if (isUniquePath) return findMatchingPath(tree, pathStrings)
|
||||
|
||||
//remove node order if path is a not unique
|
||||
val pathStringsWithoutOrder = if (isUniquePath) pathStrings else pathStrings.map { it.getWithoutOrder() }
|
||||
|
||||
val model = tree.model
|
||||
if (tree.isRootVisible) {
|
||||
if (pathStringsWithoutOrder[0] != value(tree, model.root)) throw pathNotFound(pathStringsWithoutOrder)
|
||||
if (pathStringsWithoutOrder.size == 1) return TreePath(arrayOf<Any>(model.root))
|
||||
val result: TreePath = findMatchingPath(tree, model.root,
|
||||
pathStringsWithoutOrder.subList(1, pathStringsWithoutOrder.size)) ?: throw pathNotFound(
|
||||
pathStringsWithoutOrder)
|
||||
return TreePath(arrayOf<Any>(model.root, *result.path))
|
||||
}
|
||||
else {
|
||||
return findMatchingPath(tree, model.root, pathStringsWithoutOrder) ?: throw pathNotFound(pathStringsWithoutOrder)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* this method tries to find any path. If tree contains multiple of searchable path it still accepts.
|
||||
*/
|
||||
private fun findMatchingPath(tree: JTree, node: Any, pathStrings: List<String>): TreePath? {
|
||||
val model = tree.model
|
||||
val childCount = model.getChildCount(node)
|
||||
|
||||
for (childIndex in 0..childCount - 1) {
|
||||
val child = model.getChild(node, childIndex)
|
||||
if (child is LoadingNode) throw ExtendedJTreeDriver.LoadingNodeException(child,
|
||||
getPathToNode(
|
||||
tree,
|
||||
node))
|
||||
if (pathStrings.size == 1 && value(tree, child) == pathStrings[0]) {
|
||||
|
||||
return TreePath(arrayOf<Any>(child))
|
||||
}
|
||||
else {
|
||||
if (pathStrings[0] == value(tree, child)) {
|
||||
val childResult = findMatchingPath(tree, child, pathStrings.subList(1, pathStrings.size))
|
||||
if (childResult != null) return TreePath(arrayOf<Any>(child, *childResult.path))
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun getPathToNode(tree: JTree, node: Any): TreePath {
|
||||
val treeModel = tree.model as DefaultTreeModel
|
||||
var path = treeModel.getPathToRoot(node as TreeNode)
|
||||
if (!tree.isRootVisible) path = path.sliceArray(1..path.size - 1)
|
||||
return TreePath(path)
|
||||
}
|
||||
|
||||
fun findMatchingXPath(tree: JTree, xPathStrings: List<String>): TreePath {
|
||||
val model = tree.model
|
||||
if (tree.isRootVisible) {
|
||||
if (xPathStrings[0] != value(tree, model.root)) throw pathNotFound(xPathStrings)
|
||||
if (xPathStrings.size == 1) return TreePath(arrayOf<Any>(model.root))
|
||||
|
||||
val result: TreePath = findMatchingXPath(tree, model.root, xPathStrings.subList(1, xPathStrings.size)) ?: throw pathNotFound(
|
||||
xPathStrings)
|
||||
return TreePath(arrayOf<Any>(model.root, *result.path))
|
||||
}
|
||||
else {
|
||||
return findMatchingXPath(tree, model.root, xPathStrings) ?: throw pathNotFound(xPathStrings)
|
||||
}
|
||||
}
|
||||
|
||||
private fun findMatchingXPath(tree: JTree, node: Any, xPathStrings: List<String>): TreePath? {
|
||||
val model = tree.model
|
||||
val childCount = model.getChildCount(node)
|
||||
|
||||
val order = xPathStrings[0].getOrder() ?: 0
|
||||
val original = getWithoutOrder(xPathStrings[0], order)
|
||||
var currentOrder = 0
|
||||
|
||||
for (childIndex in 0..childCount - 1) {
|
||||
val child = model.getChild(node, childIndex)
|
||||
if (original == value(tree, child)) {
|
||||
if (currentOrder == order) {
|
||||
if (xPathStrings.size == 1) {
|
||||
return TreePath(arrayOf<Any>(child))
|
||||
}
|
||||
else {
|
||||
val childResult = findMatchingXPath(tree, child, xPathStrings.subList(1, xPathStrings.size))
|
||||
if (childResult != null) return TreePath(arrayOf<Any>(child, *childResult.path))
|
||||
}
|
||||
}
|
||||
else {
|
||||
currentOrder++
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun getWithoutOrder(potentiallyOrderedNode: String, order: Int): CharSequence {
|
||||
return if (potentiallyOrderedNode.hasOrder()) potentiallyOrderedNode.subSequence(0,
|
||||
potentiallyOrderedNode.length - 2 - (order.toString().length))
|
||||
else potentiallyOrderedNode
|
||||
}
|
||||
|
||||
private fun String.getWithoutOrder(): String = getWithoutOrder(this, this.getOrder() ?: 0).toString()
|
||||
|
||||
private fun String.hasOrder(): Boolean =
|
||||
Regex("\\(\\d\\)").find(this)?.value?.isNotEmpty() ?: false
|
||||
|
||||
|
||||
private fun String.getOrder(): Int? {
|
||||
val find: MatchResult = Regex("\\(\\d\\)").find(this) ?: return null
|
||||
return find.value.removeSurrounding("(", ")").toInt()
|
||||
}
|
||||
|
||||
private fun pathNotFound(path: List<String>): LocationUnavailableException {
|
||||
throw LocationUnavailableException("Unable to find path \"$path\"")
|
||||
}
|
||||
|
||||
private fun multipleMatchingNodes(pathString: String, parentText: Any): LocationUnavailableException {
|
||||
throw LocationUnavailableException(
|
||||
"There is more than one node with value '$pathString' under \"$parentText\"")
|
||||
}
|
||||
|
||||
private fun value(tree: JTree, modelValue: Any): String {
|
||||
return eraseZeroSpaceSymbols(cellReader!!.valueAt(tree, modelValue)!!)
|
||||
}
|
||||
|
||||
private fun eraseZeroSpaceSymbols(string: String): String = string.replace("\u200B", "")
|
||||
|
||||
fun replaceCellReader(newCellReader: JTreeCellReader) {
|
||||
cellReader = newCellReader
|
||||
}
|
||||
|
||||
fun cellReader(): JTreeCellReader {
|
||||
return cellReader!!
|
||||
}
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.testGuiFramework.fixtures
|
||||
|
||||
import com.intellij.profile.codeInspection.ui.inspectionsTree.InspectionsConfigTreeTable
|
||||
import com.intellij.testGuiFramework.driver.ExtendedJTreeDriver
|
||||
import com.intellij.testGuiFramework.fixtures.extended.ExtendedTreeFixture
|
||||
import org.fest.swing.core.MouseButton
|
||||
import org.fest.swing.core.Robot
|
||||
|
||||
class InspectionsTreeFixture(val robot: Robot, val target: InspectionsConfigTreeTable) :
|
||||
ComponentFixture<InspectionsTreeFixture, InspectionsConfigTreeTable>(InspectionsTreeFixture::class.java, robot, target) {
|
||||
|
||||
@Suppress("unused")
|
||||
fun selectPath(vararg path: String) {
|
||||
val treeFixture = ExtendedTreeFixture(robot, target.tree)
|
||||
treeFixture.replaceDriverWith(ExtendedJTreeDriver(robot))
|
||||
treeFixture.clickPath(path.toList(), MouseButton.LEFT_BUTTON)
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.testGuiFramework.fixtures
|
||||
|
||||
import com.intellij.testGuiFramework.driver.ExtendedJTreeDriver
|
||||
import com.intellij.testGuiFramework.driver.ExtendedJTreePathFinder
|
||||
import com.intellij.ui.treeStructure.treetable.TreeTable
|
||||
import com.intellij.util.ui.tree.TreeUtil
|
||||
import org.fest.swing.core.MouseButton
|
||||
import org.fest.swing.core.Robot
|
||||
import org.fest.swing.driver.ComponentPreconditions
|
||||
import org.fest.swing.driver.JTreeLocation
|
||||
import java.awt.Dimension
|
||||
import java.awt.Point
|
||||
import java.awt.Rectangle
|
||||
|
||||
class TreeTableFixture(val robot: Robot, val target: TreeTable) :
|
||||
ComponentFixture<TreeTableFixture, TreeTable>(TreeTableFixture::class.java, robot, target) {
|
||||
|
||||
@Suppress("unused")
|
||||
fun selectPath(vararg pathStrings: String) {
|
||||
ComponentPreconditions.checkEnabledAndShowing(target)
|
||||
|
||||
val tree = target.tree
|
||||
val pathWithoutRoot = ExtendedJTreePathFinder().findMatchingPath(tree, pathStrings.asList())
|
||||
val path = ExtendedJTreeDriver.addRootIfInvisible(tree, pathWithoutRoot)
|
||||
val point = JTreeLocation().pathBoundsAndCoordinates(tree, path).second
|
||||
|
||||
val visibleHeight = target.visibleRect.height
|
||||
target.scrollRectToVisible(Rectangle(Point(0, point.y + visibleHeight / 2), Dimension(0, 0)))
|
||||
robot.click(target, point, MouseButton.LEFT_BUTTON, 1)
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -32,7 +32,6 @@ import com.intellij.openapi.wm.impl.ToolWindowImpl
|
||||
import com.intellij.openapi.wm.impl.ToolWindowManagerImpl
|
||||
import com.intellij.openapi.wm.impl.WindowManagerImpl
|
||||
import com.intellij.openapi.wm.impl.welcomeScreen.FlatWelcomeFrame
|
||||
import com.intellij.profile.codeInspection.ui.inspectionsTree.InspectionsConfigTreeTable
|
||||
import com.intellij.testGuiFramework.cellReader.ExtendedJListCellReader
|
||||
import com.intellij.testGuiFramework.cellReader.ExtendedJTableCellReader
|
||||
import com.intellij.testGuiFramework.driver.CheckboxTreeDriver
|
||||
@@ -59,6 +58,7 @@ import com.intellij.ui.components.labels.ActionLink
|
||||
import com.intellij.ui.components.labels.LinkLabel
|
||||
import com.intellij.ui.messages.SheetController
|
||||
import com.intellij.ui.treeStructure.SimpleTree
|
||||
import com.intellij.ui.treeStructure.treetable.TreeTable
|
||||
import com.intellij.util.ui.tree.TreeUtil
|
||||
import org.fest.reflect.core.Reflection.field
|
||||
import org.fest.swing.core.BasicRobot
|
||||
@@ -110,12 +110,12 @@ class JSpinnerGenerator : ComponentCodeGenerator<JButton> {
|
||||
}
|
||||
}
|
||||
|
||||
class InspectionsGenerator : ComponentCodeGenerator<InspectionsConfigTreeTable>{
|
||||
override fun accept(cmp: Component): Boolean = cmp is InspectionsConfigTreeTable
|
||||
override fun generate(cmp: InspectionsConfigTreeTable, me: MouseEvent, cp: Point): String {
|
||||
class TreeTableGenerator : ComponentCodeGenerator<TreeTable>{
|
||||
override fun accept(cmp: Component): Boolean = cmp is TreeTable
|
||||
override fun generate(cmp: TreeTable, me: MouseEvent, cp: Point): String {
|
||||
val path = cmp.tree.getClosestPathForLocation(cp.x, cp.y).toString()
|
||||
val realPath = path.trim('[',']').split(',').drop(1).map { it->it.trim() }.joinToString(separator = "\",\"")
|
||||
return """inspectionsTree().selectPath("$realPath")"""
|
||||
return """treeTable().selectPath("$realPath")"""
|
||||
}
|
||||
override fun priority(): Int = 10
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import com.intellij.ui.CheckboxTree
|
||||
import com.intellij.ui.HyperlinkLabel
|
||||
import com.intellij.ui.components.JBLabel
|
||||
import com.intellij.ui.components.labels.LinkLabel
|
||||
import com.intellij.ui.treeStructure.treetable.TreeTable
|
||||
import org.fest.swing.exception.ActionFailedException
|
||||
import org.fest.swing.exception.ComponentLookupException
|
||||
import org.fest.swing.exception.WaitTimedOutError
|
||||
@@ -264,13 +265,13 @@ open class GuiTestCase {
|
||||
throw UnableToFindComponent("ComponentWithBrowseButton with labelFor=$boundedLabelText")
|
||||
}
|
||||
|
||||
fun <S, C : Component> ComponentFixture<S, C>.inspectionsTree(timeout: Long = defaultTimeout): InspectionsTreeFixture {
|
||||
fun <S, C : Component> ComponentFixture<S, C>.treeTable(timeout: Long = defaultTimeout): TreeTableFixture {
|
||||
if (target() is Container) {
|
||||
val inspectionsTable = waitUntilFound(guiTestRule.robot(), target() as Container,
|
||||
typeMatcher(InspectionsConfigTreeTable::class.java) { true },
|
||||
val table = waitUntilFound(guiTestRule.robot(), target() as Container,
|
||||
typeMatcher(TreeTable::class.java) { true },
|
||||
timeout.toFestTimeout()
|
||||
)
|
||||
return InspectionsTreeFixture(guiTestRule.robot(), inspectionsTable)
|
||||
return TreeTableFixture(guiTestRule.robot(), table)
|
||||
}
|
||||
else throw UnsupportedOperationException(
|
||||
"Sorry, unable to find inspections tree with ${target()} as a Container")
|
||||
|
||||
Reference in New Issue
Block a user