mirror of https://github.com/zlatinb/muwire
repurpose collection tool to show hits
parent
ca9120e864
commit
c932e5675c
|
@ -18,70 +18,14 @@ import com.muwire.core.util.DataUtil
|
||||||
|
|
||||||
@ArtifactProviderFor(GriffonController)
|
@ArtifactProviderFor(GriffonController)
|
||||||
class CollectionsToolController {
|
class CollectionsToolController {
|
||||||
@MVCMember @Nonnull
|
|
||||||
CollectionsToolModel model
|
|
||||||
@MVCMember @Nonnull
|
@MVCMember @Nonnull
|
||||||
CollectionsToolView view
|
CollectionsToolView view
|
||||||
|
@MVCMember @Nonnull
|
||||||
@ControllerAction
|
CollectionsToolModel model
|
||||||
void delete() {
|
|
||||||
int row = view.selectedCollectionRow()
|
|
||||||
if (row < 0)
|
|
||||||
return
|
|
||||||
FileCollection collection = model.collections.get(row)
|
|
||||||
UICollectionDeletedEvent e = new UICollectionDeletedEvent(collection : collection)
|
|
||||||
model.eventBus.publish(e)
|
|
||||||
model.collections.remove(row)
|
|
||||||
view.collectionsTable.model.fireTableDataChanged()
|
|
||||||
view.clearFilesTable()
|
|
||||||
}
|
|
||||||
|
|
||||||
@ControllerAction
|
|
||||||
void close() {
|
|
||||||
view.dialog.setVisible(false)
|
|
||||||
mvcGroup.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
@ControllerAction
|
|
||||||
void viewComment() {
|
|
||||||
int row = view.selectedCollectionRow()
|
|
||||||
if (row < 0)
|
|
||||||
return
|
|
||||||
FileCollection collection = model.collections.get(row)
|
|
||||||
|
|
||||||
def params = [:]
|
|
||||||
params['text'] = collection.comment
|
|
||||||
mvcGroup.createMVCGroup("show-comment", params)
|
|
||||||
}
|
|
||||||
|
|
||||||
@ControllerAction
|
|
||||||
void viewFileComment() {
|
|
||||||
int row = view.selectedFileRow()
|
|
||||||
if (row < 0)
|
|
||||||
return
|
|
||||||
SharedFile sf = model.files.get(row)
|
|
||||||
|
|
||||||
def params = [:]
|
|
||||||
params['text'] = DataUtil.readi18nString(Base64.decode(sf.getComment()))
|
|
||||||
mvcGroup.createMVCGroup("show-comment", params)
|
|
||||||
}
|
|
||||||
|
|
||||||
@ControllerAction
|
|
||||||
void copyHash() {
|
|
||||||
int row = view.selectedCollectionRow()
|
|
||||||
if (row < 0)
|
|
||||||
return
|
|
||||||
FileCollection collection = model.collections.get(row)
|
|
||||||
|
|
||||||
String b64 = Base64.encode(collection.getInfoHash().getRoot())
|
|
||||||
StringSelection selection = new StringSelection(b64)
|
|
||||||
def clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
|
|
||||||
clipboard.setContents(selection, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
@ControllerAction
|
@ControllerAction
|
||||||
void clearHits() {
|
void clearHits() {
|
||||||
model.selectedCollection.getHits().clear()
|
model.collection.hits.clear()
|
||||||
model.hits.clear()
|
model.hits.clear()
|
||||||
view.hitsTable.model.fireTableDataChanged()
|
view.hitsTable.model.fireTableDataChanged()
|
||||||
}
|
}
|
||||||
|
|
|
@ -728,6 +728,18 @@ class MainFrameController {
|
||||||
mvcGroup.createMVCGroup("show-comment", params)
|
mvcGroup.createMVCGroup("show-comment", params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void showCollectionTool() {
|
||||||
|
int row = view.selectedCollectionRow()
|
||||||
|
if (row < 0)
|
||||||
|
return
|
||||||
|
FileCollection collection = model.localCollections.get(row)
|
||||||
|
|
||||||
|
def params = [:]
|
||||||
|
params['collection'] = collection
|
||||||
|
mvcGroup.createMVCGroup("collections-tool", params)
|
||||||
|
}
|
||||||
|
|
||||||
void startChat(Persona p) {
|
void startChat(Persona p) {
|
||||||
if (!mvcGroup.getChildrenGroups().containsKey(p.getHumanReadableName())) {
|
if (!mvcGroup.getChildrenGroups().containsKey(p.getHumanReadableName())) {
|
||||||
def params = [:]
|
def params = [:]
|
||||||
|
|
|
@ -543,7 +543,8 @@ COLLECTION_NAME_WARNING=The collection name cannot be blank. Please select a na
|
||||||
COLLECTION_NAME_WARNING_TITLE=Missing collection name
|
COLLECTION_NAME_WARNING_TITLE=Missing collection name
|
||||||
|
|
||||||
## Collections tool
|
## Collections tool
|
||||||
COLLECTION_TOOL_TITLE=Collections in your repository
|
COLLECTION_TOOL_TITLE=Search hits for {0}
|
||||||
|
COLLECTION_SHOW_HITS=Show Hits
|
||||||
CREATED=Created
|
CREATED=Created
|
||||||
AUTHOR=Author
|
AUTHOR=Author
|
||||||
COLLECTION_TOOL_HEADER=These are the collections in your repository. Deleting a collection will not affect the files included in it.
|
COLLECTION_TOOL_HEADER=These are the collections in your repository. Deleting a collection will not affect the files included in it.
|
||||||
|
|
|
@ -12,22 +12,10 @@ import griffon.metadata.ArtifactProviderFor
|
||||||
|
|
||||||
@ArtifactProviderFor(GriffonModel)
|
@ArtifactProviderFor(GriffonModel)
|
||||||
class CollectionsToolModel {
|
class CollectionsToolModel {
|
||||||
|
FileCollection collection
|
||||||
FileManager fileManager
|
|
||||||
CollectionManager collectionManager
|
|
||||||
EventBus eventBus
|
|
||||||
|
|
||||||
@Observable boolean viewCommentButtonEnabled
|
|
||||||
@Observable boolean viewFileCommentButtonEnabled
|
|
||||||
@Observable boolean deleteButtonEnabled
|
|
||||||
@Observable boolean clearHitsButtonEnabled
|
|
||||||
|
|
||||||
List<FileCollection> collections = new ArrayList<>()
|
|
||||||
List<SharedFile> files = new ArrayList<>()
|
|
||||||
FileCollection selectedCollection
|
|
||||||
List<FileCollection.SearchHit> hits = new ArrayList<>()
|
List<FileCollection.SearchHit> hits = new ArrayList<>()
|
||||||
|
|
||||||
void mvcGroupInit(Map<String,String> args) {
|
void mvcGroupInit(Map<String,String> args) {
|
||||||
collections.addAll(collectionManager.getCollections())
|
hits.addAll(collection.hits)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -40,48 +40,15 @@ class CollectionsToolView {
|
||||||
def dialog
|
def dialog
|
||||||
def mainPanel
|
def mainPanel
|
||||||
|
|
||||||
JTable collectionsTable
|
|
||||||
JTable filesTable
|
|
||||||
JTable hitsTable
|
JTable hitsTable
|
||||||
|
|
||||||
def lastCollectionSortEvent
|
|
||||||
def lastFilesSortEvent
|
|
||||||
|
|
||||||
void initUI() {
|
void initUI() {
|
||||||
mainFrame = application.windowManager.findWindow("main-frame")
|
mainFrame = application.windowManager.findWindow("main-frame")
|
||||||
int rowHeight = application.context.get("row-height")
|
int rowHeight = application.context.get("row-height")
|
||||||
dialog = new JDialog(mainFrame,trans("COLLECTION_TOOL_TITLE"),true)
|
dialog = new JDialog(mainFrame,trans("COLLECTION_TOOL_TITLE", model.collection.name),true)
|
||||||
dialog.setResizable(true)
|
dialog.setResizable(true)
|
||||||
|
|
||||||
mainPanel = builder.panel {
|
mainPanel = builder.panel {
|
||||||
gridLayout(rows : 1, cols : 2)
|
|
||||||
panel {
|
|
||||||
gridLayout(rows : 2, cols : 1)
|
|
||||||
panel {
|
|
||||||
borderLayout()
|
|
||||||
panel (constraints : BorderLayout.NORTH) {
|
|
||||||
label(text : trans("COLLECTION_TOOL_HEADER"))
|
|
||||||
}
|
|
||||||
scrollPane(constraints : BorderLayout.CENTER) {
|
|
||||||
collectionsTable = table(autoCreateRowSorter : true, rowHeight : rowHeight) {
|
|
||||||
tableModel(list : model.collections) {
|
|
||||||
closureColumn(header : trans("NAME"), preferredWidth : 100, type : String, read : {it.name})
|
|
||||||
closureColumn(header : trans("AUTHOR"), preferredWidth : 100, type : String, read : {it.author.getHumanReadableName()})
|
|
||||||
closureColumn(header : trans("FILES"), preferredWidth: 10, type : Integer, read : {it.numFiles()})
|
|
||||||
closureColumn(header : trans("SIZE"), preferredWidth : 10, type : Long, read : {it.totalSize()})
|
|
||||||
closureColumn(header : trans("COMMENT"), preferredWidth : 10, type : Boolean, read : {it.comment != ""})
|
|
||||||
closureColumn(header : trans("SEARCH_HITS"), preferredWidth : 10, type : Integer, read : {it.hits.size()})
|
|
||||||
closureColumn(header : trans("CREATED"), preferredWidth : 30, type : Long, read : {it.timestamp})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panel(constraints : BorderLayout.SOUTH) {
|
|
||||||
button(text : trans("VIEW_COMMENT"), enabled : bind {model.viewCommentButtonEnabled}, viewCommentAction)
|
|
||||||
button(text : trans("COPY_HASH_TO_CLIPBOARD"), enabled : bind {model.deleteButtonEnabled}, copyHashAction)
|
|
||||||
button(text : trans("DELETE"), enabled : bind {model.deleteButtonEnabled}, deleteAction)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panel {
|
|
||||||
borderLayout()
|
borderLayout()
|
||||||
panel(constraints : BorderLayout.NORTH) {
|
panel(constraints : BorderLayout.NORTH) {
|
||||||
label(text : trans("COLLECTION_VIEWS"))
|
label(text : trans("COLLECTION_VIEWS"))
|
||||||
|
@ -95,134 +62,12 @@ class CollectionsToolView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panel(constraints : BorderLayout.SOUTH) {
|
panel(constraints : BorderLayout.SOUTH) {
|
||||||
button(text : trans("CLEAR_HITS"), enabled : bind {model.clearHitsButtonEnabled}, clearHitsAction)
|
button(text : trans("CLEAR_HITS"), clearHitsAction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panel {
|
|
||||||
borderLayout()
|
|
||||||
panel(constraints : BorderLayout.NORTH) {
|
|
||||||
label(text : trans("FILES"))
|
|
||||||
}
|
|
||||||
scrollPane(constraints : BorderLayout.CENTER) {
|
|
||||||
filesTable = table(autoCreateRowSorter : true, rowHeight : rowHeight) {
|
|
||||||
tableModel(list : model.files) {
|
|
||||||
closureColumn(header : trans("NAME"), preferredWidth : 200, type : String, read : {it.getCachedPath()})
|
|
||||||
closureColumn(header : trans("SIZE"), preferredWidth : 10, type : Long, read : {it.getCachedLength()})
|
|
||||||
closureColumn(header : trans("COMMENT"), preferredWidth : 10, type : Boolean, read : {it.getComment() != null})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panel(constraints : BorderLayout.SOUTH) {
|
|
||||||
button(text : trans("VIEW_COMMENT"), enabled : bind{model.viewFileCommentButtonEnabled}, viewFileCommentAction)
|
|
||||||
button(text : trans("CLOSE"), closeAction)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int selectedCollectionRow() {
|
|
||||||
int selectedRow = collectionsTable.getSelectedRow()
|
|
||||||
if (selectedRow < 0)
|
|
||||||
return -1
|
|
||||||
if (lastCollectionSortEvent != null)
|
|
||||||
selectedRow = collectionsTable.rowSorter.convertRowIndexToModel(selectedRow)
|
|
||||||
selectedRow
|
|
||||||
}
|
|
||||||
|
|
||||||
int selectedFileRow() {
|
|
||||||
int selectedRow = filesTable.getSelectedRow()
|
|
||||||
if (selectedRow < 0)
|
|
||||||
return -1
|
|
||||||
if (lastFilesSortEvent != null)
|
|
||||||
selectedRow = filesTable.rowSorter.convertRowIndexToModel(selectedRow)
|
|
||||||
selectedRow
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearFilesTable() {
|
|
||||||
model.files.clear()
|
|
||||||
filesTable.model.fireTableDataChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
void mvcGroupInit(Map<String,String> args) {
|
void mvcGroupInit(Map<String,String> args) {
|
||||||
def centerRenderer = new DefaultTableCellRenderer()
|
|
||||||
centerRenderer.setHorizontalAlignment(JLabel.CENTER)
|
|
||||||
collectionsTable.setDefaultRenderer(Integer.class,centerRenderer)
|
|
||||||
collectionsTable.columnModel.getColumn(3).setCellRenderer(new SizeRenderer())
|
|
||||||
collectionsTable.columnModel.getColumn(6).setCellRenderer(new DateRenderer())
|
|
||||||
|
|
||||||
collectionsTable.rowSorter.addRowSorterListener({evt -> lastCollectionSortEvent = evt})
|
|
||||||
|
|
||||||
def selectionModel = collectionsTable.getSelectionModel()
|
|
||||||
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
|
|
||||||
selectionModel.addListSelectionListener({
|
|
||||||
int selectedRow = selectedCollectionRow()
|
|
||||||
if (selectedRow < 0) {
|
|
||||||
model.viewCommentButtonEnabled = false
|
|
||||||
model.deleteButtonEnabled = false
|
|
||||||
model.clearHitsButtonEnabled = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
model.deleteButtonEnabled = true
|
|
||||||
FileCollection collection = model.collections.get(selectedRow)
|
|
||||||
model.selectedCollection = collection
|
|
||||||
model.viewCommentButtonEnabled = collection.getComment() != ""
|
|
||||||
|
|
||||||
model.files.clear()
|
|
||||||
collection.files.each {
|
|
||||||
SharedFile sf = model.fileManager.getRootToFiles().get(it.infoHash).first()
|
|
||||||
model.files.add(sf)
|
|
||||||
}
|
|
||||||
filesTable.model.fireTableDataChanged()
|
|
||||||
|
|
||||||
model.hits.clear()
|
|
||||||
model.hits.addAll(collection.getHits())
|
|
||||||
if (!model.hits.isEmpty())
|
|
||||||
model.clearHitsButtonEnabled = true
|
|
||||||
hitsTable.model.fireTableDataChanged()
|
|
||||||
})
|
|
||||||
|
|
||||||
collectionsTable.addMouseListener(new MouseAdapter() {
|
|
||||||
public void mouseReleased(MouseEvent e) {
|
|
||||||
if (e.isPopupTrigger())
|
|
||||||
showCollectionTableMenu(e)
|
|
||||||
}
|
|
||||||
public void mousePressed(MouseEvent e) {
|
|
||||||
if (e.isPopupTrigger())
|
|
||||||
showCollectionTableMenu(e)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
// files table
|
|
||||||
|
|
||||||
filesTable.setDefaultRenderer(Long.class, new SizeRenderer())
|
|
||||||
filesTable.rowSorter.addRowSorterListener({evt -> lastFilesSortEvent = evt})
|
|
||||||
filesTable.rowSorter.setSortsOnUpdates(true)
|
|
||||||
selectionModel = filesTable.getSelectionModel()
|
|
||||||
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
|
|
||||||
selectionModel.addListSelectionListener({
|
|
||||||
int selectedRow = selectedFileRow()
|
|
||||||
if (selectedRow < 0) {
|
|
||||||
model.viewFileCommentButtonEnabled = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
SharedFile sf = model.files.get(selectedRow)
|
|
||||||
model.viewFileCommentButtonEnabled = sf.getComment() != null
|
|
||||||
})
|
|
||||||
|
|
||||||
filesTable.addMouseListener(new MouseAdapter() {
|
|
||||||
public void mouseReleased(MouseEvent e) {
|
|
||||||
if (e.isPopupTrigger())
|
|
||||||
showItemsMenu(e)
|
|
||||||
}
|
|
||||||
public void mousePressed(MouseEvent e) {
|
|
||||||
if (e.isPopupTrigger())
|
|
||||||
showItemsMenu(e)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// hits table
|
// hits table
|
||||||
hitsTable.setDefaultRenderer(Long.class, new DateRenderer())
|
hitsTable.setDefaultRenderer(Long.class, new DateRenderer())
|
||||||
|
|
||||||
|
@ -237,46 +82,4 @@ class CollectionsToolView {
|
||||||
})
|
})
|
||||||
dialog.show()
|
dialog.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showCollectionTableMenu(MouseEvent e) {
|
|
||||||
int row = selectedCollectionRow()
|
|
||||||
if (row < 0)
|
|
||||||
return
|
|
||||||
FileCollection collection = model.collections.get(row)
|
|
||||||
|
|
||||||
JPopupMenu menu = new JPopupMenu()
|
|
||||||
JMenuItem copyHashToClipboard = new JMenuItem(trans("COPY_HASH_TO_CLIPBOARD"))
|
|
||||||
copyHashToClipboard.addActionListener({controller.copyHash()})
|
|
||||||
menu.add(copyHashToClipboard)
|
|
||||||
|
|
||||||
if (collection.comment != "") {
|
|
||||||
JMenuItem viewComment = new JMenuItem(trans("VIEW_COMMENT"))
|
|
||||||
viewComment.addActionListener({controller.viewComment()})
|
|
||||||
menu.add(viewComment)
|
|
||||||
}
|
|
||||||
|
|
||||||
JMenuItem delete = new JMenuItem(trans("DELETE"))
|
|
||||||
delete.addActionListener({controller.delete()})
|
|
||||||
menu.add(delete)
|
|
||||||
|
|
||||||
showPopupMenu(menu, e)
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showItemsMenu(MouseEvent e) {
|
|
||||||
int row = selectedFileRow()
|
|
||||||
if (row < 0)
|
|
||||||
return
|
|
||||||
SharedFile item = model.files.get(row)
|
|
||||||
if (item.getComment() == null || item.getComment() == "")
|
|
||||||
return
|
|
||||||
JPopupMenu menu = new JPopupMenu()
|
|
||||||
JMenuItem viewComment = new JMenuItem(trans("VIEW_COMMENT"))
|
|
||||||
viewComment.addActionListener({controller.viewFileComment()})
|
|
||||||
menu.add(viewComment)
|
|
||||||
showPopupMenu(menu, e)
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void showPopupMenu(JPopupMenu menu, MouseEvent event) {
|
|
||||||
menu.show(event.getComponent(), event.getX(), event.getY())
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -444,6 +444,7 @@ class MainFrameView {
|
||||||
}
|
}
|
||||||
panel(constraints : BorderLayout.SOUTH) {
|
panel(constraints : BorderLayout.SOUTH) {
|
||||||
button(text : trans("VIEW_COMMENT"), enabled : bind {model.viewCollectionCommentButtonEnabled}, viewCollectionCommentAction)
|
button(text : trans("VIEW_COMMENT"), enabled : bind {model.viewCollectionCommentButtonEnabled}, viewCollectionCommentAction)
|
||||||
|
button(text : trans("COLLECTION_SHOW_HITS"), enabled : bind {model.deleteCollectionButtonEnabled}, showCollectionToolAction)
|
||||||
button(text : trans("COPY_HASH_TO_CLIPBOARD"), enabled : bind {model.deleteCollectionButtonEnabled}, copyCollectionHashAction)
|
button(text : trans("COPY_HASH_TO_CLIPBOARD"), enabled : bind {model.deleteCollectionButtonEnabled}, copyCollectionHashAction)
|
||||||
button(text : trans("DELETE"), enabled : bind {model.deleteCollectionButtonEnabled}, deleteCollectionAction)
|
button(text : trans("DELETE"), enabled : bind {model.deleteCollectionButtonEnabled}, deleteCollectionAction)
|
||||||
}
|
}
|
||||||
|
@ -1715,6 +1716,10 @@ class MainFrameView {
|
||||||
delete.addActionListener({controller.deleteCollection()})
|
delete.addActionListener({controller.deleteCollection()})
|
||||||
menu.add(delete)
|
menu.add(delete)
|
||||||
|
|
||||||
|
JMenuItem showHits = new JMenuItem(trans("COLLECTION_SHOW_HITS"))
|
||||||
|
showHits.addActionListener({controller.showCollectionTool()})
|
||||||
|
menu.add(showHits)
|
||||||
|
|
||||||
showPopupMenu(menu, e)
|
showPopupMenu(menu, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue