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:
Kirill Likhodedov
2018-07-23 14:17:03 +03:00
parent 0a14fd72e2
commit f01014ab87
@@ -82,7 +82,6 @@ open class MultipleFileMergeDialog(
@Suppress("LeakingThis")
init()
updateColumnSizes()
updateTree()
table.tree.selectionModel.addTreeSelectionListener { updateButtonState() }
selectFirstFile()
@@ -115,7 +114,7 @@ open class MultipleFileMergeDialog(
}
row {
scrollPane(TreeTable(tableModel).also {
scrollPane(MyTable(tableModel).also {
table = it
it.tree.isRootVisible = false
it.setTreeCellRenderer(virtualFileRenderer)
@@ -182,15 +181,32 @@ open class MultipleFileMergeDialog(
override fun getAdditionalWidth() = base.additionalWidth
}
private fun updateColumnSizes() {
for ((index, columnInfo) in tableModel.columns.withIndex()) {
val column = table.columnModel.getColumn(index)
columnInfo.maxStringValue?.let {
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
private class MyTable(private val tableModel: ListTreeTableModelOnColumns) : TreeTable(tableModel) {
override fun doLayout() {
if (getTableHeader().resizingColumn == null) {
updateColumnSizes()
}
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
}
}