From e10029a82e19c3811ee94626215612bb46ba41ad Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 3 Jun 2022 15:40:16 +0100 Subject: [PATCH] merge the two tables in the remote trust list view into one. Replace trust/distrust buttons with View Profile --- .../com/muwire/gui/BrowseController.groovy | 2 +- .../com/muwire/gui/MainFrameController.groovy | 2 +- .../com/muwire/gui/TrustListController.groovy | 65 ++++------ .../gui/profile/ViewProfileController.groovy | 4 +- gui/griffon-app/i18n/messages.properties | 1 + .../com/muwire/gui/TrustListModel.groovy | 17 ++- .../gui/profile/ViewProfileModel.groovy | 5 + .../views/com/muwire/gui/TrustListView.groovy | 117 +++++++----------- 8 files changed, 89 insertions(+), 124 deletions(-) diff --git a/gui/griffon-app/controllers/com/muwire/gui/BrowseController.groovy b/gui/griffon-app/controllers/com/muwire/gui/BrowseController.groovy index 54119287..5958e479 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/BrowseController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/BrowseController.groovy @@ -201,7 +201,7 @@ class BrowseController { params.core = core params.persona = model.host params.uuid = uuid - params.profileTitle = HTMLSanitizer.sanitize(header?.getTitle()) + params.profileHeader = header mvcGroup.createMVCGroup("view-profile", uuid.toString(), params) } diff --git a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy index 437f1f54..f302ca74 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy @@ -405,7 +405,7 @@ class MainFrameController { Map env = new HashMap<>() env["trustList"] = list env["trustService"] = core.trustService - env["eventBus"] = core.eventBus + env["core"] = core mvcGroup.createMVCGroup("trust-list", env) } diff --git a/gui/griffon-app/controllers/com/muwire/gui/TrustListController.groovy b/gui/griffon-app/controllers/com/muwire/gui/TrustListController.groovy index 651f02dd..c4eff7a5 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/TrustListController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/TrustListController.groovy @@ -1,5 +1,7 @@ package com.muwire.gui +import com.muwire.core.Core +import com.muwire.core.profile.MWProfileHeader import com.muwire.gui.profile.TrustPOP import griffon.core.artifact.GriffonController import griffon.core.controller.ControllerAction @@ -20,53 +22,30 @@ class TrustListController { @MVCMember @Nonnull TrustListView view - EventBus eventBus - + Core core + @ControllerAction - void trustFromTrusted() { - int selectedRow = view.getSelectedRow("trusted-table") + void viewProfile() { + int selectedRow = view.getSelectedRow() if (selectedRow < 0) return - String reason = JOptionPane.showInputDialog("Enter reason (optional)") - TrustPOP tp = model.trusted[selectedRow] - eventBus.publish(new TrustEvent(persona : tp.getPersona(), level : TrustLevel.TRUSTED, - reason : reason, profileHeader: tp.getHeader())) - view.fireUpdate("trusted-table") + + Persona persona = model.contacts[selectedRow].persona + MWProfileHeader profileHeader = model.contacts[selectedRow].getHeader() + UUID uuid = UUID.randomUUID() + + def params = [:] + params.persona = persona + params.core = core + params.uuid = uuid + params.profileHeader = profileHeader + + mvcGroup.createMVCGroup("view-profile", uuid.toString(), params) } - + @ControllerAction - void trustFromDistrusted() { - int selectedRow = view.getSelectedRow("distrusted-table") - if (selectedRow < 0) - return - String reason = JOptionPane.showInputDialog("Enter reason (optional)") - TrustPOP tp = model.distrusted[selectedRow] - eventBus.publish(new TrustEvent(persona : tp.getPersona(), level : TrustLevel.TRUSTED, - reason : reason, profileHeader: tp.getHeader())) - view.fireUpdate("distrusted-table") - } - - @ControllerAction - void distrustFromTrusted() { - int selectedRow = view.getSelectedRow("trusted-table") - if (selectedRow < 0) - return - String reason = JOptionPane.showInputDialog("Enter reason (optional)") - TrustPOP tp = model.trusted[selectedRow] - eventBus.publish(new TrustEvent(persona : tp.getPersona(), level : TrustLevel.DISTRUSTED, - reason : reason, profileHeader: tp.getHeader())) - view.fireUpdate("trusted-table") - } - - @ControllerAction - void distrustFromDistrusted() { - int selectedRow = view.getSelectedRow("distrusted-table") - if (selectedRow < 0) - return - String reason = JOptionPane.showInputDialog("Enter reason (optional)") - TrustPOP tp = model.distrusted[selectedRow] - eventBus.publish(new TrustEvent(persona : tp.getPersona(), level : TrustLevel.DISTRUSTED, - reason : reason, profileHeader: tp.getHeader())) - view.fireUpdate("distrusted-table") + void close() { + view.window.setVisible(false) + mvcGroup.destroy() } } \ No newline at end of file diff --git a/gui/griffon-app/controllers/com/muwire/gui/profile/ViewProfileController.groovy b/gui/griffon-app/controllers/com/muwire/gui/profile/ViewProfileController.groovy index 7396b6bd..ea842b4a 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/profile/ViewProfileController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/profile/ViewProfileController.groovy @@ -29,14 +29,14 @@ class ViewProfileController { void addContact() { String reason = JOptionPane.showInputDialog(trans("ENTER_REASON_OPTIONAL")) model.core.eventBus.publish(new TrustEvent(persona: model.persona, level: TrustLevel.TRUSTED, - reason: reason, profileHeader: model.profile?.getHeader())) + reason: reason, profileHeader: model.profileHeader)) } @ControllerAction void block() { String reason = JOptionPane.showInputDialog(trans("ENTER_REASON_OPTIONAL")) model.core.eventBus.publish(new TrustEvent(persona: model.persona, level: TrustLevel.DISTRUSTED, - reason: reason, profileHeader: model.profile?.getHeader())) + reason: reason, profileHeader: model.profileHeader)) } @ControllerAction diff --git a/gui/griffon-app/i18n/messages.properties b/gui/griffon-app/i18n/messages.properties index 5ceb4a31..5bdd0e1b 100644 --- a/gui/griffon-app/i18n/messages.properties +++ b/gui/griffon-app/i18n/messages.properties @@ -458,6 +458,7 @@ MAX=Max ## Trust List panel TRUST_LIST_OF=Contact List of {0} YOUR_TRUST=Your Trust +BLOCK=Block ## Content Control panel CONTENT_CONTROL_PANEL=Content Control Panel diff --git a/gui/griffon-app/models/com/muwire/gui/TrustListModel.groovy b/gui/griffon-app/models/com/muwire/gui/TrustListModel.groovy index 0948c5ff..dc8d9e8f 100644 --- a/gui/griffon-app/models/com/muwire/gui/TrustListModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/TrustListModel.groovy @@ -1,7 +1,9 @@ package com.muwire.gui import com.muwire.core.trust.RemoteTrustList +import com.muwire.core.trust.TrustLevel import com.muwire.core.trust.TrustService +import com.muwire.core.trust.TrustService.TrustEntry import com.muwire.gui.profile.TrustPOP import griffon.core.artifact.GriffonModel import griffon.transform.Observable @@ -12,11 +14,18 @@ class TrustListModel { RemoteTrustList trustList TrustService trustService - List trusted - List distrusted + List contacts void mvcGroupInit(Map args) { - trusted = trustList.good.collect {new TrustPOP(it)} - distrusted = trustList.bad.collect {new TrustPOP(it)} + contacts = trustList.good.collect {new RemoteTrustPOP(it, TrustLevel.TRUSTED)} + contacts.addAll(trustList.bad.collect {new RemoteTrustPOP(it, TrustLevel.DISTRUSTED)}) + } + + private static class RemoteTrustPOP extends TrustPOP { + final TrustLevel level + RemoteTrustPOP(TrustEntry entry, TrustLevel level) { + super(entry) + this.level = level + } } } \ No newline at end of file diff --git a/gui/griffon-app/models/com/muwire/gui/profile/ViewProfileModel.groovy b/gui/griffon-app/models/com/muwire/gui/profile/ViewProfileModel.groovy index 159cb923..f76f416b 100644 --- a/gui/griffon-app/models/com/muwire/gui/profile/ViewProfileModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/profile/ViewProfileModel.groovy @@ -7,6 +7,7 @@ import com.muwire.core.profile.MWProfileFetchEvent import com.muwire.core.profile.MWProfileFetchStatus import com.muwire.core.profile.MWProfileHeader import com.muwire.core.profile.UIProfileFetchEvent +import com.muwire.gui.HTMLSanitizer import griffon.core.artifact.GriffonModel import griffon.inject.MVCMember import griffon.metadata.ArtifactProviderFor @@ -23,6 +24,7 @@ class ViewProfileModel { Persona persona UUID uuid String profileTitle + MWProfileHeader profileHeader @Observable MWProfileFetchStatus status MWProfile profile @@ -30,6 +32,8 @@ class ViewProfileModel { private boolean registered void mvcGroupInit(Map args) { + if (profileHeader != null) + profileTitle = HTMLSanitizer.sanitize(profileHeader.getTitle()) } void register() { @@ -53,6 +57,7 @@ class ViewProfileModel { if (status == MWProfileFetchStatus.FINISHED) { view.profileFetched(event.profile) profile = event.profile + profileHeader = profile.getHeader() } } } diff --git a/gui/griffon-app/views/com/muwire/gui/TrustListView.groovy b/gui/griffon-app/views/com/muwire/gui/TrustListView.groovy index 4f80f430..b477a9d0 100644 --- a/gui/griffon-app/views/com/muwire/gui/TrustListView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/TrustListView.groovy @@ -8,7 +8,9 @@ import griffon.core.artifact.GriffonView import griffon.inject.MVCMember import griffon.metadata.ArtifactProviderFor +import javax.swing.JFrame import javax.swing.JTable +import java.awt.Dimension import static com.muwire.gui.Translator.trans import javax.swing.JDialog @@ -28,17 +30,20 @@ class TrustListView { @MVCMember @Nonnull TrustListModel model - def dialog - def mainFrame - def mainPanel - - def sortEvents = [:] + JFrame window + JFrame mainFrame + JTable contactsTable void initUI() { - mainFrame = application.windowManager.findWindow("main-frame") int rowHeight = application.context.get("row-height") - dialog = new JDialog(mainFrame, model.trustList.persona.getHumanReadableName(), true) - mainPanel = builder.panel { + mainFrame = application.windowManager.findWindow("main-frame") + + int dimX = Math.max(600, (int)(mainFrame.getWidth() / 2)) + int dimY = Math.max(500, (int)(mainFrame.getHeight() / 2)) + + window = builder.frame(visible: false, defaultCloseOperation: JFrame.DISPOSE_ON_CLOSE, + iconImage: builder.imageIcon("/MuWire-48x48.png").image, + title: model.trustList.persona.getHumanReadableName()) { borderLayout() panel(constraints : BorderLayout.NORTH) { borderLayout() @@ -50,49 +55,30 @@ class TrustListView { } } panel(constraints : BorderLayout.CENTER) { - gridLayout(rows : 1, cols : 2) - panel { - borderLayout() - scrollPane (constraints : BorderLayout.CENTER){ - table(id : "trusted-table", autoCreateRowSorter : true, rowHeight : rowHeight) { - tableModel(list : model.trusted) { - closureColumn(header: trans("TRUSTED_USERS"), type : PersonaOrProfile, read : {it}) - closureColumn(header: trans("REASON"), type : String, read : {it.reason}) - closureColumn(header: trans("YOUR_TRUST"), type : String, read : { - Persona p = it.persona - trans(model.trustService.getLevel(p.destination).name()) - }) - } + borderLayout() + scrollPane (constraints : BorderLayout.CENTER){ + contactsTable = table(id : "contacts-table", autoCreateRowSorter : true, rowHeight : rowHeight) { + tableModel(list : model.contacts) { + closureColumn(header: trans("CONTACTS"), preferredWidth: 200, type : PersonaOrProfile, read : {it}) + closureColumn(header: trans("TRUST_STATUS"), preferredWidth: 20, type: String, read: { + trans(it.level.name()) + }) + closureColumn(header: trans("REASON"), preferredWidth: 200, type : String, read : {it.reason}) + closureColumn(header: trans("YOUR_TRUST"), preferredWidth: 20, type : String, read : { + Persona p = it.persona + trans(model.trustService.getLevel(p.destination).name()) + }) } } - panel (constraints : BorderLayout.SOUTH) { - gridBagLayout() - button(text : trans("TRUST_VERB"), constraints : gbc(gridx : 0, gridy : 0), trustFromTrustedAction) - button(text : trans("DISTRUST"), constraints : gbc(gridx : 1, gridy : 0), distrustFromTrustedAction) - } } - panel { - borderLayout() - scrollPane (constraints : BorderLayout.CENTER ){ - table(id : "distrusted-table", autoCreateRowSorter : true, rowHeight : rowHeight) { - tableModel(list : model.distrusted) { - closureColumn(header: trans("DISTRUSTED_USERS"), type : PersonaOrProfile, read : {it}) - closureColumn(header: trans("REASON"), type:String, read : {it.reason}) - closureColumn(header: trans("YOUR_TRUST"), type : String, read : { - Persona p = it.persona - trans(model.trustService.getLevel(p.destination).name()) - }) - } - } - } - panel(constraints : BorderLayout.SOUTH) { - gridBagLayout() - button(text : trans("TRUST_VERB"), constraints : gbc(gridx : 0, gridy : 0), trustFromDistrustedAction) - button(text : trans("DISTRUST"), constraints : gbc(gridx : 1, gridy : 0), distrustFromDistrustedAction) - } + panel (constraints : BorderLayout.SOUTH) { + gridBagLayout() + button(text : trans("VIEW_PROFILE"), constraints : gbc(gridx : 0, gridy : 0), viewProfileAction) + button(text : trans("CLOSE"), constraints : gbc(gridx : 1, gridy : 0), closeAction) } } } + window.setPreferredSize([dimX, dimY] as Dimension) } void mvcGroupInit(Map args) { @@ -100,44 +86,29 @@ class TrustListView { def popRenderer = new PersonaOrProfileCellRenderer() def popComparator = new PersonaOrProfileComparator() - JTable trustedTable = builder.getVariable("trusted-table") - trustedTable.setDefaultRenderer(PersonaOrProfile.class, popRenderer) - trustedTable.rowSorter.setComparator(0, popComparator) - trustedTable.rowSorter.addRowSorterListener({evt -> sortEvents["trusted-table"] = evt}) - trustedTable.rowSorter.setSortsOnUpdates(true) - trustedTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION) + contactsTable.setDefaultRenderer(PersonaOrProfile.class, popRenderer) + contactsTable.rowSorter.setComparator(0, popComparator) + contactsTable.rowSorter.setSortsOnUpdates(true) + contactsTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION) - JTable distrustedTable = builder.getVariable("distrusted-table") - distrustedTable.setDefaultRenderer(Persona.class, popRenderer) - distrustedTable.rowSorter.setComparator(0, popComparator) - distrustedTable.rowSorter.addRowSorterListener({evt -> sortEvents["distrusted-table"] = evt}) - distrustedTable.rowSorter.setSortsOnUpdates(true) - distrustedTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION) - - dialog.getContentPane().add(mainPanel) - dialog.pack() - dialog.setLocationRelativeTo(mainFrame) - dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE) - dialog.addWindowListener(new WindowAdapter() { + window.pack() + window.setLocationRelativeTo(mainFrame) + window.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent e) { mvcGroup.destroy() } }) - dialog.show() + window.setVisible(true) } - int getSelectedRow(String tableName) { - def table = builder.getVariable(tableName) - int selectedRow = table.getSelectedRow() + int getSelectedRow() { + int selectedRow = contactsTable.getSelectedRow() if (selectedRow < 0) return -1 - if (sortEvents.get(tableName) != null) - selectedRow = table.rowSorter.convertRowIndexToModel(selectedRow) - selectedRow + contactsTable.rowSorter.convertRowIndexToModel(selectedRow) } - void fireUpdate(String tableName) { - def table = builder.getVariable(tableName) - table.model.fireTableDataChanged() + void updateTable() { + contactsTable.model.fireTableDataChanged() } } \ No newline at end of file