mirror of https://github.com/zlatinb/muwire
actions on the senders table and certificates table
parent
c3f9663f84
commit
e70d5f9956
|
@ -1,9 +1,39 @@
|
||||||
package com.muwire.gui
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import com.muwire.core.Persona
|
||||||
import griffon.core.artifact.GriffonController
|
import griffon.core.artifact.GriffonController
|
||||||
|
import griffon.core.controller.ControllerAction
|
||||||
|
import griffon.inject.MVCMember
|
||||||
import griffon.metadata.ArtifactProviderFor
|
import griffon.metadata.ArtifactProviderFor
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull
|
||||||
|
|
||||||
@ArtifactProviderFor(GriffonController)
|
@ArtifactProviderFor(GriffonController)
|
||||||
class ResultDetailsController {
|
class ResultDetailsController {
|
||||||
|
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
ResultDetailsView view
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
ResultDetailsModel model
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void browse() {
|
||||||
|
Persona p = view.selectedSender()
|
||||||
|
if (p == null)
|
||||||
|
return
|
||||||
|
String groupId = UUID.randomUUID().toString()
|
||||||
|
Map<String,Object> params = new HashMap<>()
|
||||||
|
params['host'] = p
|
||||||
|
params['core'] = model.core
|
||||||
|
|
||||||
|
mvcGroup.parentGroup.createMVCGroup("browse", groupId, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void copyId() {
|
||||||
|
Persona p = view.selectedSender()
|
||||||
|
if (p == null)
|
||||||
|
return
|
||||||
|
CopyPasteSupport.copyToClipboard(p.toBase64())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.muwire.core.search.UIResultEvent
|
||||||
import griffon.core.artifact.GriffonModel
|
import griffon.core.artifact.GriffonModel
|
||||||
import griffon.inject.MVCMember
|
import griffon.inject.MVCMember
|
||||||
import griffon.metadata.ArtifactProviderFor
|
import griffon.metadata.ArtifactProviderFor
|
||||||
|
import griffon.transform.Observable
|
||||||
import net.i2p.data.Base64
|
import net.i2p.data.Base64
|
||||||
|
|
||||||
import javax.annotation.Nonnull
|
import javax.annotation.Nonnull
|
||||||
|
@ -24,6 +25,9 @@ class ResultDetailsModel {
|
||||||
|
|
||||||
@MVCMember @Nonnull
|
@MVCMember @Nonnull
|
||||||
ResultDetailsView view
|
ResultDetailsView view
|
||||||
|
|
||||||
|
@Observable boolean browseActionEnabled
|
||||||
|
@Observable boolean copyIdActionEnabled
|
||||||
|
|
||||||
Core core
|
Core core
|
||||||
String fileName
|
String fileName
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.muwire.gui
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import com.muwire.core.Persona
|
||||||
import com.muwire.core.filecert.Certificate
|
import com.muwire.core.filecert.Certificate
|
||||||
|
import com.muwire.core.filecert.UIImportCertificateEvent
|
||||||
import com.muwire.core.search.UIResultEvent
|
import com.muwire.core.search.UIResultEvent
|
||||||
import com.muwire.gui.ResultDetailsModel.CertsModel
|
import com.muwire.gui.ResultDetailsModel.CertsModel
|
||||||
import griffon.core.artifact.GriffonView
|
import griffon.core.artifact.GriffonView
|
||||||
|
@ -11,6 +13,7 @@ import net.i2p.data.DataHelper
|
||||||
import javax.annotation.Nonnull
|
import javax.annotation.Nonnull
|
||||||
import javax.swing.JButton
|
import javax.swing.JButton
|
||||||
import javax.swing.JLabel
|
import javax.swing.JLabel
|
||||||
|
import javax.swing.JOptionPane
|
||||||
import javax.swing.JPanel
|
import javax.swing.JPanel
|
||||||
import javax.swing.JScrollPane
|
import javax.swing.JScrollPane
|
||||||
import javax.swing.JTabbedPane
|
import javax.swing.JTabbedPane
|
||||||
|
@ -31,6 +34,7 @@ class ResultDetailsView {
|
||||||
|
|
||||||
def parent
|
def parent
|
||||||
def p
|
def p
|
||||||
|
int rowHeight
|
||||||
JTable sendersTable
|
JTable sendersTable
|
||||||
JPanel senderDetailsPanel
|
JPanel senderDetailsPanel
|
||||||
JTabbedPane tabs
|
JTabbedPane tabs
|
||||||
|
@ -38,7 +42,7 @@ class ResultDetailsView {
|
||||||
List<CertsPanel> certsPanelList = []
|
List<CertsPanel> certsPanelList = []
|
||||||
|
|
||||||
void initUI() {
|
void initUI() {
|
||||||
int rowHeight = application.context.get("row-height")
|
rowHeight = application.context.get("row-height")
|
||||||
p = builder.panel {
|
p = builder.panel {
|
||||||
borderLayout()
|
borderLayout()
|
||||||
panel(constraints: BorderLayout.NORTH) {
|
panel(constraints: BorderLayout.NORTH) {
|
||||||
|
@ -51,8 +55,9 @@ class ResultDetailsView {
|
||||||
if (!model.localFiles.isEmpty()) {
|
if (!model.localFiles.isEmpty()) {
|
||||||
panel (border: etchedBorder(), constraints: gbc(gridx: 0, gridy: gridy++, weightx: 100, fill: GridBagConstraints.HORIZONTAL)) {
|
panel (border: etchedBorder(), constraints: gbc(gridx: 0, gridy: gridy++, weightx: 100, fill: GridBagConstraints.HORIZONTAL)) {
|
||||||
borderLayout()
|
borderLayout()
|
||||||
label(text: trans("YOU_ALREADY_HAVE_FILE", model.localFiles.size()),
|
panel(constraints: BorderLayout.NORTH) {
|
||||||
constraints: BorderLayout.NORTH)
|
label(text: trans("YOU_ALREADY_HAVE_FILE", model.localFiles.size()))
|
||||||
|
}
|
||||||
scrollPane(constraints: BorderLayout.CENTER) {
|
scrollPane(constraints: BorderLayout.CENTER) {
|
||||||
list(items : model.localFiles.collect {it.getCachedPath()})
|
list(items : model.localFiles.collect {it.getCachedPath()})
|
||||||
}
|
}
|
||||||
|
@ -60,15 +65,24 @@ class ResultDetailsView {
|
||||||
}
|
}
|
||||||
panel(border: etchedBorder(), constraints: gbc(gridx: 0, gridy: gridy++, weightx: 100, fill: GridBagConstraints.HORIZONTAL)) {
|
panel(border: etchedBorder(), constraints: gbc(gridx: 0, gridy: gridy++, weightx: 100, fill: GridBagConstraints.HORIZONTAL)) {
|
||||||
borderLayout()
|
borderLayout()
|
||||||
label(text: trans("RESULTS_CAME_FROM"), constraints: BorderLayout.NORTH)
|
panel(constraints: BorderLayout.NORTH) {
|
||||||
|
label(text: trans("RESULTS_CAME_FROM"))
|
||||||
|
}
|
||||||
scrollPane(constraints: BorderLayout.CENTER) {
|
scrollPane(constraints: BorderLayout.CENTER) {
|
||||||
sendersTable = table(autoCreateRowSorter : true, rowHeight : rowHeight) {
|
sendersTable = table(autoCreateRowSorter : true, rowHeight : rowHeight) {
|
||||||
tableModel(list: model.results) {
|
tableModel(list: model.results) {
|
||||||
closureColumn(header: trans("SENDER"), preferredWidth: 200, read : {it.sender.getHumanReadableName()})
|
closureColumn(header: trans("SENDER"), preferredWidth: 150, type: String, read : {it.sender.getHumanReadableName()})
|
||||||
closureColumn(header: trans("NAME"), read : {HTMLSanitizer.sanitize(it.getFullPath())})
|
closureColumn(header: trans("NAME"), preferredWidth: 650, type: String, read : {HTMLSanitizer.sanitize(it.getFullPath())})
|
||||||
|
closureColumn(header: trans("COMMENTS"), preferredWidth: 20, type: Boolean, read : {it.comment != null})
|
||||||
|
closureColumn(header: trans("CERTIFICATES"), preferredWidth: 20, type: Integer, read : {it.certificates})
|
||||||
|
closureColumn(header: trans("COLLECTIONS"), preferredWidth: 20, type: Integer, read: {it.collections.size()})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
panel(constraints: BorderLayout.SOUTH) {
|
||||||
|
button(text: trans("BROWSE_HOST"), enabled : bind {model.browseActionEnabled}, browseAction)
|
||||||
|
button(text: trans("COPY_FULL_ID"), enabled: bind {model.copyIdActionEnabled}, copyIdAction)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
senderDetailsPanel = panel(constraints: gbc(gridx:0, gridy: gridy++, weightx: 100, weighty: 100, fill: GridBagConstraints.BOTH)) {
|
senderDetailsPanel = panel(constraints: gbc(gridx:0, gridy: gridy++, weightx: 100, weighty: 100, fill: GridBagConstraints.BOTH)) {
|
||||||
cardLayout()
|
cardLayout()
|
||||||
|
@ -108,6 +122,8 @@ class ResultDetailsView {
|
||||||
selectionModel.addListSelectionListener({
|
selectionModel.addListSelectionListener({
|
||||||
int row = sendersTable.getSelectedRow()
|
int row = sendersTable.getSelectedRow()
|
||||||
if (row < 0) {
|
if (row < 0) {
|
||||||
|
model.copyIdActionEnabled = false
|
||||||
|
model.browseActionEnabled = false
|
||||||
showSelectSender.call()
|
showSelectSender.call()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -116,6 +132,9 @@ class ResultDetailsView {
|
||||||
row = sendersTable.rowSorter.convertRowIndexToModel(row)
|
row = sendersTable.rowSorter.convertRowIndexToModel(row)
|
||||||
UIResultEvent event = model.results[row]
|
UIResultEvent event = model.results[row]
|
||||||
|
|
||||||
|
model.copyIdActionEnabled = true
|
||||||
|
model.browseActionEnabled = event.browse
|
||||||
|
|
||||||
if (event.comment != null) {
|
if (event.comment != null) {
|
||||||
def commentPanel = builder.panel {
|
def commentPanel = builder.panel {
|
||||||
borderLayout()
|
borderLayout()
|
||||||
|
@ -168,6 +187,14 @@ class ResultDetailsView {
|
||||||
parent.removeTabAt(index)
|
parent.removeTabAt(index)
|
||||||
mvcGroup.destroy()
|
mvcGroup.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Persona selectedSender() {
|
||||||
|
int row = sendersTable.getSelectedRow()
|
||||||
|
if (row < 0)
|
||||||
|
return null
|
||||||
|
row = sendersTable.rowSorter.convertRowIndexToModel(row)
|
||||||
|
model.results[row].sender
|
||||||
|
}
|
||||||
|
|
||||||
def showTabbedPane = {
|
def showTabbedPane = {
|
||||||
senderDetailsPanel.getLayout().show(senderDetailsPanel, "sender-details")
|
senderDetailsPanel.getLayout().show(senderDetailsPanel, "sender-details")
|
||||||
|
@ -182,30 +209,101 @@ class ResultDetailsView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CertsPanel extends JPanel {
|
private class CertsPanel extends JPanel {
|
||||||
private final ResultDetailsModel.CertsModel model
|
private final ResultDetailsModel.CertsModel certsModel
|
||||||
private final JLabel statusLabel
|
private final JLabel statusLabel, countLabel
|
||||||
private JTable certsTable
|
private JTable certsTable
|
||||||
CertsPanel(ResultDetailsModel.CertsModel model) {
|
private JButton importButton, viewCommentButton
|
||||||
this.model = model
|
CertsPanel(ResultDetailsModel.CertsModel certsModel) {
|
||||||
|
this.certsModel = certsModel
|
||||||
setLayout(new BorderLayout())
|
setLayout(new BorderLayout())
|
||||||
|
def labelPanel = new JPanel()
|
||||||
statusLabel = new JLabel()
|
statusLabel = new JLabel()
|
||||||
add(statusLabel, BorderLayout.NORTH)
|
countLabel = new JLabel()
|
||||||
|
labelPanel.add(statusLabel)
|
||||||
|
labelPanel.add(countLabel)
|
||||||
|
add(labelPanel, BorderLayout.NORTH)
|
||||||
|
|
||||||
JScrollPane scrollPane = builder.scrollPane {
|
JScrollPane scrollPane = builder.scrollPane {
|
||||||
certsTable = builder.table {
|
certsTable = builder.table(autoCreateRowSorter: true, rowHeight: rowHeight) {
|
||||||
tableModel(list: model.certificates) {
|
tableModel(list: certsModel.certificates) {
|
||||||
closureColumn(header: trans("NAME"), read: { Certificate c -> c.name.name })
|
closureColumn(header: trans("ISSUER"), preferredWidth: 150, type:String,
|
||||||
|
read:{it.issuer.getHumanReadableName()})
|
||||||
|
closureColumn(header: trans("TRUST_STATUS"), preferredWidth: 30, type:String,
|
||||||
|
read:{trans(model.core.trustService.getLevel(it.issuer.destination).name())})
|
||||||
|
closureColumn(header: trans("NAME"), preferredWidth: 450,
|
||||||
|
read: { Certificate c -> HTMLSanitizer.sanitize(c.name.name) })
|
||||||
|
closureColumn(header: trans("ISSUED"), preferredWidth: 50, type: Long,
|
||||||
|
read : {it.timestamp})
|
||||||
|
closureColumn(header: trans("COMMENTS"), preferredWidth: 20, type: Boolean,
|
||||||
|
read: {it.comment != null})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add(scrollPane, BorderLayout.CENTER)
|
add(scrollPane, BorderLayout.CENTER)
|
||||||
|
|
||||||
|
JPanel buttonPanel = builder.panel {
|
||||||
|
importButton = button(text: trans("IMPORT"))
|
||||||
|
viewCommentButton = button(text : trans("VIEW_COMMENT"))
|
||||||
|
}
|
||||||
|
add(buttonPanel, BorderLayout.SOUTH)
|
||||||
|
|
||||||
|
certsTable.setDefaultRenderer(Long.class, new DateRenderer())
|
||||||
|
certsTable.rowSorter.setSortsOnUpdates(true)
|
||||||
|
def selectionModel = certsTable.getSelectionModel()
|
||||||
|
selectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION)
|
||||||
|
selectionModel.addListSelectionListener({
|
||||||
|
int [] rows = certsTable.getSelectedRows()
|
||||||
|
importButton.setEnabled(rows.length > 0)
|
||||||
|
viewCommentButton.setEnabled(false)
|
||||||
|
if (rows.length == 1) {
|
||||||
|
rows[0] = certsTable.rowSorter.convertRowIndexToModel(rows[0])
|
||||||
|
viewCommentButton.setEnabled(certsModel.certificates[rows[0]].comment != null)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
importButton.addActionListener({importCerts()})
|
||||||
|
viewCommentButton.addActionListener({showComment()})
|
||||||
}
|
}
|
||||||
|
|
||||||
void refresh() {
|
void refresh() {
|
||||||
if (model.status != null)
|
if (certsModel.status != null) {
|
||||||
statusLabel.setText(trans(model.status.name()))
|
statusLabel.setText(trans(certsModel.status.name()))
|
||||||
|
if (certsModel.count > 0)
|
||||||
|
countLabel.setText("${certsModel.certificates.size()}/${certsModel.count}")
|
||||||
|
}
|
||||||
certsTable.model.fireTableDataChanged()
|
certsTable.model.fireTableDataChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Certificate> selectedCertificates() {
|
||||||
|
int[] rows = certsTable.getSelectedRows()
|
||||||
|
if (rows.length == 0)
|
||||||
|
return Collections.emptyList()
|
||||||
|
for (int i = 0; i < rows.length; i++) {
|
||||||
|
rows[i] = certsTable.rowSorter.convertRowIndexToModel(rows[i])
|
||||||
|
}
|
||||||
|
List<Certificate> rv = []
|
||||||
|
for (int i : rows)
|
||||||
|
rv << certsModel.certificates[i]
|
||||||
|
rv
|
||||||
|
}
|
||||||
|
|
||||||
|
void showComment() {
|
||||||
|
List<Certificate> selected = selectedCertificates()
|
||||||
|
if (selected.size() != 1)
|
||||||
|
return
|
||||||
|
String comment = selected[0].comment.name
|
||||||
|
def params = [:]
|
||||||
|
params['text'] = comment
|
||||||
|
params['name'] = trans("CERTIFICATE_COMMENT")
|
||||||
|
mvcGroup.createMVCGroup("show-comment", params)
|
||||||
|
}
|
||||||
|
|
||||||
|
void importCerts() {
|
||||||
|
List<Certificate> selected = selectedCertificates()
|
||||||
|
selected.each {
|
||||||
|
model.core.eventBus.publish(new UIImportCertificateEvent(certificate : it))
|
||||||
|
}
|
||||||
|
JOptionPane.showMessageDialog(null, trans("CERTIFICATES_IMPORTED"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue