update UI more efficiently on trust change, GitHub issue #128

dbus-notify
Zlatin Balevsky 2022-03-22 14:40:58 +00:00
parent e2bdf2a57f
commit a41ccb190c
No known key found for this signature in database
GPG Key ID: A72832072D525E41
2 changed files with 40 additions and 1 deletions

View File

@ -688,7 +688,7 @@ class MainFrameModel {
results.values().each { MVCGroup group ->
if (group.alive) {
group.view.refreshResults()
group.view.onTrustChanged(e.persona)
}
}
}

View File

@ -2,6 +2,7 @@ package com.muwire.gui
import com.muwire.core.SharedFile
import griffon.core.artifact.GriffonView
import net.i2p.data.Destination
import javax.swing.AbstractAction
import javax.swing.Action
@ -9,6 +10,7 @@ import javax.swing.JPanel
import javax.swing.JTabbedPane
import javax.swing.JTextField
import javax.swing.KeyStroke
import javax.swing.RowSorter
import javax.swing.tree.TreePath
import java.awt.Component
import java.awt.event.ActionEvent
@ -735,6 +737,43 @@ class SearchTabView {
}
}
void onTrustChanged(Persona persona) {
// 1. check Senders table in group-by-sender mode.
// there should be exactly 1 entry if at all.
if (!model.sendersBucket.containsKey(persona))
return
int index = model.senders.indexOf(persona)
if (index < 0)
return // should not happen!
// 2. it exists in the senders table, update the row
JTable table = builder.getVariable("senders-table")
table.model.fireTableRowsUpdated(index, index)
// 3. if the senders table was sorted by trust status, re-sort
List<RowSorter.SortKey> keys = table.rowSorter.getSortKeys()
if (!keys.isEmpty()) {
boolean shouldSort = false
for (RowSorter.SortKey key : keys) {
if (key.column == 7) {
shouldSort = true
break
}
}
if (shouldSort)
table.rowSorter.allRowsChanged()
}
// 4. for the group-by-file view, only update if a single result is selected
table = builder.getVariable("results-table2")
int[] selectedRows = table.getSelectedRows()
if (selectedRows.length != 1)
return
// cheat - it's too expensive to figure out if the result was relevant
detailsPanelByFile.updateUI()
}
void updateUIs() {
JTable table = builder.getVariable("results-table")
table.updateUI()