mirror of https://github.com/zlatinb/muwire
merge the two tables in the remote trust list view into one. Replace trust/distrust buttons with View Profile
parent
dd5d79e27a
commit
e10029a82e
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -405,7 +405,7 @@ class MainFrameController {
|
|||
Map<String,Object> env = new HashMap<>()
|
||||
env["trustList"] = list
|
||||
env["trustService"] = core.trustService
|
||||
env["eventBus"] = core.eventBus
|
||||
env["core"] = core
|
||||
mvcGroup.createMVCGroup("trust-list", env)
|
||||
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<TrustPOP> trusted
|
||||
List<TrustPOP> distrusted
|
||||
List<RemoteTrustPOP> contacts
|
||||
|
||||
void mvcGroupInit(Map<String,String> 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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<String, String> 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String,String> 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()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue