Skip to content

Commit

Permalink
#383 adding possibility to override cell reader width when parsing text
Browse files Browse the repository at this point in the history
  • Loading branch information
nizienko committed Dec 27, 2023
1 parent 7319cb7 commit f15a695
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ class JListFixture(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) :
const fixture = new JListFixture(robot, component);
const cellReader = new com.intellij.remoterobot.fixtures.dataExtractor.server.textCellRenderers.JListTextCellReader();
fixture.replaceCellReader(cellReader);
ctx.put("cellReader", cellReader)
ctx.put("fixture", fixture)
"""
)
}

/*
Overrides cell width which will be used to parse text in it. JList::width is used as default, but sometimes you might need to make it bigger
https://github.com/JetBrains/intellij-ui-test-robot/issues/383
*/
fun setCellReaderWidth(width: Int) = runJs("ctx.get('cellReader').setCellWidth($width)")

fun collectItems() = callJs<Array<String>>("ctx.get('fixture').contents()").toList()

fun collectSelectedItems() = callJs<Array<String>>("ctx.get('fixture').selection()").toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import javax.swing.JList
import javax.swing.ListCellRenderer

class JListTextCellReader : JListCellReader {

private var cellWidth: Int? = null

fun setCellWidth(width: Int) {
cellWidth = width
}

override fun valueAt(list: JList<*>?, index: Int): String? {
require(list != null)
return computeOnEdt {
@Suppress("UNCHECKED_CAST") val renderer = list.cellRenderer as ListCellRenderer<Any>
val c = renderer.getListCellRendererComponent(JList(), list.model.getElementAt(index), index, true, true)
c.size = Dimension(list.width, 100)
c.size = Dimension(cellWidth ?: list.width, 100)
TextParser.parseCellRenderer(c).joinToString(" ") { it.trim() }
}
}
Expand Down

0 comments on commit f15a695

Please sign in to comment.