mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Make columns of the MultipleFileMergeDialog resizable
* Don't define the max size for them. * Define the preferred size as the remainder of the actual table width without column sizes. * Update these sizes on doLayout(). Fixes IDEA-195517
This commit is contained in:
@@ -82,7 +82,6 @@ open class MultipleFileMergeDialog(
|
|||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
init()
|
init()
|
||||||
|
|
||||||
updateColumnSizes()
|
|
||||||
updateTree()
|
updateTree()
|
||||||
table.tree.selectionModel.addTreeSelectionListener { updateButtonState() }
|
table.tree.selectionModel.addTreeSelectionListener { updateButtonState() }
|
||||||
selectFirstFile()
|
selectFirstFile()
|
||||||
@@ -115,7 +114,7 @@ open class MultipleFileMergeDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
row {
|
row {
|
||||||
scrollPane(TreeTable(tableModel).also {
|
scrollPane(MyTable(tableModel).also {
|
||||||
table = it
|
table = it
|
||||||
it.tree.isRootVisible = false
|
it.tree.isRootVisible = false
|
||||||
it.setTreeCellRenderer(virtualFileRenderer)
|
it.setTreeCellRenderer(virtualFileRenderer)
|
||||||
@@ -182,15 +181,32 @@ open class MultipleFileMergeDialog(
|
|||||||
override fun getAdditionalWidth() = base.additionalWidth
|
override fun getAdditionalWidth() = base.additionalWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateColumnSizes() {
|
private class MyTable(private val tableModel: ListTreeTableModelOnColumns) : TreeTable(tableModel) {
|
||||||
for ((index, columnInfo) in tableModel.columns.withIndex()) {
|
override fun doLayout() {
|
||||||
val column = table.columnModel.getColumn(index)
|
if (getTableHeader().resizingColumn == null) {
|
||||||
columnInfo.maxStringValue?.let {
|
updateColumnSizes()
|
||||||
val width = Math.max(table.getFontMetrics(table.font).stringWidth(it),
|
|
||||||
table.getFontMetrics(table.tableHeader.font).stringWidth(columnInfo.name)) + columnInfo.additionalWidth
|
|
||||||
column.maxWidth = width
|
|
||||||
column.preferredWidth = width
|
|
||||||
}
|
}
|
||||||
|
super.doLayout()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateColumnSizes() {
|
||||||
|
for ((index, columnInfo) in tableModel.columns.withIndex()) {
|
||||||
|
val column = columnModel.getColumn(index)
|
||||||
|
columnInfo.maxStringValue?.let {
|
||||||
|
val width = Math.max(getFontMetrics(font).stringWidth(it),
|
||||||
|
getFontMetrics(tableHeader.font).stringWidth(columnInfo.name)) + columnInfo.additionalWidth
|
||||||
|
column.preferredWidth = width
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var size = width
|
||||||
|
val fileColumn = 0
|
||||||
|
for (i in 0 until tableModel.columns.size) {
|
||||||
|
if (i == fileColumn) continue
|
||||||
|
size -= columnModel.getColumn(i).preferredWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
columnModel.getColumn(fileColumn).preferredWidth = size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user