From df577f97e804984a769ebd7f91f6113208208bd0 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sun, 1 Nov 2020 07:02:20 +0000 Subject: [PATCH] wip on collections tab --- .../com/muwire/gui/SearchTabController.groovy | 3 +- gui/griffon-app/i18n/messages.properties | 3 ++ .../com/muwire/gui/CollectionTabModel.groovy | 44 +++++++++++++++-- .../com/muwire/gui/CollectionTabView.groovy | 48 ++++++++++++++++++- 4 files changed, 91 insertions(+), 7 deletions(-) diff --git a/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy b/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy index 09f4ffc2..4767529a 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy @@ -173,8 +173,9 @@ class SearchTabController { def params = [:] params['fileName'] = event.name params['eventBus'] = mvcGroup.parentGroup.model.core.eventBus - params['collections'] = event.collections.collect() + params['infoHashes'] = event.collections.collect() params['uuid'] = UUID.randomUUID() + params['host'] = event.sender mvcGroup.createMVCGroup("collection-tab", params) } } \ No newline at end of file diff --git a/gui/griffon-app/i18n/messages.properties b/gui/griffon-app/i18n/messages.properties index 42767f76..37c8016b 100644 --- a/gui/griffon-app/i18n/messages.properties +++ b/gui/griffon-app/i18n/messages.properties @@ -542,3 +542,6 @@ CREATED=Created AUTHOR=Author COLLECTION_TOOL_HEADER=These are the collections in your repository. Deleting a collection will not affect the files included in it. DELETE=Delete + +## Collection tab +COLLECTION_SELECT=Select a collection to view it's description diff --git a/gui/griffon-app/models/com/muwire/gui/CollectionTabModel.groovy b/gui/griffon-app/models/com/muwire/gui/CollectionTabModel.groovy index ac0486c4..6926eefa 100644 --- a/gui/griffon-app/models/com/muwire/gui/CollectionTabModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/CollectionTabModel.groovy @@ -1,37 +1,71 @@ package com.muwire.gui +import static com.muwire.gui.Translator.trans + +import javax.annotation.Nonnull + import com.muwire.core.EventBus +import com.muwire.core.InfoHash +import com.muwire.core.Persona +import com.muwire.core.collections.CollectionFetchStatus +import com.muwire.core.collections.CollectionFetchStatusEvent import com.muwire.core.collections.CollectionFetchedEvent import com.muwire.core.collections.FileCollection import com.muwire.core.collections.FileCollectionItem +import com.muwire.core.collections.UICollectionFetchEvent import griffon.core.artifact.GriffonModel +import griffon.inject.MVCMember import griffon.transform.Observable import griffon.metadata.ArtifactProviderFor @ArtifactProviderFor(GriffonModel) class CollectionTabModel { + + @MVCMember @Nonnull + CollectionTabView view + String fileName EventBus eventBus - List collections - List items - @Observable String comment + Persona host + List infoHashes UUID uuid + List collections = new ArrayList<>() + List items = new ArrayList<>() + + @Observable CollectionFetchStatus status + @Observable String comment = trans("COLLECTION_SELECT") + @Observable int totalCollections + void mvcGroupInit(Map args) { - eventBus.register(CollectionFetchedEvent.class, this) + eventBus.with { + register(CollectionFetchStatusEvent.class, this) + register(CollectionFetchedEvent.class, this) + publish(new UICollectionFetchEvent(uuid : uuid, host : host, infoHashes : infoHashes)) + } } void mvcGroupDestroy() { eventBus.unregister(CollectionFetchedEvent.class, this) } + void onCollectionFetchStatusEvent(CollectionFetchStatusEvent e) { + if (uuid != e.uuid) + return + runInsideUIAsync { + status = e.status + if (status == CollectionFetchStatus.FETCHING) + totalCollections = e.count + } + } + void onCollectionFetchedEvent(CollectionFetchedEvent e) { if (uuid != e.uuid) return runInsideUIAsync { collections.add(e.collection) - // TODO: refresh tables + view.collectionsTable.model.fireTableDataChanged() // maybe preserving selection? } } } \ No newline at end of file diff --git a/gui/griffon-app/views/com/muwire/gui/CollectionTabView.groovy b/gui/griffon-app/views/com/muwire/gui/CollectionTabView.groovy index cdc34b9a..6b976b4c 100644 --- a/gui/griffon-app/views/com/muwire/gui/CollectionTabView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/CollectionTabView.groovy @@ -1,9 +1,14 @@ package com.muwire.gui +import static com.muwire.gui.Translator.trans import griffon.core.artifact.GriffonView import griffon.inject.MVCMember import griffon.metadata.ArtifactProviderFor + +import javax.swing.JLabel +import javax.swing.JTable import javax.swing.SwingConstants +import javax.swing.table.DefaultTableCellRenderer import java.awt.BorderLayout @@ -19,8 +24,38 @@ class CollectionTabView { def parent def p + JTable collectionsTable + def lastCollectionsTableSortEvent + void initUI() { - p = builder.panel {} + int rowHeight = application.context.get("row-height") + p = builder.panel { + gridLayout(rows : 3, cols: 1) + panel { + borderLayout() + panel(constraints : BorderLayout.NORTH) { + borderLayout() + panel(constraints : BorderLayout.NORTH) { + label(text : trans("STATUS") + ":") + label(text : bind {trans(model.status.name())}) + } + scrollPane(constraints : BorderLayout.CENTER) { + collectionsTable = table(autoCreateRowSorter : true, rowHeight : rowHeight) { + tableModel(list : model.collections) { + closureColumn(header: trans("NAME"), preferredWidth: 200, type : String, read : {it.name}) + closureColumn(header: trans("AUTHOR"), preferredWidth: 200, type : String, read : {it.author.getHumanReadableName()}) + closureColumn(header: trans("COLLECTION_TOTAL_FILES"), preferredWidth: 20, type: Integer, read : {it.numFiles()}) + closureColumn(header: trans("COLLECTION_TOTAL_SIZE"), preferredWidth: 20, type: Long, read : {it.totalSize()}) + closureColumn(header: trans("COMMENT"), preferredWidth: 20, type: Boolean, read: {it.comment != ""}) + closureColumn(header: trans("CREATED"), preferredWidth: 50, type: Long, read: {it.timestamp}) + } + } + } + } + } + panel {} + panel {} + } } void mvcGroupInit(Map args) { @@ -45,6 +80,17 @@ class CollectionTabView { } parent.setTabComponentAt(index, tabPanel) + mainFrameGroup.view.showSearchWindow.call() + + def centerRenderer = new DefaultTableCellRenderer() + centerRenderer.setHorizontalAlignment(JLabel.CENTER) + collectionsTable.setDefaultRenderer(Integer.class, centerRenderer) + + collectionsTable.columnModel.getColumn(3).setCellRenderer(new SizeRenderer()) + collectionsTable.columnModel.getColumn(5).setCellRenderer(new DateRenderer()) + + collectionsTable.rowSorter.addRowSorterListener({evt -> lastCollectionsTableSortEvent = evt}) + collectionsTable.rowSorter.setSortsOnUpdates(true) } def closeTab = {