From 8573ab2850e33fe7b484c3f41cd23f24079226f3 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Tue, 2 Jul 2019 09:35:21 +0100 Subject: [PATCH] work on trust list UI --- .../com/muwire/gui/MainFrameModel.groovy | 17 ++++- .../views/com/muwire/gui/MainFrameView.groovy | 65 +++++++++++++------ 2 files changed, 62 insertions(+), 20 deletions(-) diff --git a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy index 584d935d..8bb5f7d7 100644 --- a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy @@ -28,6 +28,8 @@ import com.muwire.core.search.UIResultBatchEvent import com.muwire.core.search.UIResultEvent import com.muwire.core.trust.TrustEvent import com.muwire.core.trust.TrustService +import com.muwire.core.trust.TrustSubscriptionEvent +import com.muwire.core.trust.TrustSubscriptionUpdatedEvent import com.muwire.core.update.UpdateAvailableEvent import com.muwire.core.update.UpdateDownloadedEvent import com.muwire.core.upload.UploadEvent @@ -64,6 +66,7 @@ class MainFrameModel { def searches = new LinkedList() def trusted = [] def distrusted = [] + def subscriptions = [] @Observable int connections @Observable String me @@ -145,6 +148,7 @@ class MainFrameModel { core.eventBus.register(RouterDisconnectedEvent.class, this) core.eventBus.register(AllFilesLoadedEvent.class, this) core.eventBus.register(UpdateDownloadedEvent.class, this) + core.eventBus.register(TrustSubscriptionUpdatedEvent.class, this) timer.schedule({ if (core.shutdown.get()) @@ -173,7 +177,6 @@ class MainFrameModel { trusted.addAll(core.trustService.good.values()) distrusted.addAll(core.trustService.bad.values()) - resumeButtonText = "Retry" } }) @@ -185,6 +188,10 @@ class MainFrameModel { watched.addAll(core.muOptions.watchedDirectories) builder.getVariable("watched-directories-table").model.fireTableDataChanged() watched.each { core.eventBus.publish(new FileSharedEvent(file : new File(it))) } + + core.muOptions.trustSubscriptions.each { + core.eventBus.publish(new TrustSubscriptionEvent(persona : it, subscribe : true)) + } } } @@ -316,6 +323,14 @@ class MainFrameModel { } } + void onTrustSubscriptionUpdatedEvent(TrustSubscriptionUpdatedEvent e) { + runInsideUIAsync { + if (!subscriptions.contains(e.trustList)) + subscriptions << e.trustList + updateTablePreservingSelection("subscription-table") + } + } + void onQueryEvent(QueryEvent e) { if (e.replyTo == core.me.destination) return diff --git a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy index 32f7e16a..f782b1cc 100644 --- a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy @@ -251,35 +251,62 @@ class MainFrameView { } } panel(constraints : "trust window") { - gridLayout(rows: 1, cols :2) - panel (border : etchedBorder()){ - borderLayout() - scrollPane(constraints : BorderLayout.CENTER) { - table(id : "trusted-table", autoCreateRowSorter : true) { - tableModel(list : model.trusted) { - closureColumn(header : "Trusted Users", type : String, read : { it.getHumanReadableName() } ) + gridLayout(rows : 2, cols : 1) + panel { + gridLayout(rows: 1, cols :2) + panel (border : etchedBorder()){ + borderLayout() + scrollPane(constraints : BorderLayout.CENTER) { + table(id : "trusted-table", autoCreateRowSorter : true) { + tableModel(list : model.trusted) { + closureColumn(header : "Trusted Users", type : String, read : { it.getHumanReadableName() } ) + } } } + panel (constraints : BorderLayout.EAST) { + gridBagLayout() + button(text : "Mark Neutral", constraints : gbc(gridx: 0, gridy: 0), markNeutralFromTrustedAction) + button(text : "Mark Distrusted", constraints : gbc(gridx: 0, gridy:1), markDistrustedAction) + } } - panel (constraints : BorderLayout.EAST) { - gridBagLayout() - button(text : "Mark Neutral", constraints : gbc(gridx: 0, gridy: 0), markNeutralFromTrustedAction) - button(text : "Mark Distrusted", constraints : gbc(gridx: 0, gridy:1), markDistrustedAction) + panel (border : etchedBorder()){ + borderLayout() + scrollPane(constraints : BorderLayout.CENTER) { + table(id : "distrusted-table", autoCreateRowSorter : true) { + tableModel(list : model.distrusted) { + closureColumn(header: "Distrusted Users", type : String, read : { it.getHumanReadableName() } ) + } + } + } + panel(constraints : BorderLayout.WEST) { + gridBagLayout() + button(text: "Mark Neutral", constraints: gbc(gridx: 0, gridy: 0), markNeutralFromDistrustedAction) + button(text: "Mark Trusted", constraints : gbc(gridx: 0, gridy : 1), markTrustedAction) + } } } - panel (border : etchedBorder()){ + panel { borderLayout() + panel (constraints : BorderLayout.NORTH){ + label(text : "Trust List Subscriptions") + } scrollPane(constraints : BorderLayout.CENTER) { - table(id : "distrusted-table", autoCreateRowSorter : true) { - tableModel(list : model.distrusted) { - closureColumn(header: "Distrusted Users", type : String, read : { it.getHumanReadableName() } ) + table(id : "subscription-table", autoCreateRowSorter : true) { + tableModel(list : model.subscriptions) { + closureColumn(header : "Name", type: String, read : {it.persona.getHumanReadableName()}) + closureColumn(header : "Trusted", type: Integer, read : {it.good.size()}) + closureColumn(header : "Distrusted", type: Integer, read : {it.bad.size()}) + closureColumn(header : "Status", type: String, read : {it.status.toString()}) + closureColumn(header : "Last Updated", type : String, read : { + String.valueOf(new Date(it.timestamp)) + }) } } } - panel(constraints : BorderLayout.WEST) { - gridBagLayout() - button(text: "Mark Neutral", constraints: gbc(gridx: 0, gridy: 0), markNeutralFromDistrustedAction) - button(text: "Mark Trusted", constraints : gbc(gridx: 0, gridy : 1), markTrustedAction) + panel(constraints : BorderLayout.SOUTH) { + button(text : "Review") + button(text : "Update") + button(text : "Unsubscribe") } } }