From a41ccb190ce98e7568a338580eae182049b84c13 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Tue, 22 Mar 2022 14:40:58 +0000 Subject: [PATCH] update UI more efficiently on trust change, GitHub issue #128 --- .../com/muwire/gui/MainFrameModel.groovy | 2 +- .../views/com/muwire/gui/SearchTabView.groovy | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy index 54a1ac77..1e18af21 100644 --- a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy @@ -688,7 +688,7 @@ class MainFrameModel { results.values().each { MVCGroup group -> if (group.alive) { - group.view.refreshResults() + group.view.onTrustChanged(e.persona) } } } diff --git a/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy b/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy index 00cd6437..07314f40 100644 --- a/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy @@ -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 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()